aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-02-07 13:20:26 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-02-07 15:22:26 +0300
commitbbfce797275cf13e8c7a0e43aa29406175c89bfc (patch)
tree43701033fd66970038db281621be9a7856c14db4 /sonar-batch/src
parentc7bbd059c973036d8a0829dcd3f09cacaa0630be (diff)
downloadsonarqube-bbfce797275cf13e8c7a0e43aa29406175c89bfc.tar.gz
sonarqube-bbfce797275cf13e8c7a0e43aa29406175c89bfc.zip
SONAR-2172: New extension point - Initializer
* Rename AbstractInitializer to Initializer * Execute Initializers before Sensors
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java73
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java17
2 files changed, 83 insertions, 7 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
new file mode 100644
index 00000000000..e84d4527ede
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java
@@ -0,0 +1,73 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.phases;
+
+import java.util.Collection;
+
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.BatchExtensionDictionnary;
+import org.sonar.api.batch.Initializer;
+import org.sonar.api.batch.maven.DependsUponMavenPlugin;
+import org.sonar.api.batch.maven.MavenPluginHandler;
+import org.sonar.api.resources.Project;
+import org.sonar.api.utils.TimeProfiler;
+import org.sonar.batch.MavenPluginExecutor;
+
+public class InitializersExecutor {
+
+ private static final Logger logger = LoggerFactory.getLogger(SensorsExecutor.class);
+
+ private MavenPluginExecutor mavenExecutor;
+
+ private Collection<Initializer> initializers;
+
+ public InitializersExecutor(BatchExtensionDictionnary selector, Project project, MavenPluginExecutor mavenExecutor) {
+ this.initializers = selector.select(Initializer.class, project, true);
+ this.mavenExecutor = mavenExecutor;
+ }
+
+ public void execute(Project project) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Initializers : {}", StringUtils.join(initializers, " -> "));
+ }
+
+ for (Initializer initializer : initializers) {
+ executeMavenPlugin(project, initializer);
+
+ TimeProfiler profiler = new TimeProfiler(logger).start("Initializer " + initializer);
+ initializer.execute(project);
+ profiler.stop();
+ }
+ }
+
+ private void executeMavenPlugin(Project project, Initializer sensor) {
+ if (sensor instanceof DependsUponMavenPlugin) {
+ MavenPluginHandler handler = ((DependsUponMavenPlugin) sensor).getMavenPluginHandler(project);
+ if (handler != null) {
+ TimeProfiler profiler = new TimeProfiler(logger).start("Execute maven plugin " + handler.getArtifactId());
+ mavenExecutor.execute(project, handler);
+ profiler.stop();
+ }
+ }
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
index 3ae372ddb16..4146e92ab75 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
@@ -19,27 +19,28 @@
*/
package org.sonar.batch.phases;
+import java.util.Arrays;
+import java.util.Collection;
+
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.PersistenceManager;
-import java.util.Arrays;
-import java.util.Collection;
-
public final class Phases {
public static Collection<Class> getPhaseClasses() {
- return Arrays.<Class>asList(
+ return Arrays.<Class> asList(
DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
- PostJobsExecutor.class, SensorsExecutor.class, UpdateStatusJob.class
- );
+ PostJobsExecutor.class, SensorsExecutor.class, UpdateStatusJob.class,
+ InitializersExecutor.class);
}
private DecoratorsExecutor decoratorsExecutor;
private MavenPhaseExecutor mavenPhaseExecutor;
private MavenPluginsConfigurator mavenPluginsConfigurator;
private PostJobsExecutor postJobsExecutor;
+ private InitializersExecutor initializersExecutor;
private SensorsExecutor sensorsExecutor;
private UpdateStatusJob updateStatusJob;
private PersistenceManager persistenceManager;
@@ -47,13 +48,14 @@ public final class Phases {
private DefaultIndex index;
public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
- MavenPluginsConfigurator mavenPluginsConfigurator,
+ MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, UpdateStatusJob updateStatusJob,
PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index) {
this.decoratorsExecutor = decoratorsExecutor;
this.mavenPhaseExecutor = mavenPhaseExecutor;
this.mavenPluginsConfigurator = mavenPluginsConfigurator;
this.postJobsExecutor = postJobsExecutor;
+ this.initializersExecutor = initializersExecutor;
this.sensorsExecutor = sensorsExecutor;
this.updateStatusJob = updateStatusJob;
this.persistenceManager = persistenceManager;
@@ -67,6 +69,7 @@ public final class Phases {
public void execute(Project project) {
mavenPluginsConfigurator.execute(project);
mavenPhaseExecutor.execute(project);
+ initializersExecutor.execute(project);
persistenceManager.setDelayedMode(true);
sensorsExecutor.execute(project, sensorContext);