]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1812 The declaration @BelongsTo(classes=GeneratesViolations.class) does not...
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 24 Sep 2010 12:24:57 +0000 (12:24 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 24 Sep 2010 12:24:57 +0000 (12:24 +0000)
12 files changed:
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdSensor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/BatchExtensionDictionnaryTest.java

index 64b65cbb8f5821bf1778537beceedba58d7d9de0..7c207ad9edd451fb88b2257a52e65cb08bae07c9 100644 (file)
  */
 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;
index 85febaa6e96f62611ec10c6424209f768def0cb8..d808990f575b6dc61749f88cd86207d73320a0b3 100644 (file)
@@ -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
index 421172e9a7052dd8e7554c46508c50cf9e0f6d2e..eb93d2fc218c7fbe5afb90d5451f023bb0680614 100644 (file)
@@ -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;
index aa499bcffd0e8c2f23645886a3eb7b2d5cec7ad2..a637d82f8fae8f52044894498d43b9077d65529b 100644 (file)
@@ -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;
index cc8ab1161b2e879f75f1767f9d646005bbc2831b..eade90a88f97efac5d4a4fb4cb8a2d58426de2c1 100644 (file)
@@ -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)
index 1ebb6654a8f5cfe8bc777bd8901e812f09c26b8a..dd291a291df99b848eb91fef78acf758aedd6611 100644 (file)
@@ -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 (file)
index 0000000..7003367
--- /dev/null
@@ -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";
+  
+}
index d8fa8938406068121b226e7df507dd3e33d007e6..6754574dc14b2e4f1996d46c16d5e163d6be1233 100644 (file)
@@ -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);
 
index 73a8093999e8191d07de11e3a626fd5f3d099c1d..7b141fc7c7592dd03b1ab5384d75b2a38a741d6b 100644 (file)
@@ -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
index 000c20614544cc706fc7b8c988595b4c53b996a3..2b76a94556c3b3a4f3c606d09ace8c6260b6ed0c 100644 (file)
@@ -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
index c37e30cca4d3392cdde55548d3ada93188f3e5ea..0c6e13c6d81c6b2c3a248fa6fd2cdce2e61c37db 100644 (file)
@@ -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);
 
index f49017099c874645466111c59b092ee97f779715..267bdfdd468456285db9f6073aee9a17b0e2dbf3 100644 (file)
@@ -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;