]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 5 Apr 2013 21:41:50 +0000 (23:41 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 5 Apr 2013 21:41:50 +0000 (23:41 +0200)
sonar-runner-api/src/main/java/org/sonar/runner/api/CommandExecutor.java
sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerVersion.java

index 4c87cfe49c842a6bdb00e804f3a4fdec2b9fa1b6..2f07c3c49ff886c7e90278ba3d77cb3150a86fab 100644 (file)
@@ -52,9 +52,7 @@ class CommandExecutor {
     StreamGobbler errorGobbler = null;
     try {
       ProcessBuilder builder = new ProcessBuilder(command.toStrings());
-      if (command.directory() != null) {
-        builder.directory(command.directory());
-      }
+      builder.directory(command.directory());
       builder.environment().putAll(command.envVariables());
       process = builder.start();
 
@@ -63,13 +61,8 @@ class CommandExecutor {
       outputGobbler.start();
       errorGobbler.start();
 
-      final Process finalProcess = process;
       executorService = Executors.newSingleThreadExecutor();
-      Future<Integer> ft = executorService.submit(new Callable<Integer>() {
-        public Integer call() throws Exception {
-          return finalProcess.waitFor();
-        }
-      });
+      Future<Integer> ft = executeProcess(executorService, process);
       int exitCode = ft.get(timeoutMilliseconds, TimeUnit.MILLISECONDS);
       waitUntilFinish(outputGobbler);
       waitUntilFinish(errorGobbler);
@@ -91,13 +84,21 @@ class CommandExecutor {
       waitUntilFinish(outputGobbler);
       waitUntilFinish(errorGobbler);
       closeStreams(process);
-
       if (executorService != null) {
         executorService.shutdown();
       }
     }
   }
 
+  private Future<Integer> executeProcess(ExecutorService executorService, Process process) {
+    final Process finalProcess = process;
+    return executorService.submit(new Callable<Integer>() {
+      public Integer call() throws InterruptedException {
+        return finalProcess.waitFor();
+      }
+    });
+  }
+
   private void verifyGobbler(Command command, StreamGobbler gobbler, String type) {
     if (gobbler.getException() != null) {
       throw new CommandException("Error inside " + type + " stream", command, gobbler.getException());
index 76ed83674391dde54cfb0ecf92af1ac2bdc847d1..b93a39f233b185a1449227a7132d0d6c4afbfd8f 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.runner.api;
 
+import org.apache.commons.io.IOUtils;
+
 import java.util.Scanner;
 
 /**
@@ -40,7 +42,7 @@ public enum RunnerVersion {
     try {
       this.version = scanner.next();
     } finally {
-      scanner.close();
+      IOUtils.closeQuietly(scanner);
     }
   }
 }