final int port;
final String workDir;
+ final String javaOpts;
final String className;
final String[] classPath;
final Map<String, String> properties;
final ProcessMXBean processMXBean;
public ProcessWrapper(String workDir, String className, Map<String, String> properties, final String name, String... classPath) {
+ this(workDir, null, className, properties, name, className);
+ LOGGER.warn("Creating process '{}' with no JAVA_OPTS", name);
+ }
+
+ public ProcessWrapper(String workDir, String javaOpts, String className, Map<String, String> properties, final String name, String... classPath) {
super(name);
this.port = NetworkUtils.freePort();
LOGGER.info("Creating Process for '{}' with workDir: '{}' and monitoring port: {}", name, workDir, port);
this.workDir = workDir;
+ this.javaOpts = javaOpts;
this.className = className;
this.classPath = classPath;
this.properties = properties;
+ separator + "bin" + separator + "java";
}
- private String getJavaOptions() {
- if (properties.containsKey(Process.JAVA_OPS)) {
- return properties.get(Process.JAVA_OPS);
- } else {
- return null;
- }
- }
-
private List<String> getJMXOptions() {
return ImmutableList.<String>of(
"-Dcom.sun.management.jmxremote",
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command().add(getJavaCommand());
- String javaOptions = getJavaOptions();
- if (!StringUtils.isEmpty(javaOptions)) {
- processBuilder.command().add(getJavaOptions());
+ if (!StringUtils.isEmpty(javaOpts)) {
+ processBuilder.command().add(javaOpts);
}
processBuilder.command().addAll(getJMXOptions());
processBuilder.command().addAll(getClassPath());
processBuilder.command().add(className);
processBuilder.command().add(getPropertyFile());
- //TODO remove once Process uses the temp file generated by getPropertyFile();
- processBuilder.environment().putAll(properties);
-
- processBuilder.environment().put(Process.SONAR_HOME, workDir);
- processBuilder.environment().put(Process.NAME_PROPERTY, this.getName());
- processBuilder.environment().put(Process.PORT_PROPERTY, Integer.toString(port));
-
//check that working directory exists.
File workDirectory = new File(workDir);
if (!workDirectory.exists()) {
import org.sonar.process.ProcessWrapper;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
public final class StartServer {
private ProcessWrapper elasticsearch;
private ProcessWrapper sonarqube;
- public StartServer(Env env, String... args) throws IOException {
+ public StartServer(Env env, String... args) throws IOException, InterruptedException {
this.env = env;
this.esPort = Integer.toString(NetworkUtils.freePort());
this.properties = new HashMap<String, String>();
shutdownHook = new Thread(new Runnable() {
@Override
public void run() {
- System.out.println("Before");
stop();
- System.out.println("After");
}
});
public void start() {
+ //Loading properties from sonar.properties file
+ Properties sonarProperties = new Properties();
+ try {
+ sonarProperties.load(new FileReader(env.getConfFile()));
+ } catch (IOException e) {
+ throw new IllegalStateException("Could not read properties from env", e);
+ }
+
String workingDirectory = env.rootDir().getAbsolutePath();
// Start ES
elasticsearch = new ProcessWrapper(
env.rootDir().getAbsolutePath(),
+ sonarProperties.getProperty("sonar.es.java_opts"),
"org.sonar.search.ElasticSearch",
ImmutableMap.of(
"esDebug", properties.containsKey("esDebug") ? properties.get("esDebug") : "false",