diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-16 14:29:56 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-16 14:29:56 +0100 |
commit | 2fc32f40571c66a5fdb29aba8e5e41de5c090f9e (patch) | |
tree | dce648a1c0adf9817d86994d4ab3c83bb2b1e6ad /src/main | |
parent | 240e7abe2af7caa5900865b4df59b3e9f6a9ec3e (diff) | |
download | sonar-scanner-cli-2fc32f40571c66a5fdb29aba8e5e41de5c090f9e.tar.gz sonar-scanner-cli-2fc32f40571c66a5fdb29aba8e5e41de5c090f9e.zip |
SONARPLUGINS-2540 Restore compatibility with older Sonar versions.
Diffstat (limited to 'src/main')
3 files changed, 27 insertions, 12 deletions
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 023974e..f6685d1 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -101,7 +101,8 @@ public final class Runner { /** * Array of prefixes of versions of Sonar without support of this runner. */ - private static final String[] UNSUPPORTED_VERSIONS = {"1", "2", "3.0", "3.1", "3.2", "3.3", "3.4"}; + private static final String[] UNSUPPORTED_VERSIONS = {"1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9", "2.10"}; + private static final String[] UNSUPPORTED_VERSIONS_FOR_TASKS = {"1", "2", "3.0", "3.1", "3.2", "3.3", "3.4"}; private static final String PROPERTY_SOURCE_ENCODING = "sonar.sourceEncoding"; @@ -250,7 +251,11 @@ public final class Runner { String serverVersion = bootstrapper.getServerVersion(); if (isUnsupportedVersion(serverVersion)) { throw new RunnerException("Sonar " + serverVersion - + " is not supported. Please upgrade Sonar to version 3.5 or more."); + + " is not supported. Please upgrade Sonar to version 2.11 or more."); + } + if (command != null && isUnsupportedVersionForTasks(serverVersion)) { + throw new RunnerException("Sonar " + serverVersion + + " doesn't support tasks. Please upgrade Sonar to version 3.5 or more."); } } @@ -300,6 +305,15 @@ public final class Runner { return false; } + static boolean isUnsupportedVersionForTasks(String version) { + for (String unsupportedVersion : UNSUPPORTED_VERSIONS_FOR_TASKS) { + if (isVersion(version, unsupportedVersion)) { + return true; + } + } + return false; + } + static boolean isVersion(String version, String prefix) { return version.startsWith(prefix + ".") || version.equals(prefix); } 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 5fa68ad..f967ede 100644 --- a/src/main/java/org/sonar/runner/internal/batch/Launcher.java +++ b/src/main/java/org/sonar/runner/internal/batch/Launcher.java @@ -25,6 +25,7 @@ import ch.qos.logback.core.joran.spi.JoranException; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; @@ -79,12 +80,16 @@ public class Launcher { setContainerExtensionsOnProject(project); String envKey = projectProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY); String envVersion = projectProperties.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION); - Batch batch = Batch.builder() - .setGlobalProperties(toMap(globalConfiguration)) - .setTaskCommand(command) + Batch.Builder builder = Batch.builder() .setProjectReactor(new ProjectReactor(project)) - .setEnvironment(new EnvironmentInformation(envKey, envVersion)) - .build(); + .setEnvironment(new EnvironmentInformation(envKey, envVersion)); + if (StringUtils.isNotBlank(command)) { + // This code can only works on Sonar 3.5+ + builder + .setGlobalProperties(toMap(globalConfiguration)) + .setTaskCommand(command); + } + Batch batch = builder.build(); batch.execute(); } 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 d9857f4..7c70650 100644 --- a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java +++ b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java @@ -29,7 +29,6 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.batch.tasks.AnalyseProjectTaskDefinition; import org.sonar.runner.RunnerException; import java.io.File; @@ -125,14 +124,11 @@ public final class SonarProjectBuilder { } public static SonarProjectBuilder create(String command, Properties properties) { - if (StringUtils.isBlank(command)) { - command = AnalyseProjectTaskDefinition.COMMAND; - } return new SonarProjectBuilder(command, properties); } public ProjectDefinition generateProjectDefinition() { - if (AnalyseProjectTaskDefinition.COMMAND.equals(command)) { + if (StringUtils.isBlank(command) || command.equals("inspect")) { ProjectDefinition rootProject = defineProject(properties, null); rootProjectWorkDir = rootProject.getWorkDir(); defineChildren(rootProject); |