aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/DifferentialValueDecorator.java15
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java5
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java (renamed from plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java)16
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java23
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java14
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java2
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java10
7 files changed, 45 insertions, 40 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/DifferentialValueDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/DifferentialValueDecorator.java
index 8ba04b4e621..2ece3f89ff1 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/DifferentialValueDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/DifferentialValueDecorator.java
@@ -31,7 +31,6 @@ import org.sonar.api.qualitymodel.Characteristic;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import java.util.Collection;
@@ -142,7 +141,7 @@ public class DifferentialValueDecorator implements Decorator {
// improvements : keep query in cache ? select only some columns ?
// TODO support measure on rules and characteristics
String hql = "select m from " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s " +
- "where m.snapshotId=s.id and m.metricId in (:metricIds) and m.rule=null and m.rulePriority=null and m.rulesCategoryId=null and m.characteristic=null "
+ "where m.snapshotId=s.id and m.metricId in (:metricIds) and m.ruleId=null and m.rulePriority=null and m.rulesCategoryId=null and m.characteristic=null "
+ "and (s.rootId=:rootSnapshotId or s.id=:rootSnapshotId) and s.resourceId=:resourceId and s.status=:status";
return session.createQuery(hql)
.setParameter("metricIds", metricByIds.keySet())
@@ -159,14 +158,14 @@ public class DifferentialValueDecorator implements Decorator {
static class MeasureKey {
Integer metricId;
- Rule rule;
+ Integer ruleId;
Integer categoryId;
RulePriority priority;
Characteristic characteristic;
MeasureKey(MeasureModel model) {
- this.metricId = model.getMetricId();
- rule = model.getRule();
+ metricId = model.getMetricId();
+ ruleId = model.getRuleId();
categoryId = model.getRulesCategoryId();
priority = model.getRulePriority();
characteristic = model.getCharacteristic();
@@ -179,7 +178,7 @@ public class DifferentialValueDecorator implements Decorator {
if (measure instanceof RuleMeasure) {
RuleMeasure rm = (RuleMeasure) measure;
categoryId = rm.getRuleCategory();
- rule = rm.getRule();
+ ruleId = (rm.getRule()==null ? null : rm.getRule().getId());
priority = rm.getRulePriority();
}
}
@@ -196,7 +195,7 @@ public class DifferentialValueDecorator implements Decorator {
return false;
if (!metricId.equals(that.metricId)) return false;
if (priority != that.priority) return false;
- if (rule != null ? !rule.equals(that.rule) : that.rule != null) return false;
+ if (ruleId != null ? !ruleId.equals(that.ruleId) : that.ruleId != null) return false;
return true;
}
@@ -204,7 +203,7 @@ public class DifferentialValueDecorator implements Decorator {
@Override
public int hashCode() {
int result = metricId.hashCode();
- result = 31 * result + (rule != null ? rule.hashCode() : 0);
+ result = 31 * result + (ruleId != null ? ruleId.hashCode() : 0);
result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0);
result = 31 * result + (priority != null ? priority.hashCode() : 0);
result = 31 * result + (characteristic != null ? characteristic.hashCode() : 0);
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
index d61ad812499..c0eb8f36207 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
@@ -26,9 +26,8 @@ import org.sonar.plugins.dbcleaner.api.Purge;
import org.sonar.plugins.dbcleaner.api.PurgeContext;
import org.sonar.plugins.dbcleaner.api.PurgeUtils;
-import java.util.List;
-
import javax.persistence.Query;
+import java.util.List;
/**
* see SONAR-522
@@ -49,7 +48,7 @@ public final class PurgeRuleMeasures extends Purge {
private void purge(Integer sid) {
Query query = getSession().createQuery("SELECT m.id FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE s.id = m.snapshotId and " +
- "(s.rootId=:rootSid OR s.id=:rootSid) and (m.rule is not null or m.rulesCategoryId is not null or m.rulePriority is not null)");
+ "(s.rootId=:rootSid OR s.id=:rootSid) and (m.ruleId is not null or m.rulesCategoryId is not null or m.rulePriority is not null)");
query.setParameter("rootSid", sid);
List<Integer> measureIds = query.getResultList();
PurgeUtils.deleteMeasuresById(getSession(), measureIds);
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java
index ab3af9d93a6..eae82300b29 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsRuleFinder.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FakeRuleFinder.java
@@ -19,26 +19,30 @@
*/
package org.sonar.plugins.findbugs;
-import java.util.Collection;
-import java.util.List;
-
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.rules.XMLRuleParser;
-public class FindbugsRuleFinder implements RuleFinder {
+import java.util.Collection;
+import java.util.List;
+
+public class FakeRuleFinder implements RuleFinder {
private final List<Rule> findbugsRules;
- public FindbugsRuleFinder() {
+ public FakeRuleFinder() {
FindbugsRuleRepository repo = new FindbugsRuleRepository(new XMLRuleParser());
findbugsRules = repo.createRules();
- for(Rule rule : findbugsRules){
+ for (Rule rule : findbugsRules) {
rule.setRepositoryKey(FindbugsConstants.REPOSITORY_KEY);
}
}
+ public Rule findById(int ruleId) {
+ throw new UnsupportedOperationException();
+ }
+
public Rule findByKey(String repositoryKey, String key) {
for (Rule rule : findbugsRules) {
if (rule.getKey().equals(key)) {
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
index 9296f03613e..206ccdfc07d 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
@@ -19,16 +19,7 @@
*/
package org.sonar.plugins.findbugs;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.List;
-
+import com.thoughtworks.xstream.XStream;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.api.profiles.RulesProfile;
@@ -38,11 +29,19 @@ import org.sonar.plugins.findbugs.xml.FindBugsFilter;
import org.sonar.plugins.findbugs.xml.Match;
import org.sonar.test.TestUtils;
-import com.thoughtworks.xstream.XStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
public class FindbugsProfileImporterTest {
- private FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder());
+ private FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder());
@Test
public void shouldImportPatterns() throws IOException {
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java
index d5124bf0f1a..9cd16af6c98 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java
@@ -48,14 +48,14 @@ public class FindbugsSensorTest extends FindbugsTests {
@Test
public void shouldExecuteWhenSomeRulesAreActive() throws Exception {
- FindbugsSensor sensor = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null);
+ FindbugsSensor sensor = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null);
Project project = createProject();
assertTrue(sensor.shouldExecuteOnProject(project));
}
@Test
public void shouldExecuteWhenReuseExistingRulesConfig() throws Exception {
- FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FindbugsRuleFinder(), null);
+ FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null);
Project pom = createProject();
when(pom.getReuseExistingRulesConfig()).thenReturn(true);
assertTrue(analyser.shouldExecuteOnProject(pom));
@@ -63,7 +63,7 @@ public class FindbugsSensorTest extends FindbugsTests {
@Test
public void shouldNotExecuteWhenNoRulesAreActive() throws Exception {
- FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FindbugsRuleFinder(), null);
+ FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null);
Project pom = createProject();
assertFalse(analyser.shouldExecuteOnProject(pom));
}
@@ -72,7 +72,7 @@ public class FindbugsSensorTest extends FindbugsTests {
public void shouldNotExecuteOnEar() {
Project project = createProject();
when(project.getPom().getPackaging()).thenReturn("ear");
- FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), null);
+ FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null);
assertFalse(analyser.shouldExecuteOnProject(project));
}
@@ -88,7 +88,7 @@ public class FindbugsSensorTest extends FindbugsTests {
when(executor.execute()).thenReturn(xmlFile);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor);
+ FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor);
analyser.analyse(project, context);
verify(executor).execute();
@@ -116,7 +116,7 @@ public class FindbugsSensorTest extends FindbugsTests {
when(project.getConfiguration()).thenReturn(conf);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor);
+ FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor);
analyser.analyse(project, context);
verify(executor, never()).execute();
@@ -144,7 +144,7 @@ public class FindbugsSensorTest extends FindbugsTests {
when(project.getConfiguration()).thenReturn(conf);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FindbugsRuleFinder(), executor);
+ FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor);
analyser.analyse(project, context);
verify(context, never()).saveViolation(any(Violation.class));
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
index 881fbf9a36b..a21e3ccaecc 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
@@ -31,7 +31,7 @@ public class SonarWayWithFindbugsProfileTest {
@Test
public void shouldCreateProfile() {
- FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder());
+ FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder());
SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(importer);
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = sonarWayWithFindbugs.createProfile(validation);
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
index c35e9440f45..a0a458758bf 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
@@ -35,7 +35,7 @@ public class PmdProfileExporterTest {
PmdRuleRepository repository = new PmdRuleRepository(fileSystem, new XMLRuleParser());
List<Rule> rules = repository.createRules();
- RuleFinder ruleFinder = new PmdRuleFinder(rules);
+ RuleFinder ruleFinder = new FakeRuleFinder(rules);
PmdProfileImporter importer = new PmdProfileImporter(ruleFinder);
Reader reader = new StringReader(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
RulesProfile rulesProfile = importer.importProfile(reader, ValidationMessages.create());
@@ -103,14 +103,18 @@ public class PmdProfileExporterTest {
assertThat(rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM).getValue(), is(xpathExpression));
}
- private static class PmdRuleFinder implements RuleFinder {
+ private static class FakeRuleFinder implements RuleFinder {
private List<Rule> rules;
- public PmdRuleFinder(List<Rule> rules) {
+ public FakeRuleFinder(List<Rule> rules) {
this.rules = rules;
}
+ public Rule findById(int ruleId) {
+ throw new UnsupportedOperationException();
+ }
+
public Rule findByKey(String repositoryKey, String key) {
throw new UnsupportedOperationException();
}