aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-08-03 09:35:32 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-08-03 11:18:10 +0200
commitfa5e4667fa79a61a14157a03c68548307f0b8f54 (patch)
tree229a32971683d03c9e4698bbab9135f7b231d867 /sonar-batch
parentcdae84ee26c9e1b136272359c66aa5ae6c21c51f (diff)
downloadsonarqube-fa5e4667fa79a61a14157a03c68548307f0b8f54.tar.gz
sonarqube-fa5e4667fa79a61a14157a03c68548307f0b8f54.zip
SONAR-6772 Do not save JSON report by default
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java29
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java41
2 files changed, 38 insertions, 32 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
index b7520f53821..22c02ff6e42 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
@@ -19,10 +19,17 @@
*/
package org.sonar.batch.scan.report;
-import org.sonar.api.batch.rule.Rule;
-
-import org.sonar.api.batch.rule.Rules;
import com.google.common.annotations.VisibleForTesting;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,8 +41,9 @@ import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.rule.Rule;
+import org.sonar.api.batch.rule.Rules;
import org.sonar.api.config.Settings;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
@@ -45,24 +53,13 @@ import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.protocol.input.BatchInput;
import org.sonar.batch.repository.user.UserRepository;
import org.sonar.batch.scan.filesystem.InputPathCache;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
+import org.sonar.core.issue.DefaultIssue;
import static com.google.common.collect.Sets.newHashSet;
@Properties({
@Property(
key = JSONReport.SONAR_REPORT_EXPORT_PATH,
- defaultValue = "sonar-report.json",
name = "Report Results Export File",
type = PropertyType.STRING,
global = false, project = false)})
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
index 544b1c065b3..74f2fa77106 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
@@ -19,11 +19,15 @@
*/
package org.sonar.batch.scan.report;
-import org.sonar.api.batch.rule.internal.RulesBuilder;
-
-import org.sonar.api.batch.rule.Rules;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.TimeZone;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -32,9 +36,10 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.rule.Rules;
+import org.sonar.api.batch.rule.internal.RulesBuilder;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -43,19 +48,13 @@ import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.protocol.input.BatchInput;
import org.sonar.batch.repository.user.UserRepository;
import org.sonar.batch.scan.filesystem.InputPathCache;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.test.JsonAssert;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.TimeZone;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
public class JSONReportTest {
@@ -116,7 +115,7 @@ public class JSONReportTest {
.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"))
.setUpdateDate(SIMPLE_DATE_FORMAT.parse("2013-04-25"))
.setNew(false);
- when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
+ when(issueCache.all()).thenReturn(Lists.newArrayList(issue));
BatchInput.User user1 = BatchInput.User.newBuilder().setLogin("julien").setName("Julien").build();
BatchInput.User user2 = BatchInput.User.newBuilder().setLogin("simon").setName("Simon").build();
when(userRepository.loadFromWs(anyListOf(String.class))).thenReturn(Lists.newArrayList(user1, user2));
@@ -140,7 +139,7 @@ public class JSONReportTest {
.setUpdateDate(SIMPLE_DATE_FORMAT.parse("2013-04-25"))
.setCloseDate(SIMPLE_DATE_FORMAT.parse("2013-04-26"))
.setNew(false);
- when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
+ when(issueCache.all()).thenReturn(Lists.newArrayList(issue));
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
@@ -151,7 +150,7 @@ public class JSONReportTest {
@Test
public void should_ignore_components_without_issue() {
- when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
+ when(issueCache.all()).thenReturn(Collections.<DefaultIssue>emptyList());
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
@@ -160,11 +159,21 @@ public class JSONReportTest {
}
@Test
+ public void should_not_export_by_default() throws IOException {
+ File workDir = temp.newFolder("sonar");
+ fs.setWorkDir(workDir);
+
+ jsonReport.execute();
+
+ verifyZeroInteractions(issueCache);
+ }
+
+ @Test
public void should_export_issues_to_file() throws IOException {
File workDir = temp.newFolder("sonar");
fs.setWorkDir(workDir);
- when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
+ when(issueCache.all()).thenReturn(Collections.<DefaultIssue>emptyList());
settings.setProperty("sonar.report.export.path", "output.json");