diff options
3 files changed, 36 insertions, 9 deletions
diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index d911b0b..f2cd606 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -29,6 +29,8 @@ import java.lang.reflect.Constructor; 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; /** @@ -106,10 +108,13 @@ public final class Runner { 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()); @@ -204,7 +209,8 @@ public final class Runner { 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) { @@ -230,8 +236,8 @@ public final class Runner { 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) { @@ -255,4 +261,13 @@ public final class Runner { 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); + } + } 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 2137567..502e5cf 100644 --- a/src/main/java/org/sonar/runner/internal/batch/Launcher.java +++ b/src/main/java/org/sonar/runner/internal/batch/Launcher.java @@ -39,6 +39,7 @@ import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.runner.Runner; import java.io.InputStream; +import java.util.List; import java.util.Properties; /** @@ -48,9 +49,11 @@ 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; } /** @@ -64,13 +67,22 @@ public class Launcher { } 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(); diff --git a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java index 489b005..979a517 100644 --- a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java +++ b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java @@ -19,7 +19,7 @@ */ 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; @@ -60,7 +60,7 @@ public class LauncherTest { @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(); @@ -69,7 +69,7 @@ public class LauncherTest { @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(); } |