diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-27 16:47:05 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-27 16:56:45 +0100 |
commit | 5446d877b4e67f2f32ac869e76d9ad02ca226773 (patch) | |
tree | f6d41e03459e2885ddc7feb62ee154e3e42e29f2 /sonar-batch/src | |
parent | b07db6de13a2f98a02cf2371ea848fc2646d4237 (diff) | |
download | sonarqube-5446d877b4e67f2f32ac869e76d9ad02ca226773.tar.gz sonarqube-5446d877b4e67f2f32ac869e76d9ad02ca226773.zip |
Remove all deprecated Violation APIs
Diffstat (limited to 'sonar-batch/src')
6 files changed, 7 insertions, 146 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; diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java index 7ffa9905721..6b33dab0611 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java @@ -30,13 +30,9 @@ import org.sonar.api.batch.debt.DebtRemediationFunction; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.rule.internal.RulesBuilder; import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.resources.File; import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.rules.Violation; import org.sonar.api.utils.Duration; import org.sonar.api.utils.MessageException; @@ -45,7 +41,6 @@ import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; @@ -201,36 +196,6 @@ public class ModuleIssuesTest { } @Test - public void add_deprecated_violation() throws Exception { - ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME); - activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); - initModuleIssues(); - - org.sonar.api.rules.Rule rule = org.sonar.api.rules.Rule.create("squid", "AvoidCycle", "Avoid Cycle"); - Resource resource = File.create("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java"); - Violation violation = new Violation(rule, resource); - violation.setLineId(42); - violation.setSeverity(RulePriority.CRITICAL); - violation.setMessage("the message"); - - when(filters.accept(any(DefaultIssue.class))).thenReturn(true); - - boolean added = moduleIssues.initAndAddViolation(violation); - assertThat(added).isTrue(); - - ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); - verify(cache).put(argument.capture()); - DefaultIssue issue = argument.getValue(); - assertThat(issue.severity()).isEqualTo(Severity.CRITICAL); - assertThat(issue.line()).isEqualTo(42); - assertThat(issue.message()).isEqualTo("the message"); - assertThat(issue.key()).isNotEmpty(); - assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle"); - assertThat(issue.componentKey()).isEqualTo("struts:src/org/struts/Action.java"); - assertThat(issue.projectKey()).isEqualTo("org.apache:struts-core"); - } - - @Test public void filter_issue() throws Exception { ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME); activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate(); |