<archive>
<manifest>
<addClasspath>false</addClasspath>
- <mainClass>org.sonar.application.DummyOkApp</mainClass>
+ <mainClass>org.sonar.application.DummyOkProcess</mainClass>
</manifest>
</archive>
</configuration>
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
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;
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;
@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;
@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);
}
}
+
+
+ @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
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;
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 {
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()) {
.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);