aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2015-12-14 22:20:07 +0100
committerJenkins CI <ci@sonarsource.com>2015-12-14 22:20:07 +0100
commitf63a3ab73d37acef942df261f13ebec7573b4e11 (patch)
treee859e40d91ba1bbe79a37a4f93b9553c3638415c /server/sonar-process
parenta4ed263e412aa7fc37d7e5dac4c231acafb1d1d6 (diff)
parent6a13e5f6ed2da5101d33b84849594814351c379a (diff)
downloadsonarqube-f63a3ab73d37acef942df261f13ebec7573b4e11.tar.gz
sonarqube-f63a3ab73d37acef942df261f13ebec7573b4e11.zip
Automatic merge from branch-5.3
* origin/branch-5.3: SONAR-7141 Fail fast if server started with Java 1.6 SONAR-7140 Do not check java.io.tmpdir in bootstrap process SONAR-6905 Batch should dump analysis-related URL into a properties file
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java37
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java40
2 files changed, 25 insertions, 52 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java
index fdbc7217611..4b182468fb3 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java
@@ -27,59 +27,50 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-public class MinimumViableSystem {
-
- private final Map<String, String> requiredJavaOptions = new HashMap<>();
-
- public MinimumViableSystem setRequiredJavaOption(String propertyKey, String expectedValue) {
- requiredJavaOptions.put(propertyKey, expectedValue);
- return this;
- }
+import static java.lang.String.format;
- /**
- * Entry point for all checks
- */
- public void check() {
- checkJavaVersion();
- checkJavaOptions();
- checkWritableTempDir();
- }
+public class MinimumViableSystem {
/**
* Verify that temp directory is writable
*/
- private void checkWritableTempDir() {
+ public MinimumViableSystem checkWritableTempDir() {
checkWritableDir(System.getProperty("java.io.tmpdir"));
+ return this;
}
+ // Visible for testing
void checkWritableDir(String tempPath) {
try {
File tempFile = File.createTempFile("check", "tmp", new File(tempPath));
FileUtils.deleteQuietly(tempFile);
} catch (IOException e) {
- throw new IllegalStateException(String.format("Temp directory is not writable: %s", tempPath), e);
+ throw new IllegalStateException(format("Temp directory is not writable: %s", tempPath), e);
}
}
- void checkJavaOptions() {
+ public MinimumViableSystem checkRequiredJavaOptions(Map<String, String> requiredJavaOptions) {
for (Map.Entry<String, String> entry : requiredJavaOptions.entrySet()) {
String value = System.getProperty(entry.getKey());
if (!StringUtils.equals(value, entry.getValue())) {
- throw new MessageException(String.format(
+ throw new MessageException(format(
"JVM option '%s' must be set to '%s'. Got '%s'", entry.getKey(), entry.getValue(), StringUtils.defaultString(value)));
}
}
+ return this;
}
- void checkJavaVersion() {
+ public MinimumViableSystem checkJavaVersion() {
String javaVersion = System.getProperty("java.specification.version");
checkJavaVersion(javaVersion);
+ return this;
}
+ // Visible for testing
void checkJavaVersion(String javaVersion) {
- if (!javaVersion.startsWith("1.6") && !javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) {
+ if (!javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) {
// still better than "java.lang.UnsupportedClassVersionError: Unsupported major.minor version 49.0
- throw new MessageException(String.format("Supported versions of Java are 1.6, 1.7 and 1.8. Got %s.", javaVersion));
+ throw new MessageException(format("Supported versions of Java are 1.7 and 1.8. Got %s.", javaVersion));
}
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java
index 88e813f4fbb..291862930be 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.process;
+import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -33,67 +34,48 @@ public class MinimumViableSystemTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- /**
- * Verifies that all checks can be verified without error.
- * Test environment does not necessarily follows all checks.
- */
- @Test
- public void check() {
- MinimumViableSystem mve = new MinimumViableSystem();
-
- try {
- mve.check();
- // ok
- } catch (MessageException e) {
- // also ok. All other exceptions are errors.
- }
- }
+ MinimumViableSystem underTest = new MinimumViableSystem();
@Test
public void checkJavaVersion() {
- MinimumViableSystem mve = new MinimumViableSystem();
-
// yes, sources are compiled with a supported Java version!
- mve.checkJavaVersion();
- mve.checkJavaVersion("1.6");
+ underTest.checkJavaVersion();
+ underTest.checkJavaVersion("1.7");
try {
- mve.checkJavaVersion("1.9");
+ underTest.checkJavaVersion("1.6");
fail();
} catch (MessageException e) {
- assertThat(e).hasMessage("Supported versions of Java are 1.6, 1.7 and 1.8. Got 1.9.");
+ assertThat(e).hasMessage("Supported versions of Java are 1.7 and 1.8. Got 1.6.");
}
}
@Test
- public void checkJavaOption() {
+ public void checkRequiredJavaOptions() {
String key = "MinimumViableEnvironmentTest.test.prop";
- MinimumViableSystem mve = new MinimumViableSystem()
- .setRequiredJavaOption(key, "true");
try {
System.setProperty(key, "false");
- mve.checkJavaOptions();
+ underTest.checkRequiredJavaOptions(ImmutableMap.of(key, "true"));
fail();
} catch (MessageException e) {
assertThat(e).hasMessage("JVM option '" + key + "' must be set to 'true'. Got 'false'");
}
System.setProperty(key, "true");
- mve.checkJavaOptions();
// do not fail
+ underTest.checkRequiredJavaOptions(ImmutableMap.of(key, "true"));
}
@Test
public void checkWritableTempDir() throws Exception {
File dir = temp.newFolder();
- MinimumViableSystem mve = new MinimumViableSystem();
- mve.checkWritableDir(dir.getAbsolutePath());
+ underTest.checkWritableDir(dir.getAbsolutePath());
dir.delete();
try {
- mve.checkWritableDir(dir.getAbsolutePath());
+ underTest.checkWritableDir(dir.getAbsolutePath());
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Temp directory is not writable: " + dir.getAbsolutePath());