diff options
Diffstat (limited to 'sonar-batch/src/main')
5 files changed, 7 insertions, 111 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java index 2a70c13ac9d..b22660d590f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java @@ -37,7 +37,6 @@ import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.Metric; import org.sonar.api.resources.*; -import org.sonar.api.rules.Violation; import org.sonar.api.utils.SonarException; import org.sonar.batch.sensor.DefaultSensorContext; import org.sonar.batch.sensor.coverage.CoverageExclusions; @@ -183,28 +182,6 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen } @Override - public void saveViolation(Violation violation, boolean force) { - if (violation.getResource() == null) { - violation.setResource(resourceOrProject(violation.getResource())); - } - index.addViolation(violation, force); - } - - @Override - public void saveViolation(Violation violation) { - saveViolation(violation, false); - } - - @Override - public void saveViolations(Collection<Violation> violations) { - if (violations != null) { - for (Violation violation : violations) { - saveViolation(violation); - } - } - } - - @Override public Dependency saveDependency(Dependency dependency) { return index.addDependency(dependency); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java index 47d75f4434d..0b63501eb80 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java @@ -29,7 +29,6 @@ import org.sonar.api.design.Dependency; import org.sonar.api.measures.*; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.api.rules.Violation; import org.sonar.api.utils.SonarException; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.duplication.DuplicationUtils; @@ -214,18 +213,4 @@ public class DefaultDecoratorContext implements DecoratorContext { public Collection<Dependency> getOutgoingDependencies() { return sonarIndex.getOutgoingEdges(resource); } - - @Override - public DefaultDecoratorContext saveViolation(Violation violation, boolean force) { - if (violation.getResource() == null) { - violation.setResource(resource); - } - sonarIndex.addViolation(violation, force); - return this; - } - - @Override - public DefaultDecoratorContext saveViolation(Violation violation) { - return saveViolation(violation, false); - } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 33f6246ea8c..7a12b86eaab 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -38,8 +38,6 @@ import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.MeasuresFilters; import org.sonar.api.resources.*; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.Violation; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.SonarException; import org.sonar.batch.ProjectTree; @@ -361,44 +359,6 @@ public class DefaultIndex extends SonarIndex { return result; } - // - // - // - // VIOLATIONS - // - // - // - - @Override - public void addViolation(Violation violation, boolean force) { - Resource resource = violation.getResource(); - if (resource == null) { - violation.setResource(currentProject); - } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) { - throw new IllegalArgumentException("Violations are only supported on files, directories and project"); - } - - Rule rule = violation.getRule(); - if (rule == null) { - LOG.warn("Rule is null. Ignoring violation {}", violation); - return; - } - - Bucket bucket = getBucket(resource); - if (bucket == null) { - LOG.warn("Resource is not indexed. Ignoring violation {}", violation); - return; - } - - // keep a limitation (bug?) of deprecated violations api : severity is always - // set by sonar. The severity set by plugins is overridden. - // This is not the case with issue api. - violation.setSeverity(null); - - violation.setResource(bucket.getResource()); - moduleIssues.initAndAddViolation(violation); - } - @Override public String getSource(Resource reference) { Resource resource = getResource(reference); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java index 64f7e8d2446..94938954ebf 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java @@ -30,10 +30,8 @@ import org.sonar.api.batch.rule.internal.DefaultActiveRule; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rules.Violation; import org.sonar.api.utils.Duration; import org.sonar.api.utils.MessageException; -import org.sonar.core.issue.DefaultIssueBuilder; import javax.annotation.Nullable; @@ -48,7 +46,7 @@ public class ModuleIssues { private final Project project; private final IssueFilters filters; - public ModuleIssues(ActiveRules activeRules, @Nullable Rules rules, IssueCache cache, @Nullable Project project, IssueFilters filters) { + public ModuleIssues(ActiveRules activeRules, @Nullable Rules rules, IssueCache cache, Project project, IssueFilters filters) { this.activeRules = activeRules; this.rules = rules; this.cache = cache; @@ -56,35 +54,10 @@ public class ModuleIssues { this.filters = filters; } - public ModuleIssues(ActiveRules activeRules, IssueCache cache, @Nullable Project project, IssueFilters filters) { + public ModuleIssues(ActiveRules activeRules, IssueCache cache, Project project, IssueFilters filters) { this(activeRules, null, cache, project, filters); } - /** - * Used by scan2 - */ - public ModuleIssues(ActiveRules activeRules, Rules rules, IssueCache cache, IssueFilters filters) { - this(activeRules, rules, cache, null, filters); - } - - public boolean initAndAddViolation(Violation violation) { - DefaultIssue issue = newIssue(violation); - return initAndAddIssue(issue); - } - - private DefaultIssue newIssue(Violation violation) { - return new DefaultIssueBuilder() - .componentKey(violation.getResource().getEffectiveKey()) - // Project can be null but Violation not used by scan2 - .projectKey(project.getRoot().getEffectiveKey()) - .ruleKey(RuleKey.of(violation.getRule().getRepositoryKey(), violation.getRule().getKey())) - .effortToFix(violation.getCost()) - .line(violation.getLineId()) - .message(violation.getMessage()) - .severity(violation.getSeverity() != null ? violation.getSeverity().name() : null) - .build(); - } - public boolean initAndAddIssue(DefaultIssue issue) { RuleKey ruleKey = issue.ruleKey(); Rule rule = null; @@ -119,10 +92,8 @@ public class ModuleIssues { if (Strings.isNullOrEmpty(issue.message())) { issue.setMessage(((DefaultActiveRule) activeRule).name()); } - if (project != null) { - issue.setCreationDate(project.getAnalysisDate()); - issue.setUpdateDate(project.getAnalysisDate()); - } + issue.setCreationDate(project.getAnalysisDate()); + issue.setUpdateDate(project.getAnalysisDate()); if (issue.severity() == null) { issue.setSeverity(activeRule.severity()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java index c886d93bf51..1895e6d103b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java @@ -23,6 +23,7 @@ package org.sonar.batch.rule; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.batch.RequiresDB; import org.sonar.api.batch.debt.DebtCharacteristic; import org.sonar.api.batch.debt.DebtModel; import org.sonar.api.batch.debt.DebtRemediationFunction; @@ -39,11 +40,13 @@ import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; import javax.annotation.Nullable; + import java.util.List; /** * Loads all enabled and non manual rules */ +@RequiresDB public class RulesProvider extends ProviderAdapter { private Rules singleton = null; |