*/
public class IsolatedLauncher {
- public void execute(Properties properties, List<Object> extensions) {
- createBatch(properties, extensions).execute();
+ public void execute(String sonarVersion, Properties properties, List<Object> extensions) {
+ createBatch(sonarVersion, properties, extensions).execute();
}
- Batch createBatch(Properties properties, List<Object> extensions) {
+ Batch createBatch(String sonarVersion, Properties properties, List<Object> extensions) {
ProjectReactor projectReactor = null;
initLogging(properties);
EnvironmentInformation env = new EnvironmentInformation(properties.getProperty("sonarRunner.app"), properties.getProperty("sonarRunner.appVersion"));
.addComponents(extensions);
String task = properties.getProperty("sonar.task", "scan");
- if ("scan".equals(task)) {
+ if (VersionUtils.isLessThan37(sonarVersion) && "scan".equals(task)) {
Properties propsClone = new Properties();
propsClone.putAll(properties);
projectReactor = new ProjectReactorBuilder(propsClone).build();
+ builder.setProjectReactor(projectReactor);
} else {
// only on sonar 3.5+... in theory
builder.setGlobalProperties((Map) properties);
}
- if (projectReactor != null) {
- builder.setProjectReactor(projectReactor);
- }
return builder.build();
}
/*
- * Sonar Runner - Batch
+ * SonarQube Runner - Batch
* Copyright (C) 2011 SonarSource
* dev@sonar.codehaus.org
*
* Class that creates a Sonar project definition based on a set of properties.
*
* @since 1.5
+ * @deprecated since 2.3. Moved to SonarQube batch 3.7. Will be deleted when SonarQube reunner will require SonarQube 3.7+.
*/
+@Deprecated
class ProjectReactorBuilder {
private static final Logger LOG = LoggerFactory.getLogger(ProjectReactorBuilder.class);
/*
- * Sonar Runner - Batch
+ * SonarQube Runner - Batch
* Copyright (C) 2011 SonarSource
* dev@sonar.codehaus.org
*
--- /dev/null
+/*
+ * SonarQube Runner - Batch
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.batch;
+
+class VersionUtils {
+
+ private static final String[] LESS_THAN_3_7 = {"0", "1", "2", "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6"};
+
+ static boolean isLessThan37(String version) {
+ return inVersions(version, LESS_THAN_3_7);
+ }
+
+ private static boolean inVersions(String version, String[] versions) {
+ for (String s : versions) {
+ if (isVersion(version, s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isVersion(String version, String prefix) {
+ return version.startsWith(prefix + ".") || version.equals(prefix);
+ }
+}
props.setProperty("sonar.projectName", "Sample");
props.setProperty("sonar.projectVersion", "1.0");
props.setProperty("sonar.sources", "src");
- Batch batch = launcher.createBatch(props, Collections.emptyList());
+ Batch batch = launcher.createBatch("3.5", props, Collections.emptyList());
assertThat(batch).isNotNull();
}
/*
- * Sonar Runner - Batch
+ * SonarQube Runner - Batch
* Copyright (C) 2011 SonarSource
* dev@sonar.codehaus.org
*
/*
- * Sonar Runner - Batch
+ * SonarQube Runner - Batch
* Copyright (C) 2011 SonarSource
* dev@sonar.codehaus.org
*
--- /dev/null
+/*
+ * SonarQube Runner - Batch
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.batch;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class VersionUtilsTest {
+
+ @Test
+ public void testIsLessThan3_7() {
+ assertThat(VersionUtils.isLessThan37("2.5")).isTrue();
+ assertThat(VersionUtils.isLessThan37("3.0")).isTrue();
+ assertThat(VersionUtils.isLessThan37("3.0.1")).isTrue();
+ assertThat(VersionUtils.isLessThan37("3.6")).isTrue();
+ assertThat(VersionUtils.isLessThan37("3.7")).isFalse();
+ assertThat(VersionUtils.isLessThan37("4.0")).isFalse();
+ }
+
+}
ServerConnection serverConnection = ServerConnection.create(props);
ServerVersion serverVersion = new ServerVersion(serverConnection);
JarDownloader jarDownloader = new JarDownloader(props, serverConnection, serverVersion);
- doExecute(jarDownloader, props, extensions);
+ doExecute(jarDownloader, serverVersion, props, extensions);
}
private static String[][] getMaskRules(final Properties props) {
/**
* @return the {@link org.sonar.runner.batch.IsolatedLauncher} instance for unit tests
*/
- Object doExecute(final JarDownloader jarDownloader, final Properties props, final List<Object> extensions) {
+ Object doExecute(final JarDownloader jarDownloader, final ServerVersion serverVersion, final Properties props, final List<Object> extensions) {
Object launcher = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
List<File> jarFiles = jarDownloader.download();
String[][] maskRules = getMaskRules(props);
IsolatedClassloader classloader = new IsolatedClassloader(getClass().getClassLoader(), maskRules);
classloader.addFiles(jarFiles);
- Object launcher = delegateExecution(classloader, props, extensions);
+ Object launcher = delegateExecution(classloader, serverVersion.version(), props, extensions);
tempCleaning.clean();
return launcher;
}
- private Object delegateExecution(IsolatedClassloader classloader, Properties properties, List<Object> extensions) {
+ private Object delegateExecution(IsolatedClassloader classloader, String sonarVersion, Properties properties, List<Object> extensions) {
ClassLoader initialContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classloader);
Class<?> launcherClass = classloader.loadClass(isolatedLauncherClass);
- Method executeMethod = launcherClass.getMethod("execute", Properties.class, List.class);
+ Method executeMethod = launcherClass.getMethod("execute", String.class, Properties.class, List.class);
Object launcher = launcherClass.newInstance();
- executeMethod.invoke(launcher, properties, extensions);
+ executeMethod.invoke(launcher, sonarVersion, properties, extensions);
return launcher;
} catch (InvocationTargetException e) {
// Unwrap original exception
props.put(InternalProperties.RUNNER_MASK_RULES, "UNMASK|org.sonar.runner.impl.");
List<Object> extensions = new ArrayList<Object>();
- FakeIsolatedLauncher isolatedLauncher = (FakeIsolatedLauncher) launcher.doExecute(jarDownloader, props, extensions);
+ FakeIsolatedLauncher isolatedLauncher = (FakeIsolatedLauncher) launcher.doExecute(jarDownloader, mock(ServerVersion.class), props, extensions);
assertThat(isolatedLauncher.props.get("foo")).isEqualTo("bar");
assertThat(isolatedLauncher.extensions).isSameAs(extensions);
verify(jarDownloader).download();
// The current classloader in not available -> fail to load FakeIsolatedLauncher
props.put(InternalProperties.RUNNER_MASK_RULES, "");
try {
- launcher.doExecute(jarDownloader, props, Collections.emptyList());
+ launcher.doExecute(jarDownloader, mock(ServerVersion.class), props, Collections.emptyList());
fail();
} catch (RunnerException e) {
// success
Properties props = new Properties();
List<Object> extensions = Collections.emptyList();
BatchLauncher launcher = spy(new BatchLauncher());
- doReturn(new Object()).when(launcher).doExecute(any(JarDownloader.class), eq(props), eq(extensions));
+ doReturn(new Object()).when(launcher).doExecute(any(JarDownloader.class), any(ServerVersion.class), eq(props), eq(extensions));
launcher.execute(props, extensions);
public static class FakeIsolatedLauncher {
public Properties props = null;
public List<Object> extensions = null;
+ private String sonarVersion;
- public void execute(Properties props, List<Object> extensions) {
+ public void execute(String sonarVersion, Properties props, List<Object> extensions) {
+ this.sonarVersion = sonarVersion;
this.props = props;
this.extensions = extensions;
}