aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Process.java9
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java20
2 files changed, 26 insertions, 3 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Process.java b/server/sonar-process/src/main/java/org/sonar/process/Process.java
index 44d7b4f028a..df605f8d172 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Process.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Process.java
@@ -44,6 +44,9 @@ public abstract class Process implements ProcessMXBean {
public static final String PORT_PROPERTY = "pPort";
public static final String MISSING_NAME_ARGUMENT = "Missing Name argument";
+ public static final String SONAR_HOME_IS_NOT_SET = "variable SONAR_HOME is not set.";
+ public static final String SONAR_HOME_DOES_NOT_EXIST = "Directory SONAR_HOME does not exist";
+ public static final String SONAR_HOME_IS_NOT_WRITABLE = "Directory SONAR_HOME is not writable";
private final static Logger LOGGER = LoggerFactory.getLogger(Process.class);
@@ -164,18 +167,18 @@ public abstract class Process implements ProcessMXBean {
// check that we have a SONAR_HOME either in props or in env.
String sonarHome = props.of(SONAR_HOME, System.getenv(SONAR_HOME));
if (StringUtils.isEmpty(sonarHome)) {
- throw new IllegalStateException("variable SONAR_HOME is not set.");
+ throw new IllegalStateException(SONAR_HOME_IS_NOT_SET);
}
// check that SONAR_HOME exists
File home = new File(sonarHome);
if(!home.exists()) {
- throw new IllegalStateException("Directory SONAR_HOME '" + sonarHome + "' is not set");
+ throw new IllegalStateException(SONAR_HOME_DOES_NOT_EXIST);
}
// check that SONAR_HOME is writable
if (!home.canWrite()) {
- throw new IllegalStateException("Directory SONAR_HOME '" + sonarHome + "' is not writable");
+ throw new IllegalStateException(SONAR_HOME_IS_NOT_WRITABLE);
}
}
} \ No newline at end of file
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java
index d7b390654d4..0a0bb26337d 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.process;
+import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -70,6 +71,22 @@ public class ProcessTest {
try {
new TestProcess(Props.create(properties));
} catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo(Process.SONAR_HOME_IS_NOT_SET);
+ }
+
+ properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, "lahdslahdslf");
+ try {
+ new TestProcess(Props.create(properties));
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo(Process.SONAR_HOME_DOES_NOT_EXIST);
+ }
+
+ properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
+ try {
+ new TestProcess(Props.create(properties));
+ } catch (Exception e) {
assertThat(e.getMessage()).isEqualTo(Process.MISSING_NAME_ARGUMENT);
}
}
@@ -80,6 +97,7 @@ public class ProcessTest {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
Props props = Props.create(properties);
process = new TestProcess(props);
@@ -102,6 +120,7 @@ public class ProcessTest {
@Test(timeout = 5000L)
public void should_stop_explicit() throws Exception {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
Props props = Props.create(properties);
process = new TestProcess(props);
@@ -133,6 +152,7 @@ public class ProcessTest {
@Test(timeout = 15000L)
public void should_stop_implicit() throws Exception {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
properties.setProperty(Process.PORT_PROPERTY, Integer.toString(freePort));
Props props = Props.create(properties);