*/
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;
}
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);
}
}
+ 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);
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;
verify(context, atLeast(100)).saveMeasure((Resource) anyObject(), (org.sonar.api.measures.Metric) anyObject(), anyDouble());
}
+ @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);