summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-10-29 14:50:27 +0100
committerDavid Gageot <david@gageot.net>2012-10-29 14:50:27 +0100
commit07e3d0d4c4341d7abd231395f41eeb1d8e05cecc (patch)
tree8f878292dd3ce6b86f55d8e0191a6890318d84dc /plugins
parent94b2a9ae7d056e97a4c259102f940098f105403f (diff)
downloadsonarqube-07e3d0d4c4341d7abd231395f41eeb1d8e05cecc.tar.gz
sonarqube-07e3d0d4c4341d7abd231395f41eeb1d8e05cecc.zip
SONAR-3890 The overall code coverage should not be computed when the code coverage by unit tests is not computed with jacoco
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java31
-rw-r--r--plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java31
2 files changed, 48 insertions, 14 deletions
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java
index fc5c61f2ced..4ead9748ed6 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java
@@ -53,7 +53,8 @@ public class JaCoCoOverallSensor implements Sensor {
}
public boolean shouldExecuteOnProject(Project project) {
- return StringUtils.isNotBlank(configuration.getItReportPath()) && project.getAnalysisType().isDynamic(true);
+ return StringUtils.isNotBlank(configuration.getItReportPath())
+ && project.getAnalysisType().isDynamic(true);
}
public void analyse(Project project, SensorContext context) {
@@ -61,6 +62,10 @@ public class JaCoCoOverallSensor implements Sensor {
File reportUTs = fs.resolvePath(configuration.getReportPath());
File reportITs = fs.resolvePath(configuration.getItReportPath());
+ if ((!reportUTs.exists()) || (!reportITs.exists())) {
+ return;
+ }
+
File reportOverall = new File(fs.getSonarWorkingDirectory(), JACOCO_OVERALL);
reportOverall.getParentFile().mkdirs();
@@ -91,19 +96,17 @@ public class JaCoCoOverallSensor implements Sensor {
private void loadSourceFiles(SessionInfoStore infoStore, ExecutionDataStore dataStore, File... reports) {
for (File report : reports) {
- if (report.exists()) {
- InputStream resourceStream = null;
- try {
- resourceStream = new BufferedInputStream(new FileInputStream(report));
- ExecutionDataReader reader = new ExecutionDataReader(resourceStream);
- reader.setSessionInfoVisitor(infoStore);
- reader.setExecutionDataVisitor(dataStore);
- reader.read();
- } catch (IOException e) {
- throw new SonarException(String.format("Unable to read %s", report.getAbsolutePath()), e);
- } finally {
- Closeables.closeQuietly(resourceStream);
- }
+ InputStream resourceStream = null;
+ try {
+ resourceStream = new BufferedInputStream(new FileInputStream(report));
+ ExecutionDataReader reader = new ExecutionDataReader(resourceStream);
+ reader.setSessionInfoVisitor(infoStore);
+ reader.setExecutionDataVisitor(dataStore);
+ reader.read();
+ } catch (IOException e) {
+ throw new SonarException(String.format("Unable to read %s", report.getAbsolutePath()), e);
+ } finally {
+ Closeables.closeQuietly(resourceStream);
}
}
}
diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java
index 60f167d7afc..b9cabe9efe8 100644
--- a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java
+++ b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java
@@ -40,6 +40,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
public class JaCoCoOverallSensorTest {
@@ -97,6 +98,36 @@ public class JaCoCoOverallSensorTest {
}
@Test
+ public void should_no_save_measures_when_it_report_is_not_found() throws IOException {
+ File outputDir = TestUtils.getResource(JaCoCoOverallSensorTest.class, ".");
+
+ when(project.getFileSystem()).thenReturn(pfs);
+ when(configuration.getReportPath()).thenReturn("ut.exec");
+ when(configuration.getItReportPath()).thenReturn("it.not.found.exec");
+ when(pfs.resolvePath("ut.exec")).thenReturn(new File(outputDir, "ut.exec"));
+ when(pfs.resolvePath("it.not.found.exec")).thenReturn(new File("it.not.found.exec"));
+
+ sensor.analyse(project, context);
+
+ verifyZeroInteractions(context);
+ }
+
+ @Test
+ public void should_no_save_measures_when_ut_report_is_not_found() throws IOException {
+ File outputDir = TestUtils.getResource(JaCoCoOverallSensorTest.class, ".");
+
+ when(project.getFileSystem()).thenReturn(pfs);
+ when(configuration.getReportPath()).thenReturn("ut.not.found.exec");
+ when(configuration.getItReportPath()).thenReturn("it.exec");
+ when(pfs.resolvePath("ut.not.found.exec")).thenReturn(new File("ut.not.found.exec"));
+ when(pfs.resolvePath("it.exec")).thenReturn(new File(outputDir, "it.exec"));
+
+ sensor.analyse(project, context);
+
+ verifyZeroInteractions(context);
+ }
+
+ @Test
public void testSensorDefinition() {
assertThat(sensor.toString()).isEqualTo("JaCoCoOverallSensor");
}