]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7896 set env var TMPDIR to make JRuby use SQ tmp dir for tmp files 1167/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 23 Aug 2016 13:07:37 +0000 (15:07 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 24 Aug 2016 08:20:24 +0000 (10:20 +0200)
these temp file are especially used when uploading

sonar-application/src/main/java/org/sonar/application/App.java
sonar-application/src/test/java/org/sonar/application/AppTest.java

index 8c8d73529a8c37ba31b17afb021b30883d7dae77..75cb88a007c31e2ee69a7d060f253470bbfea577 100644 (file)
@@ -92,6 +92,8 @@ public class App implements Stoppable {
       .addJavaOptions(props.nonNullValue(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS))
       // required for logback tomcat valve
       .setEnvVariable(ProcessProperties.PATH_LOGS, props.nonNullValue(ProcessProperties.PATH_LOGS))
+      // ensure JRuby uses SQ's temp directory as temp directory (eg. for temp files used during HTTP uploads)
+      .setEnvVariable("TMPDIR", props.nonNullValue(ProcessProperties.PATH_TEMP))
       .setClassName("org.sonar.server.app.WebServer")
       .setArguments(props.rawProperties())
       .addClasspath("./lib/common/*")
index 8150639c8659c874d7938ea371b764eefc7bbca7..2d9613a17cd03cc2f5e16f43ce2aadc03d179da5 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.process.monitor.JavaCommand;
 import org.sonar.process.monitor.Monitor;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
@@ -109,6 +110,21 @@ public class AppTest {
     assertThat(argument.getValue().get(1).getClasspath()).contains("oracle/ojdbc6.jar");
   }
 
+  @Test
+  public void sets_TMPDIR_env_var_of_Web_process() throws Exception {
+    Monitor monitor = mock(Monitor.class);
+    App app = new App(monitor);
+    Props props = initDefaultProps();
+    String expectedTmpDir = "expected tmp dir";
+    props.set("sonar.path.temp", expectedTmpDir);
+    app.start(props);
+
+    ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor();
+    verify(monitor).start(argument.capture());
+
+    assertThat(argument.getValue().get(1).getEnvVariables()).contains(entry("TMPDIR", expectedTmpDir));
+  }
+
   private Props initDefaultProps() throws IOException {
     Props props = new Props(new Properties());
     ProcessProperties.completeDefaults(props);