// default values
properties.put(Constants.HOST_URL, "http://localhost:9000");
properties.put(Constants.TASK, "scan");
- properties.put(Constants.PROP_APP, "SonarRunner");
- properties.put(Constants.PROP_APP_VERSION, RunnerVersion.version());
+ properties.put(Constants.RUNNER_APP, "SonarRunner");
+ properties.put(Constants.RUNNER_APP_VERSION, RunnerVersion.version());
}
public Properties properties() {
* User-agent used in the HTTP requests to the Sonar server
*/
public T setApp(String app, String version) {
- setProperty(Constants.PROP_APP, app);
- setProperty(Constants.PROP_APP_VERSION, version);
+ setProperty(Constants.RUNNER_APP, app);
+ setProperty(Constants.RUNNER_APP_VERSION, version);
return (T) this;
}
public String app() {
- return property(Constants.PROP_APP, null);
+ return property(Constants.RUNNER_APP, null);
}
public String appVersion() {
- return property(Constants.PROP_APP_VERSION, null);
+ return property(Constants.RUNNER_APP_VERSION, null);
}
public void execute() {
import java.util.Iterator;
class Utils {
+ private Utils() {
+ // only util static methods
+ }
+
/**
* Similar to org.apache.commons.lang.StringUtils#join()
*/
@Test
public void should_set_unmasked_packages() {
EmbeddedRunner runner = EmbeddedRunner.create();
- assertThat(runner.property(Constants.UNMASKED_PACKAGES, null)).isNull();
+ assertThat(runner.property(Constants.RUNNER_UNMASKED_PACKAGES, null)).isNull();
runner = EmbeddedRunner.create().setUnmaskedPackages("org.apache.ant", "org.ant");
- assertThat(runner.property(Constants.UNMASKED_PACKAGES, null)).isEqualTo("org.apache.ant,org.ant");
+ assertThat(runner.property(Constants.RUNNER_UNMASKED_PACKAGES, null)).isEqualTo("org.apache.ant,org.ant");
}
@Test
private boolean displayStackTrace = false;
private Properties props = new Properties();
- public boolean isDebugMode() {
+ boolean isDebugMode() {
return debugMode;
}
- public boolean isDisplayVersionOnly() {
+ boolean isDisplayVersionOnly() {
return displayVersionOnly;
}
- public boolean isDisplayStackTrace() {
+ boolean isDisplayStackTrace() {
return displayStackTrace;
}
- public Properties properties() {
+ Properties properties() {
return props;
}
*
* @since 1.0
*/
-public final class Main {
+public class Main {
public static void main(String[] args) {
Cli cli = new Cli().parse(args);
}
private void printSystem() {
- System.out.println("Runner " + RunnerVersion.version());
+ System.out.println("Sonar Runner " + RunnerVersion.version());
System.out.println("Java " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")");
System.out.println(System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
}
if (serverVersion.is35Compatible()) {
jarFiles = new Jars35(fileDownloader, new JarExtractor()).download();
} else if (serverVersion.is30Compatible()) {
- String workDir = properties.getProperty("sonarRunner.workDir");
+ String workDir = properties.getProperty(Constants.RUNNER_WORK_DIR);
jarFiles = new Jars30(fileDownloader).download(new File(workDir), new JarExtractor());
} else {
throw new IllegalStateException("Sonar " + serverVersion.version()
+ " is not supported. Please upgrade Sonar to version 3.0 or more.");
}
- String unmaskedPackages = properties.getProperty(Constants.UNMASKED_PACKAGES, "");
+ String unmaskedPackages = properties.getProperty(Constants.RUNNER_UNMASKED_PACKAGES, "");
IsolatedClassloader classloader = new IsolatedClassloader(getClass().getClassLoader(), unmaskedPackages.split(":"));
classloader.addFiles(jarFiles);
delegateExecution(classloader, properties, extensions);
try {
props.load(input);
// just to be clean, do not forward properties that do not make sense in fork mode
- props.remove(Constants.UNMASKED_PACKAGES);
+ props.remove(Constants.RUNNER_UNMASKED_PACKAGES);
} finally {
IOUtils.closeQuietly(input);
public interface Constants {
String HOST_URL = "sonar.host.url";
- String PROP_APP = "sonarRunner.app";
- String PROP_APP_VERSION = "sonarRunner.appVersion";
- String UNMASKED_PACKAGES = "sonarRunner.unmaskedPackages";
String TASK = "sonar.task";
String SOURCE_ENCODING = "sonar.sourceEncoding";
+
+ String RUNNER_APP = "sonarRunner.app";
+ String RUNNER_APP_VERSION = "sonarRunner.appVersion";
+ String RUNNER_UNMASKED_PACKAGES = "sonarRunner.unmaskedPackages";
+ String RUNNER_WORK_DIR = "sonarRunner.workDir";
}
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
-import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
static FileDownloader create(Properties properties) {
String serverUrl = properties.getProperty(Constants.HOST_URL);
- String app = properties.getProperty(Constants.PROP_APP);
- String appVersion = properties.getProperty(Constants.PROP_APP_VERSION);
+ String app = properties.getProperty(Constants.RUNNER_APP);
+ String appVersion = properties.getProperty(Constants.RUNNER_APP_VERSION);
return new FileDownloader(serverUrl, app, appVersion);
}