]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6732 add components from PlatformLevel1 to CE container
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 11 Mar 2016 12:38:03 +0000 (13:38 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 21 Mar 2016 15:44:04 +0000 (16:44 +0100)
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java

index 445c5f95c96d1a4cc4965e28d15763c16569484b..26426184039c2a6ad1437a5a0602a14ba00a46b9 100644 (file)
 package org.sonar.ce.container;
 
 import com.google.common.annotations.VisibleForTesting;
+import java.util.List;
+import org.sonar.api.utils.System2;
+import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.platform.ComponentContainer;
+import org.sonar.core.platform.Module;
+import org.sonar.core.platform.SonarQubeVersionProvider;
+import org.sonar.core.util.UuidFactoryImpl;
+import org.sonar.db.DaoModule;
+import org.sonar.db.DatabaseChecker;
+import org.sonar.db.DbClient;
+import org.sonar.db.DefaultDatabase;
+import org.sonar.db.purge.PurgeProfiler;
+import org.sonar.db.version.DatabaseVersion;
+import org.sonar.db.version.MigrationStepModule;
 import org.sonar.process.Props;
+import org.sonar.server.computation.property.CePropertyDefinitions;
+import org.sonar.server.issue.index.IssueIndex;
+import org.sonar.server.platform.DatabaseServerCompatibility;
+import org.sonar.server.platform.DefaultServerFileSystem;
+import org.sonar.server.platform.ServerImpl;
+import org.sonar.server.platform.ServerSettings;
+import org.sonar.server.platform.TempFolderProvider;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.rule.index.RuleIndex;
+import org.sonar.server.search.EsSearchModule;
 
 public class ComputeEngineContainerImpl implements ComputeEngineContainer {
+  private static final Object[] LEVEL_1_COMPONENTS = new Object[] {
+    new SonarQubeVersionProvider(),
+    ServerSettings.class,
+    ServerImpl.class,
+    UuidFactoryImpl.INSTANCE,
+    // no EmbeddedDatabaseFactory.class, creating H2 DB if responsibility of WebServer
+    DefaultDatabase.class,
+    DatabaseChecker.class,
+    // must instantiate deprecated class in 5.2 and only this one (and not its replacement)
+    // to avoid having two SqlSessionFactory instances
+    org.sonar.core.persistence.MyBatis.class,
+    DatabaseServerCompatibility.class,
+    DatabaseVersion.class,
+    PurgeProfiler.class,
+    DefaultServerFileSystem.class,
+    // no TempFolderCleaner.class, responsibility of Web Server
+    new TempFolderProvider(),
+    System2.INSTANCE,
+
+    // DB
+    DbClient.class,
+    DaoModule.class,
+    MigrationStepModule.class,
+
+    // Elasticsearch
+    EsSearchModule.class,
+
+    // rules/qprofiles
+    RuleIndex.class,
+    ActiveRuleIndex.class,
+
+    // issues
+    IssueIndex.class,
+
+    // Classes kept for backward compatibility of plugins/libs (like sonar-license) that are directly calling classes from the core
+    org.sonar.core.properties.PropertiesDao.class
+  };
+
   private final ComponentContainer componentContainer;
 
   public ComputeEngineContainerImpl() {
@@ -32,12 +93,28 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
 
   @Override
   public ComputeEngineContainer configure(Props props) {
-    this.componentContainer.add(
-      props.rawProperties()
-      );
+    this.componentContainer
+      .add(props.rawProperties())
+      .add(LEVEL_1_COMPONENTS)
+      .add(toArray(CorePropertyDefinitions.all()))
+      .add(toArray(CePropertyDefinitions.all()));
+
+    configureFromModules();
+
     return this;
   }
 
+  private static Object[] toArray(List<?> list) {
+    return list.toArray(new Object[list.size()]);
+  }
+
+  private void configureFromModules() {
+    List<Module> modules = this.componentContainer.getComponentsByType(Module.class);
+    for (Module module : modules) {
+      module.configure(this.componentContainer);
+    }
+  }
+
   @Override
   public ComputeEngineContainer start() {
     this.componentContainer.startComponents();
index bf42fa8a390ad5bd52ebe0b687cc4b1280e2927e..abd6705062be3b3d8b65b54582ee19bad9ad4497 100644 (file)
  */
 package org.sonar.ce.container;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.Properties;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.picocontainer.MutablePicoContainer;
 import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.database.DatabaseProperties;
 import org.sonar.core.platform.ComponentContainer;
+import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -31,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ComputeEngineContainerImplTest {
   private static final int COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION = 2;
 
+  @Rule
+  public TemporaryFolder tempFolder = new TemporaryFolder();
+
   private ComputeEngineContainerImpl underTest = new ComputeEngineContainerImpl();
 
   @Test
@@ -56,7 +65,31 @@ public class ComputeEngineContainerImplTest {
     underTest.configure(new Props(properties));
 
     assertThat(underTest.getComponentContainer().getPicoContainer().getComponentAdapters())
-        .hasSize(COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION + 1);
+      .hasSize(COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION
+          + 22 // level 1
+          + 47 // content of DaoModule
+          + 1  // content of EsSearchModule
+          + 58 // content of CorePropertyDefinitions
+          + 1 // content of CePropertyDefinitions
+          + 59 // content of MigrationStepModule
+      );
+  }
+
+  @Test
+  public void real_start() throws IOException {
+    Properties properties = new Properties();
+    File homeDir = tempFolder.newFolder();
+    File dataDir = new File(homeDir, "data");
+    File tmpDir = new File(homeDir, "tmp");
+    properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
+    properties.setProperty(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath());
+    properties.setProperty(ProcessProperties.PATH_TEMP, tmpDir.getAbsolutePath());
+    properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:mem:sonar");
+
+    underTest
+      .configure(new Props(properties))
+      .start();
+
   }
 
   @Test