diff options
4 files changed, 23 insertions, 26 deletions
diff --git a/it/it-tests/src/test/java/it/analysis/IssueJsonReportTest.java b/it/it-tests/src/test/java/it/analysis/IssueJsonReportTest.java index 8a2b94e50e8..b0f5afbe49e 100644 --- a/it/it-tests/src/test/java/it/analysis/IssueJsonReportTest.java +++ b/it/it-tests/src/test/java/it/analysis/IssueJsonReportTest.java @@ -31,13 +31,13 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -46,9 +46,10 @@ import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; -@Ignore("Temporarily disabled as non-SNAPSHOT versions are not supported") public class IssueJsonReportTest { + private static final String SONAR_VERSION_PLACEHOLDER = "<SONAR_VERSION>"; + @ClassRule public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; @@ -146,7 +147,7 @@ public class IssueJsonReportTest { assertThat(report).isFile().exists(); String json = sanitize(FileUtils.readFileToString(report)); - String expectedJson = sanitize(IOUtils.toString(getResourceInputStream("no-server-analysis.json"))); + String expectedJson = expected("no-server-analysis.json"); JSONAssert.assertEquals(expectedJson, json, false); } @@ -173,7 +174,7 @@ public class IssueJsonReportTest { assertThat(report).isFile().exists(); String json = sanitize(FileUtils.readFileToString(report)); - String expectedJson = sanitize(IOUtils.toString(getResourceInputStream("report-on-single-module.json"))); + String expectedJson = expected("report-on-single-module.json"); JSONAssert.assertEquals(expectedJson, json, false); } @@ -204,7 +205,7 @@ public class IssueJsonReportTest { assertThat(report).isFile().exists(); String json = sanitize(FileUtils.readFileToString(report)); - String expectedJson = sanitize(IOUtils.toString(getResourceInputStream("report-on-single-module-branch.json"))); + String expectedJson = expected("report-on-single-module-branch.json"); JSONAssert.assertEquals(expectedJson, json, false); } @@ -241,7 +242,7 @@ public class IssueJsonReportTest { String json = sanitize(FileUtils.readFileToString(report)); // SONAR-5218 All issues are updated as their root project id has changed (it's now the sub module) - String expectedJson = sanitize(IOUtils.toString(getResourceInputStream("report-on-sub-module.json"))); + String expectedJson = expected("report-on-sub-module.json"); JSONAssert.assertEquals(expectedJson, json, false); } @@ -271,17 +272,13 @@ public class IssueJsonReportTest { assertThat(report).isFile().exists(); String json = sanitize(FileUtils.readFileToString(report)); - String expectedJson = sanitize(IOUtils.toString(getResourceInputStream("report-on-root-module.json"))); + String expectedJson = expected("report-on-root-module.json"); JSONAssert.assertEquals(expectedJson, json, false); } - @Test - public void sanityCheck() { - assertThat(sanitize("5.0-SNAPSHOT")).isEqualTo("<SONAR_VERSION>"); - assertThat(sanitize("5.0.0-5868-SNAPSHOT")).isEqualTo("<SONAR_VERSION>"); - assertThat(sanitize("5.0-build1234")).isEqualTo("<SONAR_VERSION>"); - assertThat(sanitize("5.0.1-build1234")).isEqualTo("<SONAR_VERSION>"); - assertThat(sanitize("\"5.0.1-build1234\"")).isEqualTo("\"<SONAR_VERSION>\""); + private String expected(String path) throws IOException, FileNotFoundException { + return sanitize(IOUtils.toString(getResourceInputStream(path))) + .replaceAll(Pattern.quote(SONAR_VERSION_PLACEHOLDER), orchestrator.getServer().version().toString()); } @Test @@ -290,10 +287,6 @@ public class IssueJsonReportTest { } private static String sanitize(String s) { - // sanitize sonarqube version: "5.4-SNAPSHOT" or "5.4-build1234" - s = s.replaceAll("\\d\\.\\d(.\\d)?(\\-.*)?\\-SNAPSHOT", "<SONAR_VERSION>"); - s = s.replaceAll("\\d\\.\\d(.\\d)?(\\-.*)?\\-build(\\d)+", "<SONAR_VERSION>"); - // sanitize issue uuid keys s = s.replaceAll("\"[a-zA-Z_0-9\\-]{15,20}\"", "<ISSUE_KEY>"); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 563cdb422ab..54612177c24 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -222,7 +222,6 @@ public interface CoreProperties { @Deprecated String CORE_AUTHENTICATOR_UPDATE_USER_ATTRIBUTES = "sonar.security.updateUserAttributes"; - String SERVER_VERSION = "sonar.core.version"; String SERVER_ID = "sonar.core.id"; // format is yyyy-MM-dd'T'HH:mm:ssZ diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java index 8467e86097c..06f72c3d250 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java @@ -24,6 +24,7 @@ import java.util.Date; import javax.annotation.CheckForNull; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; +import org.sonar.api.SonarRuntime; import org.sonar.api.batch.ScannerSide; import org.sonar.api.config.Settings; import org.sonar.api.platform.Server; @@ -37,10 +38,12 @@ public class DefaultServer extends Server { private final Settings settings; private final ScannerWsClient client; + private final SonarRuntime runtime; - public DefaultServer(Settings settings, ScannerWsClient client) { + public DefaultServer(Settings settings, ScannerWsClient client, SonarRuntime runtime) { this.settings = settings; this.client = client; + this.runtime = runtime; } @Override @@ -50,7 +53,7 @@ public class DefaultServer extends Server { @Override public String getVersion() { - return settings.getString(CoreProperties.SERVER_VERSION); + return runtime.getApiVersion().toString(); } @Override diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 3c6df76e498..47a09228471 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -21,8 +21,11 @@ package org.sonar.scanner.platform; import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; +import org.sonar.api.SonarQubeSide; import org.sonar.api.config.MapSettings; +import org.sonar.api.config.Settings; +import org.sonar.api.internal.SonarRuntimeImpl; +import org.sonar.api.utils.Version; import org.sonar.scanner.bootstrap.ScannerWsClient; import static org.assertj.core.api.Assertions.assertThat; @@ -35,13 +38,12 @@ public class DefaultServerTest { public void shouldLoadServerProperties() { Settings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_ID, "123"); - settings.setProperty(CoreProperties.SERVER_VERSION, "2.2"); settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"); settings.setProperty(CoreProperties.PERMANENT_SERVER_ID, "abcde"); ScannerWsClient client = mock(ScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com"); - DefaultServer metadata = new DefaultServer(settings, client); + DefaultServer metadata = new DefaultServer(settings, client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER)); assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); @@ -61,7 +63,7 @@ public class DefaultServerTest { Settings settings = new MapSettings(); ScannerWsClient client = mock(ScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com/"); - DefaultServer metadata = new DefaultServer(settings, client); + DefaultServer metadata = new DefaultServer(settings, client, null); settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://server.com/"); assertThat(metadata.getPublicRootUrl()).isEqualTo("http://server.com"); @@ -75,7 +77,7 @@ public class DefaultServerTest { Settings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid"); ScannerWsClient client = mock(ScannerWsClient.class); - DefaultServer metadata = new DefaultServer(settings, client); + DefaultServer metadata = new DefaultServer(settings, client, null); metadata.getStartedAt(); } } |