]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4386 Refactor ProjectBuilder extension
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 11 Jun 2013 13:17:11 +0000 (15:17 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 11 Jun 2013 13:17:11 +0000 (15:17 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorReady.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.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 cfe6a4b99a13811a9ee1773813b9644f376e52df..550ec324b82b9db510a4befc97f8eb6b1e98e614 100644 (file)
@@ -40,17 +40,22 @@ public class ProjectReactorReady {
 
   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);
   }
index aaa1413b901134d3102bf8a1355d00073b9197b0..06030f10f2aaeb9ed2ac389bdca570171e2a758b 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.batch.DefaultFileLinesContextFactory;
 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;
@@ -151,12 +150,6 @@ public class ProjectScanContainer extends ComponentContainer {
     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);
index 4a267d55196c21d6d4f23841fc581731b69d7fef..d839b281d104e1751665d25760ac8a10cae7f701 100644 (file)
@@ -39,4 +39,9 @@ public class ProjectSettingsReady {
   public void start() {
     settings.init(reactor);
   }
+
+  public void stop() {
+    // Remove project specific settings
+    settings.restore();
+  }
 }
index 7f874f07619983236941b44cd46bd37dcf854e86..b3adf46ad6daecc16d01dc0695749f25e57e69e2 100644 (file)
@@ -37,15 +37,31 @@ import org.sonar.api.batch.InstantiationStrategy;
 @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);
 }
index 9def3de0aa806101c5fb470e066f83e003fcbb6d..2ae474e3866b7dbd4a8a6438d9c016811dc5c112 100644 (file)
@@ -19,9 +19,8 @@
  */
 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;
 
@@ -33,11 +32,11 @@ public class ProjectBuilderTest {
 
   @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();
@@ -47,12 +46,10 @@ public class ProjectBuilderTest {
   }
 
   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;
     }