]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2861 fix loading of the property sonar.core.codeCoveragePlugin
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Oct 2011 13:18:04 +0000 (15:18 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Oct 2011 13:18:32 +0000 (15:18 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java

index ce6985b8c2e75c25a5074e72895644e94ff99268..28cb581735ba5334f0b064a80db1e9713cfb75c1 100644 (file)
@@ -75,7 +75,6 @@ public class BootstrapModule extends Module {
 
     addCoreSingleton(BatchPluginRepository.class);
     addCoreSingleton(BatchExtensionInstaller.class);
-    addCoreSingleton(ProjectExtensionInstaller.class);
     addCoreSingleton(BatchSettingsEnhancer.class);
   }
 
index 145d971387e11a7d95103ca187a8dbe33477bfc1..f92163255d22c8c15e81bab8e15fc18a34443237 100644 (file)
@@ -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};
       }
index 5381fc093ed16931432416f14368912d61f4759f..04bf35c3d459c22d9b71a1a6ae93d7ec7fab2da9 100644 (file)
@@ -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);
   }
 
 
index ca5e52ff96d60bc4a72cf3c84c46f6487243d37d..b8fc2a60b84c83665fe023ef8c910b5a616331d6 100644 (file)
@@ -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);
index 1148116b2e109ba885157eb0efacc3403fd791d4..badaa62d2c803b15b64619520f4f2313c64206a7 100644 (file)
@@ -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));
 
   }