--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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 com.google.common.collect.Lists;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.resources.Project;
+import org.sonar.batch.events.EventBus;
+import org.sonar.batch.index.DefaultIndex;
+import org.sonar.batch.index.PersistenceManager;
+import org.sonar.batch.scan.filesystem.FileSystemLogger;
+import org.sonar.batch.scan.maven.MavenPhaseExecutor;
+import org.sonar.batch.scan.maven.MavenPluginsConfigurator;
+import org.sonar.core.component.ScanGraphStore;
+
+import java.util.Collection;
+
+public final class PhaseExecutor {
+
+ public static Collection<Class> getPhaseClasses() {
+ return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
+ PostJobsExecutor.class, SensorsExecutor.class,
+ InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
+ }
+
+ private EventBus eventBus;
+ private Phases phases;
+ private DecoratorsExecutor decoratorsExecutor;
+ private MavenPhaseExecutor mavenPhaseExecutor;
+ private MavenPluginsConfigurator mavenPluginsConfigurator;
+ private PostJobsExecutor postJobsExecutor;
+ private InitializersExecutor initializersExecutor;
+ private SensorsExecutor sensorsExecutor;
+ private UpdateStatusJob updateStatusJob;
+ private PersistenceManager persistenceManager;
+ private SensorContext sensorContext;
+ private DefaultIndex index;
+ private ProjectInitializer pi;
+ private ScanGraphStore graphStorage;
+ private FileSystemLogger fsLogger;
+
+ public PhaseExecutor(Phases phases, DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
+ MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
+ PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
+ PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
+ EventBus eventBus, UpdateStatusJob updateStatusJob, ProjectInitializer pi,
+ ScanGraphStore graphStorage, FileSystemLogger fsLogger) {
+ this.phases = phases;
+ this.decoratorsExecutor = decoratorsExecutor;
+ this.mavenPhaseExecutor = mavenPhaseExecutor;
+ this.mavenPluginsConfigurator = mavenPluginsConfigurator;
+ this.postJobsExecutor = postJobsExecutor;
+ this.initializersExecutor = initializersExecutor;
+ this.sensorsExecutor = sensorsExecutor;
+ this.persistenceManager = persistenceManager;
+ this.sensorContext = sensorContext;
+ this.index = index;
+ this.eventBus = eventBus;
+ this.updateStatusJob = updateStatusJob;
+ this.pi = pi;
+ this.graphStorage = graphStorage;
+ this.fsLogger = fsLogger;
+ }
+
+ public PhaseExecutor(Phases phases, DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
+ MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
+ PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
+ PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
+ EventBus eventBus, ProjectInitializer pi, ScanGraphStore graphStorage, FileSystemLogger fsLogger) {
+ this(phases, decoratorsExecutor, mavenPhaseExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
+ sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi, graphStorage, fsLogger);
+ }
+
+ /**
+ * Executed on each module
+ */
+ public void execute(Project module) {
+ pi.execute(module);
+ eventBus.fireEvent(new ProjectAnalysisEvent(module, true));
+ if (phases.isEnabled(Phases.Phase.MAVEN)) {
+ mavenPluginsConfigurator.execute(module);
+ mavenPhaseExecutor.execute(module);
+ }
+ if (phases.isEnabled(Phases.Phase.INIT)) {
+ initializersExecutor.execute();
+ fsLogger.log();
+ }
+
+ persistenceManager.setDelayedMode(true);
+ if (phases.isEnabled(Phases.Phase.SENSOR)) {
+ sensorsExecutor.execute(sensorContext);
+ }
+ if (phases.isEnabled(Phases.Phase.DECORATOR)) {
+ decoratorsExecutor.execute();
+ }
+ persistenceManager.dump();
+ persistenceManager.setDelayedMode(false);
+
+ if (module.isRoot()) {
+ graphStorage.save();
+ if (updateStatusJob != null) {
+ updateStatusJob.execute();
+ }
+ if (phases.isEnabled(Phases.Phase.POSTJOB)) {
+ postJobsExecutor.execute(sensorContext);
+ }
+ }
+ cleanMemory();
+ eventBus.fireEvent(new ProjectAnalysisEvent(module, false));
+ }
+
+ private void cleanMemory() {
+ persistenceManager.clear();
+ index.clear();
+ }
+}
*/
package org.sonar.batch.phases;
-import com.google.common.collect.Lists;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.events.EventBus;
-import org.sonar.batch.index.DefaultIndex;
-import org.sonar.batch.index.PersistenceManager;
-import org.sonar.batch.scan.filesystem.FileSystemLogger;
-import org.sonar.batch.scan.maven.MavenPhaseExecutor;
-import org.sonar.batch.scan.maven.MavenPluginsConfigurator;
-import org.sonar.core.component.ScanGraphStore;
+import com.google.common.collect.Sets;
-import java.util.Collection;
+import java.util.Arrays;
+import java.util.Set;
-public final class Phases {
+public class Phases {
- public static Collection<Class> getPhaseClasses() {
- return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
- PostJobsExecutor.class, SensorsExecutor.class,
- InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
+ public static enum Phase {
+ MAVEN, INIT, SENSOR, DECORATOR, POSTJOB
}
- private EventBus eventBus;
- private DecoratorsExecutor decoratorsExecutor;
- private MavenPhaseExecutor mavenPhaseExecutor;
- private MavenPluginsConfigurator mavenPluginsConfigurator;
- private PostJobsExecutor postJobsExecutor;
- private InitializersExecutor initializersExecutor;
- private SensorsExecutor sensorsExecutor;
- private UpdateStatusJob updateStatusJob;
- private PersistenceManager persistenceManager;
- private SensorContext sensorContext;
- private DefaultIndex index;
- private ProjectInitializer pi;
- private ScanGraphStore graphStorage;
- private FileSystemLogger fsLogger;
+ private final Set<Phase> enabled = Sets.newHashSet();
- public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
- MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
- PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
- PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus, UpdateStatusJob updateStatusJob, ProjectInitializer pi,
- ScanGraphStore graphStorage, FileSystemLogger fsLogger) {
- this.decoratorsExecutor = decoratorsExecutor;
- this.mavenPhaseExecutor = mavenPhaseExecutor;
- this.mavenPluginsConfigurator = mavenPluginsConfigurator;
- this.postJobsExecutor = postJobsExecutor;
- this.initializersExecutor = initializersExecutor;
- this.sensorsExecutor = sensorsExecutor;
- this.persistenceManager = persistenceManager;
- this.sensorContext = sensorContext;
- this.index = index;
- this.eventBus = eventBus;
- this.updateStatusJob = updateStatusJob;
- this.pi = pi;
- this.graphStorage = graphStorage;
- this.fsLogger = fsLogger;
+ public Phases enable(Phase... phases) {
+ enabled.addAll(Arrays.asList(phases));
+ return this;
}
- public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
- MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
- PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
- PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus, ProjectInitializer pi, ScanGraphStore graphStorage, FileSystemLogger fsLogger) {
- this(decoratorsExecutor, mavenPhaseExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
- sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi, graphStorage, fsLogger);
+ public boolean isEnabled(Phase phase) {
+ return enabled.contains(phase);
}
- /**
- * Executed on each module
- */
- public void execute(Project module) {
- pi.execute(module);
- eventBus.fireEvent(new ProjectAnalysisEvent(module, true));
- mavenPluginsConfigurator.execute(module);
- mavenPhaseExecutor.execute(module);
- initializersExecutor.execute();
- fsLogger.log();
-
- persistenceManager.setDelayedMode(true);
- sensorsExecutor.execute(sensorContext);
- decoratorsExecutor.execute();
- persistenceManager.dump();
- persistenceManager.setDelayedMode(false);
-
- if (module.isRoot()) {
- graphStorage.save();
- if (updateStatusJob != null) {
- updateStatusJob.execute();
- }
- postJobsExecutor.execute(sensorContext);
- }
- cleanMemory();
- eventBus.fireEvent(new ProjectAnalysisEvent(module, false));
- }
-
- private void cleanMemory() {
- persistenceManager.clear();
- index.clear();
+ public boolean isFullyEnabled() {
+ return enabled.containsAll(Arrays.asList(Phase.values()));
}
}
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.local.DryRunExporter;
-import org.sonar.batch.phases.Phases;
+import org.sonar.batch.phases.PhaseExecutor;
import org.sonar.batch.phases.PhasesTimeProfiler;
import org.sonar.batch.scan.filesystem.DeprecatedFileSystemAdapter;
import org.sonar.batch.scan.filesystem.ExclusionFilters;
add(
EventBus.class,
- Phases.class,
+ PhaseExecutor.class,
PhasesTimeProfiler.class,
UnsupportedProperties.class,
- Phases.getPhaseClasses(),
+ PhaseExecutor.getPhaseClasses(),
moduleDefinition.getContainerExtensions(),
// TODO move outside project, but not possible yet because of dependency of project settings (cf plsql)
getComponentByType(ViolationFilters.class),
getComponentByType(RulesProfile.class));
- getComponentByType(Phases.class).execute(module);
+ getComponentByType(PhaseExecutor.class).execute(module);
}
}
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.batch.bootstrap.TaskContainer;
+import org.sonar.batch.phases.Phases;
public class ScanTask implements Task {
-
public static final TaskDefinition DEFINITION = TaskDefinition.builder()
.description("Scan project")
.key(CoreProperties.SCAN_TASK)
}
public void execute() {
- new ProjectScanContainer(taskContainer).execute();
+ scan(new ProjectScanContainer(taskContainer));
}
+ void scan(ComponentContainer scanContainer) {
+ scanContainer.add(new Phases().enable(Phases.Phase.values()));
+ scanContainer.execute();
+ }
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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 org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PhaseExecutorTest {
+
+ @Test
+ public void shouldDefinePhaseClasses() {
+ assertThat(PhaseExecutor.getPhaseClasses().size()).isGreaterThan(4);
+ }
+
+}
import org.junit.Test;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class PhasesTest {
+ @Test
+ public void no_phase_should_be_enabled_by_default() {
+ Phases phases = new Phases();
+ assertThat(phases.isEnabled(Phases.Phase.DECORATOR)).isFalse();
+ }
@Test
- public void shouldDefinePhaseClasses() {
- assertThat(Phases.getPhaseClasses().size(), greaterThan(4));
+ public void phase_should_be_enabled() {
+ Phases phases = new Phases();
+ phases.enable(Phases.Phase.SENSOR, Phases.Phase.DECORATOR);
+
+ assertThat(phases.isEnabled(Phases.Phase.DECORATOR)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.SENSOR)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.POSTJOB)).isFalse();
+ assertThat(phases.isFullyEnabled()).isFalse();
}
+ @Test
+ public void all_phases_should_be_enabled() {
+ Phases phases = new Phases();
+ phases.enable(Phases.Phase.values());
+
+ assertThat(phases.isEnabled(Phases.Phase.INIT)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.MAVEN)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.DECORATOR)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.SENSOR)).isTrue();
+ assertThat(phases.isEnabled(Phases.Phase.POSTJOB)).isTrue();
+ assertThat(phases.isFullyEnabled()).isTrue();
+ }
}
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.batch.bootstrap.TaskContainer;
+import org.sonar.batch.phases.Phases;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class ScanTaskTest {
@Test
assertThat(ScanTask.DEFINITION).isNotNull();
assertThat(ScanTask.DEFINITION.key()).isEqualTo(CoreProperties.SCAN_TASK);
}
+
+ @Test
+ public void should_enable_all_phases() {
+ ScanTask task = new ScanTask(mock(TaskContainer.class));
+ ComponentContainer projectScanContainer = new ComponentContainer();
+ task.scan(projectScanContainer);
+
+ Phases phases = projectScanContainer.getComponentByType(Phases.class);
+ assertThat(phases.isFullyEnabled()).isTrue();
+ }
}