diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 18:18:52 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 19:08:27 +0100 |
commit | dada59ec30d01932c9a902b7aa5dc6a90220121f (patch) | |
tree | 7440f6469e7c20e4c7c02e306b27b164086e2874 /plugins/sonar-squid-java-plugin/src | |
parent | 95d94a9b9adf9bf69da69bcf382cccdc5fa9871b (diff) | |
download | sonarqube-dada59ec30d01932c9a902b7aa5dc6a90220121f.tar.gz sonarqube-dada59ec30d01932c9a902b7aa5dc6a90220121f.zip |
SONAR-2171 Do not compute LCOM4/RFC measures when bytecode is not available
Diffstat (limited to 'plugins/sonar-squid-java-plugin/src')
2 files changed, 30 insertions, 1 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 c96dd325793..a8b26ed1b2a 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 @@ -19,6 +19,7 @@ */ package org.sonar.plugins.squid; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.SensorContext; import org.sonar.api.checks.CheckFactory; @@ -172,7 +173,7 @@ public final class SquidExecutor { } void scanBytecode(Collection<File> bytecodeFilesOrDirectories) { - if (bytecodeFilesOrDirectories != null && !bytecodeFilesOrDirectories.isEmpty()) { + if (hasBytecode(bytecodeFilesOrDirectories)) { TimeProfiler profiler = new TimeProfiler(getClass()).start("Java bytecode scan"); BytecodeScanner bytecodeScanner = squid.register(BytecodeScanner.class); bytecodeScanner.scan(bytecodeFilesOrDirectories); @@ -183,6 +184,20 @@ public final class SquidExecutor { } } + static boolean hasBytecode(Collection<File> bytecodeFilesOrDirectories) { + if (bytecodeFilesOrDirectories == null) { + return false; + } + for (File bytecodeFilesOrDirectory : bytecodeFilesOrDirectories) { + if (bytecodeFilesOrDirectory.exists() && + (bytecodeFilesOrDirectory.isFile() || + !FileUtils.listFiles(bytecodeFilesOrDirectory, new String[]{"class"}, true).isEmpty())) { + return true; + } + } + return false; + } + void scanSquidIndex() { TimeProfiler profiler = new TimeProfiler(getClass()).start("Java Squid scan"); SquidScanner squidScanner = squid.register(SquidScanner.class); diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java index 18350132b50..0238de92434 100644 --- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java +++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java @@ -21,7 +21,9 @@ package org.sonar.plugins.squid; import static org.hamcrest.core.Is.is; import static org.hamcrest.number.OrderingComparisons.greaterThan; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyDouble; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.atLeast; @@ -102,6 +104,18 @@ public class SquidExecutorTest { } @Test + public void shouldNotHaveBytecode() { + assertFalse(SquidExecutor.hasBytecode(Collections.<File>emptyList())); + + assertFalse(SquidExecutor.hasBytecode(Arrays.asList(new File("unknown")))); + } + + @Test + public void shouldHaveBytecode() { + assertTrue(SquidExecutor.hasBytecode(Arrays.asList(new File("test-resources/commons-collections-3.2.1/bin")))); + } + + @Test public void flushSquidAfterUsage() { Squid squid = mock(Squid.class); SquidExecutor executor = new SquidExecutor(squid); |