]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 rename JavaCommandFactory to CommandFactory
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 18 Jul 2017 14:13:23 +0000 (16:13 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/application/SchedulerImpl.java
server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactory.java [new file with mode: 0644]
server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java [new file with mode: 0644]
server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactory.java [deleted file]
server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactoryImpl.java [deleted file]
server/sonar-process-monitor/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java
server/sonar-process-monitor/src/test/java/org/sonar/application/SchedulerImplTest.java
sonar-application/src/main/java/org/sonar/application/App.java

index 4446f268e360ee7a3b5291a2813f4ee695316412..d958deee9e59a475c1c281c46e4457b78629d10b 100644 (file)
@@ -30,8 +30,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.application.config.AppSettings;
 import org.sonar.application.config.ClusterSettings;
+import org.sonar.application.process.CommandFactory;
 import org.sonar.application.process.JavaCommand;
-import org.sonar.application.process.JavaCommandFactory;
 import org.sonar.application.process.ProcessLauncher;
 import org.sonar.application.process.Lifecycle;
 import org.sonar.application.process.ProcessEventListener;
@@ -45,7 +45,7 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi
 
   private final AppSettings settings;
   private final AppReloader appReloader;
-  private final JavaCommandFactory javaCommandFactory;
+  private final CommandFactory commandFactory;
   private final ProcessLauncher processLauncher;
   private final AppState appState;
   private final NodeLifecycle nodeLifecycle = new NodeLifecycle();
@@ -60,12 +60,12 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi
   private RestarterThread restarterThread;
   private long processWatcherDelayMs = SQProcess.DEFAULT_WATCHER_DELAY_MS;
 
-  public SchedulerImpl(AppSettings settings, AppReloader appReloader, JavaCommandFactory javaCommandFactory,
+  public SchedulerImpl(AppSettings settings, AppReloader appReloader, CommandFactory commandFactory,
     ProcessLauncher processLauncher,
     AppState appState) {
     this.settings = settings;
     this.appReloader = appReloader;
-    this.javaCommandFactory = javaCommandFactory;
+    this.commandFactory = commandFactory;
     this.processLauncher = processLauncher;
     this.appState = appState;
     this.appState.addListener(this);
@@ -105,7 +105,7 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi
   private void tryToStartEs() {
     SQProcess process = processesById.get(ProcessId.ELASTICSEARCH);
     if (process != null) {
-      tryToStartProcess(process, javaCommandFactory::createEsCommand);
+      tryToStartProcess(process, commandFactory::createEsCommand);
     }
   }
 
@@ -115,9 +115,9 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi
       return;
     }
     if (appState.isOperational(ProcessId.WEB_SERVER, false)) {
-      tryToStartProcess(process, () -> javaCommandFactory.createWebCommand(false));
+      tryToStartProcess(process, () -> commandFactory.createWebCommand(false));
     } else if (appState.tryToLockWebLeader()) {
-      tryToStartProcess(process, () -> javaCommandFactory.createWebCommand(true));
+      tryToStartProcess(process, () -> commandFactory.createWebCommand(true));
     } else {
       Optional<String> leader = appState.getLeaderHostName();
       if (leader.isPresent()) {
@@ -131,7 +131,7 @@ public class SchedulerImpl implements Scheduler, ProcessEventListener, ProcessLi
   private void tryToStartCe() {
     SQProcess process = processesById.get(ProcessId.COMPUTE_ENGINE);
     if (process != null && appState.isOperational(ProcessId.WEB_SERVER, false) && isEsClientStartable()) {
-      tryToStartProcess(process, javaCommandFactory::createCeCommand);
+      tryToStartProcess(process, commandFactory::createCeCommand);
     }
   }
 
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactory.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactory.java
new file mode 100644 (file)
index 0000000..6091fb9
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.process;
+
+public interface CommandFactory {
+
+  JavaCommand createEsCommand();
+
+  JavaCommand createWebCommand(boolean leader);
+
+  JavaCommand createCeCommand();
+
+}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/CommandFactoryImpl.java
new file mode 100644 (file)
index 0000000..e41304f
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.process;
+
+import org.sonar.application.config.AppSettings;
+import org.sonar.process.ProcessId;
+import org.sonar.process.ProcessProperties;
+
+import java.io.File;
+import java.util.Optional;
+
+import static org.sonar.process.ProcessProperties.*;
+
+public class CommandFactoryImpl implements CommandFactory {
+  /**
+   * Properties about proxy that must be set as system properties
+   */
+  private static final String[] PROXY_PROPERTY_KEYS = new String[] {
+    HTTP_PROXY_HOST,
+    HTTP_PROXY_PORT,
+    "http.nonProxyHosts",
+    HTTPS_PROXY_HOST,
+    HTTPS_PROXY_PORT,
+    "http.auth.ntlm.domain",
+    "socksProxyHost",
+    "socksProxyPort"};
+
+  private final AppSettings settings;
+
+  public CommandFactoryImpl(AppSettings settings) {
+    this.settings = settings;
+  }
+
+  @Override
+  public JavaCommand createEsCommand() {
+    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
+    return newJavaCommand(ProcessId.ELASTICSEARCH, homeDir)
+      .addJavaOptions("-Djava.awt.headless=true")
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS))
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS))
+      .setClassName("org.sonar.search.SearchServer")
+      .addClasspath("./lib/common/*")
+      .addClasspath("./lib/search/*");
+  }
+
+  @Override
+  public JavaCommand createWebCommand(boolean leader) {
+    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
+    JavaCommand command = newJavaCommand(ProcessId.WEB_SERVER, homeDir)
+      .addJavaOptions(ProcessProperties.WEB_ENFORCED_JVM_ARGS)
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.WEB_JAVA_OPTS))
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS))
+      // required for logback tomcat valve
+      .setEnvVariable(ProcessProperties.PATH_LOGS, settings.getProps().nonNullValue(ProcessProperties.PATH_LOGS))
+      .setArgument("sonar.cluster.web.startupLeader", Boolean.toString(leader))
+      .setClassName("org.sonar.server.app.WebServer")
+      .addClasspath("./lib/common/*")
+      .addClasspath("./lib/server/*");
+    String driverPath = settings.getProps().value(ProcessProperties.JDBC_DRIVER_PATH);
+    if (driverPath != null) {
+      command.addClasspath(driverPath);
+    }
+    return command;
+  }
+
+  @Override
+  public JavaCommand createCeCommand() {
+    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
+    JavaCommand command = newJavaCommand(ProcessId.COMPUTE_ENGINE, homeDir)
+      .addJavaOptions(ProcessProperties.CE_ENFORCED_JVM_ARGS)
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.CE_JAVA_OPTS))
+      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.CE_JAVA_ADDITIONAL_OPTS))
+      .setClassName("org.sonar.ce.app.CeServer")
+      .addClasspath("./lib/common/*")
+      .addClasspath("./lib/server/*")
+      .addClasspath("./lib/ce/*");
+    String driverPath = settings.getProps().value(ProcessProperties.JDBC_DRIVER_PATH);
+    if (driverPath != null) {
+      command.addClasspath(driverPath);
+    }
+    return command;
+  }
+
+  private JavaCommand newJavaCommand(ProcessId id, File homeDir) {
+    JavaCommand command = new JavaCommand(id)
+      .setWorkDir(homeDir)
+      .setArguments(settings.getProps().rawProperties());
+
+    for (String key : PROXY_PROPERTY_KEYS) {
+      settings.getValue(key).ifPresent(val -> command.addJavaOption("-D" + key + "=" + val));
+    }
+
+    // defaults of HTTPS are the same than HTTP defaults
+    setSystemPropertyToDefaultIfNotSet(command, HTTPS_PROXY_HOST, HTTP_PROXY_HOST);
+    setSystemPropertyToDefaultIfNotSet(command, HTTPS_PROXY_PORT, HTTP_PROXY_PORT);
+    return command;
+  }
+
+  private void setSystemPropertyToDefaultIfNotSet(JavaCommand command,
+    String httpsProperty, String httpProperty) {
+    Optional<String> httpValue = settings.getValue(httpProperty);
+    Optional<String> httpsValue = settings.getValue(httpsProperty);
+    if (!httpsValue.isPresent() && httpValue.isPresent()) {
+      command.addJavaOption("-D" + httpsProperty + "=" + httpValue.get());
+    }
+  }
+}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactory.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactory.java
deleted file mode 100644 (file)
index 9d56f2c..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.process;
-
-public interface JavaCommandFactory {
-
-  JavaCommand createEsCommand();
-
-  JavaCommand createWebCommand(boolean leader);
-
-  JavaCommand createCeCommand();
-
-}
diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactoryImpl.java b/server/sonar-process-monitor/src/main/java/org/sonar/application/process/JavaCommandFactoryImpl.java
deleted file mode 100644 (file)
index 86f4fd8..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.process;
-
-import org.sonar.application.config.AppSettings;
-import org.sonar.process.ProcessId;
-import org.sonar.process.ProcessProperties;
-
-import java.io.File;
-import java.util.Optional;
-
-import static org.sonar.process.ProcessProperties.*;
-
-public class JavaCommandFactoryImpl implements JavaCommandFactory {
-  /**
-   * Properties about proxy that must be set as system properties
-   */
-  private static final String[] PROXY_PROPERTY_KEYS = new String[] {
-    HTTP_PROXY_HOST,
-    HTTP_PROXY_PORT,
-    "http.nonProxyHosts",
-    HTTPS_PROXY_HOST,
-    HTTPS_PROXY_PORT,
-    "http.auth.ntlm.domain",
-    "socksProxyHost",
-    "socksProxyPort"};
-
-  private final AppSettings settings;
-
-  public JavaCommandFactoryImpl(AppSettings settings) {
-    this.settings = settings;
-  }
-
-  @Override
-  public JavaCommand createEsCommand() {
-    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
-    return newJavaCommand(ProcessId.ELASTICSEARCH, homeDir)
-      .addJavaOptions("-Djava.awt.headless=true")
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS))
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS))
-      .setClassName("org.sonar.search.SearchServer")
-      .addClasspath("./lib/common/*")
-      .addClasspath("./lib/search/*");
-  }
-
-  @Override
-  public JavaCommand createWebCommand(boolean leader) {
-    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
-    JavaCommand command = newJavaCommand(ProcessId.WEB_SERVER, homeDir)
-      .addJavaOptions(ProcessProperties.WEB_ENFORCED_JVM_ARGS)
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.WEB_JAVA_OPTS))
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS))
-      // required for logback tomcat valve
-      .setEnvVariable(ProcessProperties.PATH_LOGS, settings.getProps().nonNullValue(ProcessProperties.PATH_LOGS))
-      .setArgument("sonar.cluster.web.startupLeader", Boolean.toString(leader))
-      .setClassName("org.sonar.server.app.WebServer")
-      .addClasspath("./lib/common/*")
-      .addClasspath("./lib/server/*");
-    String driverPath = settings.getProps().value(ProcessProperties.JDBC_DRIVER_PATH);
-    if (driverPath != null) {
-      command.addClasspath(driverPath);
-    }
-    return command;
-  }
-
-  @Override
-  public JavaCommand createCeCommand() {
-    File homeDir = settings.getProps().nonNullValueAsFile(ProcessProperties.PATH_HOME);
-    JavaCommand command = newJavaCommand(ProcessId.COMPUTE_ENGINE, homeDir)
-      .addJavaOptions(ProcessProperties.CE_ENFORCED_JVM_ARGS)
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.CE_JAVA_OPTS))
-      .addJavaOptions(settings.getProps().nonNullValue(ProcessProperties.CE_JAVA_ADDITIONAL_OPTS))
-      .setClassName("org.sonar.ce.app.CeServer")
-      .addClasspath("./lib/common/*")
-      .addClasspath("./lib/server/*")
-      .addClasspath("./lib/ce/*");
-    String driverPath = settings.getProps().value(ProcessProperties.JDBC_DRIVER_PATH);
-    if (driverPath != null) {
-      command.addClasspath(driverPath);
-    }
-    return command;
-  }
-
-  private JavaCommand newJavaCommand(ProcessId id, File homeDir) {
-    JavaCommand command = new JavaCommand(id)
-      .setWorkDir(homeDir)
-      .setArguments(settings.getProps().rawProperties());
-
-    for (String key : PROXY_PROPERTY_KEYS) {
-      settings.getValue(key).ifPresent(val -> command.addJavaOption("-D" + key + "=" + val));
-    }
-
-    // defaults of HTTPS are the same than HTTP defaults
-    setSystemPropertyToDefaultIfNotSet(command, HTTPS_PROXY_HOST, HTTP_PROXY_HOST);
-    setSystemPropertyToDefaultIfNotSet(command, HTTPS_PROXY_PORT, HTTP_PROXY_PORT);
-    return command;
-  }
-
-  private void setSystemPropertyToDefaultIfNotSet(JavaCommand command,
-    String httpsProperty, String httpProperty) {
-    Optional<String> httpValue = settings.getValue(httpProperty);
-    Optional<String> httpsValue = settings.getValue(httpsProperty);
-    if (!httpsValue.isPresent() && httpValue.isPresent()) {
-      command.addJavaOption("-D" + httpsProperty + "=" + httpValue.get());
-    }
-  }
-}
index 151fafacdf4335712d0893be34c40dab4ccc297c..c84bcfb5ad8fa03c45432942fd04561d96bc7a2a 100644 (file)
@@ -88,7 +88,7 @@ public class ProcessLauncherImpl implements ProcessLauncher {
     commands.add(buildJavaPath());
     commands.addAll(javaCommand.getJavaOptions());
     // TODO warning - does it work if temp dir contains a whitespace ?
-    // TODO move to JavaCommandFactory ?
+    // TODO move to CommandFactory ?
     commands.add(format("-Djava.io.tmpdir=%s", tempDir.getAbsolutePath()));
     commands.addAll(buildClasspath(javaCommand));
     commands.add(javaCommand.getClassName());
index 1727336da89f604ba1842a4714fa1eb855177c28..9ad38ac6e59f1d5c8516e65c8d3f4526b4a984a1 100644 (file)
@@ -35,8 +35,8 @@ import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.mockito.Mockito;
 import org.sonar.application.config.TestAppSettings;
+import org.sonar.application.process.CommandFactory;
 import org.sonar.application.process.JavaCommand;
-import org.sonar.application.process.JavaCommandFactory;
 import org.sonar.application.process.ProcessLauncher;
 import org.sonar.application.process.ProcessMonitor;
 import org.sonar.process.ProcessId;
@@ -66,7 +66,7 @@ public class SchedulerImplTest {
 
   private AppReloader appReloader = mock(AppReloader.class);
   private TestAppSettings settings = new TestAppSettings();
-  private TestJavaCommandFactory javaCommandFactory = new TestJavaCommandFactory();
+  private TestCommandFactory javaCommandFactory = new TestCommandFactory();
   private TestProcessLauncher processLauncher = new TestProcessLauncher();
   private TestAppState appState = new TestAppState();
   private List<ProcessId> orderedStops = synchronizedList(new ArrayList<>());
@@ -305,7 +305,7 @@ public class SchedulerImplTest {
     }
   }
 
-  private static class TestJavaCommandFactory implements JavaCommandFactory {
+  private static class TestCommandFactory implements CommandFactory {
     @Override
     public JavaCommand createEsCommand() {
       return ES_COMMAND;
index ae7881660453ef57430d3216e5cd489ed53d6611..69098a0a7560d3a2ad6b7c8842301b5bc8f31fc9 100644 (file)
@@ -23,8 +23,8 @@ import java.io.IOException;
 import org.sonar.application.config.AppSettings;
 import org.sonar.application.config.AppSettingsLoader;
 import org.sonar.application.config.AppSettingsLoaderImpl;
-import org.sonar.application.process.JavaCommandFactory;
-import org.sonar.application.process.JavaCommandFactoryImpl;
+import org.sonar.application.process.CommandFactory;
+import org.sonar.application.process.CommandFactoryImpl;
 import org.sonar.application.process.ProcessLauncher;
 import org.sonar.application.process.ProcessLauncherImpl;
 import org.sonar.application.process.StopRequestWatcher;
@@ -49,11 +49,11 @@ public class App {
     try (AppState appState = new AppStateFactory(settings).create()) {
       appState.registerSonarQubeVersion(getSonarqubeVersion());
       AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging);
-      JavaCommandFactory javaCommandFactory = new JavaCommandFactoryImpl(settings);
+      CommandFactory commandFactory = new CommandFactoryImpl(settings);
       fileSystem.reset();
 
       try (ProcessLauncher processLauncher = new ProcessLauncherImpl(fileSystem.getTempDir())) {
-        Scheduler scheduler = new SchedulerImpl(settings, appReloader, javaCommandFactory, processLauncher, appState);
+        Scheduler scheduler = new SchedulerImpl(settings, appReloader, commandFactory, processLauncher, appState);
 
         // intercepts CTRL-C
         Runtime.getRuntime().addShutdownHook(new ShutdownHook(scheduler));