if (status != 0) {
if (processMonitor != null && processMonitor.stop()) {
stdOut.consumeLine(String.format("SonarQube Runner was stopped [status=%s]", status));
- }
- else {
+ } else {
throw new IllegalStateException("Error status [command: " + forkCommand.command + "]: " + status);
}
}
private String version;
- public static String version() {
- return INSTANCE.version;
- }
-
private RunnerVersion() {
Scanner scanner = new Scanner(getClass().getResourceAsStream("/org/sonar/runner/api/version.txt"), "UTF-8");
try {
scanner.close();
}
}
+
+ public static String version() {
+ return INSTANCE.version;
+ }
+
}
@ParametersAreNonnullByDefault
package org.sonar.runner.api;
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+import javax.annotation.ParametersAreNonnullByDefault;
+
*/
public class IsolatedLauncher {
+ private static final String WARN = "WARN";
+ private static final String DEBUG = "DEBUG";
+ private static final String FALSE = "false";
+
public void execute(String sonarVersion, Properties properties, List<Object> extensions) {
createBatch(sonarVersion, properties, extensions).execute();
}
jc.setContext(context);
context.reset();
InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml");
- System.setProperty("ROOT_LOGGER_LEVEL", isDebug(props) ? "DEBUG" : "INFO");
+ System.setProperty("ROOT_LOGGER_LEVEL", isDebug(props) ? DEBUG : "INFO");
context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(props));
context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(props));
try {
@VisibleForTesting
protected boolean isDebug(Properties props) {
- return Boolean.parseBoolean(props.getProperty("sonar.verbose", "false"));
+ return Boolean.parseBoolean(props.getProperty("sonar.verbose", FALSE));
}
@VisibleForTesting
protected static String getSqlLevel(Properties props) {
- boolean showSql = "true".equals(props.getProperty("sonar.showSql", "false"));
- return showSql ? "DEBUG" : "WARN";
+ boolean showSql = "true".equals(props.getProperty("sonar.showSql", FALSE));
+ return showSql ? DEBUG : WARN;
}
@VisibleForTesting
protected static String getSqlResultsLevel(Properties props) {
- boolean showSql = "true".equals(props.getProperty("sonar.showSqlResults", "false"));
- return showSql ? "DEBUG" : "WARN";
+ boolean showSql = "true".equals(props.getProperty("sonar.showSqlResults", FALSE));
+ return showSql ? DEBUG : WARN;
}
}
@ParametersAreNonnullByDefault
package org.sonar.runner.batch;
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+import javax.annotation.ParametersAreNonnullByDefault;
+
*/
public class Main {
- public static void main(String[] args) {
- Cli cli = new Cli().parse(args);
- Main main = new Main(new Exit(), cli, new Conf(cli), new RunnerFactory());
- main.execute();
- }
-
private final Exit exit;
private final Cli cli;
private final Conf conf;
this.runnerFactory = runnerFactory;
}
+ public static void main(String[] args) {
+ Cli cli = new Cli().parse(args);
+ Main main = new Main(new Exit(), cli, new Conf(cli), new RunnerFactory());
+ main.execute();
+ }
+
void execute() {
SystemInfo.print();
if (!cli.isDisplayVersionOnly()) {
Logs.error(e.getMessage());
String previousMsg = "";
for (Throwable cause = e.getCause(); cause != null
- && cause.getMessage() != null
- && !cause.getMessage().equals(previousMsg); cause = cause.getCause()) {
+ && cause.getMessage() != null
+ && !cause.getMessage().equals(previousMsg); cause = cause.getCause()) {
Logs.error("Caused by: " + cause.getMessage());
previousMsg = cause.getMessage();
}
Logs.error("Re-run SonarQube Runner using the -X switch to enable full debug logging.");
}
-
}
@ParametersAreNonnullByDefault
package org.sonar.runner;
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+import javax.annotation.ParametersAreNonnullByDefault;
+
assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2");
}
+ @Test
+ public void shouldLoadModuleConfigurationOverrideBasedir() throws Exception {
+ File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project").toURI());
+ args.setProperty("project.home", projectHome.getCanonicalPath());
+
+ Properties properties = conf.properties();
+
+ assertThat(properties.getProperty("module1.sonar.projectName")).isEqualTo("Module 1");
+ assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2");
+ assertThat(properties.getProperty("module3.sonar.projectName")).isEqualTo("Module 3");
+ }
+
@Test
public void shouldSupportSettingBaseDirFromCli() throws Exception {
File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project").toURI());
--- /dev/null
+sonar.projectName=Module 2
+sonar.projectBaseDir=module_2
--- /dev/null
+sonar.projectName=Module 1
--- /dev/null
+sonar.projectName=Module 3
--- /dev/null
+sonar.modules=module1,module2,module3
+module1.sonar.projectBaseDir=module_1
+module2.sonar.projectConfigFile=module2.properties
+module3.sonar.projectConfigFile=module_3/sonar-project.properties
* @return the {@link org.sonar.runner.batch.IsolatedLauncher} instance for unit tests
*/
Object doExecute(final JarDownloader jarDownloader, final ServerVersion serverVersion, final Properties props, final List<Object> extensions) {
- Object launcher = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
List<File> jarFiles = jarDownloader.checkVersionAndDownload();
String[][] maskRules = getMaskRules(props);
}
}
});
- return launcher;
}
}
import java.net.ConnectException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.text.MessageFormat;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class ServerConnection {
+ private static final String SONAR_SERVER_CAN_NOT_BE_REACHED = "Sonar server ''{0}'' can not be reached";
+ private static final String STATUS_RETURNED_BY_URL_IS_INVALID = "Status returned by url : ''{0}'' is invalid : {1}";
static final int CONNECT_TIMEOUT_MILLISECONDS = 30000;
static final int READ_TIMEOUT_MILLISECONDS = 60000;
private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)");
Logs.debug("Download " + fullUrl + " to " + toFile.getAbsolutePath());
HttpRequest httpRequest = newHttpRequest(new URL(fullUrl));
if (!httpRequest.ok()) {
- throw new IOException("Status returned by url : '" + fullUrl + "' is invalid : " + httpRequest.code());
+ throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
}
httpRequest.receive(toFile);
} catch (Exception e) {
if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
- Logs.error("Sonar server '" + serverUrl + "' can not be reached");
+ Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
}
FileUtils.deleteQuietly(toFile);
throw new IllegalStateException("Fail to download: " + fullUrl, e);
charset = "UTF-8";
}
if (!httpRequest.ok()) {
- throw new IOException("Status returned by url : '" + fullUrl + "' is invalid : " + httpRequest.code());
+ throw new IOException(MessageFormat.format(STATUS_RETURNED_BY_URL_IS_INVALID, fullUrl, httpRequest.code()));
}
return httpRequest.body(charset);
} catch (HttpRequest.HttpRequestException e) {
if (e.getCause() instanceof ConnectException || e.getCause() instanceof UnknownHostException) {
- Logs.error("Sonar server '" + serverUrl + "' can not be reached");
+ Logs.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED, serverUrl));
}
throw e;
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.runner.impl;
\ No newline at end of file
+package org.sonar.runner.impl;
+