diff options
5 files changed, 34 insertions, 35 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index ce6985b8c2e..28cb581735b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -75,7 +75,6 @@ public class BootstrapModule extends Module { addCoreSingleton(BatchPluginRepository.class); addCoreSingleton(BatchExtensionInstaller.class); - addCoreSingleton(ProjectExtensionInstaller.class); addCoreSingleton(BatchSettingsEnhancer.class); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java index 145d971387e..f92163255d2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java @@ -28,9 +28,11 @@ import org.sonar.api.Plugin; import org.sonar.api.batch.AbstractCoverageExtension; import org.sonar.api.batch.CoverageExtension; import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.config.Settings; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.batch.config.ProjectSettings; import java.util.List; import java.util.Map; @@ -40,42 +42,46 @@ public final class ProjectExtensionInstaller implements BatchComponent { private BatchPluginRepository pluginRepository; private EnvironmentInformation environment; private DryRun dryRun; + private Project project; + private ProjectSettings settings; - public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun) { + public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun, Project project, ProjectSettings settings) { this.pluginRepository = pluginRepository; this.environment = environment; this.dryRun = dryRun; + this.project = project; + this.settings = settings; } - public void install(Module module, Project project) { + public void install(Module module) { for (Map.Entry<String, Plugin> entry : pluginRepository.getPluginsByKey().entrySet()) { for (Object extension : entry.getValue().getExtensions()) { - installExtension(module, extension, project, entry.getKey()); + installExtension(module, extension, entry.getKey()); } } - installExtensionProviders(module, project); + installExtensionProviders(module); } - void installExtensionProviders(Module module, Project project) { + void installExtensionProviders(Module module) { List<ExtensionProvider> providers = module.getComponents(ExtensionProvider.class); for (ExtensionProvider provider : providers) { Object obj = provider.provide(); if (obj instanceof Iterable) { for (Object extension : (Iterable) obj) { - installExtension(module, extension, project, ""); + installExtension(module, extension, ""); } } else { - installExtension(module, obj, project, ""); + installExtension(module, obj, ""); } } } - private Object installExtension(Module module, Object extension, Project project, String pluginKey) { + private Object installExtension(Module module, Object extension, String pluginKey) { if (ExtensionUtils.isBatchExtension(extension) && ExtensionUtils.isSupportedEnvironment(extension, environment) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) && ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) && - !isDeactivatedCoverageExtension(extension, project, pluginKey) && + !isDeactivatedCoverageExtension(extension, pluginKey, project, settings) && !isMavenExtensionOnEmulatedMavenProject(extension, project)) { module.addCoreSingleton(extension); return extension; @@ -95,7 +101,7 @@ public final class ProjectExtensionInstaller implements BatchComponent { /** * TODO this code is specific to Java projects and should be moved somewhere else */ - static boolean isDeactivatedCoverageExtension(Object extension, Project project, String pluginKey) { + static boolean isDeactivatedCoverageExtension(Object extension, String pluginKey, Project project, Settings settings) { if (!ExtensionUtils.isType(extension, CoverageExtension.class)) { return false; } @@ -106,7 +112,7 @@ public final class ProjectExtensionInstaller implements BatchComponent { } if (StringUtils.equals(project.getLanguageKey(), Java.KEY)) { - String[] selectedPluginKeys = project.getConfiguration().getStringArray(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY); + String[] selectedPluginKeys = settings.getStringArray(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY); if (ArrayUtils.isEmpty(selectedPluginKeys)) { selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN}; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java index 5381fc093ed..04bf35c3d45 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java @@ -112,8 +112,9 @@ public class ProjectModule extends Module { } private void addProjectPluginExtensions() { + addCoreSingleton(ProjectExtensionInstaller.class); ProjectExtensionInstaller installer = getComponentByType(ProjectExtensionInstaller.class); - installer.install(this, project); + installer.install(this); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java index ca5e52ff96d..b8fc2a60b84 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java @@ -49,7 +49,7 @@ public class ProjectSettings extends Settings { public ProjectSettings load() { clear(); - + // order is important -> bottom-up. The last one overrides all the others. loadDatabaseGlobalSettings(); loadDatabaseProjectSettings(projectDefinition); diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java index 1148116b2e1..badaa62d2c8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java @@ -28,6 +28,7 @@ import org.sonar.api.*; import org.sonar.api.batch.CoverageExtension; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.SupportedEnvironment; +import org.sonar.api.config.Settings; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrapper.EnvironmentInformation; @@ -66,9 +67,9 @@ public class ProjectExtensionInstallerTest { }); when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap); Module module = new FakeModule().init(); - ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); + ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null); - installer.install(module, new Project("foo")); + installer.install(module); assertThat(module.getComponentByType(BatchService.class), nullValue()); assertThat(module.getComponentByType(ProjectService.class), not(nullValue())); @@ -86,24 +87,16 @@ public class ProjectExtensionInstallerTest { }); when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap); Module module = new FakeModule().init(); - ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); + ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null); - installer.install(module, new Project("foo")); + installer.install(module); assertThat(module.getComponentByType(MavenService.class), nullValue()); assertThat(module.getComponentByType(BuildToolService.class), not(nullValue())); } - - @Test - public void shouldRegisterOnlyCoberturaExtensionByDefault() { - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(null), "cobertura"), is(false)); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(null), "clover"), is(true)); - } - - private static Project newJavaProject(Configuration conf) { + private static Project newJavaProject() { Project project = new Project("foo").setLanguageKey(Java.KEY).setAnalysisType(Project.AnalysisType.DYNAMIC); - project.setConfiguration(conf != null ? conf : new PropertiesConfiguration()); return project; } @@ -113,22 +106,22 @@ public class ProjectExtensionInstallerTest { @Test public void shouldRegisterCustomCoverageExtension() { - Configuration conf = new PropertiesConfiguration(); + Settings conf = new Settings(); conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "clover,phpunit"); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(conf), "cobertura"), is(true)); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(conf), "clover"), is(false)); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(conf), "phpunit"), is(false)); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(conf), "other"), is(true)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "cobertura", newJavaProject(), conf), is(true)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "clover", newJavaProject(), conf), is(false)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "phpunit", newJavaProject(), conf), is(false)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "other", newJavaProject(), conf), is(true)); } @Test public void shouldNotCheckCoverageExtensionsOnNonJavaProjects() { - Configuration conf = new PropertiesConfiguration(); + Settings conf = new Settings(); conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "cobertura"); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newGroovyProject(), "groovy"), is(false)); - assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, newJavaProject(null), "groovy"), is(true)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newGroovyProject(), conf), is(false)); + assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newJavaProject(), conf), is(true)); } |