package org.sonar.batch.scan;
import org.sonar.api.batch.bootstrap.ProjectBuilder;
+import org.sonar.api.batch.bootstrap.ProjectBuilderContext;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
}
public void start() {
+ ProjectBuilderContext context = new ProjectBuilderContext() {
+
+ @Override
+ public ProjectReactor getProjectReactor() {
+ return reactor;
+ }
+ };
+
for (ProjectBuilder projectBuilder : projectBuilders) {
- projectBuilder.doBuild(reactor);
+ projectBuilder.build(context);
}
ProjectReactorValidator validator = new ProjectReactorValidator(settings);
validator.validate(reactor);
}
/**
- * This method was introduced to relax visibility of {@link #build(ProjectReactor)}
+ * Override this method to change project reactor structure.
* @since 3.7
*/
- public final void doBuild(ProjectReactor reactor) {
- build(reactor);
+ public void build(ProjectBuilderContext context) {
+ // Call deprecated method for backward compatibility
+ build(context.getProjectReactor());
}
/**
- * This method will be called by Sonar core to let you a chance to change project reactor structure.
- * @param reactor
+ * @deprecated since 3.7 override {@link #build(ProjectBuilderContext)} instead
*/
- protected abstract void build(ProjectReactor reactor);
+ @Deprecated
+ protected void build(ProjectReactor reactor) {
+ }
}
@Test
public void shouldChangeProject() {
// this reactor is created and provided by Sonar
- ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
+ final ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
ProjectBuilder builder = new ProjectBuilderSample(new Settings());
- builder.doBuild(projectReactor);
+ builder.build(new ProjectBuilderContext() {
+
+ @Override
+ public ProjectReactor getProjectReactor() {
+ return projectReactor;
+ }
+ });
assertThat(projectReactor.getProjects().size(), is(2));
ProjectDefinition root = projectReactor.getRoot();