]> source.dussan.org Git - sonarqube.git/commitdiff
add Module concept to component management
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 13 May 2015 11:43:35 +0000 (13:43 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 27 May 2015 10:11:37 +0000 (12:11 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
sonar-core/src/main/java/org/sonar/core/component/Module.java [new file with mode: 0644]

index dbb30dfdd84c2f270b3fbb02115139bf8808a5b8..28aad7223cc34f5b5a771e6ff939a3494cb5a03e 100644 (file)
 package org.sonar.server.platform.platformlevel;
 
 import java.util.Collection;
+import java.util.List;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.sonar.core.platform.ComponentContainer;
+import org.sonar.core.component.Module;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -62,7 +64,18 @@ public abstract class PlatformLevel {
     return parent.createChild();
   }
 
-  public abstract PlatformLevel configure();
+  public PlatformLevel configure() {
+    configureLevel();
+
+    List<Module> modules = container.getComponentsByType(Module.class);
+    for (Module module : modules) {
+      module.configure(container);
+    }
+
+    return this;
+  }
+
+  protected abstract void configureLevel();
 
   /**
    * Intended to be override by subclasses if needed
index 4fa1e41d2aa9005a04be3e665f0610bc557cdeec..1752c5d9a79dfa4ec0db5097031de681659a091a 100644 (file)
@@ -90,7 +90,7 @@ public class PlatformLevel1 extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  public void configureLevel() {
     add(platform, properties);
     addExtraRootComponents();
     add(
@@ -166,8 +166,6 @@ public class PlatformLevel1 extends PlatformLevel {
     addAll(CorePropertyDefinitions.all());
     addAll(MigrationSteps.CLASSES);
     addAll(DaoUtils.getDaoClasses());
-
-    return this;
   }
 
   private void addExtraRootComponents() {
index ccedb2a396149f2440dc8f44efe02830f628621a..062e796de671b1fd133cd597e484f7df495aec05 100644 (file)
@@ -41,7 +41,7 @@ public class PlatformLevel2 extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  protected void configureLevel() {
     add(
       DefaultServerUpgradeStatus.class,
       DatabaseMigrator.class,
@@ -66,6 +66,5 @@ public class PlatformLevel2 extends PlatformLevel {
       // DB migration
       PlatformDatabaseMigrationExecutorServiceImpl.class,
       PlatformDatabaseMigration.class);
-    return this;
   }
 }
index 52ec6287938ba1cfbe710cd70a795d698f432a5b..7df65744ac5d57dc03863675e4c4c9a4a1ed8931 100644 (file)
@@ -34,7 +34,7 @@ public class PlatformLevel3 extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  protected void configureLevel() {
     add(
       PersistentSettings.class,
       DefaultDatabaseConnector.class,
@@ -44,6 +44,5 @@ public class PlatformLevel3 extends PlatformLevel {
       DefaultHttpDownloader.class,
       UriReader.class,
       ServerIdGenerator.class);
-    return this;
   }
 }
index 22c6112ca22af2b2e94e4ca1c7fdfd31a77bd797..5fee29e8167a6ff35874e0092848ccab369baed3 100644 (file)
@@ -301,7 +301,7 @@ public class PlatformLevel4 extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  protected void configureLevel() {
     add(
       PluginDownloader.class,
       ChartFactory.class,
@@ -692,8 +692,6 @@ public class PlatformLevel4 extends PlatformLevel {
       NavigationWs.class);
 
     addAll(level4AddedComponents);
-
-    return this;
   }
 
   @Override
index 1fa81165fd4f95aee58ab84096462f5a33f72c5e..ac863cb139ade7265fed40241eefe66fef4c7016 100644 (file)
@@ -33,7 +33,7 @@ public class PlatformLevelSafeMode extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  protected void configureLevel() {
     add(
       // DB access required by DatabaseSessionFilter wired into ROR
       DefaultDatabaseConnector.class,
@@ -49,7 +49,5 @@ public class PlatformLevelSafeMode extends PlatformLevel {
 
       // WS engine
       WebServiceEngine.class);
-
-    return this;
   }
 }
index acfe928ddc72c57e6c505e72d5e24260488b6759..9629f23d03fc60a93683f0ed46d521e2fe72d362 100644 (file)
@@ -48,7 +48,7 @@ public class PlatformLevelStartup extends PlatformLevel {
   }
 
   @Override
-  public PlatformLevel configure() {
+  protected void configureLevel() {
     add(
       IndexSynchronizer.class,
       RegisterMetrics.class,
@@ -68,8 +68,6 @@ public class PlatformLevelStartup extends PlatformLevel {
       ReportQueueCleaner.class,
       RegisterIssueFilters.class,
       RenameIssueWidgets.class);
-
-    return this;
   }
 
   @Override
diff --git a/sonar-core/src/main/java/org/sonar/core/component/Module.java b/sonar-core/src/main/java/org/sonar/core/component/Module.java
new file mode 100644 (file)
index 0000000..6662ebd
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.component;
+
+import java.util.Collection;
+import javax.annotation.Nullable;
+import org.sonar.core.platform.ComponentContainer;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public abstract class Module {
+  private ComponentContainer container;
+
+  public Module configure(ComponentContainer container) {
+    this.container = checkNotNull(container);
+
+    configureModule();
+
+    return this;
+  }
+
+  protected abstract void configureModule();
+
+  protected void add(@Nullable Object object, boolean singleton) {
+    if (object != null) {
+      container.addComponent(object, singleton);
+    }
+  }
+
+  protected <T> T getComponentByType(Class<T> tClass) {
+    return container.getComponentByType(tClass);
+  }
+
+  protected void add(Object... objects) {
+    for (Object object : objects) {
+      if (object != null) {
+        container.addComponent(object, true);
+      }
+    }
+  }
+
+  protected void addAll(Collection<?> objects) {
+    add(objects.toArray(new Object[objects.size()]));
+  }
+
+}