aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-26 10:44:32 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-26 11:01:33 +0200
commite5afb0ad760fa38ceb624789162e01b04f49808a (patch)
treeb0d34e16c7a51c9d27a1b3c8d9700f03951965c6 /sonar-batch
parent49f880247a262ed61c3b672447c32619dd9b1fef (diff)
downloadsonarqube-e5afb0ad760fa38ceb624789162e01b04f49808a.tar.gz
sonarqube-e5afb0ad760fa38ceb624789162e01b04f49808a.zip
SONAR-3895 execute bootstrap extensions (liek ProjectBuilder) before initializing db
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java31
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java119
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java104
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java)35
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java85
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java18
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java107
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java54
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java29
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java88
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java123
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java79
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java93
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java)28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java (renamed from sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java)6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java89
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java134
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java142
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java60
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java56
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java110
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java170
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java100
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java)14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java6
34 files changed, 782 insertions, 1187 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
index c99fd70d838..6e13d83e527 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
@@ -22,14 +22,10 @@ package org.sonar.batch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.ObjectUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectBuilder;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrap.ProjectFilter;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -40,21 +36,11 @@ public class ProjectTree {
private List<Project> projects;
private Map<ProjectDefinition, Project> projectsByDef;
- private ProjectFilter projectFilter;
- public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
- ProjectConfigurator projectConfigurator,
- ProjectFilter projectFilter,
- /* Must be executed after ProjectBuilders */ProjectBuilder[] builders) {
- this(projectReactor, projectConfigurator, projectFilter);
- }
-
- public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
- ProjectConfigurator projectConfigurator,
- ProjectFilter projectFilter) {
+ public ProjectTree(ProjectReactor projectReactor,
+ ProjectConfigurator projectConfigurator) {
this.projectReactor = projectReactor;
this.configurator = projectConfigurator;
- this.projectFilter = projectFilter;
}
ProjectTree(ProjectConfigurator configurator) {
@@ -87,21 +73,8 @@ public class ProjectTree {
for (Project project : projects) {
configurator.configure(project);
}
-
- applyExclusions();
}
- void applyExclusions() {
- for (Iterator<Project> it = projects.iterator(); it.hasNext();) {
- Project project = it.next();
- if (projectFilter.isExcluded(project)) {
- project.setExcluded(true);
- LoggerFactory.getLogger(getClass()).info("Project {} excluded", project.getName());
- project.removeFromParent();
- it.remove();
- }
- }
- }
public List<Project> getProjects() {
return projects;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
index eca2765ecd0..0ed7b77a24c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
@@ -29,14 +29,16 @@ import java.util.Properties;
*/
public class BatchDatabase extends DefaultDatabase {
- public BatchDatabase(Settings settings) {
+ // the dependency on JdbcDriverHolder is required to be sure that the JDBC driver
+ // has been downloaded and injected into classloader
+ public BatchDatabase(Settings settings, JdbcDriverHolder jdbcDriverHolder) {
super(settings);
}
@Override
protected void doCompleteProperties(Properties properties) {
// two connections are required : one for Hibernate and one for MyBatis
- // Note that Hibernate will be remove soon
+ // Note that Hibernate will be removed soon
properties.setProperty("sonar.jdbc.initialSize", "2");
properties.setProperty("sonar.jdbc.maxActive", "2");
}
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
deleted file mode 100644
index 75e595e0793..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.bootstrap;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.Extension;
-import org.sonar.api.ExtensionProvider;
-import org.sonar.api.Plugin;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metrics;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.Map;
-
-public final class BatchExtensionInstaller implements BatchComponent {
-
- private BatchPluginRepository pluginRepository;
- private EnvironmentInformation environment;
- private DryRun dryRun;
-
- public BatchExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun) {
- this.pluginRepository = pluginRepository;
- this.environment = environment;
- this.dryRun = dryRun;
- }
-
- public void install(Module module) {
- ListMultimap<PluginMetadata, Object> installedExtensionsByPlugin = ArrayListMultimap.create();
- for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
- PluginMetadata metadata = entry.getKey();
- Plugin plugin = entry.getValue();
-
- module.addExtension(metadata, plugin);
-
- for (Object extension : plugin.getExtensions()) {
- if (installExtension(module, metadata, extension)) {
- installedExtensionsByPlugin.put(metadata, extension);
- } else {
- module.declareExtension(metadata, extension);
- }
- }
- }
- for (Map.Entry<PluginMetadata, Object> entry : installedExtensionsByPlugin.entries()) {
- PluginMetadata plugin = entry.getKey();
- Object extension = entry.getValue();
- if (isExtensionProvider(extension)) {
- ExtensionProvider provider = (ExtensionProvider) module.getComponentByKey(extension);
- installProvider(module, plugin, provider);
- }
- }
- installMetrics(module);
- }
-
- static boolean isExtensionProvider(Object extension) {
- return isType(extension, ExtensionProvider.class) || extension instanceof ExtensionProvider;
- }
-
- static boolean isType(Object extension, Class<? extends Extension> extensionClass) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- return extensionClass.isAssignableFrom(clazz);
- }
-
- private void installMetrics(Module module) {
- for (Metrics metrics : module.getComponents(Metrics.class)) {
- for (Metric metric : metrics.getMetrics()) {
- module.addCoreSingleton(metric);
- }
- }
- }
-
- private void installProvider(Module module, PluginMetadata plugin, ExtensionProvider provider) {
- Object obj = provider.provide();
- if (obj != null) {
- if (obj instanceof Iterable) {
- for (Object ext : (Iterable) obj) {
- installExtension(module, plugin, ext);
- }
- } else {
- installExtension(module, plugin, obj);
- }
- }
- }
-
- boolean installExtension(Module module, PluginMetadata plugin, 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);
- }
- module.addExtension(plugin, extension);
- return true;
- }
- return false;
- }
-}
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 b598f81a9ad..f7db951df26 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
@@ -20,16 +20,29 @@
package org.sonar.batch.bootstrap;
import org.sonar.api.Plugins;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.batch.DefaultFileLinesContextFactory;
import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.components.*;
-import org.sonar.batch.index.*;
+import org.sonar.batch.components.PastMeasuresLoader;
+import org.sonar.batch.components.PastSnapshotFinder;
+import org.sonar.batch.components.PastSnapshotFinderByDate;
+import org.sonar.batch.components.PastSnapshotFinderByDays;
+import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis;
+import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion;
+import org.sonar.batch.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.index.DefaultIndex;
+import org.sonar.batch.index.DefaultPersistenceManager;
+import org.sonar.batch.index.DefaultResourcePersister;
+import org.sonar.batch.index.DependencyPersister;
+import org.sonar.batch.index.EventPersister;
+import org.sonar.batch.index.LinkPersister;
+import org.sonar.batch.index.MeasurePersister;
+import org.sonar.batch.index.MemoryOptimizer;
+import org.sonar.batch.index.SourcePersister;
import org.sonar.core.metric.CacheMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.rule.CacheRuleFinder;
@@ -41,66 +54,47 @@ import org.sonar.jpa.dao.MeasuresDao;
*/
public class BatchModule extends Module {
- private final boolean dryRun;
-
- public BatchModule(boolean dryRun) {
- this.dryRun = dryRun;
- }
-
@Override
protected void configure() {
- addCoreSingleton(ProjectTree.class);
- addCoreSingleton(ProjectFilter.class);
- addCoreSingleton(ProjectConfigurator.class);
- addCoreSingleton(DefaultResourceCreationLock.class);
- addCoreSingleton(DefaultIndex.class);
- addCoreSingleton(DefaultFileLinesContextFactory.class);
-
- if (dryRun) {
- addCoreSingleton(ReadOnlyPersistenceManager.class);
- } else {
- addCoreSingleton(DefaultPersistenceManager.class);
- addCoreSingleton(DependencyPersister.class);
- addCoreSingleton(EventPersister.class);
- addCoreSingleton(LinkPersister.class);
- addCoreSingleton(MeasurePersister.class);
- addCoreSingleton(MemoryOptimizer.class);
- addCoreSingleton(DefaultResourcePersister.class);
- addCoreSingleton(SourcePersister.class);
- }
-
- addCoreSingleton(Plugins.class);
- addCoreSingleton(MeasuresDao.class);
- addCoreSingleton(CacheRuleFinder.class);
- addCoreSingleton(CacheMetricFinder.class);
- addCoreSingleton(PastSnapshotFinderByDate.class);
- addCoreSingleton(PastSnapshotFinderByDays.class);
- addCoreSingleton(PastSnapshotFinderByPreviousAnalysis.class);
- addCoreSingleton(PastSnapshotFinderByVersion.class);
- addCoreSingleton(PastSnapshotFinderByPreviousVersion.class);
- addCoreSingleton(PastMeasuresLoader.class);
- addCoreSingleton(PastSnapshotFinder.class);
- addCoreSingleton(DefaultNotificationManager.class);
- addCoreSingleton(DefaultUserFinder.class);
- addCoreSingleton(ResourceTypes.class);
- addCoreMetrics();
+ container.addSingleton(ProjectTree.class);
+ container.addSingleton(ProjectConfigurator.class);
+ container.addSingleton(DefaultResourceCreationLock.class);
+ container.addSingleton(DefaultIndex.class);
+ container.addSingleton(DefaultFileLinesContextFactory.class);
+ container.addSingleton(DefaultPersistenceManager.class);
+ container.addSingleton(DependencyPersister.class);
+ container.addSingleton(EventPersister.class);
+ container.addSingleton(LinkPersister.class);
+ container.addSingleton(MeasurePersister.class);
+ container.addSingleton(MemoryOptimizer.class);
+ container.addSingleton(DefaultResourcePersister.class);
+ container.addSingleton(SourcePersister.class);
+ container.addSingleton(Plugins.class);
+ container.addSingleton(MeasuresDao.class);
+ container.addSingleton(CacheRuleFinder.class);
+ container.addSingleton(CacheMetricFinder.class);
+ container.addSingleton(PastSnapshotFinderByDate.class);
+ container.addSingleton(PastSnapshotFinderByDays.class);
+ container.addSingleton(PastSnapshotFinderByPreviousAnalysis.class);
+ container.addSingleton(PastSnapshotFinderByVersion.class);
+ container.addSingleton(PastSnapshotFinderByPreviousVersion.class);
+ container.addSingleton(PastMeasuresLoader.class);
+ container.addSingleton(PastSnapshotFinder.class);
+ container.addSingleton(DefaultNotificationManager.class);
+ container.addSingleton(DefaultUserFinder.class);
+ container.addSingleton(ResourceTypes.class);
+ container.addSingleton(MetricProvider.class);
addBatchExtensions();
}
private void addBatchExtensions() {
- BatchExtensionInstaller installer = getComponentByType(BatchExtensionInstaller.class);
- installer.install(this);
- }
-
- void addCoreMetrics() {
- for (Metric metric : CoreMetrics.getMetrics()) {
- addCoreSingleton(metric);
- }
+ ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class);
+ installer.install(container, InstantiationStrategy.BATCH);
}
@Override
protected void doStart() {
- ProjectTree projectTree = getComponentByType(ProjectTree.class);
+ ProjectTree projectTree = container.getComponentByType(ProjectTree.class);
analyze(projectTree.getRootProject());
}
@@ -109,7 +103,7 @@ public class BatchModule extends Module {
analyze(subProject);
}
- Module projectComponents = installChild(new ProjectModule(project, dryRun));
+ Module projectComponents = installChild(new ProjectModule(project));
try {
projectComponents.start();
} finally {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java
index 618a1e764c7..6fc42e4e6ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java
@@ -19,32 +19,27 @@
*/
package org.sonar.batch.bootstrap;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.Property;
-import org.sonar.api.config.Settings;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.platform.ComponentContainer;
-/**
- * @since 3.4
- */
-@Property(key = "sonar.local", defaultValue = "false", name = "Local Mode")
-public class LocalMode implements BatchComponent {
- private static final Logger LOG = LoggerFactory.getLogger(LocalMode.class);
-
- private final boolean enabled;
+public class BootstrapExtensionExecutor {
- public LocalMode(Settings settings) {
- enabled = settings.getBoolean("sonar.local");
- }
+ private ComponentContainer container;
+ private ExtensionInstaller installer;
- public boolean isEnabled() {
- return enabled;
+ public BootstrapExtensionExecutor(ComponentContainer container, ExtensionInstaller installer) {
+ this.container = container;
+ this.installer = installer;
}
public void start() {
- if (enabled) {
- LOG.info("Local Mode");
- }
+ LoggerFactory.getLogger(BootstrapExtensionExecutor.class).debug("Execute bootstrap extensions");
+ ComponentContainer childContainer = container.createChild();
+ installer.install(childContainer, InstantiationStrategy.BOOTSTRAP);
+ childContainer.addSingleton(ProjectExclusions.class);
+ childContainer.startComponents();
+ childContainer.stopComponents();
+ container.removeChild();
}
}
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 f5bfb3eadd4..d7dedb1c1e1 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
@@ -29,7 +29,7 @@ import org.sonar.batch.MavenPluginExecutor;
import org.sonar.batch.RemoteServerMetadata;
import org.sonar.batch.ServerMetadata;
import org.sonar.batch.config.BatchDatabaseSettingsLoader;
-import org.sonar.batch.config.BatchSettings;
+import org.sonar.batch.config.BootstrapSettings;
import org.sonar.batch.local.LocalDatabase;
import org.sonar.core.config.Logback;
import org.sonar.core.i18n.I18nManager;
@@ -41,8 +41,6 @@ import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
-import java.net.URLClassLoader;
-
/**
* Level 1 components
*/
@@ -58,55 +56,51 @@ public class BootstrapModule extends Module {
@Override
protected void configure() {
- addCoreSingleton(reactor);
- addCoreSingleton(new PropertiesConfiguration());
- addCoreSingleton(BatchSettings.class);
- addCoreSingleton(DryRun.class);
- addCoreSingleton(Logback.class);
- addCoreSingleton(ServerMetadata.class);// registered here because used by BootstrapClassLoader
- addCoreSingleton(TempDirectories.class);// registered here because used by BootstrapClassLoader
- addCoreSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
- addCoreSingleton(UriReader.class);// registered here because used by BootstrapClassLoader
- addCoreSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
- addCoreSingleton(JdbcDriverHolder.class);
- addCoreSingleton(EmailSettings.class);
- addCoreSingleton(I18nManager.class);
- addCoreSingleton(RuleI18nManager.class);
-
- URLClassLoader bootstrapClassLoader = getComponentByType(JdbcDriverHolder.class).getClassLoader();
- // set as the current context classloader for hibernate, else it does not find the JDBC driver.
- Thread.currentThread().setContextClassLoader(bootstrapClassLoader);
-
- addCoreSingleton(RemoteServerMetadata.class);
+ container.addSingleton(reactor);
+ container.addSingleton(new PropertiesConfiguration());
+ container.addSingleton(BootstrapSettings.class);
+ container.addSingleton(BatchPluginRepository.class);
+ container.addSingleton(ExtensionInstaller.class);
+ container.addSingleton(DryRun.class);
+ container.addSingleton(Logback.class);
+ container.addSingleton(ServerMetadata.class);// registered here because used by BootstrapClassLoader
+ container.addSingleton(TempDirectories.class);// registered here because used by BootstrapClassLoader
+ container.addSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
+ container.addSingleton(UriReader.class);// registered here because used by BootstrapClassLoader
+ container.addSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
+ container.addSingleton(EmailSettings.class);
+ container.addSingleton(RemoteServerMetadata.class);
+ container.addSingleton(I18nManager.class);
+ container.addSingleton(RuleI18nManager.class);
+ for (Object component : boostrapperComponents) {
+ container.addSingleton(component);
+ }
+ container.addSingleton(BootstrapExtensionExecutor.class);
+ if (!isMavenPluginExecutorRegistered()) {
+ container.addSingleton(FakeMavenPluginExecutor.class);
+ }
+ addDatabaseComponents();
+ }
- // local mode
- addCoreSingleton(LocalMode.class);
- addCoreSingleton(LocalDatabase.class);
+ private void addDatabaseComponents() {
+ container.addSingleton(JdbcDriverHolder.class);
+ container.addSingleton(LocalDatabase.class);
// mybatis
- addCoreSingleton(BatchDatabase.class);
- addCoreSingleton(MyBatis.class);
- addCoreSingleton(DatabaseVersion.class);
+ container.addSingleton(BatchDatabase.class);
+ container.addSingleton(MyBatis.class);
+ container.addSingleton(DatabaseVersion.class);
for (Class daoClass : DaoUtils.getDaoClasses()) {
- addCoreSingleton(daoClass);
+ container.addSingleton(daoClass);
}
// hibernate
- addCoreSingleton(DefaultDatabaseConnector.class);
- addCoreSingleton(ThreadLocalDatabaseSessionFactory.class);
- addAdapter(new DatabaseSessionProvider());
-
- addCoreSingleton(DatabaseBatchCompatibility.class);
- for (Object component : boostrapperComponents) {
- addCoreSingleton(component);
- }
- if (!isMavenPluginExecutorRegistered()) {
- addCoreSingleton(FakeMavenPluginExecutor.class);
- }
+ container.addSingleton(DefaultDatabaseConnector.class);
+ container.addSingleton(ThreadLocalDatabaseSessionFactory.class);
+ container.addPicoAdapter(new DatabaseSessionProvider());
- addCoreSingleton(BatchPluginRepository.class);
- addCoreSingleton(BatchExtensionInstaller.class);
- addCoreSingleton(BatchDatabaseSettingsLoader.class);
+ container.addSingleton(DatabaseBatchCompatibility.class);
+ container.addSingleton(BatchDatabaseSettingsLoader.class);
}
boolean isMavenPluginExecutorRegistered() {
@@ -122,8 +116,7 @@ public class BootstrapModule extends Module {
@Override
protected void doStart() {
- boolean dryRun = getComponentByType(DryRun.class).isEnabled();
- Module batchComponents = installChild(new BatchModule(dryRun));
+ Module batchComponents = installChild(new BatchModule());
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
index 574ab37aa6a..d0f6c97f941 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java
@@ -19,27 +19,27 @@
*/
package org.sonar.batch.bootstrap;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
import org.sonar.api.config.Settings;
-import org.sonar.api.utils.Logs;
-@Property(key="sonar.dryRun", defaultValue = "false", name="Dry Run")
+@Property(key = "sonar.dryRun", defaultValue = "false", name = "Dry Run", type = PropertyType.BOOLEAN)
public class DryRun implements BatchComponent {
private boolean enabled;
public DryRun(Settings settings) {
enabled = settings.getBoolean("sonar.dryRun");
- if (enabled) {
- Logs.INFO.info("Dry run");
- }
- }
-
- DryRun(boolean enabled) {
- this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
+
+ public void start() {
+ if (enabled) {
+ LoggerFactory.getLogger(DryRun.class).info("Dry run");
+ }
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
new file mode 100644
index 00000000000..0e31db355fa
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
@@ -0,0 +1,107 @@
+/*
+ * 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.bootstrap;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.config.Settings;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.resources.Project;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Map;
+
+public class ExtensionInstaller implements BatchComponent {
+
+ private BatchPluginRepository pluginRepository;
+ private EnvironmentInformation environment;
+ private Settings settings;
+
+ public ExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, Settings settings) {
+ this.pluginRepository = pluginRepository;
+ this.environment = environment;
+ this.settings = settings;
+ }
+
+ public void install(ComponentContainer container, String instantiationStrategy) {
+ boolean dryRun = settings.getBoolean("sonar.dryRun");
+ for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
+ PluginMetadata metadata = entry.getKey();
+ Plugin plugin = entry.getValue();
+
+ container.addExtension(metadata, plugin);
+ for (Object extension : plugin.getExtensions()) {
+ installExtension(container, metadata, extension, dryRun, instantiationStrategy);
+ }
+ }
+
+ List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class);
+ for (ExtensionProvider provider : providers) {
+ executeProvider(container, instantiationStrategy, dryRun, provider);
+ }
+ }
+
+ private void executeProvider(ComponentContainer container, String instantiationStrategy, boolean dryRun, ExtensionProvider provider) {
+ Object obj = provider.provide();
+ if (obj instanceof Iterable) {
+ for (Object extension : (Iterable) obj) {
+ installExtension(container, null, extension, dryRun, instantiationStrategy);
+ }
+ } else {
+ installExtension(container, null, obj, dryRun, instantiationStrategy);
+ }
+ }
+
+ boolean installExtension(ComponentContainer container, @Nullable PluginMetadata plugin, Object extension, boolean dryRun, String instantiationStrategy) {
+ boolean installed;
+ if (ExtensionUtils.isBatchExtension(extension) &&
+ ExtensionUtils.supportsEnvironment(extension, environment) &&
+ (!dryRun || ExtensionUtils.supportsDryRun(extension)) &&
+ ExtensionUtils.isInstantiationStrategy(extension, instantiationStrategy) &&
+ !isMavenExtensionOnEmulatedMavenProject(extension, instantiationStrategy, container)) {
+
+ container.addExtension(plugin, extension);
+ installed = true;
+ } else {
+ container.declareExtension(plugin, extension);
+ installed = false;
+ }
+ return installed;
+ }
+
+ /**
+ * Special use-case: the extension point ProjectBuilder is used in a Maven environment to define some
+ * new sub-projects without pom.
+ * Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom.
+ */
+ static boolean isMavenExtensionOnEmulatedMavenProject(Object extension, String instantiationStrategy, ComponentContainer container) {
+ if (InstantiationStrategy.PROJECT.equals(instantiationStrategy) && ExtensionUtils.isMavenExtensionOnly(extension)) {
+ Project project = container.getComponentByType(Project.class);
+ return project!=null && project.getPom()==null;
+ }
+ return false;
+ }
+}
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 da9c7ffc214..901dad13ab6 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
@@ -28,28 +28,26 @@ import org.sonar.api.utils.AnnotationUtils;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.core.NotDryRun;
-public final class ExtensionUtils {
+final class ExtensionUtils {
private ExtensionUtils() {
// only static methods
}
static boolean isInstantiationStrategy(Object extension, String strategy) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- InstantiationStrategy extStrategy = AnnotationUtils.getAnnotation(clazz, InstantiationStrategy.class);
- if (extStrategy != null) {
- return strategy.equals(extStrategy.value());
+ InstantiationStrategy annotation = AnnotationUtils.getAnnotation(extension, InstantiationStrategy.class);
+ if (annotation != null) {
+ return strategy.equals(annotation.value());
}
- return InstantiationStrategy.PER_PROJECT.equals(strategy);
+ return InstantiationStrategy.PROJECT.equals(strategy);
}
static boolean isBatchExtension(Object extension) {
return isType(extension, BatchExtension.class);
}
- static boolean isSupportedEnvironment(Object extension, EnvironmentInformation environment) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- SupportedEnvironment env = AnnotationUtils.getAnnotation(clazz, SupportedEnvironment.class);
+ static boolean supportsEnvironment(Object extension, EnvironmentInformation environment) {
+ SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
if (env == null) {
return true;
}
@@ -61,13 +59,12 @@ public final class ExtensionUtils {
return false;
}
- static boolean checkDryRun(Object extension, boolean dryRun) {
- return !dryRun || AnnotationUtils.getAnnotation(extension, NotDryRun.class) == null;
+ static boolean supportsDryRun(Object extension) {
+ return AnnotationUtils.getAnnotation(extension, NotDryRun.class) == null;
}
static boolean isMavenExtensionOnly(Object extension) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- SupportedEnvironment env = AnnotationUtils.getAnnotation(clazz, SupportedEnvironment.class);
+ SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
return env!=null && env.value().length==1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
index 1cdb7b9217c..8de5ca9147d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
@@ -57,6 +57,11 @@ public class JdbcDriverHolder {
return classLoader;
}
+ public void start() {
+ // set as the current context classloader for hibernate, else it does not find the JDBC driver.
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+
/**
* This method automatically invoked by PicoContainer and deregisters JDBC drivers, which were forgotten.
* <p>
@@ -86,7 +91,7 @@ public class JdbcDriverHolder {
private static class JdbcDriverClassLoader extends URLClassLoader {
public JdbcDriverClassLoader(URL jdbcDriver, ClassLoader parent) {
- super(new URL[] { jdbcDriver }, parent);
+ super(new URL[]{jdbcDriver}, parent);
}
public void clearReferencesJdbc() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java
new file mode 100644
index 00000000000..d74c221b1d9
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java
@@ -0,0 +1,54 @@
+/*
+ * 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.bootstrap;
+
+import com.google.common.collect.Lists;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.Metrics;
+
+import java.util.List;
+
+@InstantiationStrategy(InstantiationStrategy.BATCH)
+public class MetricProvider extends ExtensionProvider implements BatchExtension {
+
+ private Metrics[] factories;
+
+ public MetricProvider(Metrics[] factories) {
+ this.factories = factories;
+ }
+
+ public MetricProvider() {
+ this.factories = new Metrics[0];
+ }
+
+ public List<Metric> provide() {
+ LoggerFactory.getLogger(MetricProvider.class).debug("Load metrics");
+ List<Metric> metrics = Lists.newArrayList(CoreMetrics.getMetrics());
+ for (Metrics factory : factories) {
+ metrics.addAll(factory.getMetrics());
+ }
+ return metrics;
+ }
+}
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 df51d635ce2..b6d20d190e6 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
@@ -23,6 +23,8 @@ import org.picocontainer.ComponentAdapter;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.PluginMetadata;
+import javax.annotation.Nullable;
+
import java.util.List;
/**
@@ -111,31 +113,4 @@ public abstract class Module {
*/
protected abstract void configure();
- protected final void addCoreSingleton(Object component) {
- container.addSingleton(component);
- }
-
- protected final void declareExtension(PluginMetadata plugin, Object extension) {
- container.declareExtension(plugin, extension);
- }
-
- protected final void addExtension(PluginMetadata plugin, Object extension) {
- container.addExtension(plugin, extension);
- }
-
- protected final void addAdapter(ComponentAdapter<?> componentAdapter) {
- container.addPicoAdapter(componentAdapter);
- }
-
- public final <T> T getComponentByType(Class<T> componentType) {
- return container.getComponentByType(componentType);
- }
-
- public final Object getComponentByKey(Object key) {
- return container.getComponentByKey(key);
- }
-
- public final <T> List<T> getComponents(Class<T> componentType) {
- return container.getComponentsByType(componentType);
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java
new file mode 100644
index 00000000000..148fb355824
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java
@@ -0,0 +1,88 @@
+/*
+ * 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.bootstrap;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+
+/**
+ * Exclude the sub-projects as defined by the properties sonar.skippedModules and sonar.includedModules
+ *
+ * @since 2.12
+ */
+@InstantiationStrategy(InstantiationStrategy.BOOTSTRAP)
+public class ProjectExclusions implements BatchComponent {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class);
+
+ private Settings settings;
+ private ProjectReactor reactor;
+
+ public ProjectExclusions(Settings settings, ProjectReactor reactor) {
+ this.settings = settings;
+ this.reactor = reactor;
+ }
+
+ public void start() {
+ LOG.debug("Apply project exclusions");
+ for (ProjectDefinition project : reactor.getProjects()) {
+ if (isExcluded(key(project), project == reactor.getRoot())) {
+ exclude(project);
+ }
+ }
+ }
+
+ private boolean isExcluded(String projectKey, boolean isRoot) {
+ String[] includedKeys = settings.getStringArray("sonar.includedModules");
+ boolean excluded = false;
+ if (!isRoot && includedKeys.length > 0) {
+ excluded = !ArrayUtils.contains(includedKeys, projectKey);
+ }
+ if (!excluded) {
+ String[] excludedKeys = settings.getStringArray("sonar.skippedModules");
+ excluded = ArrayUtils.contains(excludedKeys, projectKey);
+ }
+ if (excluded && isRoot) {
+ throw new IllegalArgumentException("The root project can't be excluded. Please check the parameters sonar.skippedModules and sonar.includedModules.");
+ }
+ return excluded;
+ }
+
+ private void exclude(ProjectDefinition project) {
+ LOG.info(String.format("Exclude project: %s [%s]", project.getName(), project.getKey()));
+ project.remove();
+ }
+
+ // TODO see http://jira.codehaus.org/browse/SONAR-2324
+ static String key(ProjectDefinition project) {
+ String key = project.getKey();
+ if (key.contains(":")) {
+ return StringUtils.substringAfter(key, ":");
+ }
+ return key;
+ }
+}
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
deleted file mode 100644
index 108c80356b6..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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.bootstrap;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.ExtensionProvider;
-import org.sonar.api.Plugin;
-import org.sonar.api.batch.AbstractCoverageExtension;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.config.ProjectSettings;
-
-import java.util.List;
-import java.util.Map;
-
-public final class ProjectExtensionInstaller implements BatchComponent {
-
- private BatchPluginRepository pluginRepository;
- private EnvironmentInformation environment;
- private DryRun dryRun;
- private Project project;
- private ProjectSettings settings;
-
- public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun, Project project, ProjectSettings settings) {
- this.pluginRepository = pluginRepository;
- this.environment = environment;
- this.dryRun = dryRun;
- this.project = project;
- this.settings = settings;
- }
-
- public void install(Module module) {
- for (Map.Entry<String, Plugin> entry : pluginRepository.getPluginsByKey().entrySet()) {
- for (Object extension : entry.getValue().getExtensions()) {
- installExtension(module, extension, entry.getKey());
- }
- }
- installExtensionProviders(module);
- }
-
- void installExtensionProviders(Module module) {
- List<ExtensionProvider> providers = module.getComponents(ExtensionProvider.class);
- for (ExtensionProvider provider : providers) {
- Object obj = provider.provide();
- if (obj instanceof Iterable) {
- for (Object extension : (Iterable) obj) {
- installExtension(module, extension, "");
- }
- } else {
- installExtension(module, obj, "");
- }
- }
- }
-
- private Object installExtension(Module module, Object extension, String pluginKey) {
- if (ExtensionUtils.isBatchExtension(extension) &&
- ExtensionUtils.isSupportedEnvironment(extension, environment) &&
- ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) &&
- ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
- !isDeactivatedCoverageExtension(extension, pluginKey, project, settings) &&
- !isMavenExtensionOnEmulatedMavenProject(extension, project)) {
- module.addCoreSingleton(extension);
- return extension;
- }
- return null;
- }
-
- /**
- * Special use-case: the extension point ProjectBuilder is used in a Maven environment to define some
- * new sub-projects without pom.
- * Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom.
- */
- static boolean isMavenExtensionOnEmulatedMavenProject(Object extension, Project project) {
- return ExtensionUtils.isMavenExtensionOnly(extension) && project.getPom() == null;
- }
-
- /**
- * TODO this code is specific to Java projects and should be moved somewhere else
- */
- static boolean isDeactivatedCoverageExtension(Object extension, String pluginKey, Project project, Settings settings) {
- if (!ExtensionUtils.isType(extension, CoverageExtension.class)) {
- return false;
- }
-
- if (!project.getAnalysisType().isDynamic(true)) {
- // not dynamic and not reuse reports
- return true;
- }
-
- if (StringUtils.equals(project.getLanguageKey(), Java.KEY)) {
- String[] selectedPluginKeys = settings.getStringArray(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY);
- if (ArrayUtils.isEmpty(selectedPluginKeys)) {
- selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN};
- }
- return !ArrayUtils.contains(selectedPluginKeys, pluginKey);
- }
- return false;
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
deleted file mode 100644
index 9727a74dbab..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.bootstrap;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
-
-/**
- * Filter projects to analyze by using the properties sonar.skippedModules and sonar.includedModules
- *
- * @since 2.12
- */
-public class ProjectFilter {
-
- private Settings settings;
-
- public ProjectFilter(Settings settings) {
- this.settings = settings;
- }
-
- public boolean isExcluded(Project project) {
- Project p = project;
- while (p != null) {
- if (isExcludedModule(getArtifactId(p), p.isRoot())) {
- return true;
- }
- p = p.getParent();
- }
- return false;
- }
-
- private boolean isExcludedModule(String artifactId, boolean isRoot) {
- String[] includedArtifactIds = settings.getStringArray("sonar.includedModules");
- boolean excluded = false;
- if (!isRoot && includedArtifactIds.length > 0) {
- excluded = !ArrayUtils.contains(includedArtifactIds, artifactId);
- }
- if (!excluded) {
- String[] excludedArtifactIds = settings.getStringArray("sonar.skippedModules");
- excluded = ArrayUtils.contains(excludedArtifactIds, artifactId);
- }
- if (excluded && isRoot) {
- throw new IllegalArgumentException("The root module can't be skipped. Please check the parameter sonar.skippedModules.");
- }
- return excluded;
- }
-
- // TODO see http://jira.codehaus.org/browse/SONAR-2324
- static String getArtifactId(Project project) {
- String key = project.getKey();
- if (StringUtils.isNotBlank(project.getBranch())) {
- // remove branch part
- key = StringUtils.removeEnd(project.getKey(), ":" + project.getBranch());
- }
- if (key.contains(":")) {
- return StringUtils.substringAfter(key, ":");
- }
- return key;
- }
-}
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 02cb458c473..13bde69f4da 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
@@ -22,12 +22,21 @@ package org.sonar.batch.bootstrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchExtensionDictionnary;
+import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.IocContainer;
-import org.sonar.batch.*;
+import org.sonar.batch.DefaultProfileLoader;
+import org.sonar.batch.DefaultProjectClasspath;
+import org.sonar.batch.DefaultProjectFileSystem2;
+import org.sonar.batch.DefaultSensorContext;
+import org.sonar.batch.DefaultTimeMachine;
+import org.sonar.batch.ProfileProvider;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.config.ProjectSettings;
import org.sonar.batch.config.UnsupportedProperties;
@@ -43,11 +52,9 @@ import org.sonar.jpa.dao.RulesDao;
public class ProjectModule extends Module {
private static final Logger LOG = LoggerFactory.getLogger(ProjectModule.class);
private Project project;
- private boolean dryRun;
- public ProjectModule(Project project, boolean dryRun) {
+ public ProjectModule(Project project) {
this.project = project;
- this.dryRun = dryRun;
}
@Override
@@ -60,52 +67,50 @@ public class ProjectModule extends Module {
private void addProjectComponents() {
- ProjectDefinition projectDefinition = getComponentByType(ProjectTree.class).getProjectDefinition(project);
- addCoreSingleton(projectDefinition);
- addCoreSingleton(project);
- addCoreSingleton(project.getConfiguration());
- addCoreSingleton(ProjectSettings.class);
- addCoreSingleton(UnsupportedProperties.class);
- addCoreSingleton(IocContainer.class);
+ ProjectDefinition projectDefinition = container.getComponentByType(ProjectTree.class).getProjectDefinition(project);
+ container.addSingleton(projectDefinition);
+ container.addSingleton(project);
+ container.addSingleton(project.getConfiguration());
+ container.addSingleton(ProjectSettings.class);
+ container.addSingleton(UnsupportedProperties.class);
+ container.addSingleton(IocContainer.class);
for (Object component : projectDefinition.getContainerExtensions()) {
- addCoreSingleton(component);
+ container.addSingleton(component);
}
- addCoreSingleton(Languages.class);
- addCoreSingleton(DefaultProjectClasspath.class);
- addCoreSingleton(DefaultProjectFileSystem2.class);
- addCoreSingleton(RulesDao.class);
+ container.addSingleton(Languages.class);
+ container.addSingleton(DefaultProjectClasspath.class);
+ container.addSingleton(DefaultProjectFileSystem2.class);
+ container.addSingleton(RulesDao.class);
- if (!dryRun) {
- // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
- addCoreSingleton(getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
- }
- addCoreSingleton(TimeMachineConfiguration.class);
- addCoreSingleton(org.sonar.api.database.daos.MeasuresDao.class);
- addCoreSingleton(ProfilesDao.class);
- addCoreSingleton(DefaultSensorContext.class);
- addCoreSingleton(BatchExtensionDictionnary.class);
- addCoreSingleton(DefaultTimeMachine.class);
- addCoreSingleton(ViolationFilters.class);
- addCoreSingleton(ResourceFilters.class);
- addCoreSingleton(DefaultModelFinder.class);
- addCoreSingleton(DefaultProfileLoader.class);
- addAdapter(new ProfileProvider());
+ // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
+ container.addSingleton(container.getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
+
+ container.addSingleton(TimeMachineConfiguration.class);
+ container.addSingleton(org.sonar.api.database.daos.MeasuresDao.class);
+ container.addSingleton(ProfilesDao.class);
+ container.addSingleton(DefaultSensorContext.class);
+ container.addSingleton(BatchExtensionDictionnary.class);
+ container.addSingleton(DefaultTimeMachine.class);
+ container.addSingleton(ViolationFilters.class);
+ container.addSingleton(ResourceFilters.class);
+ container.addSingleton(DefaultModelFinder.class);
+ container.addSingleton(DefaultProfileLoader.class);
+ container.addPicoAdapter(new ProfileProvider());
}
private void addCoreComponents() {
- addCoreSingleton(EventBus.class);
- addCoreSingleton(Phases.class);
- addCoreSingleton(PhasesTimeProfiler.class);
- for (Class clazz : Phases.getPhaseClasses(dryRun)) {
- addCoreSingleton(clazz);
+ container.addSingleton(EventBus.class);
+ container.addSingleton(Phases.class);
+ container.addSingleton(PhasesTimeProfiler.class);
+ for (Class clazz : Phases.getPhaseClasses()) {
+ container.addSingleton(clazz);
}
}
private void addProjectPluginExtensions() {
- addCoreSingleton(ProjectExtensionInstaller.class);
- ProjectExtensionInstaller installer = getComponentByType(ProjectExtensionInstaller.class);
- installer.install(this);
+ ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class);
+ installer.install(container, InstantiationStrategy.PROJECT);
}
@@ -119,12 +124,12 @@ public class ProjectModule extends Module {
*/
@Override
protected void doStart() {
- DefaultIndex index = getComponentByType(DefaultIndex.class);
+ DefaultIndex index = container.getComponentByType(DefaultIndex.class);
index.setCurrentProject(project,
- getComponentByType(ResourceFilters.class),
- getComponentByType(ViolationFilters.class),
- getComponentByType(RulesProfile.class));
+ container.getComponentByType(ResourceFilters.class),
+ container.getComponentByType(ViolationFilters.class),
+ container.getComponentByType(RulesProfile.class));
- getComponentByType(Phases.class).execute(project);
+ container.getComponentByType(Phases.class).execute(project);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java
index e409d67c9e5..e287adbdf9a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java
@@ -17,31 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
+@ParametersAreNonnullByDefault
package org.sonar.batch.bootstrap;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LocalModeTest {
- Settings settings = new Settings();
-
- @Test
- public void should_be_disabled() {
- LocalMode localMode = new LocalMode(settings);
- localMode.start();
-
- assertThat(localMode.isEnabled()).isFalse();
- }
-
- @Test
- public void should_enable() {
- settings.setProperty("sonar.local", "true");
-
- LocalMode localMode = new LocalMode(settings);
- localMode.start();
-
- assertThat(localMode.isEnabled()).isTrue();
- }
-}
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
index f47146f28ee..1e907c30c0e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
@@ -25,9 +25,11 @@ import java.util.List;
/**
* Describes order of projects.
+ * Used by sonar-runner 1.x. Gradle 1.0 already uses {#link org.sonar.api.batch.bootstrap.ProjectReactor}.
*
* @since 2.6
*/
+@Deprecated
public class Reactor {
private ProjectDefinition root;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
index 5f91446ddf7..8a03eb01053 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
@@ -33,10 +33,10 @@ import java.util.List;
public final class BatchDatabaseSettingsLoader {
private PropertiesDao propertiesDao;
- private BatchSettings settings;
+ private BootstrapSettings settings;
private ProjectReactor reactor;
- public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BatchSettings settings, ProjectReactor reactor) {
+ public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BootstrapSettings settings, ProjectReactor reactor) {
this.propertiesDao = propertiesDao;
this.settings = settings;
this.reactor = reactor;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
index 5eb75bc6e18..0d54743e0f6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
@@ -28,18 +28,18 @@ import org.sonar.core.config.ConfigurationUtils;
/**
* @since 2.12
*/
-public final class BatchSettings extends Settings {
+public final class BootstrapSettings extends Settings {
private Configuration deprecatedConfiguration;
private ProjectReactor reactor;
- public BatchSettings(PropertyDefinitions propertyDefinitions, ProjectReactor reactor, Configuration deprecatedConfiguration) {
+ public BootstrapSettings(PropertyDefinitions propertyDefinitions, ProjectReactor reactor, Configuration deprecatedConfiguration) {
super(propertyDefinitions);
this.reactor = reactor;
this.deprecatedConfiguration = deprecatedConfiguration;
load();
}
- public BatchSettings load() {
+ public BootstrapSettings load() {
clear();
// order is important -> bottom-up. The last one overrides all the others.
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
deleted file mode 100644
index 1091375cc73..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.index;
-
-import com.google.common.collect.Maps;
-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;
-import java.util.Map;
-
-public final class ReadOnlyPersistenceManager implements PersistenceManager {
-
- private Map<Resource, String> sources = Maps.newHashMap();
-
- public void clear() {
- sources.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) {
- sources.put(file, source);
- }
-
- public String getSource(Resource resource) {
- return sources.get(resource);
- }
-
- 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/local/LocalDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
index 199541c12a0..be9b447ab89 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
@@ -29,7 +29,7 @@ import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrap.LocalMode;
+import org.sonar.batch.bootstrap.DryRun;
import org.sonar.batch.bootstrap.TempDirectories;
import java.io.File;
@@ -48,12 +48,12 @@ public class LocalDatabase implements BatchComponent {
private static final String USER = "sonar";
private static final String PASSWORD = "sonar";
- private final LocalMode localMode;
+ private final DryRun localMode;
private final Settings settings;
private final Server server;
private final TempDirectories tempDirectories;
- public LocalDatabase(LocalMode localMode, Settings settings, Server server, TempDirectories tempDirectories) {
+ public LocalDatabase(DryRun localMode, Settings settings, Server server, TempDirectories tempDirectories) {
this.localMode = localMode;
this.settings = settings;
this.server = server;
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 e57e8e3fd80..f90c60d3480 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
@@ -32,14 +32,10 @@ import java.util.List;
public final class Phases {
- public static Collection<Class> getPhaseClasses(boolean dryRun) {
- List<Class> classes = Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
+ public static Collection<Class> getPhaseClasses() {
+ return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
PostJobsExecutor.class, SensorsExecutor.class,
- InitializersExecutor.class, ProjectInitializer.class);
- if (!dryRun) {
- classes.add(UpdateStatusJob.class);
- }
- return classes;
+ InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
}
private EventBus eventBus;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
index 7e5cabb7afc..38ea6b9ed94 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
@@ -24,7 +24,6 @@ import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrap.DryRun;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
@@ -34,12 +33,10 @@ import org.sonar.core.resource.ResourceDto;
public class ProjectInitializer implements BatchComponent {
private ResourceDao resourceDao;
- private DryRun dryRun;
private Languages languages;
- public ProjectInitializer(ResourceDao resourceDao, DryRun dryRun, Languages languages) {
+ public ProjectInitializer(ResourceDao resourceDao, Languages languages) {
this.resourceDao = resourceDao;
- this.dryRun = dryRun;
this.languages = languages;
}
@@ -53,7 +50,7 @@ public class ProjectInitializer implements BatchComponent {
throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found");
}
project.setLanguage(language);
- if (!dryRun.isEnabled() && project.getId() != null) {
+ if (project.getId() != null) {
ResourceDto dto = resourceDao.getResource(project.getId());
dto.setLanguage(project.getLanguageKey());
resourceDao.insertOrUpdate(dto);
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
deleted file mode 100644
index 7230e87f561..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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.bootstrap;
-
-import com.google.common.collect.Maps;
-import org.junit.Test;
-import org.sonar.api.*;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class BatchExtensionInstallerTest {
-
- private static final PluginMetadata METADATA = mock(PluginMetadata.class);
-
- private static Map<PluginMetadata, Plugin> newPlugin(final Class... classes) {
- Map<PluginMetadata, Plugin> result = Maps.newHashMap();
- result.put(METADATA,
- new SonarPlugin() {
- public List<Class> getExtensions() {
- return Arrays.asList(classes);
- }
- }
- );
- return result;
- }
-
- @Test
- public void shouldInstallExtensionsWithBatchInstantiationStrategy() {
- BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchService.class, ProjectService.class, ServerService.class));
- Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
- installer.install(module);
-
- assertThat(module.getComponentByType(BatchService.class), not(nullValue()));
- assertThat(module.getComponentByType(ProjectService.class), nullValue());
- assertThat(module.getComponentByType(ServerService.class), nullValue());
- }
-
- @Test
- public void shouldInstallProvidersWithBatchInstantiationStrategy() {
- BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchServiceProvider.class, ProjectServiceProvider.class));
- Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
- installer.install(module);
-
- assertThat(module.getComponentByType(BatchService.class), not(nullValue()));
- assertThat(module.getComponentByType(ProjectService.class), nullValue());
- assertThat(module.getComponentByType(ServerService.class), nullValue());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotSupportCoverageExtensionsWithBatchInstantiationStrategy() {
- // the reason is that CoverageExtensions currently depend on Project
- BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(InvalidCoverageExtension.class));
- Module module = new FakeModule().init();
- BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
- installer.install(module);
- }
-
- public static class FakeModule extends Module {
- @Override
- protected void configure() {
- }
- }
-
- @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
- public static class BatchService implements BatchExtension {
-
- }
-
- public static class ProjectService implements BatchExtension {
-
- }
-
- public static class ServerService implements ServerExtension {
-
- }
-
- @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
- public static class BatchServiceProvider extends ExtensionProvider implements BatchExtension {
-
- @Override
- public Object provide() {
- return Arrays.<Object> asList(BatchService.class, ServerService.class);
- }
- }
-
- public static class ProjectServiceProvider extends ExtensionProvider implements BatchExtension {
- @Override
- public Object provide() {
- return ProjectService.class;
- }
- }
-
- @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
- public static class InvalidCoverageExtension implements CoverageExtension {
- // strategy PER_BATCH is not allowed
- }
-}
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
index 52b421efeb9..f0b514fff0f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java
@@ -19,27 +19,29 @@
*/
package org.sonar.batch.bootstrap;
-import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class DryRunTest {
+ Settings settings = new Settings();
@Test
- public void shouldReadSettings() {
- Settings settings = Settings.createForComponent(DryRun.class);
- settings.setProperty("sonar.dryRun", true);
- assertThat(new DryRun(settings).isEnabled(), Is.is(true));
+ public void should_be_disabled() {
+ DryRun dryRun = new DryRun(settings);
+ dryRun.start();
- settings.setProperty("sonar.dryRun", false);
- assertThat(new DryRun(settings).isEnabled(), Is.is(false));
+ assertThat(dryRun.isEnabled()).isFalse();
}
@Test
- public void shouldNotEnableDryRunByDefault() {
- Settings settings = Settings.createForComponent(DryRun.class);
- assertThat(new DryRun(settings).isEnabled(), Is.is(false));
+ public void should_enable() {
+ settings.setProperty("sonar.dryRun", "true");
+
+ DryRun dryRun = new DryRun(settings);
+ dryRun.start();
+
+ assertThat(dryRun.isEnabled()).isTrue();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
new file mode 100644
index 00000000000..1f65e534fd3
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
@@ -0,0 +1,142 @@
+/*
+* 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.bootstrap;
+
+import com.google.common.collect.Maps;
+import org.junit.Test;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.SonarPlugin;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.SupportedEnvironment;
+import org.sonar.api.config.Settings;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ExtensionInstallerTest {
+
+ private static final PluginMetadata METADATA = mock(PluginMetadata.class);
+
+ private static Map<PluginMetadata, Plugin> newPlugin(final Class... classes) {
+ Map<PluginMetadata, Plugin> result = Maps.newHashMap();
+ result.put(METADATA,
+ new SonarPlugin() {
+ public List<Class> getExtensions() {
+ return Arrays.asList(classes);
+ }
+ }
+ );
+ return result;
+ }
+
+ @Test
+ public void shouldInstallExtensionsWithBatchInstantiationStrategy() {
+ BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+ when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchService.class, ProjectService.class, ServerService.class));
+ ComponentContainer container = new ComponentContainer();
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+ installer.install(container, InstantiationStrategy.BATCH);
+
+ assertThat(container.getComponentByType(BatchService.class)).isNotNull();
+ assertThat(container.getComponentByType(ProjectService.class)).isNull();
+ assertThat(container.getComponentByType(ServerService.class)).isNull();
+ }
+
+ @Test
+ public void shouldInstallProvidersWithBatchInstantiationStrategy() {
+ BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+ when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchServiceProvider.class, ProjectServiceProvider.class));
+ ComponentContainer container = new ComponentContainer();
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+ installer.install(container, InstantiationStrategy.BATCH);
+
+ assertThat(container.getComponentByType(BatchService.class)).isNotNull();
+ assertThat(container.getComponentByType(ProjectService.class)).isNull();
+ assertThat(container.getComponentByType(ServerService.class)).isNull();
+ }
+
+
+ @Test
+ public void shouldNotInstallPluginsOnNonSupportedEnvironment() {
+ BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+ when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(MavenService.class, BuildToolService.class));
+
+ ComponentContainer container = new ComponentContainer();
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+ installer.install(container, InstantiationStrategy.PROJECT);
+
+ assertThat(container.getComponentByType(MavenService.class)).isNull();
+ assertThat(container.getComponentByType(BuildToolService.class)).isNotNull();
+ }
+
+ @InstantiationStrategy(InstantiationStrategy.BATCH)
+ public static class BatchService implements BatchExtension {
+
+ }
+
+ public static class ProjectService implements BatchExtension {
+
+ }
+
+ public static class ServerService implements ServerExtension {
+
+ }
+
+ @InstantiationStrategy(InstantiationStrategy.BATCH)
+ public static class BatchServiceProvider extends ExtensionProvider implements BatchExtension {
+
+ @Override
+ public Object provide() {
+ return Arrays.<Object>asList(BatchService.class, ServerService.class);
+ }
+ }
+
+ public static class ProjectServiceProvider extends ExtensionProvider implements BatchExtension {
+ @Override
+ public Object provide() {
+ return ProjectService.class;
+ }
+ }
+
+ @SupportedEnvironment("maven")
+ public static class MavenService implements BatchExtension {
+
+ }
+
+ @SupportedEnvironment({"maven", "ant", "gradle"})
+ public static class BuildToolService implements BatchExtension {
+
+ }
+
+}
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 a6d34d3a3a5..ef85fb296c4 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
@@ -34,22 +34,22 @@ public class ExtensionUtilsTest {
@Test
public void shouldBeBatchInstantiationStrategy() {
- assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_BATCH), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_BATCH), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_BATCH), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.BATCH), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.BATCH), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.BATCH), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.BATCH), is(false));
}
@Test
public void shouldBeProjectInstantiationStrategy() {
- assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_PROJECT), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_PROJECT), is(false));
- assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_PROJECT), is(true));
- assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PROJECT), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PROJECT), is(false));
+ assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PROJECT), is(true));
+ assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PROJECT), is(true));
}
@Test
@@ -63,11 +63,11 @@ public class ExtensionUtilsTest {
@Test
public void shouldCheckEnvironment() {
- assertThat(ExtensionUtils.isSupportedEnvironment(new MavenService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
- assertThat(ExtensionUtils.isSupportedEnvironment(new BuildToolService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
- assertThat(ExtensionUtils.isSupportedEnvironment(new DefaultService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+ assertThat(ExtensionUtils.supportsEnvironment(new MavenService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+ assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+ assertThat(ExtensionUtils.supportsEnvironment(new DefaultService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
- assertThat(ExtensionUtils.isSupportedEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1")), is(false));
+ assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1")), is(false));
}
@Test
@@ -76,24 +76,24 @@ 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)
+// @Test
+// public void shouldCheckDryRun() {
+// assertThat(ExtensionUtils.supportsDryRun(BatchService.class, true), is(true));
+// assertThat(ExtensionUtils.supportsDryRun(PersistentService.class, true), is(false));
+// }
+//
+// @Test
+// public void shouldNotCheckDryRun() {
+// assertThat(ExtensionUtils.supportsDryRun(BatchService.class, false), is(true));
+// assertThat(ExtensionUtils.supportsDryRun(PersistentService.class, false), is(true));
+// }
+
+ @InstantiationStrategy(InstantiationStrategy.BATCH)
public static class BatchService implements BatchExtension {
}
- @InstantiationStrategy(InstantiationStrategy.PER_PROJECT)
+ @InstantiationStrategy(InstantiationStrategy.PROJECT)
public static class ProjectService implements BatchExtension {
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java
index ae134ec1e95..96250202acc 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java
@@ -1,22 +1,22 @@
/*
- * 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
- */
+* 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.bootstrap;
import org.hamcrest.Matchers;
@@ -34,7 +34,7 @@ public class ModuleTest {
public void shouldInitModule() {
Module module = new FakeModule(FakeService.class).init();
- FakeService service = module.getComponentByType(FakeService.class);
+ FakeService service = module.container.getComponentByType(FakeService.class);
assertThat(service, not(nullValue()));
assertThat(service.started, is(false));
assertThat(module.container, notNullValue());
@@ -45,7 +45,7 @@ public class ModuleTest {
Module module = new FakeModule(FakeService.class).init();
module.start();
- FakeService service = module.getComponentByType(FakeService.class);
+ FakeService service = module.container.getComponentByType(FakeService.class);
assertThat(service.started, is(true));
module.stop();
@@ -69,7 +69,7 @@ public class ModuleTest {
public void componentsShouldBeSingletons() {
Module module = new FakeModule(FakeService.class).init();
- assertThat(module.getComponentByType(FakeService.class) == module.getComponentByType(FakeService.class), is(true));
+ assertThat(module.container.getComponentByType(FakeService.class) == module.container.getComponentByType(FakeService.class), is(true));
}
@Test
@@ -79,16 +79,16 @@ public class ModuleTest {
Module child = parent.installChild(new FakeModule(ChildService.class));
- assertThat(parent.getComponentByType(ChildService.class), Matchers.nullValue());// child not accessible from parent
- assertThat(child.getComponentByType(FakeService.class), not(nullValue()));
- assertThat(child.getComponentByType(ChildService.class).started, is(false));
- assertThat(child.getComponentByType(ChildService.class).dependency, not(nullValue()));
+ assertThat(parent.container.getComponentByType(ChildService.class), Matchers.nullValue());// child not accessible from parent
+ assertThat(child.container.getComponentByType(FakeService.class), not(nullValue()));
+ assertThat(child.container.getComponentByType(ChildService.class).started, is(false));
+ assertThat(child.container.getComponentByType(ChildService.class).dependency, not(nullValue()));
child.start();
- assertThat(child.getComponentByType(ChildService.class).started, is(true));
+ assertThat(child.container.getComponentByType(ChildService.class).started, is(true));
child.stop();
- assertThat(child.getComponentByType(ChildService.class).started, is(false));
+ assertThat(child.container.getComponentByType(ChildService.class).started, is(false));
}
public static class FakeModule extends Module {
@@ -101,7 +101,7 @@ public class ModuleTest {
@Override
protected void configure() {
for (Class component : components) {
- addCoreSingleton(component);
+ container.addSingleton(component);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java
new file mode 100644
index 00000000000..8270a05b211
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.bootstrap;
+
+import org.junit.Test;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+
+public class ProjectExclusionsTest {
+
+ ProjectReactor newReactor(String rootKey, String... moduleKeys) {
+ ProjectDefinition root = ProjectDefinition.create().setKey(rootKey);
+ for (String moduleKey : moduleKeys) {
+ ProjectDefinition module = ProjectDefinition.create().setKey(moduleKey);
+ root.addSubProject(module);
+ }
+ return new ProjectReactor(root);
+ }
+
+ @Test
+ public void testSkippedModules() {
+ Settings settings = new Settings();
+ settings.setProperty("sonar.skippedModules", "sub1,sub3");
+
+ ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+
+ ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+ exclusions.start();
+
+ assertThat(reactor.getProject("root")).isNotNull();
+ assertThat(reactor.getProject("sub1")).isNull();
+ assertThat(reactor.getProject("sub2")).isNotNull();
+ }
+
+ @Test
+ public void testNoSkippedModules() {
+ Settings settings = new Settings();
+ ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+ ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+ exclusions.start();
+
+ assertThat(reactor.getProject("root")).isNotNull();
+ assertThat(reactor.getProject("sub1")).isNotNull();
+ assertThat(reactor.getProject("sub2")).isNotNull();
+ }
+
+ @Test
+ public void testIncludedModules() {
+ Settings settings = new Settings();
+ settings.setProperty("sonar.includedModules", "sub1");
+ ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+ ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+ exclusions.start();
+
+ assertThat(reactor.getProject("root")).isNotNull();
+ assertThat(reactor.getProject("sub1")).isNotNull();
+ assertThat(reactor.getProject("sub2")).isNull();
+ }
+
+ @Test
+ public void shouldBeExcludedIfParentIsExcluded() {
+ ProjectDefinition sub11 = ProjectDefinition.create().setKey("sub11");
+ ProjectDefinition sub1 = ProjectDefinition.create().setKey("sub1").addSubProject(sub11);
+ ProjectDefinition root = ProjectDefinition.create().setKey("root").addSubProject(sub1);
+
+ Settings settings = new Settings();
+ settings.setProperty("sonar.skippedModules", "sub1");
+
+ ProjectReactor reactor = new ProjectReactor(root);
+ ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+ exclusions.start();
+
+
+ assertThat(reactor.getProject("root")).isNotNull();
+ assertThat(reactor.getProject("sub1")).isNull();
+ assertThat(reactor.getProject("sub11")).isNull();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldFailIfExcludingRoot() {
+ Settings settings = new Settings();
+ settings.setProperty("sonar.skippedModules", "sub1,root");
+
+ ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+ ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+ exclusions.start();
+
+ }
+}
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
deleted file mode 100644
index 5690e949b4b..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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.bootstrap;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.Extension;
-import org.sonar.api.Plugin;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.SonarPlugin;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ProjectExtensionInstallerTest {
-
- @Test
- public void shouldBeMavenExtensionOnEmulatedMavenProject() {
- Project mavenProject = new Project("foo").setPom(new MavenProject());
- Project otherProject = new Project("bar");
- assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(MavenService.class, mavenProject), is(false));
- assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(MavenService.class, otherProject), is(true));
-
- // this service is not for Maven only
- assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(BuildToolService.class, mavenProject), is(false));
- assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(BuildToolService.class, otherProject), is(false));
- }
-
- @Test
- public void shouldInstallExtensionsWithProjectInstantiationStrategy() {
- BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- Map<String, Plugin> pluginsMap = Maps.newHashMap();
- pluginsMap.put("fooPlugin", new SonarPlugin() {
- public List<Class<? extends Extension>> getExtensions() {
- return ImmutableList.of(BatchService.class, ProjectService.class, ServerService.class);
- }
- });
- when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
- Module module = new FakeModule().init();
- ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null);
-
- installer.install(module);
-
- assertThat(module.getComponentByType(BatchService.class), nullValue());
- assertThat(module.getComponentByType(ProjectService.class), not(nullValue()));
- assertThat(module.getComponentByType(ServerService.class), nullValue());
- }
-
- @Test
- public void shouldNotInstallPluginsOnNonSupportedEnvironment() {
- BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- Map<String, Plugin> pluginsMap = Maps.newHashMap();
- pluginsMap.put("fooPlugin", new SonarPlugin() {
- public List<Class<? extends BatchExtension>> getExtensions() {
- return ImmutableList.of(MavenService.class, BuildToolService.class);
- }
- });
- when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
- Module module = new FakeModule().init();
- ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null);
-
- installer.install(module);
-
- assertThat(module.getComponentByType(MavenService.class), nullValue());
- assertThat(module.getComponentByType(BuildToolService.class), not(nullValue()));
- }
-
- private static Project newJavaProject() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty("sonar.language", Java.KEY);
- Project project = new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
- return project;
- }
-
- private static Project newGroovyProject() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty("sonar.language", "grvy");
- return new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
- }
-
- @Test
- public void shouldRegisterCustomCoverageExtension() {
- Settings conf = new Settings();
- conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "clover,phpunit");
-
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "cobertura", newJavaProject(), conf), is(true));
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "clover", newJavaProject(), conf), is(false));
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "phpunit", newJavaProject(), conf), is(false));
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "other", newJavaProject(), conf), is(true));
- }
-
- @Test
- public void shouldNotCheckCoverageExtensionsOnNonJavaProjects() {
- Settings conf = new Settings();
- conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "cobertura");
-
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newGroovyProject(), conf), is(false));
- assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newJavaProject(), conf), is(true));
-
- }
-
- @SupportedEnvironment("maven")
- public static class MavenService implements BatchExtension {
-
- }
-
- @SupportedEnvironment({"maven", "ant", "gradle"})
- public static class BuildToolService implements BatchExtension {
-
- }
-
- @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
- public static class BatchService implements BatchExtension {
-
- }
-
- public static class ProjectService implements BatchExtension {
-
- }
-
- public static class ServerService implements ServerExtension {
-
- }
-
- public static class FakeCoverageExtension implements CoverageExtension {
-
- }
-
- public static class FakeModule extends Module {
- @Override
- protected void configure() {
- }
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
deleted file mode 100644
index 3e5cb64429b..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.bootstrap;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
-
-public class ProjectFilterTest {
-
- private Project root = new Project("root");
-
- @Test
- public void testSkippedModules() {
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "foo,bar");
-
- ProjectFilter filter = new ProjectFilter(settings);
- assertTrue(filter.isExcluded(new Project("foo").setParent(root)));
- assertFalse(filter.isExcluded(new Project("other").setParent(root)));
- }
-
- @Test
- public void testNoSkippedModules() {
- Settings settings = new Settings();
- ProjectFilter filter = new ProjectFilter(settings);
-
- assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
- assertFalse(filter.isExcluded(root));
- }
-
- @Test
- public void testIncludedModules() {
- Settings settings = new Settings();
- settings.setProperty("sonar.includedModules", "foo");
- ProjectFilter filter = new ProjectFilter(settings);
-
- assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
- assertTrue(filter.isExcluded(new Project("bar").setParent(root)));
- }
-
- @Test
- public void includingRootShouldBeOptional() {
- Settings settings = new Settings();
- settings.setProperty("sonar.includedModules", "foo,bar");
- ProjectFilter filter = new ProjectFilter(settings);
-
- assertFalse(filter.isExcluded(root));
- }
-
- @Test
- public void shouldBeExcludedIfParentIsExcluded() {
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "parent");
-
- Project parent = new Project("parent").setParent(root);
- Project child = new Project("child").setParent(parent);
-
- ProjectFilter filter = new ProjectFilter(settings);
- assertTrue(filter.isExcluded(parent));
- assertTrue(filter.isExcluded(child));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldFailIfExcludingRoot() {
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "foo,root");
-
- ProjectFilter filter = new ProjectFilter(settings);
-
- filter.isExcluded(root);
- }
-
- @Test
- public void testGetArtifactId() {
- assertThat(ProjectFilter.getArtifactId(new Project("org:foo")), is("foo"));
- assertThat(ProjectFilter.getArtifactId(new Project("foo")), is("foo"));
- assertThat(ProjectFilter.getArtifactId(new Project("org:foo:1.x").setBranch("1.x")), is("foo"));
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java
index f001afb4aa0..1d68dfa3cdc 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java
@@ -28,7 +28,7 @@ import org.sonar.api.config.PropertyDefinitions;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public class BatchSettingsTest {
+public class BootstrapSettingsTest {
@Test
public void shouldLoadBuildModel() {
@@ -37,7 +37,7 @@ public class BatchSettingsTest {
project.setProperty("foo", "bar");
ProjectReactor reactor = new ProjectReactor(project);
- BatchSettings settings = new BatchSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
+ BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
assertThat(settings.getString("foo"), is("bar"));
}
@@ -45,13 +45,13 @@ public class BatchSettingsTest {
@Test
public void environmentShouldOverrideBuildModel() {
ProjectDefinition project = ProjectDefinition.create();
- project.setProperty("BatchSettingsTest.testEnv", "build");
- System.setProperty("BatchSettingsTest.testEnv", "env");
+ project.setProperty("BootstrapSettingsTest.testEnv", "build");
+ System.setProperty("BootstrapSettingsTest.testEnv", "env");
ProjectReactor reactor = new ProjectReactor(project);
- BatchSettings settings = new BatchSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
+ BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
- assertThat(settings.getString("BatchSettingsTest.testEnv"), is("env"));
+ assertThat(settings.getString("BootstrapSettingsTest.testEnv"), is("env"));
}
@Test
@@ -61,7 +61,7 @@ public class BatchSettingsTest {
ProjectReactor reactor = new ProjectReactor(project);
BaseConfiguration deprecatedConfiguration = new BaseConfiguration();
- new BatchSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
+ new BootstrapSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
assertThat(deprecatedConfiguration.getString("foo"), is("bar"));
}
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 3d67d1a985b..0e4d0157a7a 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,11 +28,7 @@ public class PhasesTest {
@Test
public void shouldDefinePhaseClasses() {
- assertThat(Phases.getPhaseClasses(false).size(), greaterThan(4));
+ assertThat(Phases.getPhaseClasses().size(), greaterThan(4));
}
- @Test
- public void someComponentsShouldBeDisabledOnDryRun() {
- assertThat(Phases.getPhaseClasses(false).size(), greaterThan(Phases.getPhaseClasses(true).size()));
- }
}