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();
}
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);
}
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);
}
Aggregations