aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-30 11:28:58 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-30 11:28:58 +0000
commit9db8ba7bf8f6450d309878fa2ad607e3ef9831b4 (patch)
tree9a4e0a73be6b59a75c44501b1d53f3415b98cb3d /sonar-batch
parent4b6828f0e98b5284ff0eacda9bcd8796bc6b8d10 (diff)
downloadsonarqube-9db8ba7bf8f6450d309878fa2ad607e3ef9831b4.tar.gz
sonarqube-9db8ba7bf8f6450d309878fa2ad607e3ef9831b4.zip
do use the parameter sonar.core.codeCoveragePlugin only for java projects
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java50
2 files changed, 47 insertions, 22 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
index 891d8e1fbf7..acfc42b355f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
@@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.Plugin;
import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
import org.sonar.core.plugin.AbstractPluginRepository;
@@ -123,7 +124,7 @@ public class BatchPluginRepository extends AbstractPluginRepository {
protected boolean shouldRegisterExtension(PicoContainer container, String pluginKey, Object extension) {
boolean ok = isType(extension, BatchExtension.class);
if (ok && isType(extension, AbstractCoverageExtension.class)) {
- ok = shouldRegisterCoverageExtension(pluginKey, container.getComponent(Configuration.class));
+ ok = shouldRegisterCoverageExtension(pluginKey, container.getComponent(Project.class), container.getComponent(Configuration.class));
if (!ok) {
LOG.debug("The following extension is ignored: " + extension + ". See the parameter " + AbstractCoverageExtension.PARAM_PLUGIN);
}
@@ -131,12 +132,16 @@ public class BatchPluginRepository extends AbstractPluginRepository {
return ok;
}
- boolean shouldRegisterCoverageExtension(String pluginKey, Configuration conf) {
- String[] selectedPluginKeys = conf.getStringArray(AbstractCoverageExtension.PARAM_PLUGIN);
- if (ArrayUtils.isEmpty(selectedPluginKeys)) {
- selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN};
+ boolean shouldRegisterCoverageExtension(String pluginKey, Project project, Configuration conf) {
+ boolean ok=true;
+ if (StringUtils.equals(project.getLanguageKey(), Java.KEY)) {
+ String[] selectedPluginKeys = conf.getStringArray(AbstractCoverageExtension.PARAM_PLUGIN);
+ if (ArrayUtils.isEmpty(selectedPluginKeys)) {
+ selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN};
+ }
+ String oldCoveragePluginKey = getOldCoveragePluginKey(pluginKey);
+ ok = ArrayUtils.contains(selectedPluginKeys, pluginKey) || ArrayUtils.contains(selectedPluginKeys, oldCoveragePluginKey);
}
- String oldCoveragePluginKey = getOldCoveragePluginKey(pluginKey);
- return ArrayUtils.contains(selectedPluginKeys, pluginKey) || ArrayUtils.contains(selectedPluginKeys, oldCoveragePluginKey);
+ return ok;
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java
index 604c8296206..02bee6344fe 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java
@@ -26,6 +26,8 @@ import org.picocontainer.MutablePicoContainer;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Project;
import org.sonar.api.utils.IocContainer;
import static org.hamcrest.core.Is.is;
@@ -54,8 +56,8 @@ public class BatchPluginRepositoryTest {
public void shouldRegisterOnlyCoberturaExtensionByDefault() {
BatchPluginRepository repository = new BatchPluginRepository();
PropertiesConfiguration conf = new PropertiesConfiguration();
- assertThat(repository.shouldRegisterCoverageExtension("cobertura", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("clover", conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("cobertura", newJavaProject(), conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("clover", newJavaProject(),conf), is(false));
}
@Test
@@ -63,10 +65,10 @@ public class BatchPluginRepositoryTest {
Configuration conf = new PropertiesConfiguration();
conf.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "clover,phpunit");
BatchPluginRepository repository = new BatchPluginRepository();
- assertThat(repository.shouldRegisterCoverageExtension("cobertura", conf), is(false));
- assertThat(repository.shouldRegisterCoverageExtension("clover", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("phpunit", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("other", conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("cobertura", newJavaProject(),conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("clover", newJavaProject(), conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("phpunit", newJavaProject(),conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("other", newJavaProject(),conf), is(false));
}
@Test
@@ -75,13 +77,13 @@ public class BatchPluginRepositoryTest {
conf.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "emma");
BatchPluginRepository repository = new BatchPluginRepository();
- assertThat(repository.shouldRegisterCoverageExtension("sonar-emma-plugin", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("emma", conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("sonar-emma-plugin", newJavaProject(),conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("emma", newJavaProject(),conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("sonar-jacoco-plugin", conf), is(false));
- assertThat(repository.shouldRegisterCoverageExtension("jacoco", conf), is(false));
- assertThat(repository.shouldRegisterCoverageExtension("clover", conf), is(false));
- assertThat(repository.shouldRegisterCoverageExtension("cobertura", conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("sonar-jacoco-plugin", newJavaProject(),conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("jacoco", newJavaProject(),conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("clover", newJavaProject(),conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("cobertura", newJavaProject(),conf), is(false));
}
@Test
@@ -90,9 +92,27 @@ public class BatchPluginRepositoryTest {
conf.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "cobertura,jacoco");
BatchPluginRepository repository = new BatchPluginRepository();
- assertThat(repository.shouldRegisterCoverageExtension("sonar-jacoco-plugin", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("jacoco", conf), is(true));
- assertThat(repository.shouldRegisterCoverageExtension("emma", conf), is(false));
+ assertThat(repository.shouldRegisterCoverageExtension("sonar-jacoco-plugin", newJavaProject(),conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("jacoco", newJavaProject(),conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("emma", newJavaProject(),conf), is(false));
+ }
+
+ @Test
+ public void shouldNotCheckCoverageExtensionsOnNonJavaProjects() {
+ Configuration conf = new PropertiesConfiguration();
+ conf.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "cobertura");
+ BatchPluginRepository repository = new BatchPluginRepository();
+
+ assertThat(repository.shouldRegisterCoverageExtension("groovy", newGroovyProject(),conf), is(true));
+ assertThat(repository.shouldRegisterCoverageExtension("groovy", newJavaProject(),conf), is(false));
+ }
+
+ private static Project newJavaProject() {
+ return new Project("foo").setLanguageKey(Java.KEY);
+ }
+
+ private static Project newGroovyProject() {
+ return new Project("foo").setLanguageKey("grvy");
}
public static class FakeBatchExtension implements BatchExtension {