import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
/**
private File projectDir;
private File workDir;
+ private String[] unmaskedPackages;
+ private List<Object> containerExtensions = new ArrayList<Object>();
private Properties properties;
private Runner(Properties props) {
this.properties = props;
+ this.unmaskedPackages = new String[0];
// set the default values for the Sonar Runner - they can be overriden with #setEnvironmentInformation
this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_KEY, "Runner");
this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_VERSION, SonarRunnerVersion.getVersion());
URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
return bootstrapper.createClassLoader(
new URL[] {url}, // Add JAR with Sonar Runner - it's a Jar which contains this class
- getClass().getClassLoader());
+ getClass().getClassLoader(),
+ unmaskedPackages);
}
static boolean isUnsupportedVersion(String version) {
try {
Thread.currentThread().setContextClassLoader(sonarClassLoader);
Class<?> launcherClass = sonarClassLoader.findClass("org.sonar.runner.internal.batch.Launcher");
- Constructor<?> constructor = launcherClass.getConstructor(Properties.class);
- Object launcher = constructor.newInstance(getProperties());
+ Constructor<?> constructor = launcherClass.getConstructor(Properties.class, List.class);
+ Object launcher = constructor.newInstance(getProperties(), containerExtensions);
Method method = launcherClass.getMethod("execute");
method.invoke(launcher);
} catch (InvocationTargetException e) {
this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_KEY, key);
this.properties.put(PROPERTY_ENVIRONMENT_INFORMATION_VERSION, version);
}
+
+ public void setUnmaskedPackages(String... unmaskedPackages) {
+ this.unmaskedPackages = unmaskedPackages;
+ }
+
+ public void addContainerExtension(Object extension) {
+ containerExtensions.add(extension);
+ }
+
}
import org.sonar.runner.Runner;
import java.io.InputStream;
+import java.util.List;
import java.util.Properties;
/**
public class Launcher {
private Properties propertiesFromRunner;
+ private List<Object> containerExtensions;
- public Launcher(Properties properties) {
+ public Launcher(Properties properties, List<Object> containerExtensions) {
this.propertiesFromRunner = properties;
+ this.containerExtensions = containerExtensions;
}
/**
}
private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) {
- ProjectReactor reactor = new ProjectReactor(project);
+ setContainerExtensionsOnProject(project);
String envKey = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
String envVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
- Batch batch = Batch.create(reactor, initialConfiguration, new EnvironmentInformation(envKey, envVersion));
+ Batch batch = Batch.create(new ProjectReactor(project), initialConfiguration, new EnvironmentInformation(envKey, envVersion));
batch.execute();
}
+ private void setContainerExtensionsOnProject(ProjectDefinition projectDefinition) {
+ for (Object extension : containerExtensions) {
+ projectDefinition.addContainerExtension(extension);
+ }
+ for (ProjectDefinition module : projectDefinition.getSubProjects()) {
+ setContainerExtensionsOnProject(module);
+ }
+ }
+
private void initLogging(Configuration initialConfiguration) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
*/
package org.sonar.runner.internal.batch;
-
+import com.google.common.collect.Lists;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.junit.Test;
@Test
public void shouldDetermineVerboseMode() {
Properties properties = new Properties();
- Launcher launcher = new Launcher(properties);
+ Launcher launcher = new Launcher(properties, Lists.newArrayList());
assertThat(launcher.isDebug()).isFalse();
properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
assertThat(launcher.isDebug()).isTrue();
@Test
public void shouldSupportDeprecatedDebugProperty() {
Properties properties = new Properties();
- Launcher launcher = new Launcher(properties);
+ Launcher launcher = new Launcher(properties, Lists.newArrayList());
properties.setProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "true");
assertThat(launcher.isDebug()).isTrue();
}