Browse Source

SQSCANNER-10 Display correct version in logs and update labels

tags/2.5
Julien HENRY 8 years ago
parent
commit
0078dd22d4

+ 6
- 0
pom.xml View File

@@ -84,6 +84,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

+ 2
- 2
src/main/java/org/sonarsource/scanner/cli/Conf.java View 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();
}


+ 4
- 4
src/main/java/org/sonarsource/scanner/cli/Main.java View 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.");
}

}

+ 43
- 0
src/main/java/org/sonarsource/scanner/cli/ScannerVersion.java View File

@@ -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;
}

}

+ 1
- 3
src/main/java/org/sonarsource/scanner/cli/SystemInfo.java View 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");

+ 1
- 0
src/main/resources/version.txt View File

@@ -0,0 +1 @@
${project.version}

+ 1
- 8
src/test/java/org/sonarsource/scanner/cli/MainTest.java View 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

+ 8
- 11
src/test/java/org/sonarsource/scanner/cli/SystemInfoTest.java View File

@@ -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");

Loading…
Cancel
Save