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() {
@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();
*/
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;
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
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