Search in sources :

Example 1 with InputPath

use of org.sonar.api.batch.fs.InputPath in project sonarqube by SonarSource.

the class JSONReport method writeJsonIssues.

private void writeJsonIssues(JsonWriter json, Set<RuleKey> ruleKeys, Set<String> logins) throws IOException {
    json.name("issues").beginArray();
    for (TrackedIssue issue : getIssues()) {
        if (issue.resolution() == null) {
            InputComponent component = componentStore.getByKey(issue.componentKey());
            String componentKey = getModule(component).definition().getKeyWithBranch();
            if (component instanceof InputPath) {
                componentKey = ComponentKeys.createEffectiveKey(componentKey, (InputPath) component);
            }
            json.beginObject().prop("key", issue.key()).prop("component", componentKey).prop("line", issue.startLine()).prop("startLine", issue.startLine()).prop("startOffset", issue.startLineOffset()).prop("endLine", issue.endLine()).prop("endOffset", issue.endLineOffset()).prop("message", issue.getMessage()).prop("severity", issue.severity()).prop("rule", issue.getRuleKey().toString()).prop("status", issue.status()).prop("resolution", issue.resolution()).prop("isNew", issue.isNew()).prop("assignee", issue.assignee()).prop("effortToFix", issue.gap()).propDateTime("creationDate", issue.creationDate());
            if (!StringUtils.isEmpty(issue.assignee())) {
                logins.add(issue.assignee());
            }
            json.endObject();
            ruleKeys.add(issue.getRuleKey());
        }
    }
    json.endArray();
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) InputPath(org.sonar.api.batch.fs.InputPath) InputComponent(org.sonar.api.batch.fs.InputComponent)

Example 2 with InputPath

use of org.sonar.api.batch.fs.InputPath in project sonar-java by SonarSource.

the class SonarComponents method reportIssue.

public void reportIssue(AnalyzerMessage analyzerMessage) {
    JavaCheck check = analyzerMessage.getCheck();
    Preconditions.checkNotNull(check);
    Preconditions.checkNotNull(analyzerMessage.getMessage());
    RuleKey key = getRuleKey(check);
    if (key == null) {
        return;
    }
    File file = analyzerMessage.getFile();
    InputPath inputPath = inputPathFromIOFile(file);
    if (inputPath == null) {
        return;
    }
    Double cost = analyzerMessage.getCost();
    reportIssue(analyzerMessage, key, inputPath, cost);
}
Also used : InputPath(org.sonar.api.batch.fs.InputPath) RuleKey(org.sonar.api.rule.RuleKey) JavaCheck(org.sonar.plugins.java.api.JavaCheck) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File)

Example 3 with InputPath

use of org.sonar.api.batch.fs.InputPath in project sonarqube by SonarSource.

the class InputComponentStoreTest method should_add_input_file.

@Test
public void should_add_input_file() throws Exception {
    String rootModuleKey = "struts";
    String subModuleKey = "struts-core";
    File rootBaseDir = temp.newFolder();
    ProjectDefinition moduleDef = ProjectDefinition.create().setKey(subModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder());
    ProjectDefinition rootDef = ProjectDefinition.create().setKey(rootModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder()).addSubProject(moduleDef);
    DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(rootDef);
    DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
    InputComponentStore store = new InputComponentStore(mock(BranchConfiguration.class), sonarRuntime);
    store.put(subModule);
    DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
    store.put(rootProject.key(), fooFile);
    store.put(subModuleKey, new TestInputFileBuilder(rootModuleKey, "src/main/java/Bar.java").setLanguage("bla").setPublish(false).setType(Type.MAIN).setStatus(Status.ADDED).setLines(2).setCharset(StandardCharsets.UTF_8).setModuleBaseDir(temp.newFolder().toPath()).build());
    DefaultInputFile loadedFile = (DefaultInputFile) store.getFile(subModuleKey, "src/main/java/Bar.java");
    assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
    assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
    assertThat(store.filesByModule(rootModuleKey)).hasSize(1);
    assertThat(store.filesByModule(subModuleKey)).hasSize(1);
    assertThat(store.inputFiles()).hasSize(2);
    for (InputPath inputPath : store.inputFiles()) {
        assertThat(inputPath.relativePath()).startsWith("src/main/java/");
    }
    List<InputFile> toPublish = new LinkedList<>();
    store.allFilesToPublish().forEach(toPublish::add);
    assertThat(toPublish).containsExactly(fooFile);
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) InputPath(org.sonar.api.batch.fs.InputPath) LinkedList(java.util.LinkedList) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Aggregations

InputPath (org.sonar.api.batch.fs.InputPath)3 File (java.io.File)2 InputFile (org.sonar.api.batch.fs.InputFile)2 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 RuleKey (org.sonar.api.rule.RuleKey)1 JavaCheck (org.sonar.plugins.java.api.JavaCheck)1 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)1 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)1