</dependencies> | </dependencies> | ||||
<build> | <build> | ||||
<resources> | |||||
<resource> | |||||
<directory>src/main/resources</directory> | |||||
<filtering>true</filtering> | |||||
</resource> | |||||
</resources> | |||||
<plugins> | <plugins> | ||||
<plugin> | <plugin> | ||||
<groupId>org.apache.maven.plugins</groupId> | <groupId>org.apache.maven.plugins</groupId> |
private Properties loadGlobalProperties() throws IOException { | private Properties loadGlobalProperties() throws IOException { | ||||
File settingsFile = locatePropertiesFile(cli.properties(), RUNNER_HOME, "conf/sonar-runner.properties", RUNNER_SETTINGS); | File settingsFile = locatePropertiesFile(cli.properties(), RUNNER_HOME, "conf/sonar-runner.properties", RUNNER_SETTINGS); | ||||
if (settingsFile != null && settingsFile.isFile() && settingsFile.exists()) { | if (settingsFile != null && settingsFile.isFile() && settingsFile.exists()) { | ||||
logger.info("Runner configuration file: " + settingsFile.getAbsolutePath()); | |||||
logger.info("Scanner configuration file: " + settingsFile.getAbsolutePath()); | |||||
return toProperties(settingsFile); | return toProperties(settingsFile); | ||||
} | } | ||||
logger.info("Runner configuration file: NONE"); | |||||
logger.info("Scanner configuration file: NONE"); | |||||
return new Properties(); | return new Properties(); | ||||
} | } | ||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
displayExecutionResult(stats, "FAILURE"); | 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); | shutdown.exit(Exit.ERROR); | ||||
} | } | ||||
runAnalysis(stats, p); | runAnalysis(stats, p); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
displayExecutionResult(stats, "FAILURE"); | displayExecutionResult(stats, "FAILURE"); | ||||
showError("Error during Sonar runner execution", e, cli.isDisplayStackTrace()); | |||||
showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace()); | |||||
} | } | ||||
} while (waitForUser()); | } while (waitForUser()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
logger.error(""); | 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()) { | if (!cli.isDebugMode()) { | ||||
suggestDebugMode(); | suggestDebugMode(); | ||||
} | } | ||||
} | } | ||||
private void suggestDebugMode() { | 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."); | |||||
} | } | ||||
} | } |
/* | |||||
* 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; | |||||
} | |||||
} |
*/ | */ | ||||
package org.sonarsource.scanner.cli; | package org.sonarsource.scanner.cli; | ||||
import org.sonar.runner.api.RunnerVersion; | |||||
class SystemInfo { | class SystemInfo { | ||||
private static System2 system = new System2(); | private static System2 system = new System2(); | ||||
} | } | ||||
static void print(Logs logger) { | static void print(Logs logger) { | ||||
logger.info("SonarQube Runner " + RunnerVersion.version()); | |||||
logger.info("SonarQube Scanner " + ScannerVersion.version()); | |||||
logger.info(java()); | logger.info(java()); | ||||
logger.info(os()); | logger.info(os()); | ||||
String runnerOpts = system.getenv("SONAR_RUNNER_OPTS"); | String runnerOpts = system.getenv("SONAR_RUNNER_OPTS"); |
${project.version} |
import org.mockito.Mockito; | import org.mockito.Mockito; | ||||
import org.mockito.MockitoAnnotations; | import org.mockito.MockitoAnnotations; | ||||
import org.sonar.runner.api.EmbeddedRunner; | 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.Matchers.any; | ||||
import static org.mockito.Mockito.doThrow; | import static org.mockito.Mockito.doThrow; | ||||
verify(runner).stop(); | verify(runner).stop(); | ||||
verify(shutdown).exit(Exit.ERROR); | verify(shutdown).exit(Exit.ERROR); | ||||
verify(logs).error("Error during Sonar runner execution", e); | |||||
verify(logs).error("Error during SonarQube Scanner execution", e); | |||||
} | } | ||||
@Test | @Test |
*/ | */ | ||||
package org.sonarsource.scanner.cli; | 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.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonarsource.scanner.cli.SystemInfo.System2; | |||||
import static org.fest.assertions.Assertions.assertThat; | 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 { | public class SystemInfoTest { | ||||
System2 mockSystem; | System2 mockSystem; | ||||
verify(mockSystem).getProperty("os.version"); | verify(mockSystem).getProperty("os.version"); | ||||
verify(mockSystem).getenv("SONAR_RUNNER_OPTS"); | 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("Java 1.9 oracle (64-bit)"); | ||||
verify(logs).info("linux 2.5 x64"); | verify(logs).info("linux 2.5 x64"); | ||||
verify(logs).info("SONAR_RUNNER_OPTS=arg"); | verify(logs).info("SONAR_RUNNER_OPTS=arg"); |