Skip to content

Commit

Permalink
add Module concept to component management
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed May 27, 2015
1 parent f5704c2 commit 28d2d52
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 17 deletions.
Expand Up @@ -20,9 +20,11 @@
package org.sonar.server.platform.platformlevel; package org.sonar.server.platform.platformlevel;


import java.util.Collection; import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.component.Module;


import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;


Expand Down Expand Up @@ -62,7 +64,18 @@ protected ComponentContainer createContainer(@Nullable ComponentContainer parent
return parent.createChild(); 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 * Intended to be override by subclasses if needed
Expand Down
Expand Up @@ -90,7 +90,7 @@ public PlatformLevel1(Platform platform, Properties properties, Object... extraR
} }


@Override @Override
public PlatformLevel configure() { public void configureLevel() {
add(platform, properties); add(platform, properties);
addExtraRootComponents(); addExtraRootComponents();
add( add(
Expand Down Expand Up @@ -166,8 +166,6 @@ public PlatformLevel configure() {
addAll(CorePropertyDefinitions.all()); addAll(CorePropertyDefinitions.all());
addAll(MigrationSteps.CLASSES); addAll(MigrationSteps.CLASSES);
addAll(DaoUtils.getDaoClasses()); addAll(DaoUtils.getDaoClasses());

return this;
} }


private void addExtraRootComponents() { private void addExtraRootComponents() {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public PlatformLevel2(PlatformLevel parent) {
} }


@Override @Override
public PlatformLevel configure() { protected void configureLevel() {
add( add(
DefaultServerUpgradeStatus.class, DefaultServerUpgradeStatus.class,
DatabaseMigrator.class, DatabaseMigrator.class,
Expand All @@ -66,6 +66,5 @@ public PlatformLevel configure() {
// DB migration // DB migration
PlatformDatabaseMigrationExecutorServiceImpl.class, PlatformDatabaseMigrationExecutorServiceImpl.class,
PlatformDatabaseMigration.class); PlatformDatabaseMigration.class);
return this;
} }
} }
Expand Up @@ -34,7 +34,7 @@ public PlatformLevel3(PlatformLevel parent) {
} }


@Override @Override
public PlatformLevel configure() { protected void configureLevel() {
add( add(
PersistentSettings.class, PersistentSettings.class,
DefaultDatabaseConnector.class, DefaultDatabaseConnector.class,
Expand All @@ -44,6 +44,5 @@ public PlatformLevel configure() {
DefaultHttpDownloader.class, DefaultHttpDownloader.class,
UriReader.class, UriReader.class,
ServerIdGenerator.class); ServerIdGenerator.class);
return this;
} }
} }
Expand Up @@ -301,7 +301,7 @@ public PlatformLevel4(PlatformLevel parent, List<Object> level4AddedComponents)
} }


@Override @Override
public PlatformLevel configure() { protected void configureLevel() {
add( add(
PluginDownloader.class, PluginDownloader.class,
ChartFactory.class, ChartFactory.class,
Expand Down Expand Up @@ -692,8 +692,6 @@ public PlatformLevel configure() {
NavigationWs.class); NavigationWs.class);


addAll(level4AddedComponents); addAll(level4AddedComponents);

return this;
} }


@Override @Override
Expand Down
Expand Up @@ -33,7 +33,7 @@ public PlatformLevelSafeMode(PlatformLevel parent) {
} }


@Override @Override
public PlatformLevel configure() { protected void configureLevel() {
add( add(
// DB access required by DatabaseSessionFilter wired into ROR // DB access required by DatabaseSessionFilter wired into ROR
DefaultDatabaseConnector.class, DefaultDatabaseConnector.class,
Expand All @@ -49,7 +49,5 @@ public PlatformLevel configure() {


// WS engine // WS engine
WebServiceEngine.class); WebServiceEngine.class);

return this;
} }
} }
Expand Up @@ -48,7 +48,7 @@ public PlatformLevelStartup(PlatformLevel parent) {
} }


@Override @Override
public PlatformLevel configure() { protected void configureLevel() {
add( add(
IndexSynchronizer.class, IndexSynchronizer.class,
RegisterMetrics.class, RegisterMetrics.class,
Expand All @@ -68,8 +68,6 @@ public PlatformLevel configure() {
ReportQueueCleaner.class, ReportQueueCleaner.class,
RegisterIssueFilters.class, RegisterIssueFilters.class,
RenameIssueWidgets.class); RenameIssueWidgets.class);

return this;
} }


@Override @Override
Expand Down
63 changes: 63 additions & 0 deletions sonar-core/src/main/java/org/sonar/core/component/Module.java
@@ -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()]));
}

}

0 comments on commit 28d2d52

Please sign in to comment.