aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@sonarsource.com>2015-12-03 15:26:11 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-12-04 17:42:53 +0100
commit4a403cd45546e9f3748c8a2399159ca9e1eaa621 (patch)
tree9a9e794c7ecb35d55f38271681e4dc505030ed15 /sonar-batch
parente3f24eae9edd75b198183ee7239c33918d9c8a2e (diff)
downloadsonarqube-4a403cd45546e9f3748c8a2399159ca9e1eaa621.tar.gz
sonarqube-4a403cd45546e9f3748c8a2399159ca9e1eaa621.zip
SONAR-6905 replace analysis-details.json by report-task.txt
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java47
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java33
2 files changed, 39 insertions, 41 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
index 6f96639d2bd..2da734f8dde 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
@@ -23,17 +23,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import com.google.common.io.Files;
import com.squareup.okhttp.HttpUrl;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.BatchSide;
@@ -43,7 +33,6 @@ import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.ZipUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.text.JsonWriter;
import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.batch.protocol.output.BatchReportWriter;
@@ -53,7 +42,15 @@ import org.sonarqube.ws.WsCe;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsResponse;
-import static org.apache.commons.lang.StringUtils.defaultIfBlank;
+import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.Map;
@BatchSide
public class ReportPublisher implements Startable {
@@ -62,7 +59,7 @@ public class ReportPublisher implements Startable {
public static final String KEEP_REPORT_PROP_KEY = "sonar.batch.keepReport";
public static final String VERBOSE_KEY = "sonar.verbose";
- public static final String METADATA_DUMP_FILENAME = "analysis-details.json";
+ public static final String METADATA_DUMP_FILENAME = "report-task.txt";
private final Settings settings;
private final BatchWsClient wsClient;
@@ -76,7 +73,7 @@ public class ReportPublisher implements Startable {
private BatchReportWriter writer;
public ReportPublisher(Settings settings, BatchWsClient wsClient, AnalysisContextReportPublisher contextPublisher,
- ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
+ ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
this.settings = settings;
this.wsClient = wsClient;
this.contextPublisher = contextPublisher;
@@ -129,13 +126,13 @@ public class ReportPublisher implements Startable {
publisher.publish(writer);
}
long stopTime = System.currentTimeMillis();
- LOG.info("Analysis report generated in " + (stopTime - startTime) + "ms, dir size=" + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir)));
+ LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir)));
startTime = System.currentTimeMillis();
File reportZip = temp.newFile("batch-report", ".zip");
ZipUtils.zipDir(reportDir, reportZip);
stopTime = System.currentTimeMillis();
- LOG.info("Analysis reports compressed in " + (stopTime - startTime) + "ms, zip size=" + FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip)));
+ LOG.info("Analysis reports compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip)));
return reportZip;
} catch (IOException e) {
throw new IllegalStateException("Unable to prepare analysis report", e);
@@ -202,12 +199,12 @@ public class ReportPublisher implements Startable {
private void dumpMetadata(Map<String, String> metadata) {
File file = new File(projectReactor.getRoot().getWorkDir(), METADATA_DUMP_FILENAME);
try (Writer output = Files.newWriter(file, StandardCharsets.UTF_8)) {
- JsonWriter json = JsonWriter.of(output);
- json.beginObject();
for (Map.Entry<String, String> entry : metadata.entrySet()) {
- json.prop(entry.getKey(), entry.getValue());
+ output.write(entry.getKey());
+ output.write("=");
+ output.write(entry.getValue());
+ output.write("\n");
}
- json.endObject();
LOG.debug("Report metadata written to {}", file);
} catch (IOException e) {
@@ -220,10 +217,12 @@ public class ReportPublisher implements Startable {
* See https://jira.sonarsource.com/browse/SONAR-4239
*/
private String publicUrl() {
- String publicUrl = settings.getString(CoreProperties.SERVER_BASE_URL);
- if (StringUtils.isBlank(publicUrl)) {
- return wsClient.baseUrl();
+ String baseUrl = settings.getString(CoreProperties.SERVER_BASE_URL);
+ if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) {
+ // crap workaround for https://jira.sonarsource.com/browse/SONAR-7109
+ // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side
+ baseUrl = wsClient.baseUrl();
}
- return publicUrl.replaceAll("(/)+$", "") + "/";
+ return baseUrl.replaceAll("(/)+$", "") + "/";
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java
index ebc2e97735f..576a2dcdf8a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java
@@ -30,6 +30,7 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.log.LogTester;
@@ -37,7 +38,7 @@ import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.batch.scan.ImmutableProjectReactor;
-import org.sonar.test.JsonAssert;
+import org.sonar.core.config.CorePropertyDefinitions;
import static org.apache.commons.io.FileUtils.readFileToString;
import static org.assertj.core.api.Assertions.assertThat;
@@ -53,7 +54,7 @@ public class ReportPublisherTest {
public TemporaryFolder temp = new TemporaryFolder();
DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class);
- Settings settings = new Settings();
+ Settings settings = new Settings(new PropertyDefinitions(CorePropertyDefinitions.all()));
BatchWsClient wsClient = mock(BatchWsClient.class, Mockito.RETURNS_DEEP_STUBS);
ImmutableProjectReactor reactor = mock(ImmutableProjectReactor.class);
ProjectDefinition root;
@@ -77,13 +78,12 @@ public class ReportPublisherTest {
.contains("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report")
.contains("More about the report processing at https://localhost/api/ce/task?id=TASK-123");
- File detailsFile = new File(temp.getRoot(), "analysis-details.json");
- JsonAssert.assertJson(readFileToString(detailsFile)).isSimilarTo("{" +
- "\"projectKey\": \"struts\"," +
- "\"dashboardUrl\": \"https://localhost/dashboard/index/struts\"," +
- "\"ceTaskId\": \"TASK-123\"," +
- "\"ceTaskUrl\": \"https://localhost/api/ce/task?id=TASK-123\"" +
- "}"
+ File detailsFile = new File(temp.getRoot(), "report-task.txt");
+ assertThat(readFileToString(detailsFile)).isEqualTo(
+ "projectKey=struts\n" +
+ "dashboardUrl=https://localhost/dashboard/index/struts\n" +
+ "ceTaskId=TASK-123\n" +
+ "ceTaskUrl=https://localhost/api/ce/task?id=TASK-123\n"
);
}
@@ -98,13 +98,12 @@ public class ReportPublisherTest {
.contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard/index/struts")
.contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123");
- File detailsFile = new File(temp.getRoot(), "analysis-details.json");
- JsonAssert.assertJson(readFileToString(detailsFile)).isSimilarTo("{" +
- "\"projectKey\": \"struts\"," +
- "\"dashboardUrl\": \"https://publicserver/sonarqube/dashboard/index/struts\"," +
- "\"ceTaskId\": \"TASK-123\"," +
- "\"ceTaskUrl\": \"https://publicserver/sonarqube/api/ce/task?id=TASK-123\"" +
- "}"
+ File detailsFile = new File(temp.getRoot(), "report-task.txt");
+ assertThat(readFileToString(detailsFile)).isEqualTo(
+ "projectKey=struts\n" +
+ "dashboardUrl=https://publicserver/sonarqube/dashboard/index/struts\n" +
+ "ceTaskId=TASK-123\n" +
+ "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"
);
}
@@ -118,7 +117,7 @@ public class ReportPublisherTest {
.contains("ANALYSIS SUCCESSFUL")
.doesNotContain("dashboard/index");
- File detailsFile = new File(temp.getRoot(), "analysis-details.json");
+ File detailsFile = new File(temp.getRoot(), ReportPublisher.METADATA_DUMP_FILENAME);
assertThat(detailsFile).doesNotExist();
}