]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5410 - Added SQ as a wrapped process in sonar-start
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 07:40:54 +0000 (09:40 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 07:40:54 +0000 (09:40 +0200)
sonar-start/src/main/java/org/sonar/start/StartServer.java

index 3062343c563696929e187fcbd72fbc8f2d9d0ac4..a48745f30ded852d7927722674967924b94d3733 100644 (file)
@@ -38,41 +38,29 @@ public final class StartServer {
   private final static Logger LOGGER = LoggerFactory.getLogger(StartServer.class);
 
   private final Env env;
+  private final ExecutorService executor;
+  private final MonitorService monitor;
+  private final String esPort;
 
-  public StartServer(Env env) {
-    this.env = env;
-  }
-
-  private DatagramSocket systemAvailableSocket() throws IOException {
-    return new DatagramSocket(0);
-  }
+  private ProcessWrapper elasticsearch;
+  private ProcessWrapper sonarqube;
 
-  public void start() throws IOException {
-
-    final ExecutorService executor = Executors.newFixedThreadPool(2);
-    final MonitorService monitor = new MonitorService(systemAvailableSocket());
-
-    final String esPort = Integer.toString(NetworkUtils.freePort());
-
-    //Create the processes
-    //final ProcessWrapper sonarQube = new ProcessWrapper("SQ", monitor);
-    final ProcessWrapper elasticsearch = new ProcessWrapper(
-      "org.sonar.search.ElasticSearch",
-      new String[]{env.rootDir().getAbsolutePath() + "/lib/search/sonar-search-4.5-SNAPSHOT.jar"},
-      ImmutableMap.of(
-        "esPort",esPort,
-        "esHome", env.rootDir().getAbsolutePath()),
-      "ES", monitor.getMonitoringPort());
-
-    //Register processes to monitor
-    monitor.register(elasticsearch);
+  public StartServer(Env env) throws IOException {
+    this.env = env;
+    this.executor = Executors.newFixedThreadPool(2);
+    this.monitor = new MonitorService(systemAvailableSocket());
+    this.esPort = Integer.toString(NetworkUtils.freePort());
 
     Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         LOGGER.info("Shutting down sonar Node");
-        //sonarQube.shutdown();
-        elasticsearch.shutdown();
+        if (elasticsearch != null) {
+          elasticsearch.shutdown();
+        }
+        if (sonarqube != null) {
+          sonarqube.shutdown();
+        }
         executor.shutdown();
         try {
           executor.awaitTermination(10L, TimeUnit.SECONDS);
@@ -81,11 +69,19 @@ public final class StartServer {
         }
       }
     });
+  }
 
-    // Start our processes
-    LOGGER.info("Starting Child processes...");
-    executor.submit(elasticsearch);
-    //executor.submit(sonarQube);
+  private DatagramSocket systemAvailableSocket() throws IOException {
+    return new DatagramSocket(0);
+  }
+
+  public void start() {
+
+    // Start ES
+    this.startES();
+
+    // Start SQ
+    this.startSQ();
 
     // And monitor the activity
     monitor.run();
@@ -93,6 +89,38 @@ public final class StartServer {
 
     // If monitor is finished, we're done. Cleanup
     executor.shutdownNow();
+
+  }
+
+  private void registerProcess(ProcessWrapper process) {
+    //Register processes to monitor
+    monitor.register(process);
+
+    // Start our processes
+    LOGGER.info("Starting Child processes...");
+    executor.submit(process);
+  }
+
+  private void startSQ() {
+    sonarqube = new ProcessWrapper(
+      "org.sonar.application.StartServer",
+      new String[]{env.rootDir().getAbsolutePath() + "/lib/server/sonar-application-4.5-SNAPSHOT.jar"},
+      ImmutableMap.of("test", "test"),
+      "SQ", monitor.getMonitoringPort());
+
+    registerProcess(sonarqube);
+  }
+
+  private void startES() {
+    elasticsearch = new ProcessWrapper(
+      "org.sonar.search.ElasticSearch",
+      new String[]{env.rootDir().getAbsolutePath() + "/lib/search/sonar-search-4.5-SNAPSHOT.jar"},
+      ImmutableMap.of(
+        "esPort", esPort,
+        "esHome", env.rootDir().getAbsolutePath()),
+      "ES", monitor.getMonitoringPort());
+
+    registerProcess(elasticsearch);
   }
 
   public static void main(String... args) throws InterruptedException, IOException, URISyntaxException {