From a7a4837bcb2487b0b83bf3489099e3efe0f64e49 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 19 Jan 2016 16:07:28 +0100 Subject: [PATCH] SONAR-7234 Remove @SupportedEnvironment --- .../batch/bootstrap/ExtensionInstaller.java | 10 ++--- .../sonar/batch/bootstrap/ExtensionUtils.java | 21 ---------- .../bootstrap/ExtensionInstallerTest.java | 33 ++------------- .../batch/bootstrap/ExtensionUtilsTest.java | 32 --------------- .../sonar/api/batch/SupportedEnvironment.java | 41 ------------------- 5 files changed, 6 insertions(+), 131 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java 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 { - - } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java deleted file mode 100644 index 4e435e57c23..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SupportedEnvironment.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation allows to specify in which environments {@link BatchSide} components would be active. - * For example: "maven", "ant". - * Usage of this annotation is discouraged and we strictly recommend you to not overuse it. - * Most preferable is to design components to work in all environments. - * - * @since 2.6 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface SupportedEnvironment { - - String[] value(); - -} -- 2.39.5