aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-06-15 10:55:55 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-06-15 10:56:24 +0200
commit1063d63ad0fef20b898376d4465e4c88cc061c1b (patch)
treee02735640b26715c8aae7396e3cf3e0cba3e93e4 /sonar-batch
parenteb3c0dc7dec66ad446e41a8291836af352bbc819 (diff)
downloadsonarqube-1063d63ad0fef20b898376d4465e4c88cc061c1b.tar.gz
sonarqube-1063d63ad0fef20b898376d4465e4c88cc061c1b.zip
SONAR-2505 core components which write to database are disabled on dry runs
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java33
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java38
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java19
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java79
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java33
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java45
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java18
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java7
18 files changed, 272 insertions, 40 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
index add063534aa..0ff9542667b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
@@ -29,7 +29,6 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.DefaultIndex;
@@ -68,14 +67,14 @@ public class DefaultTimeMachine implements TimeMachine {
Map<Integer, Metric> metricById = getMetricsById(query);
List<Object[]> rows = execute(query, false, metricById.keySet());
for (Object[] fields : rows) {
- fields[1]=metricById.get(fields[1]);
+ fields[1] = metricById.get(fields[1]);
}
return rows;
}
protected List execute(TimeMachineQuery query, boolean selectAllFields, Set<Integer> metricIds) {
Resource resource = query.getResource();
- if (resource!=null && resource.getId()==null) {
+ if (resource != null && resource.getId() == null) {
resource = index.getResource(query.getResource());
}
if (resource == null) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
index cee17e434d7..f91054793b8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
@@ -34,10 +34,12 @@ public final class BatchExtensionInstaller implements BatchComponent {
private BatchPluginRepository pluginRepository;
private EnvironmentInformation environment;
+ private DryRun dryRun;
- public BatchExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment) {
+ public BatchExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun) {
this.pluginRepository = pluginRepository;
this.environment = environment;
+ this.dryRun = dryRun;
}
public void install(Module module) {
@@ -75,6 +77,7 @@ public final class BatchExtensionInstaller implements BatchComponent {
void installExtension(Module module, Object extension) {
if (ExtensionUtils.isBatchExtension(extension) &&
ExtensionUtils.isSupportedEnvironment(extension, environment) &&
+ ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_BATCH)) {
if (ExtensionUtils.isType(extension, CoverageExtension.class)) {
throw new IllegalArgumentException("Instantiation strategy " + InstantiationStrategy.PER_BATCH + " is not supported on CoverageExtension components: " + extension);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
index 8081cda1366..eb6c4552073 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
@@ -36,20 +36,33 @@ import org.sonar.jpa.dao.MeasuresDao;
* Level-2 components. Connected to database.
*/
public class BatchModule extends Module {
+
+ private final boolean dryRun;
+
+ public BatchModule(boolean dryRun) {
+ this.dryRun = dryRun;
+ }
+
@Override
protected void configure() {
addComponent(ProjectTree.class);
addComponent(DefaultResourceCreationLock.class);
addComponent(DefaultIndex.class);
- addComponent(DefaultPersistenceManager.class);
- addComponent(DependencyPersister.class);
- addComponent(EventPersister.class);
- addComponent(LinkPersister.class);
- addComponent(MeasurePersister.class);
- addComponent(MemoryOptimizer.class);
- addComponent(DefaultResourcePersister.class);
- addComponent(SourcePersister.class);
- addComponent(ViolationPersister.class);
+
+ if (dryRun) {
+ addComponent(ReadOnlyPersistenceManager.class);
+ } else {
+ addComponent(DefaultPersistenceManager.class);
+ addComponent(DependencyPersister.class);
+ addComponent(EventPersister.class);
+ addComponent(LinkPersister.class);
+ addComponent(MeasurePersister.class);
+ addComponent(MemoryOptimizer.class);
+ addComponent(DefaultResourcePersister.class);
+ addComponent(SourcePersister.class);
+ addComponent(ViolationPersister.class);
+ }
+
addComponent(Plugins.class);
addComponent(ServerHttpClient.class);
addComponent(MeasuresDao.class);
@@ -87,7 +100,7 @@ public class BatchModule extends Module {
analyze(subProject);
}
- Module projectComponents = installChild(new ProjectModule(project));
+ Module projectComponents = installChild(new ProjectModule(project, dryRun));
try {
projectComponents.start();
} finally {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
index fc09ef25dd0..6d0a84372b5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
@@ -51,6 +51,7 @@ public class BootstrapModule extends Module {
protected void configure() {
addComponent(reactor);
addComponent(configuration);
+ addComponent(DryRun.class);
addComponent(ServerMetadata.class);// registered here because used by BootstrapClassLoader
addComponent(TempDirectories.class);// registered here because used by BootstrapClassLoader
addComponent(HttpDownloader.class);// registered here because used by BootstrapClassLoader
@@ -90,7 +91,8 @@ public class BootstrapModule extends Module {
@Override
protected void doStart() {
addPlugins();
- Module batchComponents = installChild(new BatchModule());
+ boolean dryRun = getComponent(DryRun.class).isEnabled();
+ Module batchComponents = installChild(new BatchModule(dryRun));
batchComponents.start();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java
new file mode 100644
index 00000000000..01376022d90
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java
@@ -0,0 +1,38 @@
+/*
+ * 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.bootstrap;
+
+import org.apache.commons.configuration.Configuration;
+
+public class DryRun {
+ private boolean enabled;
+
+ public DryRun(Configuration conf) {
+ enabled=conf.getBoolean("sonar.dryRun", Boolean.FALSE);
+ }
+
+ DryRun(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
index 6214d8d4e53..a1f6c0643f8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
@@ -23,9 +23,11 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.Extension;
import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.Purge;
import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.core.NotDryRun;
public final class ExtensionUtils {
@@ -60,6 +62,10 @@ public final class ExtensionUtils {
return false;
}
+ static boolean checkDryRun(Object extension, boolean dryRun) {
+ return !dryRun || AnnotationUtils.getClassAnnotation(extension, NotDryRun.class)==null;
+ }
+
static boolean isMavenExtensionOnly(Object extension) {
Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
SupportedEnvironment env = AnnotationUtils.getClassAnnotation(clazz, SupportedEnvironment.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java
index 0fab9682c7b..df9991e89a5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java
@@ -35,6 +35,7 @@ public abstract class Module {
private MutablePicoContainer container;
+
/**
* @return this
*/
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
index 194d2f022ed..0ec164f7ca4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
@@ -39,10 +39,12 @@ public final class ProjectExtensionInstaller implements BatchComponent {
private BatchPluginRepository pluginRepository;
private EnvironmentInformation environment;
+ private DryRun dryRun;
- public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment) {
+ public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun) {
this.pluginRepository = pluginRepository;
this.environment = environment;
+ this.dryRun = dryRun;
}
public void install(Module module, Project project) {
@@ -72,6 +74,7 @@ public final class ProjectExtensionInstaller implements BatchComponent {
if (ExtensionUtils.isBatchExtension(extension) &&
ExtensionUtils.isSupportedEnvironment(extension, environment) &&
ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) &&
+ ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
!isDeactivatedCoverageExtension(extension, project, pluginKey) &&
!isMavenExtensionOnEmulatedMavenProject(extension, project)) {
module.addComponent(extension);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
index ae0c69aec40..d603c34a1df 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
@@ -23,9 +23,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchExtensionDictionnary;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metrics;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
@@ -49,9 +46,11 @@ import java.util.Arrays;
public class ProjectModule extends Module {
private static final Logger LOG = LoggerFactory.getLogger(ProjectModule.class);
private Project project;
+ private boolean dryRun;
- public ProjectModule(Project project) {
+ public ProjectModule(Project project, boolean dryRun) {
this.project = project;
+ this.dryRun = dryRun;
}
@Override
@@ -77,8 +76,12 @@ public class ProjectModule extends Module {
addComponent(DaoFacade.class);
addComponent(RulesDao.class);
- // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
- addComponent(getComponent(DefaultResourcePersister.class).getSnapshot(project));
+ if (!dryRun) {
+ // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
+ addComponent(getComponent(DefaultResourcePersister.class).getSnapshot(project));
+ addComponent(TimeMachineConfiguration.class);
+ addComponent(PastViolationsLoader.class);
+ }
addComponent(org.sonar.api.database.daos.MeasuresDao.class);
addComponent(ProfilesDao.class);
addComponent(AsyncMeasuresDao.class);
@@ -91,8 +94,6 @@ public class ProjectModule extends Module {
addComponent(ViolationFilters.class);
addComponent(ResourceFilters.class);
addComponent(DefaultModelFinder.class);
- addComponent(TimeMachineConfiguration.class);
- addComponent(PastViolationsLoader.class);
addComponent(ProfileLoader.class, DefaultProfileLoader.class);
addAdapter(new ProfileProvider());
}
@@ -101,7 +102,7 @@ public class ProjectModule extends Module {
addComponent(EventBus.class);
addComponent(Phases.class);
addComponent(PhasesTimeProfiler.class);
- for (Class clazz : Phases.getPhaseClasses()) {
+ for (Class clazz : Phases.getPhaseClasses(dryRun)) {
addComponent(clazz);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java
index 805a2b696e3..6168ebca199 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java
@@ -27,10 +27,12 @@ import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.index.ResourcePersister;
+import org.sonar.core.NotDryRun;
import java.util.Collections;
import java.util.List;
+@NotDryRun
public class PastViolationsLoader implements BatchExtension {
private DatabaseSession session;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java
new file mode 100644
index 00000000000..7682a3dbb6e
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java
@@ -0,0 +1,79 @@
+/*
+ * 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.index;
+
+import org.sonar.api.batch.Event;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.design.Dependency;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.ProjectLink;
+import org.sonar.api.resources.Resource;
+
+import java.util.Collections;
+import java.util.List;
+
+public final class ReadOnlyPersistenceManager implements PersistenceManager {
+
+ public void clear() {
+ }
+
+ public void setDelayedMode(boolean b) {
+ }
+
+ public void dump() {
+ }
+
+ public void saveProject(Project project, Project parent) {
+ }
+
+ public Snapshot saveResource(Project project, Resource resource, Resource parent) {
+ return null;
+ }
+
+ public void setSource(Resource file, String source) {
+ }
+
+ public void saveMeasure(Resource resource, Measure measure) {
+ }
+
+ public Measure reloadMeasure(Measure measure) {
+ return measure;
+ }
+
+ public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) {
+ }
+
+ public void saveLink(Project project, ProjectLink link) {
+ }
+
+ public void deleteLink(Project project, String key) {
+ }
+
+ public List<Event> getEvents(Resource resource) {
+ return Collections.emptyList();
+ }
+
+ public void deleteEvent(Event event) {
+ }
+
+ public void saveEvent(Resource resource, Event event) {
+ }
+}
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 a9d69e72a23..d8a7506303d 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,22 +19,26 @@
*/
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 java.util.Arrays;
import java.util.Collection;
+import java.util.List;
public final class Phases {
- public static Collection<Class> getPhaseClasses() {
- return Arrays.<Class> asList(
- DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
- PostJobsExecutor.class, SensorsExecutor.class, UpdateStatusJob.class,
+ public static Collection<Class> getPhaseClasses(boolean dryRun) {
+ List<Class> classes = Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
+ PostJobsExecutor.class, SensorsExecutor.class,
InitializersExecutor.class);
+ if (!dryRun) {
+ classes.add(UpdateStatusJob.class);
+ }
+ return classes;
}
private EventBus eventBus;
@@ -51,20 +55,29 @@ public final class Phases {
public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
- PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, UpdateStatusJob updateStatusJob,
+ PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus) {
+ EventBus eventBus, UpdateStatusJob updateStatusJob) {
this.decoratorsExecutor = decoratorsExecutor;
this.mavenPhaseExecutor = mavenPhaseExecutor;
this.mavenPluginsConfigurator = mavenPluginsConfigurator;
this.postJobsExecutor = postJobsExecutor;
this.initializersExecutor = initializersExecutor;
this.sensorsExecutor = sensorsExecutor;
- this.updateStatusJob = updateStatusJob;
this.persistenceManager = persistenceManager;
this.sensorContext = sensorContext;
this.index = index;
this.eventBus = eventBus;
+ this.updateStatusJob = updateStatusJob;
+ }
+
+ public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
+ MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
+ PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
+ PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
+ EventBus eventBus) {
+ this(decoratorsExecutor, mavenPhaseExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
+ sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null);
}
/**
@@ -83,7 +96,9 @@ public final class Phases {
persistenceManager.setDelayedMode(false);
if (project.isRoot()) {
- updateStatusJob.execute();
+ if (updateStatusJob != null) {
+ updateStatusJob.execute();
+ }
postJobsExecutor.execute(sensorContext);
}
cleanMemory();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
index cc742bdc0d4..ea93e4992a7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
@@ -26,10 +26,12 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Scopes;
import org.sonar.batch.ServerMetadata;
import org.sonar.batch.index.ResourcePersister;
+import org.sonar.core.NotDryRun;
import javax.persistence.Query;
import java.util.List;
+@NotDryRun
public class UpdateStatusJob implements BatchComponent {
private DatabaseSession session;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
index 4f81bd34294..10c19e6d415 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
@@ -45,7 +45,7 @@ public class BatchExtensionInstallerTest {
}
}));
Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"));
+ BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
installer.install(module);
@@ -63,7 +63,7 @@ public class BatchExtensionInstallerTest {
}
}));
Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"));
+ BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
installer.install(module);
@@ -82,7 +82,7 @@ public class BatchExtensionInstallerTest {
}
}));
Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"));
+ BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
installer.install(module);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java
new file mode 100644
index 00000000000..5b278b0285d
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.bootstrap;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.hamcrest.core.Is;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+
+public class DryRunTest {
+
+ @Test
+ public void shouldReadConfiguration() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty("sonar.dryRun", "true");
+ assertThat(new DryRun(conf).isEnabled(), Is.is(true));
+
+ conf.setProperty("sonar.dryRun", "false");
+ assertThat(new DryRun(conf).isEnabled(), Is.is(false));
+ }
+
+ @Test
+ public void shouldNotEnableDryRunByDefault() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ assertThat(new DryRun(conf).isEnabled(), Is.is(false));
+ }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
index 2e6abe8621c..23cc30d560a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
@@ -25,6 +25,7 @@ import org.sonar.api.ServerExtension;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.core.NotDryRun;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -75,6 +76,18 @@ public class ExtensionUtilsTest {
assertThat(ExtensionUtils.isMavenExtensionOnly(BuildToolService.class), is(false));
}
+ @Test
+ public void shouldCheckDryRun() {
+ assertThat(ExtensionUtils.checkDryRun(BatchService.class, true), is(true));
+ assertThat(ExtensionUtils.checkDryRun(PersistentService.class, true), is(false));
+ }
+
+ @Test
+ public void shouldNotCheckDryRun() {
+ assertThat(ExtensionUtils.checkDryRun(BatchService.class, false), is(true));
+ assertThat(ExtensionUtils.checkDryRun(PersistentService.class, false), is(true));
+ }
+
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class BatchService implements BatchExtension {
@@ -102,4 +115,9 @@ public class ExtensionUtilsTest {
public static class BuildToolService implements BatchExtension {
}
+
+ @NotDryRun
+ public static class PersistentService implements BatchExtension {
+
+ }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
index b8020422a15..9e9fcd60fa6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
@@ -66,7 +66,7 @@ public class ProjectExtensionInstallerTest {
});
when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
Module module = new FakeModule().init();
- ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"));
+ ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
installer.install(module, new Project("foo"));
@@ -86,7 +86,7 @@ public class ProjectExtensionInstallerTest {
});
when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
Module module = new FakeModule().init();
- ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"));
+ ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
installer.install(module, new Project("foo"));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java
index d14d30d7ae4..ae8a6d0b962 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java
@@ -28,6 +28,11 @@ public class PhasesTest {
@Test
public void shouldDefinePhaseClasses() {
- assertThat(Phases.getPhaseClasses().size(), greaterThan(4));
+ assertThat(Phases.getPhaseClasses(false).size(), greaterThan(4));
+ }
+
+ @Test
+ public void someComponentsShouldBeDisabledOnDryRun() {
+ assertThat(Phases.getPhaseClasses(false).size(), greaterThan(Phases.getPhaseClasses(true).size()));
}
}