]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Fix build on Java 6
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 5 Apr 2013 22:07:52 +0000 (00:07 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 5 Apr 2013 22:07:52 +0000 (00:07 +0200)
sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerVersion.java
sonar-runner-dist/src/main/java/org/sonar/runner/Main.java
sonar-runner-dist/src/main/java/org/sonar/runner/SystemInfo.java [new file with mode: 0644]
sonar-runner-dist/src/test/java/org/sonar/runner/SystemInfoTest.java [new file with mode: 0644]
sonar-runner-impl/src/main/java/org/sonar/runner/impl/ServerVersion.java

index b93a39f233b185a1449227a7132d0d6c4afbfd8f..61b356fd8af4034c3c26b8781e539ce7cd45c53f 100644 (file)
  */
 package org.sonar.runner.api;
 
-import org.apache.commons.io.IOUtils;
-
 import java.util.Scanner;
 
 /**
  * Version of this sonar-runner API.
+ *
  * @since 2.2
  */
 public enum RunnerVersion {
@@ -42,7 +41,7 @@ public enum RunnerVersion {
     try {
       this.version = scanner.next();
     } finally {
-      IOUtils.closeQuietly(scanner);
+      scanner.close();
     }
   }
 }
index 69022f3f430afb21b843ea3f2ccac1c9f231bb4c..8e3a83313a6862e094a613cceaf400feddca1ce0 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.runner;
 
 import org.sonar.runner.api.EmbeddedRunner;
-import org.sonar.runner.api.RunnerVersion;
 import org.sonar.runner.impl.Logs;
 
 import java.util.Properties;
@@ -51,19 +50,13 @@ public class Main {
   }
 
   void execute() {
-    printSystem();
+    SystemInfo.print();
     if (!cli.isDisplayVersionOnly()) {
       int status = doExecute(new Conf(cli));
       System.exit(status);
     }
   }
 
-  private void printSystem() {
-    System.out.println("Sonar Runner " + RunnerVersion.version());
-    System.out.println("Java " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")");
-    System.out.println(System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
-  }
-
   private int doExecute(Conf conf) {
     if (cli.isDisplayStackTrace()) {
       Logs.info("Error stacktraces are turned on.");
@@ -72,15 +65,8 @@ public class Main {
     try {
       Properties properties = conf.load();
       EmbeddedRunner.create().addProperties(properties).execute();
+     // Logs.info("Work directory: " + runner.getWorkDir().getCanonicalPath());
 
-//      Logs.debug("Other system properties:");
-//      Logs.debug("  - sun.arch.data.model: \"" + System.getProperty("sun.arch.data.model") + "\"");
-//      Logs.info("Server: " + runner.getSonarServerURL());
-//      try {
-//        Logs.info("Work directory: " + runner.getWorkDir().getCanonicalPath());
-//      } catch (IOException e) {
-//        throw new RunnerException("Unable to resolve directory", e);
-//      }
     } catch (Exception e) {
       displayExecutionResult(stats, "FAILURE");
       showError("Error during Sonar runner execution", e, cli.isDisplayStackTrace());
diff --git a/sonar-runner-dist/src/main/java/org/sonar/runner/SystemInfo.java b/sonar-runner-dist/src/main/java/org/sonar/runner/SystemInfo.java
new file mode 100644 (file)
index 0000000..c199d5b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Sonar Runner - Distribution
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * 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  02
+ */
+package org.sonar.runner;
+
+import org.sonar.runner.api.RunnerVersion;
+
+class SystemInfo {
+
+  static void print() {
+    System.out.println("Sonar Runner " + RunnerVersion.version());
+    System.out.println(java());
+    System.out.println(os());
+  }
+
+  static String java() {
+    StringBuilder sb = new StringBuilder();
+    sb
+        .append("Java ")
+        .append(System.getProperty("java.version"))
+        .append(" ")
+        .append(System.getProperty("java.vendor"));
+    String bits = System.getProperty("sun.arch.data.model");
+    if ("32".equals(bits) || "64".equals(bits)) {
+      sb.append(" (").append(bits).append("-bit)");
+    }
+    return sb.toString();
+  }
+
+  static String os() {
+    StringBuilder sb = new StringBuilder();
+    sb
+        .append(System.getProperty("os.name"))
+        .append(" ")
+        .append(System.getProperty("os.version"))
+        .append(" ")
+        .append(System.getProperty("os.arch"));
+    return sb.toString();
+  }
+}
diff --git a/sonar-runner-dist/src/test/java/org/sonar/runner/SystemInfoTest.java b/sonar-runner-dist/src/test/java/org/sonar/runner/SystemInfoTest.java
new file mode 100644 (file)
index 0000000..0e57284
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Sonar Runner - Distribution
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * 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  02
+ */
+package org.sonar.runner;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SystemInfoTest {
+  @Test
+  public void test_java() {
+    assertThat(SystemInfo.java()).matches("Java .* \\((32|64)-bit\\)");
+  }
+
+  @Test
+  public void test_os() {
+    assertThat(SystemInfo.os()).isNotEmpty();
+  }
+}
index b4db8a511793a42289940861c7a1c9b085758cb3..8f5af45d1c395679ab3d090d1c9ffd62f75f0128 100644 (file)
@@ -38,6 +38,7 @@ class ServerVersion {
     // Guava Suppliers#memoize() would be great here :D
     if (version == null) {
       version = downloadVersion();
+      Logs.info("Sonar Server " + version);
     }
     return version;
   }