private final ProjectReactor reactor;
private final Settings settings;
+ private ProjectBuilder[] projectBuilders;
public ProjectReactorReady(ProjectExclusions exclusions, ProjectReactor reactor, Settings settings, @Nullable ProjectBuilder[] projectBuilders) {
this.reactor = reactor;
this.settings = settings;
+ this.projectBuilders = projectBuilders;
}
public ProjectReactorReady(ProjectExclusions exclusions, ProjectReactor reactor, Settings settings) {
- this(exclusions, reactor, settings, null);
+ this(exclusions, reactor, settings, new ProjectBuilder[0]);
}
public void start() {
+ for (ProjectBuilder projectBuilder : projectBuilders) {
+ projectBuilder.doBuild(reactor);
+ }
ProjectReactorValidator validator = new ProjectReactorValidator(settings);
validator.validate(reactor);
}
import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.bootstrap.BatchSettings;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
scanRecursively(tree.getRootProject());
}
- public void stop() {
- // Remove project specific settings
- BatchSettings settings = getComponentByType(BatchSettings.class);
- settings.restore();
- }
-
private void scanRecursively(Project module) {
for (Project subModules : module.getModules()) {
scanRecursively(subModules);
public void start() {
settings.init(reactor);
}
+
+ public void stop() {
+ // Remove project specific settings
+ settings.restore();
+ }
}
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public abstract class ProjectBuilder implements BatchExtension {
- private ProjectReactor reactor;
-
+ /**
+ * Don't inject ProjectReactor as it may not be available
+ * @deprecated since 3.7 use {@link #ProjectBuilder()}
+ */
+ @Deprecated
protected ProjectBuilder(final ProjectReactor reactor) {
- this.reactor = reactor;
}
- public final void start() {
+ /**
+ * @since 3.7
+ */
+ protected ProjectBuilder() {
+ }
+
+ /**
+ * This method was introduced to relax visibility of {@link #build(ProjectReactor)}
+ * @since 3.7
+ */
+ public final void doBuild(ProjectReactor reactor) {
build(reactor);
}
+ /**
+ * This method will be called by Sonar core to let you a chance to change project reactor structure.
+ * @param reactor
+ */
protected abstract void build(ProjectReactor reactor);
}
*/
package org.sonar.api.batch.bootstrap;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
+import org.sonar.api.config.Settings;
import java.io.File;
@Test
public void shouldChangeProject() {
- // this reactor is created and injected by Sonar
+ // this reactor is created and provided by Sonar
ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
- ProjectBuilder builder = new ProjectBuilderSample(projectReactor, new PropertiesConfiguration());
- builder.start();
+ ProjectBuilder builder = new ProjectBuilderSample(new Settings());
+ builder.doBuild(projectReactor);
assertThat(projectReactor.getProjects().size(), is(2));
ProjectDefinition root = projectReactor.getRoot();
}
final static class ProjectBuilderSample extends ProjectBuilder {
- private Configuration conf;
+ private Settings conf;
- public ProjectBuilderSample(ProjectReactor reactor, Configuration conf) {
- super(reactor);
-
- // A real implementation should for example use the configuration
+ public ProjectBuilderSample(Settings conf) {
+ // A real implementation should for example use the settings
this.conf = conf;
}