From: Julien HENRY Date: Wed, 12 Jun 2013 15:15:16 +0000 (+0200) Subject: SONAR-4386 Provide a context to ProjectBuilder for later evolutions X-Git-Tag: 3.7~504 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f29ce9033080ae74a2f31541fe09c755376a61e2;p=sonarqube.git SONAR-4386 Provide a context to ProjectBuilder for later evolutions --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java index 550ec324b82..bf535ddf90a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java @@ -20,6 +20,7 @@ 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; @@ -53,8 +54,16 @@ public class ProjectReactorReady { } 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); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java index b3adf46ad6d..c5fe2aee67a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java @@ -52,16 +52,18 @@ public abstract class ProjectBuilder implements BatchExtension { } /** - * 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) { + } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java index 2ae474e3866..14b57bb10ac 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java @@ -33,10 +33,16 @@ public class ProjectBuilderTest { @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();