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;
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);
}
}
-
void scanSources(Collection<InputFile> sourceFiles) {
if (sourceFiles != null && !sourceFiles.isEmpty()) {
TimeProfiler profiler = new TimeProfiler(getClass()).start("Java AST scan");
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;
}
}
*/
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 {
// 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);
*/
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) {
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";