]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4386 Provide a context to ProjectBuilder for later evolutions
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 12 Jun 2013 15:15:16 +0000 (17:15 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 12 Jun 2013 15:15:16 +0000 (17:15 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java

index 550ec324b82b9db510a4befc97f8eb6b1e98e614..bf535ddf90abd21f7d03048fd17c3e4021a6214f 100644 (file)
@@ -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);
index b3adf46ad6daecc16d01dc0695749f25e57e69e2..c5fe2aee67aafd6883608faae68a48be7aa38b7e 100644 (file)
@@ -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) {
+  }
 }
index 2ae474e3866b7dbd4a8a6438d9c016811dc5c112..14b57bb10acd33d61538b00420c0ee2139dc611a 100644 (file)
@@ -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();