aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java2
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java3
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java3
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java37
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java29
12 files changed, 68 insertions, 29 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
index 64b65cbb8f5..7c207ad9edd 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
@@ -19,13 +19,12 @@
*/
package org.sonar.plugins.checkstyle;
-import org.sonar.api.batch.GeneratesViolations;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
-public class CheckstyleSensor implements Sensor, GeneratesViolations {
+public class CheckstyleSensor implements Sensor {
private RulesProfile profile;
private CheckstyleExecutor executor;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
index 85febaa6e96..d808990f575 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
@@ -32,7 +32,7 @@ import org.sonar.api.rules.Violation;
import java.util.*;
-@DependsUpon(classes = GeneratesViolations.class)
+@DependsUpon(value = DecoratorBarriers.END_OF_VIOLATIONS_GENERATION)
public class ViolationsDecorator implements Decorator {
// temporary data for current resource
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java
index 421172e9a70..eb93d2fc218 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java
@@ -26,7 +26,6 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.GeneratesViolations;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.maven.DependsUponMavenPlugin;
@@ -38,7 +37,7 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.Violation;
-public class FindbugsSensor implements Sensor, DependsUponMavenPlugin, GeneratesViolations {
+public class FindbugsSensor implements Sensor, DependsUponMavenPlugin {
private RulesProfile profile;
private RuleFinder ruleFinder;
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
index aa499bcffd0..a637d82f8fa 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
@@ -21,7 +21,6 @@ package org.sonar.plugins.pmd;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.AbstractViolationsStaxParser;
-import org.sonar.api.batch.GeneratesViolations;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
@@ -31,7 +30,7 @@ import org.sonar.api.utils.XmlParserException;
import java.io.File;
-public class PmdSensor implements Sensor, GeneratesViolations {
+public class PmdSensor implements Sensor {
private RulesProfile profile;
private RulesManager rulesManager;
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
index cc8ab1161b2..eade90a88f9 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
@@ -46,8 +46,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
import org.sonar.java.bytecode.check.BytecodeChecks;
-/* The phase can be removed as soon as all needed sensors implements GeneratesViolations */
-
@Phase(name = Phase.Name.PRE)
/* TODO is the flag still used ? */
@DependedUpon(value = Sensor.FLAG_SQUID_ANALYSIS, classes = NoSonarFilter.class)
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
index 1ebb6654a8f..dd291a291df 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
@@ -21,6 +21,7 @@ package org.sonar.api.batch;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
import org.apache.commons.lang.ClassUtils;
import org.picocontainer.MutablePicoContainer;
import org.sonar.api.BatchExtension;
@@ -68,7 +69,7 @@ public class BatchExtensionDictionnary {
public Collection<MavenPluginHandler> selectMavenPluginHandlers(Project project) {
Collection<DependsUponMavenPlugin> selectedExtensions = select(DependsUponMavenPlugin.class, project, true);
- List<MavenPluginHandler> handlers = new ArrayList<MavenPluginHandler>();
+ List<MavenPluginHandler> handlers = Lists.newArrayList();
for (DependsUponMavenPlugin extension : selectedExtensions) {
MavenPluginHandler handler = extension.getMavenPluginHandler(project);
if (handler != null) {
@@ -90,7 +91,7 @@ public class BatchExtensionDictionnary {
}
private <T> List<T> getFilteredExtensions(Class<T> type, Project project) {
- List<T> result = new ArrayList<T>();
+ List<T> result = Lists.newArrayList();
for (BatchExtension extension : getExtensions()) {
if (shouldKeep(type, extension, project)) {
result.add((T) extension);
@@ -153,7 +154,7 @@ public class BatchExtensionDictionnary {
protected List evaluateAnnotatedClasses(Object extension, Class annotation) {
- List results = new ArrayList();
+ List results = Lists.newArrayList();
Class aClass = extension.getClass();
while (aClass != null) {
evaluateClass(aClass, annotation, results);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java
new file mode 100644
index 00000000000..7003367da48
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.batch;
+
+/**
+ * Barriers are used to define the order of execution of Decorators.
+ * @since 2.3
+ */
+public interface DecoratorBarriers {
+
+ /**
+ * This barrier is used by a decorator in order to :
+ * <ul>
+ * <li>be executed after all the decorators which generate violations : <code>@DependsUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION</code></li>
+ * <li>declare that it generates violations : <code>@DependedUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION</code></li>
+ * </ul>
+ */
+ String END_OF_VIOLATIONS_GENERATION = "END_OF_VIOLATIONS_GENERATION";
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
index d8fa8938406..6754574dc14 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
@@ -112,7 +112,8 @@ public interface DecoratorContext {
/**
- * Save a coding rule violation. The decorator which calls this method must implement org.sonar.api.batch.GeneratesViolations
+ * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
+ * @see org.sonar.api.batch.BatchBarriers
*/
DecoratorContext saveViolation(Violation violation);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java
index 73a8093999e..7b141fc7c75 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java
@@ -37,6 +37,9 @@ public @interface DependedUpon {
*/
String[] value() default {};
+ /**
+ * Used only on classes. Must be keep empty on methods.
+ */
Class[] classes() default {};
} \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java
index 000c2061454..2b76a94556c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java
@@ -36,6 +36,9 @@ public @interface DependsUpon {
*/
String[] value() default {};
+ /**
+ * Used only on classes. Must be keep empty on methods.
+ */
Class[] classes() default {};
} \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
index c37e30cca4d..0c6e13c6d81 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
@@ -102,7 +102,7 @@ public interface SensorContext {
// ----------- RULE VIOLATIONS --------------
/**
- * Save a coding rule violation. The sensor which calls this method must implement org.sonar.api.batch.GeneratesViolations
+ * Save a coding rule violation.
*/
void saveViolation(Violation violation);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java
index f49017099c8..267bdfdd468 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.batch;
+import com.google.common.collect.Lists;
import org.junit.Test;
import org.picocontainer.containers.TransientPicoContainer;
import org.sonar.api.BatchExtension;
@@ -65,7 +66,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension c = new MethodDependentOf(b);
BatchExtensionDictionnary selector = newSelector(b, c, a);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertThat(extensions.size(), is(3));
assertThat(extensions.get(0), is(a));
@@ -79,7 +80,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension b = new MethodDependentOf("foo");
BatchExtensionDictionnary selector = newSelector(a, b);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertThat(extensions.size(), is(2));
assertThat(extensions.get(0), is(a));
@@ -87,7 +88,7 @@ public class BatchExtensionDictionnaryTest {
// different initial order
selector = newSelector(b, a);
- extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(2, extensions.size());
assertEquals(a, extensions.get(0));
@@ -100,7 +101,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension b = new ClassDependsUpon();
BatchExtensionDictionnary selector = newSelector(a, b);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertThat(extensions.size(), is(2));
assertThat(extensions.get(0), is(a));
@@ -108,7 +109,7 @@ public class BatchExtensionDictionnaryTest {
// different initial order
selector = newSelector(b, a);
- extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(2, extensions.size());
assertEquals(a, extensions.get(0));
@@ -124,7 +125,7 @@ public class BatchExtensionDictionnaryTest {
};
BatchExtensionDictionnary selector = newSelector(a, b);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertThat(extensions.size(), is(2));
assertThat(extensions.get(0), is(a));
@@ -132,7 +133,7 @@ public class BatchExtensionDictionnaryTest {
// different initial order
selector = newSelector(b, a);
- extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(2, extensions.size());
assertEquals(a, extensions.get(0));
@@ -146,7 +147,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension ko = new CheckProjectKO();
BatchExtensionDictionnary selector = newSelector(ok, ko);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, new Project("key"), true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, new Project("key"), true));
assertThat(extensions.size(), is(1));
assertThat(extensions.get(0), is(CheckProjectOK.class));
@@ -158,7 +159,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension b = new MethodDependentOf("foo");
BatchExtensionDictionnary selector = newSelector(b, a);
- List<BatchExtension> extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(2, extensions.size());
assertEquals(a, extensions.get(0));
@@ -166,7 +167,7 @@ public class BatchExtensionDictionnaryTest {
// change initial order
selector = newSelector(a, b);
- extensions = new ArrayList<BatchExtension>(selector.select(BatchExtension.class, null, true));
+ extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(2, extensions.size());
assertEquals(a, extensions.get(0));
@@ -192,7 +193,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension post = new PostSensor();
BatchExtensionDictionnary selector = newSelector(analyze, post, pre);
- List extensions = new ArrayList(selector.select(BatchExtension.class, null, true));
+ List extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(3, extensions.size());
assertEquals(pre, extensions.get(0));
@@ -207,7 +208,7 @@ public class BatchExtensionDictionnaryTest {
BatchExtension post = new PostSensorSubclass();
BatchExtensionDictionnary selector = newSelector(analyze, post, pre);
- List extensions = new ArrayList(selector.select(BatchExtension.class, null, true));
+ List extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(3, extensions.size());
assertEquals(pre, extensions.get(0));
@@ -215,7 +216,6 @@ public class BatchExtensionDictionnaryTest {
assertEquals(post, extensions.get(2));
}
-
@Test
public void buildStatusCheckersAreExecutedAfterOtherPostJobs() {
BuildBreaker checker = new BuildBreaker() {
@@ -224,7 +224,7 @@ public class BatchExtensionDictionnaryTest {
};
BatchExtensionDictionnary selector = newSelector(new FakePostJob(), checker, new FakePostJob());
- List extensions = new ArrayList(selector.select(BatchExtension.class, null, true));
+ List extensions = Lists.newArrayList(selector.select(BatchExtension.class, null, true));
assertEquals(3, extensions.size());
assertEquals(checker, extensions.get(2));
@@ -270,7 +270,6 @@ public class BatchExtensionDictionnaryTest {
interface InterfaceDependedUpon extends BatchExtension {
}
-
class GeneratesSomething implements BatchExtension {
private Object gen;