• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Issuable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.sonar.api.issue.Issuable的典型用法代码示例。如果您正苦于以下问题:Java Issuable类的具体用法?Java Issuable怎么用?Java Issuable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Issuable类属于org.sonar.api.issue包,在下文中一共展示了Issuable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addIssue

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void addIssue(Project project, double coverage, double previousCoverage) {
  Issuable issuable = perspectives.as(Issuable.class, (Resource) project);
  if (issuable == null) {
    LOGGER.warn("Could not get a perspective of Issuable to create an issue for {}, skipping",
        project);
    return;
  }

  Optional<RuleKey> ruleKey = CoverageRule.decreasingOverallLineCoverageRule(fileSystem);
  if (ruleKey.isPresent()) {
    LOGGER.debug("RuleKey: {}", ruleKey.get());
    addIssue(issuable,
        formatIssueMessage("the project", coverage, previousCoverage),
        ruleKey.get());
  } else {
    LOGGER.warn("Could not determine the RuleKey for the project {}", project.getEffectiveKey());
  }
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:19,代码来源:CoverageSensor.java


示例2: addError

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Override
public void addError(AuditEvent event) {
    final String ruleKey = getRuleKey(event);
    if (ruleKey != null) {
        final String message = getMessage(event);
        // In Checkstyle 5.5 exceptions are reported as an events from
        // TreeWalker
        if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
            LOG.warn("{} : {}", event.getFileName(), message);
        }
        initResource(event);
        final Issuable issuable = perspectives.as(Issuable.class, currentResource);
        final Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
        if (rule != null && issuable != null) {
            final IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(rule.ruleKey())
                    .message(message).line(getLineId(event));
            issuable.addIssue(issueBuilder.build());
        }
    }
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:21,代码来源:CheckstyleAuditListener.java


示例3: addErrorTest

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void addErrorTest() {
    final Rule rule = setupRule("repo", "key");

    final Issuable issuable = setupIssuable();
    final IssueBuilder issueBuilder = mock(IssueBuilder.class);
    final Issue issue = mock(Issue.class);
    when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
    when(issueBuilder.ruleKey(RuleKey.of("repo", "key"))).thenReturn(issueBuilder);
    when(issueBuilder.message(event.getMessage())).thenReturn(issueBuilder);
    when(issueBuilder.line(event.getLine())).thenReturn(issueBuilder);
    when(issueBuilder.build()).thenReturn(issue);

    addErrorToListener();

    verify(issuable).addIssue(issue);
    verify(issueBuilder).ruleKey(RuleKey.of("repo", "key"));
    verify(issueBuilder).message(event.getMessage());
    verify(issueBuilder).line(event.getLine());
    verify(rule).ruleKey();
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:22,代码来源:CheckstyleAuditListenerTest.java


示例4: saveIssues

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
/**
 * Saves issues form input file and source file.
 *
 * @param sonarFile input file.
 * @param squidFile source file.
 */
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
    Collection<CheckMessage> messages = squidFile.getCheckMessages();
    messages.forEach(message -> {
        RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
        Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);

        if (issuable != null) {
            Issue issue = issuable.newIssueBuilder()
                    .ruleKey(ruleKey)
                    .line(message.getLine())
                    .message(message.getText(Locale.ENGLISH))
                    .build();
            issuable.addIssue(issue);
        }
    });
}
 
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:23,代码来源:ApexSquidSensor.java


示例5: createIssueSensorBackedByMocks

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
  public void createIssueSensorBackedByMocks() {
    ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
    Checks<Object> checks = mock(Checks.class);
    CheckFactory checkFactory = mock(CheckFactory.class);
    when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
    List<Object> checksList = Arrays.asList(new Object[] {realIfOneStringExistsBothMustExistMultiFileCheck});
    when(checks.all()).thenReturn(checksList);

    when(checks.ruleKey(Mockito.isA(StringDisallowedIfMatchInAnotherFileCheck.class))).thenReturn(RuleKey.of("text", "StringDisallowedIfMatchInAnotherFileCheck"));
    when(checks.ruleKey(Mockito.isA(MultiFileIfOneStringExistsThenBothMustExistCheck.class))).thenReturn(RuleKey.of("text", "MultiFileIfOneStringExistsThenBothMustExistCheck"));
//    realStringDisallowedMultiFileCheck.setRuleKey(RuleKey.parse("text:StringDisallowedIfMatchInAnotherFileCheck")); // Not strictly necessary here. Normally set by the framework to the value in the Check class's annotation

    when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
    mockIssuable = mock(Issuable.class);
    when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
    IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
    when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));

    sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
  }
 
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:26,代码来源:MultiFileIfOneExistsThenBothMustExistCheckTest.java


示例6: createIssueSensorBackedByMocks

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
  public void createIssueSensorBackedByMocks() {
    ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
    Checks<Object> checks = mock(Checks.class);
    CheckFactory checkFactory = mock(CheckFactory.class);
    when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
    List<Object> checksList = Arrays.asList(new Object[] {realStringDisallowedMultiFileCheck});
    when(checks.all()).thenReturn(checksList);

    when(checks.ruleKey(Mockito.isA(StringDisallowedIfMatchInAnotherFileCheck.class))).thenReturn(RuleKey.of("text", "StringDisallowedIfMatchInAnotherFileCheck"));
//    realStringDisallowedMultiFileCheck.setRuleKey(RuleKey.parse("text:StringDisallowedIfMatchInAnotherFileCheck")); // Not strictly necessary here. Normally set by the framework to the value in the Check class's annotation

    when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
    mockIssuable = mock(Issuable.class);
    when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
    IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
    when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
    when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));

    sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
  }
 
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:25,代码来源:StringDisallowedIfMatchInAnotherFileCheckTest.java


示例7: createIssueSensorBackedByMocks

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void createIssueSensorBackedByMocks() {
ResourcePerspectives resourcePerspectives = mock(ResourcePerspectives.class);
Checks<Object> checks = mock(Checks.class);
CheckFactory checkFactory = mock(CheckFactory.class);
when(checkFactory.create(Mockito.anyString())).thenReturn(checks);
textCheckMock = mock(AbstractTextCheck.class);
List<Object> checksList = Arrays.asList(new Object[] {textCheckMock});
when(checks.all()).thenReturn(checksList);

when(checks.addAnnotatedChecks(Mockito.anyCollection())).thenReturn(checks);
mockIssuable = mock(Issuable.class);
when(resourcePerspectives.as(Mockito.eq(Issuable.class), Mockito.isA(InputFile.class))).thenReturn(mockIssuable);
IssueBuilder mockIssueBuilder = mock(IssueBuilder.class);
when(mockIssuable.newIssueBuilder()).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.ruleKey(Mockito.isA(RuleKey.class))).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.line(Mockito.anyInt())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.message(Mockito.anyString())).thenReturn(mockIssueBuilder);
when(mockIssueBuilder.build()).thenReturn(mock(Issue.class));

sensor = new TextIssueSensor(fs, resourcePerspectives, checkFactory, project);
}
 
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:23,代码来源:IssueSensorTest.java


示例8: analyse

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
public void analyse(Project project, SensorContext sensorContext) {
	if (CodeReviewInitialize.reviewResult == null || CodeReviewInitialize.reviewResult.getProjectBasedir() == null) return;

	logger.debug("Project basedir : " + CodeReviewInitialize.reviewResult.getProjectBasedir());

	File projectBasedir = new File(CodeReviewInitialize.reviewResult.getProjectBasedir());
	for (RuleType rule : CodeReviewInitialize.reviewResult.getRule()) {
		if (rule.getResult().size() > 0) {
			logger.debug("Found one non conformity : " + rule.getRule().getKey());
			RuleKey ruleKey = RuleKey.of("FCCodeReviewRepository", rule.getRule().getKey());
			for (Result result : rule.getResult()) {
				File resourceToFind = new File(projectBasedir.getAbsolutePath() + result.getResource());
				InputFile resource = fs.inputFile(fs.predicates().hasPath(projectBasedir.getAbsolutePath() + result.getResource()));
				if (resource != null) {
					logger.debug("Resource found : " + resourceToFind.getAbsolutePath());
					Issuable issuable = perspectives.as(Issuable.class, resource);
					issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).line(1).build());
				} else {
					logger.debug("Resource not found : " + resourceToFind.getAbsolutePath());
				}
			}
		}
	}
}
 
开发者ID:fastconnect,项目名称:tibco-codereview,代码行数:25,代码来源:IssueSensor.java


示例9: whenDecorateIsInvokedThenAllViolationsShouldBeProcessed

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void whenDecorateIsInvokedThenAllViolationsShouldBeProcessed() {

  int count = 10;

  DecoratorContext context = mock(DecoratorContext.class);
  Resource resource = mock(Resource.class);
  configureProject("Java");

  List<Issue> issues = new ArrayList<Issue>();
  for (int i = 0; i < count; i++) {
    issues.add(createIssue("", DebtProcessorFactory.MISSING_SWITCH_DEFAULT_CHECK_STYLE, ""));
  }

  Issuable issuable = mock(Issuable.class);
  when(issuable.issues()).thenReturn(issues);

  when(perspectivesMock.as(Issuable.class, resource)).thenReturn(issuable);

  decorator.decorate(resource, context);
}
 
开发者ID:cezarcoca,项目名称:sonar-toxicity-chart,代码行数:22,代码来源:ToxicityChartDecoratorTest.java


示例10: saveMetrics

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void saveMetrics(org.sonar.api.resources.File sonarFile, SensorContext context, SourceCode sourceCode) {
    for (Issue issue : sourceCode.getIssues()) {
        logger.finer("Saving issue: " + issue);
        Issuable issuable = perspectives.as(Issuable.class, sonarFile);
        if (issuable != null) {
            org.sonar.api.issue.Issue sIssue = issuable.newIssueBuilder()
                    .ruleKey(issue.rule())
                    .line(issue.line())
                    .message(issue.message())
                    .build();
            issuable.addIssue(sIssue);
        }
    }
    for (Measure measure : sourceCode.getMeasures()) {
        logger.finer("Saving measure: " + measure);
        context.saveMeasure(sourceCode.getResource(), measure);
    }
    for (Dependency dependency : sourceCode.getDependencies()) {
        logger.finer("Saving dependency: " + dependency);
        context.saveDependency(dependency);
    }
}
 
开发者ID:malteseduck,项目名称:sonar-xquery-plugin,代码行数:23,代码来源:XQuerySensor.java


示例11: setUp

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Before
public void setUp() {
  project = new Project("foo:bar");
  settings.setProperty("sonar.scanAllFiles", true);

  when(rp.as(eq(Issuable.class), any(Resource.class))).thenReturn(issuable);
  when(rp.as(eq(Issuable.class), any(InputFile.class))).thenReturn(issuable);
  Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class, Answers.RETURNS_SELF);
  when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:11,代码来源:CoverageSensorTest.java


示例12: testAnalyse

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void testAnalyse() {
    String relativePath = "src/test/resources/sensor/Book.cls";
    DefaultInputFile inputFile = new DefaultInputFile(relativePath).setLanguage(Apex.KEY);
    inputFile.setAbsolutePath((new File(relativePath)).getAbsolutePath());
    fileSystem.add(inputFile);

    Issuable issuable = mock(Issuable.class);
    Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class);
    when(perspectives.as(Mockito.eq(Issuable.class), Mockito.any(InputFile.class))).thenReturn(issuable);
    when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
    when(issueBuilder.ruleKey(Mockito.any(RuleKey.class))).thenReturn(issueBuilder);
    when(issueBuilder.line(Mockito.any(Integer.class))).thenReturn(issueBuilder);
    when(issueBuilder.message(Mockito.any(String.class))).thenReturn(issueBuilder);

    Project project = new Project("cls");
    SensorContext context = mock(SensorContext.class);
    squidSensor.analyse(project, context);

    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FILES), eq(1.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.LINES), eq(7.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.NCLOC), eq(6.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.STATEMENTS), eq(2.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FUNCTIONS), eq(1.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.CLASSES), eq(1.0));
    verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.COMPLEXITY), eq(1.0));
}
 
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:28,代码来源:ApexSquidSensorTest.java


示例13: saveViolations

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void saveViolations(InputFile inputFile, SourceFile squidFile) {
	Collection<CheckMessage> messages = squidFile.getCheckMessages();
	if (messages != null) {
		for (CheckMessage message : messages) {
			SquidCheck<Grammar> c = (SquidCheck<Grammar>) message.getCheck();
			logger.debug("+++File: " + squidFile.getKey() + " - Checking message ToplevelService: " + squidFile.getInt(FlowMetric.IS_TOP_LEVEL) + " TopLevelCheck: " +  String.valueOf(c instanceof TopLevelCheck));
			if(squidFile.getInt(FlowMetric.IS_TOP_LEVEL)!=1 && c instanceof TopLevelCheck){
				logger.debug("+++Ignoring toplevelCheck: " + c.getKey() + " for file: " + squidFile.getKey());
			}else{
				logger.debug("+++ Message " + message.getDefaultMessage());
				logger.debug("+++ Message " + message.toString());
				RuleKey ruleKey;
				if(message.getCheck() instanceof NodeCheck){
					ruleKey = nodeChecks.ruleKey((SquidCheck<Grammar>) message.getCheck());
				}else
					ruleKey = checks.ruleKey((SquidCheck<Grammar>) message.getCheck());
				Issuable issuable = resourcePerspectives.as(Issuable.class, inputFile);
				if (issuable != null) {
					IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(ruleKey).line(message.getLine())
							.message(message.getText(Locale.ENGLISH));

					if (message.getCost() != null) {
						issueBuilder.effortToFix(message.getCost());
					}

					issuable.addIssue(issueBuilder.build());
				}
			}
		}
	}
}
 
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:32,代码来源:FlowSquidSensor.java


示例14: saveIssues

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void saveIssues(final List<TextIssue> issuesList, final InputFile againstThisFile) {
  for (TextIssue issue : issuesList) {
    Issuable issuable = resourcePerspectives.as(Issuable.class, againstThisFile);

    if (issuable != null) {
      issuable.addIssue(
        issuable.newIssueBuilder()
          .ruleKey(issue.getRuleKey())
          .line(issue.getLine())
          .message(issue.getMessage())
          .build());
    }
  }
}
 
开发者ID:gjd6640,项目名称:sonar-text-plugin,代码行数:15,代码来源:TextIssueSensor.java


示例15: decorate

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Override
public void decorate(Resource resource, DecoratorContext context) {

    Issuable issuable = perspectives.as(Issuable.class, resource);
    if (issuable != null) {
        for (Issue issue : issuable.issues()) {
            DebtsFilter.getInstance().filter(issue);
        }
    }

    if (allResourcesAreProcessed(resource)) {
        saveMeasures(context);
    }
}
 
开发者ID:cezarcoca,项目名称:sonar-toxicity-chart,代码行数:15,代码来源:ToxicityChartDecorator.java


示例16: addErrorOnUnknownRule

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void addErrorOnUnknownRule() {
    final Issuable issuable = setupIssuable();
    addErrorToListener();
    verifyZeroInteractions(issuable);
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:7,代码来源:CheckstyleAuditListenerTest.java


示例17: setupIssuable

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private Issuable setupIssuable() {
    final Issuable issuable = mock(Issuable.class);
    when(perspectives.as(Issuable.class, inputFile)).thenReturn(issuable);
    return issuable;
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:6,代码来源:CheckstyleAuditListenerTest.java


示例18: analyse

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Override
public void analyse(Project project, SensorContext sensorContext) {
    LOG.info("Starting analyse of Project " + fileSystem.baseDir().getName());
    for (InputFile inputFile : fileSystem.inputFiles(fileSystem.predicates().hasLanguage("bpel"))) {

        PortabilityAnalyzer analyzer = new PortabilityAnalyzer();
        Path currentFilePath = Paths.get(inputFile.absolutePath());
        List<ReportEntry> entries = analyzer.analyzeFile(currentFilePath);

        if (entries.size() > 0) {
            for (ReportEntry currentEntry : entries) {
                for (String currentMetric : currentEntry.getVariableNames())
                    if (currentMetric.equals("class")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<String>(PortabilityMetrics.CLASSIFICATION, currentEntry.getVariableValue(currentMetric)));
                    } else if (currentMetric.equals("N")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<Integer>(PortabilityMetrics.N, (double) Integer.valueOf(currentEntry.getVariableValue(currentMetric))));
                    } else if (currentMetric.equals("Mb")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<Double>(PortabilityMetrics.MB, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
                    } else if (currentMetric.equals("Me")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<Double>(PortabilityMetrics.ME, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
                    } else if (currentMetric.equals("Ma")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<Double>(PortabilityMetrics.MA, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
                    } else if (currentMetric.equals("Ms")) {
                        sensorContext.saveMeasure(inputFile,
                                new Measure<Double>(PortabilityMetrics.MS, Double.valueOf(currentEntry.getVariableValue(currentMetric)), 2));
                    }
            }
        }

        List<Warning> warnings = analyzer.getWarningsFromLastAnalysis();
        if (warnings.size() > 0) {
            Issuable issuable = perspectives.as(Issuable.class, inputFile);
            for (Warning warning : warnings) {
                if (issuable != null) {
                    // can be used
                    Issue issue = issuable.newIssueBuilder()
                            .ruleKey(RuleKey.of("portability-issues", warning.getAssertion().getId()))
                            .line(warning.getLine())
                            .message(warning.getAssertion().getDiagnosticMessage())
                            .build();
                    issuable.addIssue(issue);
                }
            }
        }
    }
}
 
开发者ID:uniba-dsg,项目名称:sonar-prope-plugin,代码行数:52,代码来源:PortabilitySensor.java


示例19: parseReport

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
private void parseReport(FileProvider fileProvider, ReSharperReportParser parser, File reportFile) {
  LOG.info("Parsing ReSharper report: " + reportFile);
  File solutionFile = new File(settings.getString(ReSharperPlugin.SOLUTION_FILE_PROPERTY_KEY));
  String projectName = settings.getString(ReSharperPlugin.PROJECT_NAME_SONAR_PROPERTY_KEY);
  LOG.info(ReSharperPlugin.PROJECT_NAME_SONAR_PROPERTY_KEY + " " + projectName);
  List<ReSharperIssue> parse = parser.parse(reportFile, projectName);
  for (ReSharperIssue issue : parse) {
    if (!hasFileAndLine(issue)) {
      logSkippedIssue(issue, "which has no associated file.");
      continue;
    }

    File file = fileProvider.fileInSolution(solutionFile, issue.filePath());

    //The below code is implemented to try to resolve an issue where something is passing a wonky file path i.e.
    // "D:\\vssrc\\GregsProject\\\"D:\\vssrc\\GregsProject\\Common Libraries\\Common Libraries\\Class1.cs\"";
    //The below condition will attempt to detect this type of string and rip out only the full path to the file
    if(file.getAbsolutePath().contains("\\\"") && file.getAbsolutePath().endsWith("\"")){
      String badFilePath = file.getAbsolutePath();
      int position = badFilePath.indexOf("\\\"");
      String newPath = file.getAbsolutePath().substring(position + 2,file.getAbsolutePath().length()-1);

      //change the file variable to the new filePath.
      file = new File(newPath);
    }

    InputFile inputFile;
    try {
      inputFile = fileSystem.inputFile(
              fileSystem.predicates().and(
                      fileSystem.predicates().hasAbsolutePath(file.getAbsolutePath()),
                      fileSystem.predicates().hasType(InputFile.Type.MAIN))
      );
    }catch (Exception ex){
      logSkippedIssue(issue, "Failed to get input file: \"" + ex.getMessage() +"\"");
      continue;
    }
    if (inputFile == null) {
      logSkippedIssueOutsideOfSonarQube(issue, file);
    } else if (reSharperConf.languageKey().equals(inputFile.language())) {
      Issuable issuable = perspectives.as(Issuable.class, inputFile);
      if (issuable == null) {
        logSkippedIssueOutsideOfSonarQube(issue, file);
      } else if (!enabledRuleKeys().contains(issue.ruleKey())) {
        logSkippedIssue(issue, "because the rule \"" + issue.ruleKey() + "\" is either missing or inactive in the quality profile.");
      } else {
        issuable.addIssue(
          issuable.newIssueBuilder()
            .ruleKey(RuleKey.of(reSharperConf.repositoryKey(), issue.ruleKey()))
            .line(issue.line())
            .message(issue.message())
            .build());
      }
    }
  }
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:57,代码来源:ReSharperSensor.java


示例20: analyze_report_path

import org.sonar.api.issue.Issuable; //导入依赖的package包/类
@Test
public void analyze_report_path() throws Exception {
  String languageKey = "foo";
  String reportPathKey = "fooReport";
  Settings settings = new Settings();
  settings.setProperty(ReSharperPlugin.SOLUTION_FILE_PROPERTY_KEY, "CSharpPlayground.sln");
  settings.setProperty(ReSharperPlugin.PROJECT_NAME_PROPERTY_KEY, "MyLibrary");
  settings.setProperty(reportPathKey, "src/test/resources/SensorTest/report.xml");

  RulesProfile profile = mock(RulesProfile.class);
  DefaultFileSystem fileSystem = new DefaultFileSystem();
  ResourcePerspectives perspectives = mock(ResourcePerspectives.class);

  ReSharperSensor sensor = new ReSharperSensor(
    new ReSharperConfiguration(languageKey, "foo-resharper", "fooReport"),
    settings, profile, fileSystem, perspectives);

  List<ActiveRule> activeRules = mockActiveRules("RedundantUsingDirective");
  when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(activeRules);

  File workingDir = new File("src/test/resources/SensorTest");
  fileSystem.setWorkDir(workingDir);

  DefaultInputFile class1Cs = new DefaultInputFile("MyLibrary/Class1.cs").setAbsolutePath(new File("MyLibrary/Class1.cs").getAbsolutePath()).setLanguage(languageKey);
  fileSystem.add(class1Cs);
  DefaultInputFile assemblyInfoCs = new DefaultInputFile("MyLibrary/Properties/AssemblyInfo.cs").setAbsolutePath(new File("MyLibrary/Properties/AssemblyInfo.cs").getAbsolutePath()).setLanguage(languageKey);
  fileSystem.add(assemblyInfoCs);

  Issue issue1 = mock(Issue.class);
  IssueBuilder issueBuilder1 = mockIssueBuilder();
  when(issueBuilder1.build()).thenReturn(issue1);

  Issuable issuable1 = mock(Issuable.class);
  when(perspectives.as(Issuable.class, class1Cs)).thenReturn(issuable1);
  when(issuable1.newIssueBuilder()).thenReturn(issueBuilder1);

  Issue issue2 = mock(Issue.class);
  IssueBuilder issueBuilder2 = mockIssueBuilder();
  when(issueBuilder2.build()).thenReturn(issue2);

  Issuable issuable2 = mock(Issuable.class);
  when(perspectives.as(Issuable.class, assemblyInfoCs)).thenReturn(issuable2);
  when(issuable2.newIssueBuilder()).thenReturn(issueBuilder2);

  sensor.analyse(mock(Project.class), mock(SensorContext.class));

  verify(issuable1).addIssue(issue1);
  verify(issuable2).addIssue(issue2);

  verify(issueBuilder1).line(1);
  verify(issueBuilder1).message("Using directive is not required by the code and can be safely removed");

  verify(issueBuilder2).line(2);
  verify(issueBuilder2).message("Using directive is not required by the code and can be safely removed");
}
 
开发者ID:GregBartlett,项目名称:sonar-resharper,代码行数:56,代码来源:ReSharperSensorTest.java



注:本文中的org.sonar.api.issue.Issuable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EaseLinear类代码示例发布时间:2022-05-22
下一篇:
Java RMState类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap