]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7441 add annotation ComputeEngineSide
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 23 Mar 2016 08:56:27 +0000 (09:56 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 29 Mar 2016 11:06:51 +0000 (13:06 +0200)
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/platform/ComputeEngineExtensionInstaller.java [new file with mode: 0644]
server/sonar-ce/src/main/java/org/sonar/ce/platform/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java
server/sonar-server/src/main/java/org/sonar/server/plugins/WebServerExtensionInstaller.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/ce/ComputeEngineSide.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/ce/package-info.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java

index cee129ecb32e80c1d30902e98df3d79404ead409..ef095ab7de73f3ef65c7b3f000eee07e1a79def0 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.api.utils.UriReader;
 import org.sonar.ce.db.CeDbClient;
 import org.sonar.ce.db.ReadOnlyPropertiesDao;
 import org.sonar.ce.es.EsIndexerEnabler;
+import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
 import org.sonar.ce.property.CePropertyDefinitions;
 import org.sonar.ce.settings.ComputeEngineSettings;
 import org.sonar.ce.user.CeUserSession;
@@ -191,7 +192,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
     PluginLoader.class,
     CePluginRepository.class,
     InstalledPluginReferentialFactory.class,
-    ServerExtensionInstaller.class,
+    ComputeEngineExtensionInstaller.class,
 
     // depends on plugins
     // RailsAppsDeployer.class,
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/platform/ComputeEngineExtensionInstaller.java b/server/sonar-ce/src/main/java/org/sonar/ce/platform/ComputeEngineExtensionInstaller.java
new file mode 100644 (file)
index 0000000..70c0d74
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.ce.platform;
+
+import org.sonar.api.SonarQubeVersion;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.core.platform.PluginRepository;
+import org.sonar.server.plugins.ServerExtensionInstaller;
+
+public class ComputeEngineExtensionInstaller extends ServerExtensionInstaller {
+  public ComputeEngineExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository) {
+    super(sonarQubeVersion, pluginRepository, ComputeEngineSide.class);
+  }
+}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/platform/package-info.java b/server/sonar-ce/src/main/java/org/sonar/ce/platform/package-info.java
new file mode 100644 (file)
index 0000000..29dc7df
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.ce.platform;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 83de0bd37c6630a870c315c2c98886abd554e44e..f1ddb825890070c81fc8e6a8538713a5e0b7a5ad 100644 (file)
@@ -30,9 +30,9 @@ import org.sonar.server.db.migrations.PlatformDatabaseMigrationExecutorServiceIm
 import org.sonar.server.platform.DefaultServerUpgradeStatus;
 import org.sonar.server.platform.RailsAppsDeployer;
 import org.sonar.server.plugins.InstalledPluginReferentialFactory;
-import org.sonar.server.plugins.ServerExtensionInstaller;
 import org.sonar.server.plugins.ServerPluginJarExploder;
 import org.sonar.server.plugins.ServerPluginRepository;
+import org.sonar.server.plugins.WebServerExtensionInstaller;
 import org.sonar.server.ruby.PlatformRubyBridge;
 import org.sonar.server.ui.JRubyI18n;
 
@@ -56,7 +56,7 @@ public class PlatformLevel2 extends PlatformLevel {
       PluginLoader.class,
       PluginClassloaderFactory.class,
       InstalledPluginReferentialFactory.class,
-      ServerExtensionInstaller.class,
+      WebServerExtensionInstaller.class,
 
       // depends on plugins
       RailsAppsDeployer.class,
index 53fe385e2e3636de1c2ba10fb52e168915a4640a..5ed1fac8f05f40ab3aa162d61700772148e9856d 100644 (file)
@@ -21,30 +21,34 @@ package org.sonar.server.plugins;
 
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
+import java.lang.annotation.Annotation;
 import java.util.Map;
 import org.sonar.api.Extension;
 import org.sonar.api.ExtensionProvider;
 import org.sonar.api.Plugin;
-import org.sonar.api.SonarPlugin;
 import org.sonar.api.SonarQubeVersion;
-import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.AnnotationUtils;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.platform.PluginRepository;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Loads the plugins server extensions and injects them to DI container
  */
-@ServerSide
-public class ServerExtensionInstaller {
+public abstract class ServerExtensionInstaller {
 
   private final SonarQubeVersion sonarQubeVersion;
   private final PluginRepository pluginRepository;
+  private final Class<? extends Annotation> supportedAnnotationType;
 
-  public ServerExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository) {
+  protected ServerExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository,
+    Class<? extends Annotation> supportedAnnotationType) {
+    requireNonNull(supportedAnnotationType, "At least one supported annotation type must be specified");
     this.sonarQubeVersion = sonarQubeVersion;
     this.pluginRepository = pluginRepository;
+    this.supportedAnnotationType = supportedAnnotationType;
   }
 
   public void installExtensions(ComponentContainer container) {
@@ -99,7 +103,7 @@ public class ServerExtensionInstaller {
   }
 
   Object installExtension(ComponentContainer container, PluginInfo pluginInfo, Object extension, boolean acceptProvider) {
-    if (AnnotationUtils.getAnnotation(extension, ServerSide.class) != null) {
+    if (AnnotationUtils.getAnnotation(extension, supportedAnnotationType) != null) {
       if (!acceptProvider && isExtensionProvider(extension)) {
         throw new IllegalStateException("ExtensionProvider can not include providers itself: " + extension);
       }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/WebServerExtensionInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/WebServerExtensionInstaller.java
new file mode 100644 (file)
index 0000000..9e6483d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.server.plugins;
+
+import org.sonar.api.SonarQubeVersion;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.platform.PluginRepository;
+
+@ServerSide
+public class WebServerExtensionInstaller extends ServerExtensionInstaller {
+  public WebServerExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository) {
+    super(sonarQubeVersion, pluginRepository, ServerSide.class);
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/ComputeEngineSide.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/ComputeEngineSide.java
new file mode 100644 (file)
index 0000000..9db92b2
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.ce;
+
+import com.google.common.annotations.Beta;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.sonar.api.batch.BatchSide;
+
+/**
+ * Same as {@link BatchSide} but for components for the Compute Engine Server.
+ *
+ * @since 5.5
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Beta
+public @interface ComputeEngineSide {
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/package-info.java
new file mode 100644 (file)
index 0000000..5cf986e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.ce;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index f83920847e3f3c218017ee79271bafc05ee22ec3..f4b685a57a410778521cfdd0fc24d585e16f127e 100644 (file)
@@ -23,6 +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.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -57,6 +58,8 @@ public class ExtensionUtilsTest {
 
     assertThat(ExtensionUtils.isBatchSide(ServerService.class)).isFalse();
     assertThat(ExtensionUtils.isBatchSide(new ServerService())).isFalse();
+    assertThat(ExtensionUtils.isBatchSide(new WebServerService())).isFalse();
+    assertThat(ExtensionUtils.isBatchSide(new ComputeEngineService())).isFalse();
   }
 
   @BatchSide
@@ -85,4 +88,14 @@ public class ExtensionUtilsTest {
 
   }
 
+  @ServerSide
+  public static class WebServerService {
+
+  }
+
+  @ComputeEngineSide
+  public static class ComputeEngineService {
+
+  }
+
 }