]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2674 The method Sensor#shouldExecuteOnProject() must not be executed before...
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 8 Aug 2011 14:23:22 +0000 (16:23 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 8 Aug 2011 14:23:22 +0000 (16:23 +0200)
sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java
sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java
sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java

index c205df16034cdf9c195b254c0947a000818e065d..50b0d9751709860dfd55932df0e027ade97fd87c 100644 (file)
@@ -39,18 +39,19 @@ public class InitializersExecutor {
 
   private MavenPluginExecutor mavenExecutor;
 
-  private Collection<Initializer> initializers;
   private ProjectDefinition projectDef;
   private Project project;
+  private BatchExtensionDictionnary selector;
 
   public InitializersExecutor(BatchExtensionDictionnary selector, Project project, ProjectDefinition projectDef, MavenPluginExecutor mavenExecutor) {
-    this.initializers = selector.select(Initializer.class, project, true);
+    this.selector = selector;
     this.mavenExecutor = mavenExecutor;
     this.project = project;
     this.projectDef = projectDef;
   }
 
   public void execute() {
+    Collection<Initializer> initializers = selector.select(Initializer.class, project, true);
     if (logger.isDebugEnabled()) {
       logger.debug("Initializers : {}", StringUtils.join(initializers, " -> "));
     }
index 3f6b6433cbcd2e43d8fb974794206c5d0198885b..aa5ca9873b9074bdd3ac2c23fa38dac0fd1e8f19 100644 (file)
@@ -38,24 +38,25 @@ import java.util.List;
 public class PostJobsExecutor implements BatchComponent {
   private static final Logger LOG = LoggerFactory.getLogger(PostJobsExecutor.class);
 
-  private Collection<PostJob> postJobs;
   private MavenPluginExecutor mavenExecutor;
   private ProjectDefinition projectDefinition;
   private Project project;
+  private BatchExtensionDictionnary selector;
 
   public PostJobsExecutor(BatchExtensionDictionnary selector, Project project, ProjectDefinition projectDefinition, MavenPluginExecutor mavenExecutor) {
-    this(selector.select(PostJob.class, project, true), project, projectDefinition, mavenExecutor);
-  }
-
-  PostJobsExecutor(Collection<PostJob> jobs, Project project, ProjectDefinition projectDefinition, MavenPluginExecutor mavenExecutor) {
-    this.postJobs = jobs;
+    this.selector = selector;
     this.mavenExecutor = mavenExecutor;
     this.project = project;
     this.projectDefinition = projectDefinition;
   }
 
   public void execute(SensorContext context) {
-    logPostJobs();
+    Collection<PostJob> postJobs = selector.select(PostJob.class, project, true);
+    execute(context, postJobs);
+  }
+
+  void execute(SensorContext context, Collection<PostJob> postJobs) {
+    logPostJobs(postJobs);
 
     for (PostJob postJob : postJobs) {
       LOG.info("Executing post-job {}", postJob.getClass());
@@ -64,7 +65,7 @@ public class PostJobsExecutor implements BatchComponent {
     }
   }
 
-  private void logPostJobs() {
+  private void logPostJobs(Collection<PostJob> postJobs) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> "));
     }
index f59d9c5fe55f0a2592862a0fe408e7fcf390477f..df810a1535570a6926926105a2cfdcb3b2030eb1 100644 (file)
@@ -39,14 +39,14 @@ import java.util.Collection;
 public class SensorsExecutor implements BatchComponent {
   private static final Logger LOG = LoggerFactory.getLogger(SensorsExecutor.class);
 
-  private Collection<Sensor> sensors;
   private MavenPluginExecutor mavenExecutor;
   private EventBus eventBus;
   private Project project;
   private ProjectDefinition projectDefinition;
+  private BatchExtensionDictionnary selector;
 
   public SensorsExecutor(BatchExtensionDictionnary selector, Project project, ProjectDefinition projectDefinition, MavenPluginExecutor mavenExecutor, EventBus eventBus) {
-    this.sensors = selector.select(Sensor.class, project, true);
+    this.selector = selector;
     this.mavenExecutor = mavenExecutor;
     this.eventBus = eventBus;
     this.project = project;
@@ -54,6 +54,7 @@ public class SensorsExecutor implements BatchComponent {
   }
 
   public void execute(SensorContext context) {
+    Collection<Sensor> sensors = selector.select(Sensor.class, project, true);
     eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), true));
 
     for (Sensor sensor : sensors) {
index 60efff9650989b72b878d83633addebe5c675f56..b17c0de0350f267fced9cde231d79ce8f45f6360 100644 (file)
@@ -42,9 +42,9 @@ public class PostJobsExecutorTest {
 
     Project project = new Project("project");
     ProjectDefinition projectDefinition = ProjectDefinition.create();
-    PostJobsExecutor executor = new PostJobsExecutor(jobs, project, projectDefinition, mock(MavenPluginExecutor.class));
+    PostJobsExecutor executor = new PostJobsExecutor(null, project, projectDefinition, mock(MavenPluginExecutor.class));
     SensorContext context = mock(SensorContext.class);
-    executor.execute(context);
+    executor.execute(context, jobs);
 
     verify(job1).executeOn(project, context);
     verify(job2).executeOn(project, context);