diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-01-19 16:07:28 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-01-20 20:12:44 +0100 |
commit | a7a4837bcb2487b0b83bf3489099e3efe0f64e49 (patch) | |
tree | 0ee6b9866ff1858b946004fd088304dc291a1ea9 /sonar-batch | |
parent | acdb68379316021febe9c6c435bbe4450d137ed0 (diff) | |
download | sonarqube-a7a4837bcb2487b0b83bf3489099e3efe0f64e49.tar.gz sonarqube-a7a4837bcb2487b0b83bf3489099e3efe0f64e49.zip |
SONAR-7234 Remove @SupportedEnvironment
Diffstat (limited to 'sonar-batch')
4 files changed, 6 insertions, 90 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java index 80c73e48dae..02517f6d696 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java @@ -23,7 +23,6 @@ import java.util.List; import javax.annotation.Nullable; import org.sonar.api.ExtensionProvider; import org.sonar.api.SonarPlugin; -import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; @@ -31,11 +30,9 @@ import org.sonar.core.platform.PluginRepository; public class ExtensionInstaller { private final PluginRepository pluginRepository; - private final EnvironmentInformation env; - public ExtensionInstaller(PluginRepository pluginRepository, EnvironmentInformation env) { + public ExtensionInstaller(PluginRepository pluginRepository) { this.pluginRepository = pluginRepository; - this.env = env; } public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) { @@ -66,9 +63,8 @@ public class ExtensionInstaller { return this; } - private void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginInfo pluginInfo, Object extension) { - if (ExtensionUtils.supportsEnvironment(extension, env) - && matcher.accept(extension)) { + private static void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginInfo pluginInfo, Object extension) { + if (matcher.accept(extension)) { container.addExtension(pluginInfo, extension); } else { container.declareExtension(pluginInfo, extension); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java index 74735c7cd34..adf16a40315 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java @@ -19,12 +19,9 @@ */ package org.sonar.batch.bootstrap; -import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.SupportedEnvironment; import org.sonar.api.utils.AnnotationUtils; -import org.sonar.batch.bootstrapper.EnvironmentInformation; public class ExtensionUtils { @@ -44,24 +41,6 @@ public class ExtensionUtils { return AnnotationUtils.getAnnotation(extension, BatchSide.class) != null; } - public static boolean supportsEnvironment(Object extension, EnvironmentInformation environment) { - SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class); - if (env == null) { - return true; - } - for (String supported : env.value()) { - if (StringUtils.equalsIgnoreCase(environment.getKey(), supported)) { - return true; - } - } - return false; - } - - public static boolean isMavenExtensionOnly(Object extension) { - SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class); - return env != null && env.value().length == 1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]); - } - public static boolean isType(Object extension, Class<?> extensionClass) { Class clazz = extension instanceof Class ? (Class) extension : extension.getClass(); return extensionClass.isAssignableFrom(clazz); diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java index f234e5d0ab5..948f54dde46 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java @@ -27,8 +27,6 @@ import org.junit.Test; import org.sonar.api.BatchExtension; import org.sonar.api.ExtensionProvider; import org.sonar.api.SonarPlugin; -import org.sonar.api.batch.SupportedEnvironment; -import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.PluginInfo; @@ -60,7 +58,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class)); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository); installer.install(container, new FooMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); @@ -72,7 +70,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository); installer.install(container, new FooMatcher()); @@ -85,7 +83,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository); installer.install(container, new TrueMatcher()); @@ -93,21 +91,6 @@ public class ExtensionInstallerTest { assertThat(container.getComponentByType(Bar.class)).isNotNull(); } - @Test - public void should_not_install_on_unsupported_environment() { - when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); - when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, MavenExtension.class, AntExtension.class, new BarProvider())); - ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); - - installer.install(container, new TrueMatcher()); - - assertThat(container.getComponentByType(MavenExtension.class)).isNull(); - assertThat(container.getComponentByType(AntExtension.class)).isNotNull(); - assertThat(container.getComponentByType(Foo.class)).isNotNull(); - assertThat(container.getComponentByType(Bar.class)).isNotNull(); - } - private static class FooMatcher implements ExtensionMatcher { public boolean accept(Object extension) { return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()) || ClassUtils.isAssignable(FooProvider.class, extension.getClass()); @@ -128,16 +111,6 @@ public class ExtensionInstallerTest { } - @SupportedEnvironment("maven") - public static class MavenExtension implements BatchExtension { - - } - - @SupportedEnvironment("ant") - public static class AntExtension implements BatchExtension { - - } - public static class FooProvider extends ExtensionProvider implements BatchExtension { @Override public Object provide() { diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java index beb875bb4e2..f83920847e3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java @@ -23,9 +23,7 @@ import org.junit.Test; import org.sonar.api.BatchComponent; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.SupportedEnvironment; import org.sonar.api.server.ServerSide; -import org.sonar.batch.bootstrapper.EnvironmentInformation; import static org.assertj.core.api.Assertions.assertThat; @@ -61,25 +59,6 @@ public class ExtensionUtilsTest { assertThat(ExtensionUtils.isBatchSide(new ServerService())).isFalse(); } - @Test - public void shouldCheckEnvironment() { - assertThat(ExtensionUtils.supportsEnvironment(new MavenService(), new EnvironmentInformation("maven", "2.2.1"))).isTrue(); - assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("maven", "2.2.1"))).isTrue(); - assertThat(ExtensionUtils.supportsEnvironment(new DefaultService(), new EnvironmentInformation("maven", "2.2.1"))).isTrue(); - - assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1"))).isFalse(); - } - - @Test - public void shouldBeMavenExtensionOnly() { - assertThat(ExtensionUtils.isMavenExtensionOnly(DefaultService.class)).isFalse(); - assertThat(ExtensionUtils.isMavenExtensionOnly(new DefaultService())).isFalse(); - assertThat(ExtensionUtils.isMavenExtensionOnly(MavenService.class)).isTrue(); - assertThat(ExtensionUtils.isMavenExtensionOnly(new MavenService())).isTrue(); - assertThat(ExtensionUtils.isMavenExtensionOnly(BuildToolService.class)).isFalse(); - assertThat(ExtensionUtils.isMavenExtensionOnly(new BuildToolService())).isFalse(); - } - @BatchSide @InstantiationStrategy(InstantiationStrategy.PER_BATCH) public static class BatchService { @@ -106,15 +85,4 @@ public class ExtensionUtilsTest { } - @BatchSide - @SupportedEnvironment("maven") - public static class MavenService { - - } - - @BatchSide - @SupportedEnvironment({"maven", "ant", "gradle"}) - public static class BuildToolService { - - } } |