aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-01-17 16:07:29 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2013-01-17 18:15:06 +0100
commita10143d0914482a570ef930f2e32279438d1210d (patch)
tree47f3234eb43d033cac67301e7a7ebb079cf486a6 /src/main
parent2fc32f40571c66a5fdb29aba8e5e41de5c090f9e (diff)
downloadsonar-scanner-cli-a10143d0914482a570ef930f2e32279438d1210d.tar.gz
sonar-scanner-cli-a10143d0914482a570ef930f2e32279438d1210d.zip
SONARPLUGINS-2540 Allow to provide task command by a property for testing purpose.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/sonar/runner/Main.java9
-rw-r--r--src/main/java/org/sonar/runner/Runner.java6
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/Launcher.java25
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java5
4 files changed, 28 insertions, 17 deletions
diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java
index 59c302c..90994fb 100644
--- a/src/main/java/org/sonar/runner/Main.java
+++ b/src/main/java/org/sonar/runner/Main.java
@@ -46,6 +46,8 @@ public final class Main {
private static final String RUNNER_SETTINGS = "runner.settings";
private static final String PROJECT_HOME = "project.home";
private static final String PROJECT_SETTINGS = "project.settings";
+ // TODO Remove this after everything is updated to support tasks
+ private static final String TASK_COMMAND = "sonar.task";
private boolean debugMode = false;
private boolean displayVersionOnly = false;
@@ -296,7 +298,12 @@ public final class Main {
key = arg.substring(0, j);
value = arg.substring(j + 1);
}
- props.setProperty(key, value);
+ if (TASK_COMMAND.equals(key)) {
+ command = value;
+ }
+ else {
+ props.setProperty(key, value);
+ }
}
private void printError(String message) {
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java
index f6685d1..e075f62 100644
--- a/src/main/java/org/sonar/runner/Runner.java
+++ b/src/main/java/org/sonar/runner/Runner.java
@@ -134,7 +134,9 @@ public final class Runner {
/**
* Creates a Runner based only on the given properties.
+ * @deprecated Use {@link Runner#create(String, Properties, Properties)}
*/
+ @Deprecated
public static Runner create(Properties props) {
return create(null, new Properties(), props);
}
@@ -148,7 +150,9 @@ public final class Runner {
/**
* Creates a Runner based only on the properties and with the given base directory.
+ * @deprecated Use {@link Runner#create(String, Properties, Properties, File)}
*/
+ @Deprecated
public static Runner create(Properties props, File basedir) {
return create(null, new Properties(), props, basedir);
}
@@ -180,7 +184,7 @@ public final class Runner {
if (!projectDir.isDirectory()) {
throw new RunnerException("Project home must be an existing directory: " + path);
}
- // project home exists: add its absolute path as "sonar.runner.projectDir" property
+ // project home exists: add its absolute path as "sonar.projectBaseDir" property
projectProperties.put(PROPERTY_SONAR_PROJECT_BASEDIR, projectDir.getAbsolutePath());
workDir = initWorkDir();
}
diff --git a/src/main/java/org/sonar/runner/internal/batch/Launcher.java b/src/main/java/org/sonar/runner/internal/batch/Launcher.java
index f967ede..5e36cfa 100644
--- a/src/main/java/org/sonar/runner/internal/batch/Launcher.java
+++ b/src/main/java/org/sonar/runner/internal/batch/Launcher.java
@@ -68,21 +68,27 @@ public class Launcher {
public void execute() {
Properties globalConfiguration = getInitialConfiguration();
globalConfiguration.putAll(globalProperties);
+ initLogging(globalConfiguration);
+
Properties projectConfiguration = new Properties();
projectConfiguration.putAll(globalConfiguration);
projectConfiguration.putAll(projectProperties);
ProjectDefinition project = SonarProjectBuilder.create(command, projectConfiguration).generateProjectDefinition();
- initLogging(globalConfiguration);
+
executeBatch(globalConfiguration, project);
}
private void executeBatch(Properties globalConfiguration, ProjectDefinition project) {
- setContainerExtensionsOnProject(project);
- String envKey = projectProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
- String envVersion = projectProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
+ String envKey = globalProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
+ String envVersion = globalProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
Batch.Builder builder = Batch.builder()
- .setProjectReactor(new ProjectReactor(project))
.setEnvironment(new EnvironmentInformation(envKey, envVersion));
+ for (Object extension : containerExtensions) {
+ builder.addComponent(extension);
+ }
+ if (project != null) {
+ builder.setProjectReactor(new ProjectReactor(project));
+ }
if (StringUtils.isNotBlank(command)) {
// This code can only works on Sonar 3.5+
builder
@@ -101,15 +107,6 @@ public class Launcher {
return result;
}
- private void setContainerExtensionsOnProject(ProjectDefinition projectDefinition) {
- for (Object extension : containerExtensions) {
- projectDefinition.addContainerExtension(extension);
- }
- for (ProjectDefinition module : projectDefinition.getSubProjects()) {
- setContainerExtensionsOnProject(module);
- }
- }
-
private void initLogging(Properties props) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
index 7c70650..46171b4 100644
--- a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
+++ b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
@@ -135,9 +135,12 @@ public final class SonarProjectBuilder {
cleanAndCheckProjectDefinitions(rootProject);
return rootProject;
}
- else {
+ else if (properties.containsKey(PROPERTY_PROJECT_KEY)) {
return defineTaskContext();
}
+ else {
+ return null;
+ }
}
private ProjectDefinition defineTaskContext() {