use of org.sonar.api.batch.fs.InputComponent 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.InputComponent in project sonarqube by SonarSource.
the class DefaultIndexTest method shouldGetHierarchy.
@Test
public void shouldGetHierarchy() {
InputComponent component = new DefaultInputModule("module1");
InputFile file1 = new TestInputFileBuilder("module1", "src/org/foo/Bar.java").build();
when(componentStore.getByKey("module1")).thenReturn(component);
when(componentStore.getByKey("module1:src/org/foo/Bar.java")).thenReturn(file1);
when(componentTree.getParent(file1)).thenReturn(component);
when(componentTree.getChildren(component)).thenReturn(Collections.singleton(file1));
assertThat(index.getParent("module1:src/org/foo/Bar.java").getKey()).isEqualTo("module1");
assertThat(index.getParent("module1")).isNull();
assertThat(index.getChildren("module1")).containsOnly(File.create("src/org/foo/Bar.java"));
assertThat(index.getChildren("module1:src/org/foo/Bar.java")).isEmpty();
}
use of org.sonar.api.batch.fs.InputComponent in project sonarlint-core by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(Issue issue) {
InputComponent inputComponent = issue.primaryLocation().inputComponent();
DefaultRule rule = validateRule(issue);
ActiveRule activeRule = activeRules.find(issue.ruleKey());
if (activeRule == null) {
// rule does not exist or is not enabled -> ignore the issue
return;
}
String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message();
org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
String severity = overriddenSeverity != null ? overriddenSeverity.name() : activeRule.severity();
String type = rule.type();
DefaultClientIssue newIssue = new DefaultClientIssue(severity, type, activeRule, rules.find(activeRule.ruleKey()), primaryMessage, issue.primaryLocation().textRange(), inputComponent.isFile() ? ((SonarLintInputFile) inputComponent).getClientInputFile() : null, issue.flows());
if (filters.accept(inputComponent, newIssue)) {
issueListener.handle(newIssue);
}
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class EnforceIssuesFilter method accept.
@Override
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
boolean atLeastOneRuleMatched = false;
boolean atLeastOnePatternFullyMatched = false;
IssuePattern matchingPattern = null;
for (IssuePattern pattern : multicriteriaPatterns) {
if (ruleMatches(pattern, issue.ruleKey())) {
atLeastOneRuleMatched = true;
InputComponent component = ((DefaultFilterableIssue) issue).getComponent();
if (component.isFile()) {
DefaultInputFile file = (DefaultInputFile) component;
if (pattern.matchFile(file.getProjectRelativePath())) {
atLeastOnePatternFullyMatched = true;
matchingPattern = pattern;
} else if (pattern.matchFile(file.getModuleRelativePath())) {
warnOnceDeprecatedIssuePattern("Specifying module-relative paths at project level in property '" + IssueInclusionPatternInitializer.CONFIG_KEY + "' is deprecated. " + "To continue matching files like '" + file.getProjectRelativePath() + "', update this property so that patterns refer to project-relative paths.");
atLeastOnePatternFullyMatched = true;
matchingPattern = pattern;
}
}
}
}
if (atLeastOneRuleMatched) {
if (atLeastOnePatternFullyMatched) {
LOG.debug("Issue '{}' enforced by pattern '{}'", issue, matchingPattern);
}
return atLeastOnePatternFullyMatched;
} else {
return chain.accept(issue);
}
}
use of org.sonar.api.batch.fs.InputComponent in project sonarqube by SonarSource.
the class AbstractDefaultIssue method rewriteLocation.
private DefaultIssueLocation rewriteLocation(DefaultIssueLocation location) {
InputComponent component = location.inputComponent();
Optional<Path> dirOrModulePath = Optional.empty();
if (component instanceof DefaultInputDir) {
DefaultInputDir dirComponent = (DefaultInputDir) component;
dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path()));
} else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) {
DefaultInputModule moduleComponent = (DefaultInputModule) component;
dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
}
if (dirOrModulePath.isPresent()) {
String path = PathUtils.sanitize(dirOrModulePath.get().toString());
DefaultIssueLocation fixedLocation = new DefaultIssueLocation();
fixedLocation.on(project);
StringBuilder fullMessage = new StringBuilder();
if (path != null && !path.isEmpty()) {
fullMessage.append("[").append(path).append("] ");
}
fullMessage.append(location.message());
fixedLocation.message(fullMessage.toString());
return fixedLocation;
} else {
return location;
}
}
Aggregations