From 3d58102c0564f72a49d6d8a691eabbf760d2d20a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 8 Aug 2011 16:23:22 +0200 Subject: [PATCH] SONAR-2674 The method Sensor#shouldExecuteOnProject() must not be executed before Initializer extensions --- .../batch/phases/InitializersExecutor.java | 5 +++-- .../sonar/batch/phases/PostJobsExecutor.java | 17 +++++++++-------- .../org/sonar/batch/phases/SensorsExecutor.java | 5 +++-- .../batch/phases/PostJobsExecutorTest.java | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java index c205df16034..50b0d975170 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java @@ -39,18 +39,19 @@ public class InitializersExecutor { private MavenPluginExecutor mavenExecutor; - private Collection 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 initializers = selector.select(Initializer.class, project, true); if (logger.isDebugEnabled()) { logger.debug("Initializers : {}", StringUtils.join(initializers, " -> ")); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java index 3f6b6433cbc..aa5ca9873b9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java @@ -38,24 +38,25 @@ import java.util.List; public class PostJobsExecutor implements BatchComponent { private static final Logger LOG = LoggerFactory.getLogger(PostJobsExecutor.class); - private Collection 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 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 postJobs = selector.select(PostJob.class, project, true); + execute(context, postJobs); + } + + void execute(SensorContext context, Collection 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 postJobs) { if (LOG.isDebugEnabled()) { LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> ")); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java index f59d9c5fe55..df810a15355 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java @@ -39,14 +39,14 @@ import java.util.Collection; public class SensorsExecutor implements BatchComponent { private static final Logger LOG = LoggerFactory.getLogger(SensorsExecutor.class); - private Collection 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 sensors = selector.select(Sensor.class, project, true); eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), true)); for (Sensor sensor : sensors) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java index 60efff96509..b17c0de0350 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java @@ -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); -- 2.39.5