@@ -22,11 +22,13 @@ package org.sonar.plugins.core.sensors; | |||
import org.sonar.api.batch.Phase; | |||
import org.sonar.api.batch.Sensor; | |||
import org.sonar.api.batch.SensorContext; | |||
import org.sonar.core.NotDryRun; | |||
import org.sonar.jpa.dao.AsyncMeasuresService; | |||
import org.sonar.api.database.model.Snapshot; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.resources.ResourceUtils; | |||
@NotDryRun | |||
@Phase(name = Phase.Name.PRE) | |||
public class AsynchronousMeasuresSensor implements Sensor { | |||
@@ -33,10 +33,12 @@ import org.sonar.api.resources.Project; | |||
import org.sonar.api.resources.Resource; | |||
import org.sonar.api.resources.ResourceUtils; | |||
import org.sonar.batch.index.ResourcePersister; | |||
import org.sonar.core.NotDryRun; | |||
/** | |||
* Decorator that currently only closes a review when its corresponding violation has been fixed. | |||
*/ | |||
@NotDryRun | |||
@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING) | |||
public class CloseReviewsDecorator implements Decorator { | |||
@@ -25,9 +25,11 @@ import org.sonar.api.batch.Event; | |||
import org.sonar.api.batch.Sensor; | |||
import org.sonar.api.batch.SensorContext; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.Iterator; | |||
@NotDryRun | |||
public class VersionEventsSensor implements Sensor { | |||
private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; |
@@ -33,6 +33,7 @@ import org.sonar.api.resources.Scopes; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.batch.components.PastSnapshot; | |||
import org.sonar.batch.components.TimeMachineConfiguration; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.Arrays; | |||
import java.util.Date; | |||
@@ -42,6 +43,7 @@ import java.util.Map; | |||
/** | |||
* @since 2.7 | |||
*/ | |||
@NotDryRun | |||
@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE) | |||
public final class NewCoverageFileAnalyzer implements Decorator { | |||
@@ -32,9 +32,11 @@ import org.sonar.api.rules.RulePriority; | |||
import org.sonar.api.rules.Violation; | |||
import org.sonar.batch.components.PastSnapshot; | |||
import org.sonar.batch.components.TimeMachineConfiguration; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.*; | |||
@NotDryRun | |||
@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING) | |||
public class NewViolationsDecorator implements Decorator { | |||
@@ -32,9 +32,11 @@ import org.sonar.api.resources.Project; | |||
import org.sonar.api.resources.Resource; | |||
import org.sonar.api.resources.Scopes; | |||
import org.sonar.batch.components.TimeMachineConfiguration; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.List; | |||
@NotDryRun | |||
@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE) | |||
public class TendencyDecorator implements Decorator { | |||
@@ -28,9 +28,11 @@ import org.sonar.api.resources.Resource; | |||
import org.sonar.api.resources.ResourceUtils; | |||
import org.sonar.batch.components.PastSnapshot; | |||
import org.sonar.batch.components.TimeMachineConfiguration; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.List; | |||
@NotDryRun | |||
public final class TimeMachineConfigurationPersister implements Decorator { | |||
private TimeMachineConfiguration configuration; |
@@ -30,11 +30,13 @@ import org.sonar.api.resources.Scopes; | |||
import org.sonar.batch.components.PastMeasuresLoader; | |||
import org.sonar.batch.components.PastSnapshot; | |||
import org.sonar.batch.components.TimeMachineConfiguration; | |||
import org.sonar.core.NotDryRun; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.Map; | |||
@NotDryRun | |||
@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE) | |||
public class VariationDecorator implements Decorator { | |||
@@ -44,7 +44,9 @@ import org.sonar.batch.index.ViolationPersister; | |||
import com.google.common.collect.LinkedHashMultimap; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Multimap; | |||
import org.sonar.core.NotDryRun; | |||
@NotDryRun | |||
@DependsUpon({ DecoratorBarriers.END_OF_VIOLATIONS_GENERATION, DecoratorBarriers.START_VIOLATION_TRACKING }) | |||
@DependedUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING) | |||
public class ViolationPersisterDecorator implements Decorator { |
@@ -27,10 +27,12 @@ import org.sonar.api.database.DatabaseSession; | |||
import org.sonar.api.database.model.Snapshot; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.utils.TimeProfiler; | |||
import org.sonar.core.NotDryRun; | |||
import org.sonar.plugins.dbcleaner.api.Purge; | |||
import javax.persistence.Query; | |||
@NotDryRun | |||
public final class PurgeRunner implements PostJob { | |||
private DatabaseSession session; |
@@ -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) { |
@@ -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); |
@@ -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 { |
@@ -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(); | |||
} | |||
@@ -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; | |||
} | |||
} |
@@ -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); |
@@ -35,6 +35,7 @@ public abstract class Module { | |||
private MutablePicoContainer container; | |||
/** | |||
* @return this | |||
*/ |
@@ -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); |
@@ -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); | |||
} | |||
} |
@@ -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; |
@@ -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) { | |||
} | |||
} |
@@ -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(); |
@@ -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; |
@@ -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); | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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 { | |||
} | |||
} |
@@ -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")); | |||
@@ -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())); | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
/* | |||
* 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.core; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
/** | |||
* Disables component on dry runs. | |||
* This annotation must be used by core modules only. It MUST not be used by external plugins. | |||
* @since 2.9 | |||
*/ | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Target(ElementType.TYPE) | |||
public @interface NotDryRun { | |||
} |