]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2164 Add an option to skip package design analysis
authorEvgeny Mandrikov <mandrikov@gmail.com>
Sun, 29 May 2011 21:35:03 +0000 (01:35 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Sun, 29 May 2011 23:45:52 +0000 (03:45 +0400)
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index 4be634b0546a662d9e36b1eb5f7ccbbe336d2c26..bd295bcff532c674f4c06492c934e9686b8532a0 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.plugins.squid;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.SensorContext;
 import org.sonar.api.checks.CheckFactory;
 import org.sonar.api.checks.NoSonarFilter;
@@ -93,7 +94,14 @@ public final class SquidExecutor {
     if (sourceScanned) {
       TimeProfiler profiler = new TimeProfiler(getClass()).start("Squid extraction");
       ResourceIndex resourceIndex = new ResourceIndex().loadSquidResources(squid, context, project);
-      List<Bridge> bridges = BridgeFactory.create(bytecodeScanned, context, checkFactory, resourceIndex, squid, noSonarFilter);
+
+      boolean skipPackageDesignAnalysis = CoreProperties.DESIGN_SKIP_PACKAGE_DESIGN_DEFAULT_VALUE;
+      if (project.getConfiguration() != null) {
+        skipPackageDesignAnalysis = project.getConfiguration()
+            .getBoolean(CoreProperties.DESIGN_SKIP_PACKAGE_DESIGN_PROPERTY, CoreProperties.DESIGN_SKIP_PACKAGE_DESIGN_DEFAULT_VALUE);
+      }
+
+      List<Bridge> bridges = BridgeFactory.create(bytecodeScanned, skipPackageDesignAnalysis, context, checkFactory, resourceIndex, squid, noSonarFilter);
       saveProject(resourceIndex, bridges);
       savePackages(resourceIndex, bridges);
       saveFiles(resourceIndex, bridges);
@@ -155,7 +163,6 @@ public final class SquidExecutor {
     }
   }
 
-
   void scanSources(Collection<InputFile> sourceFiles) {
     if (sourceFiles != null && !sourceFiles.isEmpty()) {
       TimeProfiler profiler = new TimeProfiler(getClass()).start("Java AST scan");
@@ -188,7 +195,7 @@ public final class SquidExecutor {
     for (File bytecodeFilesOrDirectory : bytecodeFilesOrDirectories) {
       if (bytecodeFilesOrDirectory.exists() &&
           (bytecodeFilesOrDirectory.isFile() ||
-          !FileUtils.listFiles(bytecodeFilesOrDirectory, new String[]{"class"}, true).isEmpty())) {
+          !FileUtils.listFiles(bytecodeFilesOrDirectory, new String[] { "class" }, true).isEmpty())) {
         return true;
       }
     }
index 2ebc7a286908840d5e69c38ff7b985d2d53a65e3..578ee211cdd65763d00a6524ccd94001437f222e 100644 (file)
  */
 package org.sonar.plugins.squid.bridges;
 
+import com.google.common.collect.Lists;
 import org.sonar.api.batch.SensorContext;
 import org.sonar.api.checks.CheckFactory;
 import org.sonar.api.checks.NoSonarFilter;
 import org.sonar.squid.Squid;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 public final class BridgeFactory {
@@ -34,17 +34,26 @@ public final class BridgeFactory {
     // only static methods
   }
 
-  private static List<Bridge> create(NoSonarFilter noSonarFilter) {
-    return Arrays.asList(new CopyBasicMeasuresBridge(), new PackagesBridge(), new PublicUndocumentedApiBridge(),
+  private static List<Bridge> create(NoSonarFilter noSonarFilter, boolean skipPackageDesignAnalysis) {
+    ArrayList<Bridge> result = Lists.newArrayList(
+        new CopyBasicMeasuresBridge(),
+        new PackagesBridge(),
+        new PublicUndocumentedApiBridge(),
         new NoSonarFilterLoader(noSonarFilter),
-        new ChidamberKemererBridge(), new RobertCMartinBridge(), new DesignBridge(),
-        new Lcom4BlocksBridge(), new ChecksBridge());
+        new ChidamberKemererBridge(),
+        new RobertCMartinBridge(),
+        new Lcom4BlocksBridge(),
+        new ChecksBridge());
+    if (!skipPackageDesignAnalysis) {
+      result.add(new DesignBridge());
+    }
+    return result;
   }
 
-  public static List<Bridge> create(boolean bytecodeScanned, SensorContext context, CheckFactory checkFactory,
+  public static List<Bridge> create(boolean bytecodeScanned, boolean skipPackageDesignAnalysis, SensorContext context, CheckFactory checkFactory,
                                     ResourceIndex resourceIndex, Squid squid, NoSonarFilter noSonarFilter) {
     List<Bridge> result = new ArrayList<Bridge>();
-    for (Bridge bridge : create(noSonarFilter)) {
+    for (Bridge bridge : create(noSonarFilter, skipPackageDesignAnalysis)) {
       bridge.setCheckFactory(checkFactory);
       if (!bridge.needsBytecode() || bytecodeScanned) {
         bridge.setContext(context);
index 783b24fa7d68d4924c3264a732608bfa85e25b66..f274bd6f0389fc44dfffb35337801902636e7507 100644 (file)
  */
 package org.sonar.plugins.squid.bridges;
 
-import java.util.List;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import java.util.List;
 
 public class BridgeFactoryTest {
 
   @Test
   public void createForSourceAnalysis() {
-    List<Bridge> astBridges = BridgeFactory.create(false, null, null, null, null, null);
+    List<Bridge> astBridges = BridgeFactory.create(false, true, null, null, null, null, null);
     assertFalse(has(astBridges, DesignBridge.class));
     assertTrue(has(astBridges, CopyBasicMeasuresBridge.class));
   }
 
   @Test
   public void createForSourceAndBytecodeAnalysis() {
-    List<Bridge> allBridges = BridgeFactory.create(true, null, null, null, null, null);
+    List<Bridge> allBridges = BridgeFactory.create(true, false, null, null, null, null, null);
     assertTrue(has(allBridges, DesignBridge.class));
     assertTrue(has(allBridges, CopyBasicMeasuresBridge.class));
+    assertTrue(has(allBridges, Lcom4BlocksBridge.class));
+  }
 
+  @Test
+  public void createForSourceAndBytecodeWithoutDesignAnalysis() {
+    List<Bridge> allBridges = BridgeFactory.create(true, true, null, null, null, null, null);
+    assertFalse(has(allBridges, DesignBridge.class));
+    assertTrue(has(allBridges, CopyBasicMeasuresBridge.class));
+    assertTrue(has(allBridges, Lcom4BlocksBridge.class));
   }
 
   private boolean has(List<Bridge> bridges, Class<? extends Bridge> bridgeClass) {
index 9bdd1c3218d38d015fcf88b2577d634c12e42435..d946bcad9a403dff98e804fafcb82d7bed44f7ac 100644 (file)
@@ -118,6 +118,14 @@ public interface CoreProperties {
   String DESIGN_SKIP_DESIGN_PROPERTY = "sonar.skipDesign";
   boolean DESIGN_SKIP_DESIGN_DEFAULT_VALUE = false;
 
+  /**
+   * Indicates whether Package Design Analysis should be skipped.
+   * 
+   * @since 2.9
+   */
+  String DESIGN_SKIP_PACKAGE_DESIGN_PROPERTY = "sonar.skipPackageDesign";
+  boolean DESIGN_SKIP_PACKAGE_DESIGN_DEFAULT_VALUE = false;
+
   /* Findbugs */
   String FINDBUGS_PLUGIN = "findbugs";
   String FINDBUGS_EFFORT_PROPERTY = "sonar.findbugs.effort";