]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SQSCANNER-10 Display correct version in logs and update labels
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 13 Jan 2016 09:48:39 +0000 (10:48 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 13 Jan 2016 09:48:39 +0000 (10:48 +0100)
pom.xml
src/main/java/org/sonarsource/scanner/cli/Conf.java
src/main/java/org/sonarsource/scanner/cli/Main.java
src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java [new file with mode: 0644]
src/main/java/org/sonarsource/scanner/cli/SystemInfo.java
src/main/resources/version.txt [new file with mode: 0644]
src/test/java/org/sonarsource/scanner/cli/MainTest.java
src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java

diff --git a/pom.xml b/pom.xml
index 3c80dd2ee9e28700a2c3008c8079863c60001c1f..9b7c41c573e56729842638493805097841577682 100644 (file)
--- a/pom.xml
+++ b/pom.xml
   </dependencies>
 
   <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
index c1e94870ffbd576defda3ec34cc8eb9e04d1937b..7746ee82db3136d1ac30b70071b8cf2734870a9d 100644 (file)
@@ -61,10 +61,10 @@ class Conf {
   private Properties loadGlobalProperties() throws IOException {
     File settingsFile = locatePropertiesFile(cli.properties(), RUNNER_HOME, "conf/sonar-runner.properties", RUNNER_SETTINGS);
     if (settingsFile != null && settingsFile.isFile() && settingsFile.exists()) {
-      logger.info("Runner configuration file: " + settingsFile.getAbsolutePath());
+      logger.info("Scanner configuration file: " + settingsFile.getAbsolutePath());
       return toProperties(settingsFile);
     }
-    logger.info("Runner configuration file: NONE");
+    logger.info("Scanner configuration file: NONE");
     return new Properties();
   }
 
index 6a617dd73f96ebce67e7e0790fedabd61c0badd6..a4b2526c823eb6cef87cba914723330dd68c644f 100644 (file)
@@ -81,7 +81,7 @@ public class Main {
       }
     } catch (Exception e) {
       displayExecutionResult(stats, "FAILURE");
-      showError("Error during Sonar runner execution", e, cli.isDisplayStackTrace());
+      showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace());
       shutdown.exit(Exit.ERROR);
     }
 
@@ -96,7 +96,7 @@ public class Main {
         runAnalysis(stats, p);
       } catch (Exception e) {
         displayExecutionResult(stats, "FAILURE");
-        showError("Error during Sonar runner execution", e, cli.isDisplayStackTrace());
+        showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace());
       }
     } while (waitForUser());
   }
@@ -171,7 +171,7 @@ public class Main {
         }
       }
       logger.error("");
-      logger.error("To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.");
+      logger.error("To see the full stack trace of the errors, re-run SonarQube Scanner with the -e switch.");
       if (!cli.isDebugMode()) {
         suggestDebugMode();
       }
@@ -179,7 +179,7 @@ public class Main {
   }
 
   private void suggestDebugMode() {
-    logger.error("Re-run SonarQube Runner using the -X switch to enable full debug logging.");
+    logger.error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
   }
 
 }
diff --git a/src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java b/src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java
new file mode 100644 (file)
index 0000000..18cf7e5
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube Scanner
+ * Copyright (C) 2011-2016 SonarSource SA
+ * mailto:contact 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.sonarsource.scanner.cli;
+
+import java.util.Scanner;
+
+public enum ScannerVersion {
+
+  INSTANCE;
+
+  private String version;
+
+  private ScannerVersion() {
+    Scanner scanner = new Scanner(getClass().getResourceAsStream("/version.txt"), "UTF-8");
+    try {
+      this.version = scanner.next();
+    } finally {
+      scanner.close();
+    }
+  }
+
+  public static String version() {
+    return INSTANCE.version;
+  }
+
+}
index 382529a45dc116133dcbe06a76ba1848ce1f7cd3..dadde0d7996eed5211f65771065aea81cac3caaa 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonarsource.scanner.cli;
 
-import org.sonar.runner.api.RunnerVersion;
-
 class SystemInfo {
   private static System2 system = new System2();
 
@@ -32,7 +30,7 @@ class SystemInfo {
   }
 
   static void print(Logs logger) {
-    logger.info("SonarQube Runner " + RunnerVersion.version());
+    logger.info("SonarQube Scanner " + ScannerVersion.version());
     logger.info(java());
     logger.info(os());
     String runnerOpts = system.getenv("SONAR_RUNNER_OPTS");
diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt
new file mode 100644 (file)
index 0000000..f2ab45c
--- /dev/null
@@ -0,0 +1 @@
+${project.version}
\ No newline at end of file
index 05afccf04eeaceeb9fa2a204b9241ddf8e2753cf..8e9cdf3a56fd435a5040f2cf7cc9d45f57d8dc09 100644 (file)
@@ -32,13 +32,6 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.sonar.runner.api.EmbeddedRunner;
-import org.sonarsource.scanner.cli.Cli;
-import org.sonarsource.scanner.cli.Conf;
-import org.sonarsource.scanner.cli.Exit;
-import org.sonarsource.scanner.cli.Logs;
-import org.sonarsource.scanner.cli.Main;
-import org.sonarsource.scanner.cli.RunnerFactory;
-import org.sonarsource.scanner.cli.Shutdown;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
@@ -117,7 +110,7 @@ public class MainTest {
 
     verify(runner).stop();
     verify(shutdown).exit(Exit.ERROR);
-    verify(logs).error("Error during Sonar runner execution", e);
+    verify(logs).error("Error during SonarQube Scanner execution", e);
   }
 
   @Test
index f8e57a81f49b243bafdf561b6f144e57f1cfa1bd..0c1fa8fa31d5e1cb7be688ed0c1e50d7a836ea0b 100644 (file)
  */
 package org.sonarsource.scanner.cli;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
-
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.sonar.runner.api.RunnerVersion;
-import org.sonarsource.scanner.cli.Logs;
-import org.sonarsource.scanner.cli.SystemInfo;
-import org.sonarsource.scanner.cli.SystemInfo.System2;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonarsource.scanner.cli.SystemInfo.System2;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
 
 public class SystemInfoTest {
   System2 mockSystem;
@@ -88,7 +84,8 @@ public class SystemInfoTest {
     verify(mockSystem).getProperty("os.version");
     verify(mockSystem).getenv("SONAR_RUNNER_OPTS");
 
-    verify(logs).info("SonarQube Runner " + RunnerVersion.version());
+    verify(logs, never()).info("SonarQube Scanner null");
+    verify(logs).info("SonarQube Scanner " + ScannerVersion.version());
     verify(logs).info("Java 1.9 oracle (64-bit)");
     verify(logs).info("linux 2.5 x64");
     verify(logs).info("SONAR_RUNNER_OPTS=arg");