From 0078dd22d4846868b808d83a2d53dad5676268f7 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 13 Jan 2016 10:48:39 +0100 Subject: [PATCH] SQSCANNER-10 Display correct version in logs and update labels --- pom.xml | 6 +++ .../org/sonarsource/scanner/cli/Conf.java | 4 +- .../org/sonarsource/scanner/cli/Main.java | 8 ++-- .../scanner/cli/ScannerVersion.java | 43 +++++++++++++++++++ .../sonarsource/scanner/cli/SystemInfo.java | 4 +- src/main/resources/version.txt | 1 + .../org/sonarsource/scanner/cli/MainTest.java | 9 +--- .../scanner/cli/SystemInfoTest.java | 19 ++++---- 8 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java create mode 100644 src/main/resources/version.txt diff --git a/pom.xml b/pom.xml index 3c80dd2..9b7c41c 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins diff --git a/src/main/java/org/sonarsource/scanner/cli/Conf.java b/src/main/java/org/sonarsource/scanner/cli/Conf.java index c1e9487..7746ee8 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Conf.java +++ b/src/main/java/org/sonarsource/scanner/cli/Conf.java @@ -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(); } diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index 6a617dd..a4b2526 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -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 index 0000000..18cf7e5 --- /dev/null +++ b/src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java @@ -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; + } + +} diff --git a/src/main/java/org/sonarsource/scanner/cli/SystemInfo.java b/src/main/java/org/sonarsource/scanner/cli/SystemInfo.java index 382529a..dadde0d 100644 --- a/src/main/java/org/sonarsource/scanner/cli/SystemInfo.java +++ b/src/main/java/org/sonarsource/scanner/cli/SystemInfo.java @@ -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 index 0000000..f2ab45c --- /dev/null +++ b/src/main/resources/version.txt @@ -0,0 +1 @@ +${project.version} \ No newline at end of file diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java index 05afccf..8e9cdf3 100644 --- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java @@ -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 diff --git a/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java b/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java index f8e57a8..0c1fa8f 100644 --- a/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java @@ -19,20 +19,16 @@ */ 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"); -- 2.39.5