]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4898 - Can run in install dir with spaces in path.
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 12 Aug 2014 12:25:26 +0000 (14:25 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 12 Aug 2014 12:25:50 +0000 (14:25 +0200)
server/process/sonar-dummy-app/pom.xml
server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkApp.java [deleted file]
server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java [new file with mode: 0644]
server/process/sonar-process-test/src/test/java/org/sonar/application/ProcessWrapperTest.java
server/process/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
sonar-application/src/main/java/org/sonar/application/App.java

index 4829cd17693b9b8061e7615b786e6ca9301dd1a4..ded06395f6efaa513afc77b61ff467d886f01b0a 100644 (file)
@@ -69,7 +69,7 @@
           <archive>
             <manifest>
               <addClasspath>false</addClasspath>
-              <mainClass>org.sonar.application.DummyOkApp</mainClass>
+              <mainClass>org.sonar.application.DummyOkProcess</mainClass>
             </manifest>
           </archive>
         </configuration>
diff --git a/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkApp.java b/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkApp.java
deleted file mode 100644 (file)
index 7492547..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.application;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.process.MonitoredProcess;
-import org.sonar.process.Props;
-
-import java.util.Properties;
-
-public class DummyOkApp extends MonitoredProcess {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DummyOkApp.class);
-
-  private boolean isReady = false;
-  private boolean isRunning = true;
-
-  protected DummyOkApp(Props props) throws Exception {
-    super(props);
-  }
-
-  @Override
-  protected void doStart() {
-    isReady = true;
-    LOGGER.info("Starting Dummy OK Process");
-    while (isRunning) {
-      try {
-        Thread.sleep(100);
-      } catch (InterruptedException e) {
-        isRunning = false;
-      }
-    }
-  }
-
-  @Override
-  protected void doTerminate() {
-    LOGGER.info("Terminating Dummy OK Process");
-    this.isRunning = false;
-  }
-
-  @Override
-  protected boolean doIsReady() {
-    return isReady;
-  }
-
-  public static void main(String[] args) throws Exception {
-    Props props = new Props(new Properties());
-    props.set(MonitoredProcess.NAME_PROPERTY, DummyOkApp.class.getSimpleName());
-    new DummyOkApp(props).start();
-    System.exit(1);
-  }
-}
diff --git a/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java b/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java
new file mode 100644 (file)
index 0000000..10b95d8
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.application;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.process.MonitoredProcess;
+import org.sonar.process.Props;
+
+import java.io.File;
+import java.util.Properties;
+
+public class DummyOkProcess extends MonitoredProcess {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DummyOkProcess.class);
+
+  private boolean isReady = false;
+  private boolean isRunning = true;
+
+  protected DummyOkProcess(Props props) throws Exception {
+    super(props);
+    File temp = File.createTempFile("hello", ".tmp");
+
+  }
+
+  @Override
+  protected void doStart() {
+    isReady = true;
+    LOGGER.info("Starting Dummy OK Process");
+    while (isRunning) {
+      try {
+        Thread.sleep(100);
+      } catch (InterruptedException e) {
+        isRunning = false;
+      }
+    }
+  }
+
+  @Override
+  protected void doTerminate() {
+    LOGGER.info("Terminating Dummy OK Process");
+    this.isRunning = false;
+  }
+
+  @Override
+  protected boolean doIsReady() {
+    return isReady;
+  }
+
+  public static void main(String[] args) throws Exception {
+    Props props = new Props(new Properties());
+    props.set(MonitoredProcess.NAME_PROPERTY, DummyOkProcess.class.getSimpleName());
+    new DummyOkProcess(props).start();
+    System.exit(1);
+  }
+}
index 1555df9ae8d0dfddaea96901d1a97d256126dca7..760b964cf67ff2a60467f560659b3acea3866cf3 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.application;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -27,10 +28,12 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.process.MonitoredProcess;
 import org.sonar.process.ProcessWrapper;
+import org.sonar.process.Props;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.ServerSocket;
+import java.util.Properties;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
@@ -41,7 +44,7 @@ public class ProcessWrapperTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private static final String DUMMY_OK_APP = "org.sonar.application.DummyOkApp";
+  private static final String DUMMY_OK_APP = "org.sonar.application.DummyOkProcess";
 
   int freePort;
   File dummyAppJar;
@@ -92,10 +95,11 @@ public class ProcessWrapperTest {
   @Test
   public void execute_dummy_app() throws Exception {
 
-    ProcessWrapper process = new ProcessWrapper("DummyOkApp")
-      .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkApp")
+    ProcessWrapper process = new ProcessWrapper("DummyOkProcess")
+      .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkProcess")
       .addClasspath(dummyAppJar.getAbsolutePath())
       .setWorkDir(temp.getRoot())
+      .setTempDirectory(temp.getRoot())
       .setJmxPort(freePort)
       .setClassName(DUMMY_OK_APP);
 
@@ -113,4 +117,36 @@ public class ProcessWrapperTest {
 
     }
   }
+
+
+  @Test
+  public void execute_dummy_in_space_folder_app() throws Exception {
+
+    // 0 create a home with space...
+    File home = temp.newFolder("t est");
+    assertThat(home.canWrite()).isTrue();
+    File lib = new File(home, "lib");
+    File tempdir = new File(home, "temp");
+    FileUtils.copyFileToDirectory(dummyAppJar, lib);
+
+    // 1 Create Properties
+    Props props = new Props(new Properties());
+    props.set("spaceHome", home.getAbsolutePath());
+
+    // 3 start dummy app
+    File effectiveHome = props.fileOf("spaceHome");
+
+    String cp = FilenameUtils.concat(new File(effectiveHome, "lib").getAbsolutePath(), "*");
+    System.out.println("cp = " + cp);
+    ProcessWrapper process = new ProcessWrapper("DummyOkProcess")
+      .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkProcess")
+      .setTempDirectory(tempdir)
+      .addClasspath(cp)
+      .setWorkDir(home)
+      .setJmxPort(freePort)
+      .setClassName(DUMMY_OK_APP);
+
+    assertThat(process.isAlive()).isFalse();
+    assertCanStart(process);
+  }
 }
\ No newline at end of file
index e4324a2c94671ca1d68b42d7b73b1ae9509f5115..5ed52d9da8009064c1868b68116d45ae3571b06e 100644 (file)
@@ -118,6 +118,17 @@ public class ProcessWrapper extends Thread implements Terminable {
     return this;
   }
 
+  public ProcessWrapper setTempDirectory(File tempDirectory) {
+    this.setEnvProperty("java.io.tmpdir", tempDirectory.getAbsolutePath());
+    return this;
+  }
+
+  public ProcessWrapper setLogDir(File logDirectory) {
+    this.setEnvProperty("sonar.path.logs",logDirectory.getAbsolutePath());
+    return this;
+  }
+
+
   @CheckForNull
   public Process process() {
     return process;
@@ -195,8 +206,8 @@ public class ProcessWrapper extends Thread implements Terminable {
 
   private String buildJavaCommand() {
     String separator = System.getProperty("file.separator");
-    return System.getProperty("java.home")
-      + separator + "bin" + separator + "java";
+    return new File(new File(System.getProperty("java.home")),
+      "bin" + separator + "java").getAbsolutePath();
   }
 
   private List<String> buildJMXOptions() throws Exception {
index 3bdcf63a21d09aa01fbec33575434057881f4742..fb8941d71b603615fb736c9de8e74300c18cc840 100644 (file)
@@ -56,16 +56,16 @@ public class App implements ProcessMXBean {
       monitor.start();
 
       File homeDir = props.fileOf("sonar.path.home");
-      String tempDir = props.of("sonar.path.temp");
+      File tempDir = props.fileOf("sonar.path.temp");
       elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME)
         .setWorkDir(homeDir)
         .setJmxPort(props.intOf(DefaultSettings.SEARCH_JMX_PORT))
         .addJavaOpts(props.of(DefaultSettings.SEARCH_JAVA_OPTS))
-        .addJavaOpts(String.format("-Djava.io.tmpdir=%s", tempDir))
+        .setTempDirectory(tempDir.getAbsoluteFile())
         .setClassName("org.sonar.search.SearchServer")
         .addProperties(props.rawProperties())
-        .addClasspath(starPath(homeDir, "lib/common"))
-        .addClasspath(starPath(homeDir, "lib/search"));
+        .addClasspath("./lib/common/*")
+        .addClasspath("./lib/search/*");
       if (elasticsearch.execute()) {
         monitor.registerProcess(elasticsearch);
         if (elasticsearch.waitForReady()) {
@@ -77,13 +77,13 @@ public class App implements ProcessMXBean {
               .setWorkDir(homeDir)
               .setJmxPort(props.intOf(DefaultSettings.WEB_JMX_PORT))
               .addJavaOpts(props.of(DefaultSettings.WEB_JAVA_OPTS))
-              .addJavaOpts(String.format("-Djava.io.tmpdir=%s", tempDir))
+              .setTempDirectory(tempDir.getAbsoluteFile())
               // required for logback tomcat valve
-              .addJavaOpts(String.format("-Dsonar.path.logs=%s", props.of("sonar.path.logs")))
+              .setLogDir(props.fileOf("sonar.path.logs"))
               .setClassName("org.sonar.server.app.WebServer")
               .addProperties(props.rawProperties())
-              .addClasspath(starPath(homeDir, "lib/common"))
-              .addClasspath(starPath(homeDir, "lib/server"));
+              .addClasspath("./lib/common/*")
+              .addClasspath("./lib/server/*");
             String driverPath = props.of(JdbcSettings.PROPERTY_DRIVER_PATH);
             if (driverPath != null) {
               server.addClasspath(driverPath);