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;
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;
/**
* 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;
}
}
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};
}
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;
});
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()));
});
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;
}
@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));
}