aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-squid-java-plugin
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-05-30 01:35:03 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-05-30 03:45:52 +0400
commitc55c3c916bd1f76f52a237e5b49eca880f8a2945 (patch)
tree84d41d7959b7388aa97f9734b1057ed66d7dd57f /plugins/sonar-squid-java-plugin
parent78b3c4c0badeadef7bed763a15cd9e3318a4fb3e (diff)
downloadsonarqube-c55c3c916bd1f76f52a237e5b49eca880f8a2945.tar.gz
sonarqube-c55c3c916bd1f76f52a237e5b49eca880f8a2945.zip
SONAR-2164 Add an option to skip package design analysis
Diffstat (limited to 'plugins/sonar-squid-java-plugin')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java13
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java23
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java18
3 files changed, 39 insertions, 15 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
index 4be634b0546..bd295bcff53 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
@@ -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;
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java
index 2ebc7a28690..578ee211cdd 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/BridgeFactory.java
@@ -19,13 +19,13 @@
*/
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);
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
index 783b24fa7d6..f274bd6f038 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeFactoryTest.java
@@ -19,28 +19,36 @@
*/
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) {