]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3726 Cobertura Sensor should not execute if non Java project
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Thu, 20 Sep 2012 16:37:20 +0000 (18:37 +0200)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Fri, 21 Sep 2012 08:26:25 +0000 (10:26 +0200)
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java

index 11ec1de43a3c4bde4d9a68ff3b76e12ab406660d..31ce963af740401679c015626e5a241e06feb5c0 100644 (file)
@@ -35,7 +35,7 @@ import java.io.File;
 public class CoberturaSensor implements Sensor, CoverageExtension {
 
   public boolean shouldExecuteOnProject(Project project) {
-    return !project.getFileSystem().mainFiles(Java.KEY).isEmpty();
+    return Java.KEY.equals(project.getLanguageKey()) && project.getAnalysisType().isDynamic(true);
   }
 
   public void analyse(Project project, SensorContext context) {
index 83db39159c6d5e3b0f5a76f38bb713354aec4ac2..adb06be473ffa1331733b9d74948766ef5fee498 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.SensorContext;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
+import org.sonar.api.resources.Java;
 import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.JavaPackage;
 import org.sonar.api.resources.Project;
@@ -39,6 +40,8 @@ import java.io.File;
 import java.net.URISyntaxException;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyDouble;
 import static org.mockito.Matchers.anyString;
@@ -60,6 +63,30 @@ public class CoberturaSensorTest {
     sensor = new CoberturaSensor();
   }
 
+  @Test
+  public void shouldNotAnalyseIfNoJavaProject() {
+    Project project = mock(Project.class);
+    when(project.getLanguageKey()).thenReturn("php");
+    when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
+    assertFalse(sensor.shouldExecuteOnProject(project));
+  }
+
+  @Test
+  public void shouldNotAnalyseIfStaticAnalysis() {
+    Project project = mock(Project.class);
+    when(project.getLanguageKey()).thenReturn(Java.KEY);
+    when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
+    assertFalse(sensor.shouldExecuteOnProject(project));
+  }
+
+  @Test
+  public void shouldAnalyseIfReuseDynamicReports() {
+    Project project = mock(Project.class);
+    when(project.getLanguageKey()).thenReturn(Java.KEY);
+    when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
+    assertThat(sensor.shouldExecuteOnProject(project), is(true));
+  }
+
   @Test
   public void shouldNotFailIfReportNotSpecifiedOrNotFound() {
     ProjectFileSystem pfs = mock(ProjectFileSystem.class);