aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java')
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java91
1 files changed, 55 insertions, 36 deletions
diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
index b4e06bc..081b7f7 100644
--- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
+++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java
@@ -24,8 +24,6 @@ import org.sonar.runner.impl.InternalProperties;
import javax.annotation.Nullable;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
import java.util.Properties;
/**
@@ -33,14 +31,14 @@ import java.util.Properties;
*/
public abstract class Runner<T extends Runner> {
- private final Properties properties = new Properties();
+ private final Properties globalProperties = new Properties();
protected Runner() {
}
- public Properties properties() {
+ public Properties globalProperties() {
Properties clone = new Properties();
- clone.putAll(properties);
+ clone.putAll(globalProperties);
return clone;
}
@@ -49,8 +47,8 @@ public abstract class Runner<T extends Runner> {
*
* @see #setProperty(String, String)
*/
- public T addProperties(Properties p) {
- properties.putAll(p);
+ public T addGlobalProperties(Properties p) {
+ globalProperties.putAll(p);
return (T) this;
}
@@ -60,65 +58,86 @@ public abstract class Runner<T extends Runner> {
* @see RunnerProperties
* @see ScanProperties
*/
- public T setProperty(String key, String value) {
- properties.setProperty(key, value);
+ public T setGlobalProperty(String key, String value) {
+ globalProperties.setProperty(key, value);
return (T) this;
}
- public String property(String key, @Nullable String defaultValue) {
- return properties.getProperty(key, defaultValue);
+ public String globalProperty(String key, @Nullable String defaultValue) {
+ return globalProperties.getProperty(key, defaultValue);
}
/**
* User-agent used in the HTTP requests to the Sonar server
*/
public T setApp(String app, String version) {
- setProperty(InternalProperties.RUNNER_APP, app);
- setProperty(InternalProperties.RUNNER_APP_VERSION, version);
+ setGlobalProperty(InternalProperties.RUNNER_APP, app);
+ setGlobalProperty(InternalProperties.RUNNER_APP_VERSION, version);
return (T) this;
}
public String app() {
- return property(InternalProperties.RUNNER_APP, null);
+ return globalProperty(InternalProperties.RUNNER_APP, null);
}
public String appVersion() {
- return property(InternalProperties.RUNNER_APP_VERSION, null);
+ return globalProperty(InternalProperties.RUNNER_APP_VERSION, null);
}
- public void execute() {
- initDefaultValues();
- new SourceEncoding().init(this);
- new Dirs().init(this);
- String dumpToFile = properties.getProperty(InternalProperties.RUNNER_DUMP_TO_FILE);
+ public void runAnalysis(Properties analysisProperties) {
+ Properties copy = new Properties();
+ copy.putAll(analysisProperties);
+ initAnalysisProperties(copy);
+
+ String dumpToFile = copy.getProperty(InternalProperties.RUNNER_DUMP_TO_FILE);
if (dumpToFile != null) {
File dumpFile = new File(dumpToFile);
- writeProperties(dumpFile);
+ Utils.writeProperties(dumpFile, copy);
System.out.println("Simulation mode. Configuration written to " + dumpFile.getAbsolutePath());
} else {
- doExecute();
+ doExecute(copy);
}
}
- private void writeProperties(File outputFile) {
- try (OutputStream output = new FileOutputStream(outputFile)) {
- properties().store(output, "Generated by sonar-runner");
- } catch (Exception e) {
- throw new IllegalStateException("Fail to export sonar-runner properties", e);
- }
+ public void start() {
+ initGlobalDefaultValues();
+ doStart();
+ }
+
+ public void stop() {
+ doStop();
+ }
+
+ /**
+ * @deprecated since 2.5 use {@link #start()}, {@link #runAnalysis(Properties)} and then {@link #stop()}
+ */
+ @Deprecated
+ public final void execute() {
+ start();
+ runAnalysis(new Properties());
+ stop();
}
- protected abstract void doExecute();
+ protected abstract void doStart();
+
+ protected abstract void doStop();
+
+ protected abstract void doExecute(Properties analysisProperties);
+
+ private void initGlobalDefaultValues() {
+ setGlobalDefaultValue(RunnerProperties.HOST_URL, "http://localhost:9000");
+ setGlobalDefaultValue(InternalProperties.RUNNER_APP, "SonarQubeRunner");
+ setGlobalDefaultValue(InternalProperties.RUNNER_APP_VERSION, RunnerVersion.version());
+ }
- private void initDefaultValues() {
- setDefaultValue(RunnerProperties.HOST_URL, "http://localhost:9000");
- setDefaultValue(InternalProperties.RUNNER_APP, "SonarQubeRunner");
- setDefaultValue(InternalProperties.RUNNER_APP_VERSION, RunnerVersion.version());
+ private static void initAnalysisProperties(Properties p) {
+ SourceEncoding.init(p);
+ Dirs.init(p);
}
- private void setDefaultValue(String key, String value) {
- if (!properties.containsKey(key)) {
- setProperty(key, value);
+ private void setGlobalDefaultValue(String key, String value) {
+ if (!globalProperties.containsKey(key)) {
+ setGlobalProperty(key, value);
}
}