001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.batch.phases;
021
022 import com.google.common.collect.Lists;
023 import org.sonar.api.batch.SensorContext;
024 import org.sonar.api.resources.Project;
025 import org.sonar.batch.phases.ProjectInitializer;
026 import org.sonar.batch.events.EventBus;
027 import org.sonar.batch.index.DefaultIndex;
028 import org.sonar.batch.index.PersistenceManager;
029
030 import java.util.Collection;
031 import java.util.List;
032
033 public final class Phases {
034
035 public static Collection<Class> getPhaseClasses(boolean dryRun) {
036 List<Class> classes = Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
037 PostJobsExecutor.class, SensorsExecutor.class,
038 InitializersExecutor.class, ProjectInitializer.class);
039 if (!dryRun) {
040 classes.add(UpdateStatusJob.class);
041 }
042 return classes;
043 }
044
045 private EventBus eventBus;
046 private DecoratorsExecutor decoratorsExecutor;
047 private MavenPhaseExecutor mavenPhaseExecutor;
048 private MavenPluginsConfigurator mavenPluginsConfigurator;
049 private PostJobsExecutor postJobsExecutor;
050 private InitializersExecutor initializersExecutor;
051 private SensorsExecutor sensorsExecutor;
052 private UpdateStatusJob updateStatusJob;
053 private PersistenceManager persistenceManager;
054 private SensorContext sensorContext;
055 private DefaultIndex index;
056 private ProjectInitializer pi;
057
058 public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
059 MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
060 PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
061 PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
062 EventBus eventBus, UpdateStatusJob updateStatusJob, ProjectInitializer pi) {
063 this.decoratorsExecutor = decoratorsExecutor;
064 this.mavenPhaseExecutor = mavenPhaseExecutor;
065 this.mavenPluginsConfigurator = mavenPluginsConfigurator;
066 this.postJobsExecutor = postJobsExecutor;
067 this.initializersExecutor = initializersExecutor;
068 this.sensorsExecutor = sensorsExecutor;
069 this.persistenceManager = persistenceManager;
070 this.sensorContext = sensorContext;
071 this.index = index;
072 this.eventBus = eventBus;
073 this.updateStatusJob = updateStatusJob;
074 this.pi = pi;
075 }
076
077 public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
078 MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
079 PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
080 PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
081 EventBus eventBus, ProjectInitializer pi) {
082 this(decoratorsExecutor, mavenPhaseExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
083 sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi);
084 }
085
086 /**
087 * Executed on each module
088 */
089 public void execute(Project project) {
090 pi.execute(project);
091 eventBus.fireEvent(new ProjectAnalysisEvent(project, true));
092 mavenPluginsConfigurator.execute(project);
093 mavenPhaseExecutor.execute(project);
094 initializersExecutor.execute();
095
096 persistenceManager.setDelayedMode(true);
097 sensorsExecutor.execute(sensorContext);
098 decoratorsExecutor.execute();
099 persistenceManager.dump();
100 persistenceManager.setDelayedMode(false);
101
102 if (project.isRoot()) {
103 if (updateStatusJob != null) {
104 updateStatusJob.execute();
105 }
106 postJobsExecutor.execute(sensorContext);
107 }
108 cleanMemory();
109 eventBus.fireEvent(new ProjectAnalysisEvent(project, false));
110 }
111
112 private void cleanMemory() {
113 persistenceManager.clear();
114 index.clear();
115 }
116 }