summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-05-12 17:03:50 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-05-13 10:49:59 +0200
commit8d727d037967e6d2a3c6a998e48f3ebcee6059b0 (patch)
tree1d386a546cd0e0bdd493cda7097ad6b90c7e5d8a /server
parent26528fdc3a6fcdf197008b6da6210473d9f5681d (diff)
downloadsonarqube-8d727d037967e6d2a3c6a998e48f3ebcee6059b0.tar.gz
sonarqube-8d727d037967e6d2a3c6a998e48f3ebcee6059b0.zip
SONAR-7154 main process must create property file in SQ's temp dir
because the JVM's temp dir might just be read only (eg. temp dir of windows services launched with Local System Account on recent windows versions is actuallt read only)
Diffstat (limited to 'server')
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java5
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java21
2 files changed, 12 insertions, 14 deletions
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
index 07556a80e5f..a1db8436737 100644
--- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
+++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
@@ -105,8 +105,7 @@ class JavaProcessLauncher {
private String buildJavaPath() {
String separator = System.getProperty("file.separator");
- return new File(new File(System.getProperty("java.home")),
- "bin" + separator + "java").getAbsolutePath();
+ return new File(new File(System.getProperty("java.home")), "bin" + separator + "java").getAbsolutePath();
}
private List<String> buildClasspath(JavaCommand javaCommand) {
@@ -116,7 +115,7 @@ class JavaProcessLauncher {
private File buildPropertiesFile(JavaCommand javaCommand) {
File propertiesFile = null;
try {
- propertiesFile = File.createTempFile("sq-process", "properties");
+ propertiesFile = File.createTempFile("sq-process", "properties", tempDir);
Properties props = new Properties();
props.putAll(javaCommand.getArguments());
props.setProperty(PROPERTY_PROCESS_KEY, javaCommand.getProcessId().getKey());
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
index df9ae973d17..0ed382ac24a 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/JavaProcessLauncherTest.java
@@ -22,29 +22,28 @@ package org.sonar.process.monitor;
import java.io.File;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.process.ProcessId;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
public class JavaProcessLauncherTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
@Test
public void fail_to_launch() throws Exception {
File tempDir = temp.newFolder();
JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH);
JavaProcessLauncher launcher = new JavaProcessLauncher(new Timeouts(), tempDir);
- try {
- // command is not correct (missing options), java.lang.ProcessBuilder#start()
- // throws an exception
- launcher.launch(command);
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Fail to launch [es]");
- }
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Fail to launch [es]");
+
+ // command is not correct (missing options), java.lang.ProcessBuilder#start()
+ // throws an exception
+ launcher.launch(command);
}
}