aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/sonar/runner/Runner.java18
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/Launcher.java15
-rw-r--r--src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java6
-rw-r--r--src/test/java/org/sonar/runner/RunnerTest.java51
4 files changed, 70 insertions, 20 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);
diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java
index 2752999..d3e89de 100644
--- a/src/test/java/org/sonar/runner/RunnerTest.java
+++ b/src/test/java/org/sonar/runner/RunnerTest.java
@@ -80,16 +80,35 @@ public class RunnerTest {
assertThat(Runner.isUnsupportedVersion("2.4")).isTrue();
assertThat(Runner.isUnsupportedVersion("2.4.1")).isTrue();
assertThat(Runner.isUnsupportedVersion("2.5")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.11")).isTrue();
- assertThat(Runner.isUnsupportedVersion("3.0")).isTrue();
- assertThat(Runner.isUnsupportedVersion("3.1")).isTrue();
- assertThat(Runner.isUnsupportedVersion("3.2")).isTrue();
- assertThat(Runner.isUnsupportedVersion("3.3")).isTrue();
- assertThat(Runner.isUnsupportedVersion("3.4")).isTrue();
+ assertThat(Runner.isUnsupportedVersion("2.11")).isFalse();
+ assertThat(Runner.isUnsupportedVersion("3.0")).isFalse();
+ assertThat(Runner.isUnsupportedVersion("3.1")).isFalse();
+ assertThat(Runner.isUnsupportedVersion("3.2")).isFalse();
+ assertThat(Runner.isUnsupportedVersion("3.3")).isFalse();
+ assertThat(Runner.isUnsupportedVersion("3.4")).isFalse();
assertThat(Runner.isUnsupportedVersion("3.5")).isFalse();
}
@Test
+ public void shouldCheckVersionForTasks() {
+ assertThat(Runner.isUnsupportedVersionForTasks("1.0")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.0")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.1")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.2")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.3")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.4")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.4.1")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.5")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("2.11")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.0")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.1")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.2")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.3")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.4")).isTrue();
+ assertThat(Runner.isUnsupportedVersionForTasks("3.5")).isFalse();
+ }
+
+ @Test
public void shouldGetServerUrl() {
Properties properties = new Properties();
Runner runner = Runner.create(properties);
@@ -176,14 +195,30 @@ public class RunnerTest {
Bootstrapper bootstrapper = mock(Bootstrapper.class);
// nothing happens, OK
- when(bootstrapper.getServerVersion()).thenReturn("3.5");
+ when(bootstrapper.getServerVersion()).thenReturn("3.0");
runner.checkSonarVersion(bootstrapper);
// but fails with older versions
when(bootstrapper.getServerVersion()).thenReturn("2.1");
thrown.expect(RunnerException.class);
- thrown.expectMessage("Sonar 2.1 is not supported. Please upgrade Sonar to version 3.5 or more.");
+ thrown.expectMessage("Sonar 2.1 is not supported. Please upgrade Sonar to version 2.11 or more.");
runner.checkSonarVersion(bootstrapper);
}
+ @Test
+ public void shouldCheckSonarVersionForTasks() {
+ Properties properties = new Properties();
+ Runner runner = Runner.create("foo-cmd", properties, properties);
+ Bootstrapper bootstrapper = mock(Bootstrapper.class);
+
+ // nothing happens, OK
+ when(bootstrapper.getServerVersion()).thenReturn("3.5");
+ runner.checkSonarVersion(bootstrapper);
+
+ // but fails with older versions
+ when(bootstrapper.getServerVersion()).thenReturn("3.4");
+ thrown.expect(RunnerException.class);
+ thrown.expectMessage("Sonar 3.4 doesn't support tasks. Please upgrade Sonar to version 3.5 or more.");
+ runner.checkSonarVersion(bootstrapper);
+ }
}