aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-10-05 00:44:37 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-10-07 13:36:25 +0200
commitef5bf7fdece84e5a52c8d478c8a733ecdf4d57f1 (patch)
treec64a8a041183379e92fbc81becc77af07c9b38e3 /sonar-batch
parent3174a29201e922db758b51f4b693ca131e7037ec (diff)
downloadsonarqube-ef5bf7fdece84e5a52c8d478c8a733ecdf4d57f1.tar.gz
sonarqube-ef5bf7fdece84e5a52c8d478c8a733ecdf4d57f1.zip
SONAR-2861 New Configuration API
The component org.apache.commons.Configuration is still available but plugins should use org.sonar.api.config.Settings. It also implies the following issues : SONAR-2870 do not rebuild the WAR file when editing sonar.properties SONAR-2869 allow to use the annotations @Properties/@Property on extensions
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/Batch.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java98
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java19
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java18
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java65
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java62
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java22
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java67
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java67
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java80
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java60
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java58
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/DeprecatedConfigurationProvider.java33
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java86
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java87
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java47
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java47
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java18
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java23
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java10
25 files changed, 634 insertions, 388 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/Batch.java
index 2461b865064..70c92d06097 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/Batch.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/Batch.java
@@ -30,11 +30,11 @@ public final class Batch {
private Module bootstrapModule;
/**
- * @deprecated since 2.9. Replaced by the factory method.
+ * @deprecated since 2.9. Replaced by the factory method. Use by Ant Task 1.1
*/
@Deprecated
public Batch(Configuration configuration, Object... bootstrapperComponents) {
- this.bootstrapModule = new BootstrapModule(extractProjectReactor(bootstrapperComponents), configuration, bootstrapperComponents).init();
+ this.bootstrapModule = new BootstrapModule(extractProjectReactor(bootstrapperComponents), bootstrapperComponents).init();
}
static ProjectReactor extractProjectReactor(Object[] components) {
@@ -54,12 +54,12 @@ public final class Batch {
return deprecatedReactor.toProjectReactor();
}
- private Batch(ProjectReactor reactor, Configuration configuration, Object... bootstrapperComponents) {
- this.bootstrapModule = new BootstrapModule(reactor, configuration, bootstrapperComponents).init();
+ private Batch(ProjectReactor reactor, Object... bootstrapperComponents) {
+ this.bootstrapModule = new BootstrapModule(reactor, bootstrapperComponents).init();
}
public static Batch create(ProjectReactor projectReactor, Configuration configuration, Object... bootstrapperComponents) {
- return new Batch(projectReactor, configuration, bootstrapperComponents);
+ return new Batch(projectReactor, bootstrapperComponents);
}
/**
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
index 6659aa5618f..ed9db7d9e05 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
@@ -19,38 +19,38 @@
*/
package org.sonar.batch;
-import org.apache.commons.configuration.*;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DateUtils;
import org.apache.maven.project.MavenProject;
+import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
-import org.sonar.api.utils.SonarException;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
-public class ProjectConfigurator {
+public class ProjectConfigurator implements BatchComponent {
private DatabaseSession databaseSession;
+ private Settings settings;
- public ProjectConfigurator(DatabaseSession databaseSession) {
+ public ProjectConfigurator(DatabaseSession databaseSession, Settings settings) {
this.databaseSession = databaseSession;
+ this.settings = settings;
}
public Project create(ProjectDefinition definition) {
- Configuration configuration = getStartupConfiguration(definition);
- Project project = new Project(definition.getKey(), loadProjectBranch(configuration), definition.getName())
- .setDescription(StringUtils.defaultString(definition.getDescription(), ""))
- .setPackaging("jar");
+ Project project = new Project(definition.getKey(), loadProjectBranch(), definition.getName());
+
// For backward compatibility we must set POM and actual packaging
+ project.setDescription(StringUtils.defaultString(definition.getDescription()));
+ project.setPackaging("jar");
+
for (Object component : definition.getContainerExtensions()) {
if (component instanceof MavenProject) {
MavenProject pom = (MavenProject) component;
@@ -61,39 +61,25 @@ public class ProjectConfigurator {
return project;
}
- Configuration getStartupConfiguration(ProjectDefinition project) {
- CompositeConfiguration configuration = new CompositeConfiguration();
- configuration.addConfiguration(new SystemConfiguration());
- configuration.addConfiguration(new EnvironmentConfiguration());
- configuration.addConfiguration(new MapConfiguration(project.getProperties()));
- return configuration;
- }
-
- String loadProjectBranch(Configuration configuration) {
- return configuration.getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
- }
-
- public void configure(Project project, ProjectDefinition def) {
- ProjectConfiguration projectConfiguration = new ProjectConfiguration(databaseSession, def);
- configure(project, projectConfiguration);
+ String loadProjectBranch() {
+ return settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
}
- void configure(Project project, Configuration projectConfiguration) {
- Date analysisDate = loadAnalysisDate(projectConfiguration);
- project.setConfiguration(projectConfiguration)
- .setExclusionPatterns(loadExclusionPatterns(projectConfiguration))
+ public ProjectConfigurator configure(Project project) {
+ Date analysisDate = loadAnalysisDate();
+ project
+ .setConfiguration(new PropertiesConfiguration()) // will be populated by ProjectSettings
+ .setExclusionPatterns(loadExclusionPatterns())
.setAnalysisDate(analysisDate)
.setLatestAnalysis(isLatestAnalysis(project.getKey(), analysisDate))
- .setAnalysisVersion(loadAnalysisVersion(projectConfiguration))
- .setAnalysisType(loadAnalysisType(projectConfiguration))
- .setLanguageKey(loadLanguageKey(projectConfiguration));
+ .setAnalysisVersion(loadAnalysisVersion())
+ .setAnalysisType(loadAnalysisType())
+ .setLanguageKey(loadLanguageKey());
+ return this;
}
- static String[] loadExclusionPatterns(Configuration configuration) {
- String[] exclusionPatterns = configuration.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
- if (exclusionPatterns == null) {
- exclusionPatterns = new String[0];
- }
+ String[] loadExclusionPatterns() {
+ String[] exclusionPatterns = settings.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
for (int i = 0; i < exclusionPatterns.length; i++) {
exclusionPatterns[i] = StringUtils.trim(exclusionPatterns[i]);
}
@@ -109,28 +95,18 @@ public class ProjectConfigurator {
return true;
}
- Date loadAnalysisDate(Configuration configuration) {
- String formattedDate = configuration.getString(CoreProperties.PROJECT_DATE_PROPERTY);
- if (formattedDate == null) {
- return new Date();
- }
-
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- try {
- // see SONAR-908 make sure that a time is defined for the date.
- Date date = DateUtils.setHours(format.parse(formattedDate), 0);
- return DateUtils.setMinutes(date, 1);
-
- } catch (ParseException e) {
- throw new SonarException("The property " + CoreProperties.PROJECT_DATE_PROPERTY
- + " does not respect the format yyyy-MM-dd (for example 2008-05-23) : " + formattedDate, e);
+ Date loadAnalysisDate() {
+ Date date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY);
+ if (date == null) {
+ date = new Date();
}
+ return date;
}
- Project.AnalysisType loadAnalysisType(Configuration configuration) {
- String value = configuration.getString(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY);
+ Project.AnalysisType loadAnalysisType() {
+ String value = settings.getString(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY);
if (value == null) {
- return (configuration.getBoolean("sonar.light", false) ? Project.AnalysisType.STATIC : Project.AnalysisType.DYNAMIC);
+ return ("true".equals(settings.getString("sonar.light")) ? Project.AnalysisType.STATIC : Project.AnalysisType.DYNAMIC);
}
if ("true".equals(value)) {
return Project.AnalysisType.DYNAMIC;
@@ -141,11 +117,11 @@ public class ProjectConfigurator {
return Project.AnalysisType.STATIC;
}
- String loadAnalysisVersion(Configuration configuration) {
- return configuration.getString(CoreProperties.PROJECT_VERSION_PROPERTY);
+ String loadAnalysisVersion() {
+ return settings.getString(CoreProperties.PROJECT_VERSION_PROPERTY);
}
- String loadLanguageKey(Configuration configuration) {
- return configuration.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY, Java.KEY);
+ String loadLanguageKey() {
+ return StringUtils.defaultIfBlank(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY), Java.KEY);
}
}
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 10548b7169e..7d9524ca93b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
@@ -21,13 +21,13 @@ package org.sonar.batch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
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.database.DatabaseSession;
import org.sonar.api.resources.Project;
import java.io.IOException;
@@ -42,14 +42,15 @@ public class ProjectTree {
private Map<ProjectDefinition, Project> projectsByDef;
public ProjectTree(ProjectReactor projectReactor, //NOSONAR the unused parameter 'builders' is used for the startup order of components
- DatabaseSession databaseSession,
+ ProjectConfigurator projectConfigurator,
/* Must be executed after ProjectBuilders */ ProjectBuilder[] builders) {
- this(projectReactor, databaseSession);
+ this(projectReactor, projectConfigurator);
}
- public ProjectTree(ProjectReactor projectReactor, DatabaseSession databaseSession) {
- configurator = new ProjectConfigurator(databaseSession);
+ public ProjectTree(ProjectReactor projectReactor, //NOSONAR the unused parameter 'builders' is used for the startup order of components
+ ProjectConfigurator projectConfigurator) {
this.projectReactor = projectReactor;
+ this.configurator = projectConfigurator;
}
ProjectTree(ProjectConfigurator configurator) {
@@ -79,8 +80,8 @@ public class ProjectTree {
}
// Configure
- for (Map.Entry<ProjectDefinition, Project> entry : projectsByDef.entrySet()) {
- configurator.configure(entry.getValue(), entry.getKey());
+ for (Project project : projects) {
+ configurator.configure(project);
}
applyExclusions();
@@ -91,8 +92,8 @@ public class ProjectTree {
String[] excludedArtifactIds = project.getConfiguration().getStringArray("sonar.skippedModules");
String[] includedArtifactIds = project.getConfiguration().getStringArray("sonar.includedModules");
- Set<String> includedModulesIdSet = new HashSet<String>();
- Set<String> excludedModulesIdSet = new HashSet<String>();
+ Set<String> includedModulesIdSet = Sets.newHashSet();
+ Set<String> excludedModulesIdSet = Sets.newHashSet();
if (includedArtifactIds != null) {
includedModulesIdSet.addAll(Arrays.asList(includedArtifactIds));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java
index 97dae9df62f..fcd0951dd52 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java
@@ -19,10 +19,10 @@
*/
package org.sonar.batch;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
import java.text.ParseException;
@@ -31,22 +31,22 @@ import java.util.Date;
public class ServerMetadata extends Server {
- private Configuration conf;
+ private Settings settings;
- public ServerMetadata(Configuration conf) {
- this.conf = conf;
+ public ServerMetadata(Settings settings) {
+ this.settings = settings;
}
public String getId() {
- return conf.getString(CoreProperties.SERVER_ID);
+ return settings.getString(CoreProperties.SERVER_ID);
}
public String getVersion() {
- return conf.getString(CoreProperties.SERVER_VERSION);
+ return settings.getString(CoreProperties.SERVER_VERSION);
}
public Date getStartedAt() {
- String dateString = conf.getString(CoreProperties.SERVER_STARTTIME);
+ String dateString = settings.getString(CoreProperties.SERVER_STARTTIME);
if (dateString != null) {
try {
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(dateString);
@@ -59,11 +59,11 @@ public class ServerMetadata extends Server {
}
public String getURL() {
- return StringUtils.removeEnd(conf.getString("sonar.host.url", "http://localhost:9000"), "/");
+ return StringUtils.removeEnd(StringUtils.defaultIfBlank(settings.getString("sonar.host.url"), "http://localhost:9000"), "/");
}
@Override
public String getPermanentServerId() {
- return conf.getString(CoreProperties.PERMANENT_SERVER_ID);
+ return settings.getString(CoreProperties.PERMANENT_SERVER_ID);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
index 75dec73bac8..4a690ac1a45 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
@@ -19,16 +19,20 @@
*/
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.List;
+import java.util.Map;
public final class BatchExtensionInstaller implements BatchComponent {
@@ -43,40 +47,63 @@ public final class BatchExtensionInstaller implements BatchComponent {
}
public void install(Module module) {
- for (Plugin plugin : pluginRepository.getPlugins()) {
+ 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()) {
- installExtension(module, extension);
+ 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);
}
}
- installExtensionProviders(module);
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.addComponent(metric.getKey(), metric);
+ module.addCoreSingleton(metric);
}
}
}
- void installExtensionProviders(Module module) {
- List<ExtensionProvider> providers = module.getComponents(ExtensionProvider.class);
- for (ExtensionProvider provider : providers) {
- Object obj = provider.provide();
- if (obj != null) {
- if (obj instanceof Iterable) {
- for (Object extension : (Iterable) obj) {
- installExtension(module, extension);
- }
- } else {
- installExtension(module, obj);
+ 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);
}
}
}
- void installExtension(Module module, Object extension) {
+ boolean installExtension(Module module, PluginMetadata plugin, Object extension) {
if (ExtensionUtils.isBatchExtension(extension) &&
ExtensionUtils.isSupportedEnvironment(extension, environment) &&
ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
@@ -84,7 +111,9 @@ public final class BatchExtensionInstaller implements BatchComponent {
if (ExtensionUtils.isType(extension, CoverageExtension.class)) {
throw new IllegalArgumentException("Instantiation strategy " + InstantiationStrategy.PER_BATCH + " is not supported on CoverageExtension components: " + extension);
}
- module.addComponent(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 3134c5ec39f..822d6ca7a8d 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
@@ -25,7 +25,7 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.ServerHttpClient;
import org.sonar.batch.DefaultResourceCreationLock;
-import org.sonar.batch.ProjectConfiguration;
+import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.components.*;
import org.sonar.batch.index.*;
@@ -48,55 +48,55 @@ public class BatchModule extends Module {
@Override
protected void configure() {
- addComponent(ProjectConfiguration.class);
- addComponent(ProjectTree.class);
- addComponent(DefaultResourceCreationLock.class);
- addComponent(DefaultIndex.class);
+ addCoreSingleton(ProjectTree.class);
+ addCoreSingleton(ProjectConfigurator.class);
+ addCoreSingleton(DefaultResourceCreationLock.class);
+ addCoreSingleton(DefaultIndex.class);
if (dryRun) {
- addComponent(ReadOnlyPersistenceManager.class);
+ addCoreSingleton(ReadOnlyPersistenceManager.class);
} else {
- addComponent(DefaultPersistenceManager.class);
- addComponent(DependencyPersister.class);
- addComponent(EventPersister.class);
- addComponent(LinkPersister.class);
- addComponent(MeasurePersister.class);
- addComponent(MemoryOptimizer.class);
- addComponent(DefaultResourcePersister.class);
- addComponent(SourcePersister.class);
+ addCoreSingleton(DefaultPersistenceManager.class);
+ addCoreSingleton(DependencyPersister.class);
+ addCoreSingleton(EventPersister.class);
+ addCoreSingleton(LinkPersister.class);
+ addCoreSingleton(MeasurePersister.class);
+ addCoreSingleton(MemoryOptimizer.class);
+ addCoreSingleton(DefaultResourcePersister.class);
+ addCoreSingleton(SourcePersister.class);
}
- addComponent(Plugins.class);
- addComponent(ServerHttpClient.class);
- addComponent(MeasuresDao.class);
- addComponent(CacheRuleFinder.class);
- addComponent(CacheMetricFinder.class);
- addComponent(PastSnapshotFinderByDate.class);
- addComponent(PastSnapshotFinderByDays.class);
- addComponent(PastSnapshotFinderByPreviousAnalysis.class);
- addComponent(PastSnapshotFinderByVersion.class);
- addComponent(PastMeasuresLoader.class);
- addComponent(PastSnapshotFinder.class);
- addComponent(DefaultNotificationManager.class);
- addComponent(DefaultUserFinder.class);
+ addCoreSingleton(Plugins.class);
+ addCoreSingleton(ServerHttpClient.class);
+ addCoreSingleton(MeasuresDao.class);
+ addCoreSingleton(CacheRuleFinder.class);
+ addCoreSingleton(CacheMetricFinder.class);
+ addCoreSingleton(PastSnapshotFinderByDate.class);
+ addCoreSingleton(PastSnapshotFinderByDays.class);
+ addCoreSingleton(PastSnapshotFinderByPreviousAnalysis.class);
+ addCoreSingleton(PastSnapshotFinderByVersion.class);
+ addCoreSingleton(PastMeasuresLoader.class);
+ addCoreSingleton(PastSnapshotFinder.class);
+ addCoreSingleton(DefaultNotificationManager.class);
+ addCoreSingleton(DefaultUserFinder.class);
addCoreMetrics();
addBatchExtensions();
}
private void addBatchExtensions() {
- BatchExtensionInstaller installer = getComponent(BatchExtensionInstaller.class);
+ BatchExtensionInstaller installer = getComponentByType(BatchExtensionInstaller.class);
installer.install(this);
}
void addCoreMetrics() {
for (Metric metric : CoreMetrics.getMetrics()) {
- addComponent(metric.getKey(), metric);
+ addCoreSingleton(metric);
}
}
@Override
protected void doStart() {
- ProjectTree projectTree = getComponent(ProjectTree.class);
+ ProjectTree projectTree = getComponentByType(ProjectTree.class);
analyze(projectTree.getRootProject());
}
@@ -110,7 +110,7 @@ public class BatchModule extends Module {
projectComponents.start();
} finally {
projectComponents.stop();
- uninstallChild(projectComponents);
+ uninstallChild();
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
index 249c94b79b7..27061aadc67 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
@@ -22,7 +22,6 @@ package org.sonar.batch.bootstrap;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,6 +29,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.Plugin;
import org.sonar.api.Properties;
import org.sonar.api.Property;
+import org.sonar.api.config.Settings;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.core.plugins.PluginClassloaders;
@@ -51,14 +51,14 @@ public class BatchPluginRepository implements PluginRepository {
private Set<String> blackList = null;
private PluginClassloaders classLoaders;
- public BatchPluginRepository(ArtifactDownloader artifactDownloader, Configuration configuration) {
+ public BatchPluginRepository(ArtifactDownloader artifactDownloader, Settings settings) {
this.artifactDownloader = artifactDownloader;
- if (configuration.getString(CoreProperties.BATCH_INCLUDE_PLUGINS) != null) {
- whiteList = Sets.newTreeSet(Arrays.asList(configuration.getStringArray(CoreProperties.BATCH_INCLUDE_PLUGINS)));
+ if (settings.hasKey(CoreProperties.BATCH_INCLUDE_PLUGINS)) {
+ whiteList = Sets.newTreeSet(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_INCLUDE_PLUGINS)));
LOG.info("Include plugins: " + Joiner.on(", ").join(whiteList));
}
- if (configuration.getString(CoreProperties.BATCH_EXCLUDE_PLUGINS) != null) {
- blackList = Sets.newTreeSet(Arrays.asList(configuration.getStringArray(CoreProperties.BATCH_EXCLUDE_PLUGINS)));
+ if (settings.hasKey(CoreProperties.BATCH_EXCLUDE_PLUGINS)) {
+ blackList = Sets.newTreeSet(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_EXCLUDE_PLUGINS)));
LOG.info("Exclude plugins: " + Joiner.on(", ").join(blackList));
}
// TODO reactivate somewhere else: LOG.info("Execution environment: {} {}", environment.getKey(), environment.getVersion());
@@ -133,4 +133,14 @@ public class BatchPluginRepository implements PluginRepository {
}
return blackList == null || !blackList.contains(pluginKey);
}
+
+ public Map<PluginMetadata,Plugin> getPluginsByMetadata() {
+ Map<PluginMetadata, Plugin> result = Maps.newHashMap();
+ for (Map.Entry<String, PluginMetadata> entry : metadataByKey.entrySet()) {
+ String pluginKey = entry.getKey();
+ PluginMetadata metadata = entry.getValue();
+ result.put(metadata, pluginsByKey.get(pluginKey));
+ }
+ return result;
+ }
}
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 2c925b71674..ce6985b8c2e 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
@@ -19,13 +19,15 @@
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.Plugin;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.FakeMavenPluginExecutor;
import org.sonar.batch.MavenPluginExecutor;
import org.sonar.batch.ServerMetadata;
+import org.sonar.batch.config.BatchSettings;
+import org.sonar.batch.config.BatchSettingsEnhancer;
import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DriverDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
@@ -37,52 +39,52 @@ import java.net.URLClassLoader;
*/
public class BootstrapModule extends Module {
- private Configuration configuration;
private Object[] boostrapperComponents;
private ProjectReactor reactor;
- public BootstrapModule(ProjectReactor reactor, Configuration configuration, Object... boostrapperComponents) {
+ public BootstrapModule(ProjectReactor reactor, Object... boostrapperComponents) {
this.reactor = reactor;
- this.configuration = configuration;
this.boostrapperComponents = boostrapperComponents;
}
@Override
protected void configure() {
- addComponent(reactor);
- addComponent(configuration);// this configuration does not access database
- addComponent(DryRun.class);
- addComponent(ServerMetadata.class);// registered here because used by BootstrapClassLoader
- addComponent(TempDirectories.class);// registered here because used by BootstrapClassLoader
- addComponent(HttpDownloader.class);// registered here because used by BootstrapClassLoader
- addComponent(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
- addComponent(JdbcDriverHolder.class);
+ addCoreSingleton(reactor);
+ addCoreSingleton(new PropertiesConfiguration());
+ addCoreSingleton(BatchSettings.class);
+ addCoreSingleton(DryRun.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(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
+ addCoreSingleton(JdbcDriverHolder.class);
- URLClassLoader bootstrapClassLoader = getComponent(JdbcDriverHolder.class).getClassLoader();
+ 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);
- addComponent(new DriverDatabaseConnector(configuration, bootstrapClassLoader));
- addComponent(ThreadLocalDatabaseSessionFactory.class);
+ addCoreSingleton(new DriverDatabaseConnector(getComponentByType(Settings.class), bootstrapClassLoader));
+ addCoreSingleton(ThreadLocalDatabaseSessionFactory.class);
addAdapter(new DatabaseSessionProvider());
for (Object component : boostrapperComponents) {
- addComponent(component);
+ addCoreSingleton(component);
}
if (!isMavenPluginExecutorRegistered()) {
- addComponent(FakeMavenPluginExecutor.class);
+ addCoreSingleton(FakeMavenPluginExecutor.class);
}
- // LIMITATION : list of plugins to download is currently loaded from database. It should be loaded from
- // remote HTTP index.
- addComponent(BatchPluginRepository.class);
- addComponent(BatchExtensionInstaller.class);
- addComponent(ProjectExtensionInstaller.class);
+ addCoreSingleton(BatchPluginRepository.class);
+ addCoreSingleton(BatchExtensionInstaller.class);
+ addCoreSingleton(ProjectExtensionInstaller.class);
+ addCoreSingleton(BatchSettingsEnhancer.class);
}
boolean isMavenPluginExecutorRegistered() {
- for (Object component : boostrapperComponents) {
- if (component instanceof Class && MavenPluginExecutor.class.isAssignableFrom((Class<?>) component)) {
- return true;
+ if (boostrapperComponents != null) {
+ for (Object component : boostrapperComponents) {
+ if (component instanceof Class && MavenPluginExecutor.class.isAssignableFrom((Class<?>) component)) {
+ return true;
+ }
}
}
return false;
@@ -90,19 +92,8 @@ public class BootstrapModule extends Module {
@Override
protected void doStart() {
- addPlugins();
- boolean dryRun = getComponent(DryRun.class).isEnabled();
+ boolean dryRun = getComponentByType(DryRun.class).isEnabled();
Module batchComponents = installChild(new BatchModule(dryRun));
batchComponents.start();
}
-
- private void addPlugins() {
- // Plugins have been loaded during the startup of BatchPluginRepository.
- // In a perfect world BatchPluginRepository should be a factory which injects new components into container, but
- // (it seems that) this feature does not exist in PicoContainer.
- // Limitation: the methods start() and stop() are not called on org.sonar.api.Plugin instances.
- for (Plugin plugin : getComponent(BatchPluginRepository.class).getPlugins()) {
- addComponent(plugin);
- }
- }
}
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 c269fc6b126..c3a96ab63de 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,14 +19,17 @@
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.Configuration;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.Property;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.Logs;
-public class DryRun {
+@Property(key="sonar.dryRun", defaultValue = "false", name="Dry Run")
+public class DryRun implements BatchComponent {
private boolean enabled;
- public DryRun(Configuration conf) {
- enabled = conf.getBoolean("sonar.dryRun", Boolean.FALSE);
+ public DryRun(Settings settings) {
+ enabled = settings.getBoolean("sonar.dryRun");
if (enabled) {
Logs.INFO.info("Dry run");
}
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 df9991e89a5..bba921ab6de 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
@@ -19,10 +19,9 @@
*/
package org.sonar.batch.bootstrap;
-import org.picocontainer.Characteristics;
import org.picocontainer.ComponentAdapter;
-import org.picocontainer.MutablePicoContainer;
-import org.sonar.api.utils.IocContainer;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
import java.util.List;
@@ -33,20 +32,19 @@ import java.util.List;
*/
public abstract class Module {
- private MutablePicoContainer container;
-
+ ComponentContainer container;
/**
* @return this
*/
public final Module init() {
- return init(IocContainer.buildPicoContainer());
+ return init(new ComponentContainer());
}
/**
* @return this
*/
- private Module init(MutablePicoContainer container) {
+ private Module init(ComponentContainer container) {
this.container = container;
configure();
return this;
@@ -68,24 +66,23 @@ public abstract class Module {
* @return installed module
*/
public final Module installChild(Module child) {
- MutablePicoContainer childContainer = container.makeChildContainer();
+ ComponentContainer childContainer = container.createChild();
// register container as a component, because it used for example in BatchExtensionDictionnary,
// but in fact this is anti-pattern - http://picocontainer.codehaus.org/container-dependency-antipattern.html
- childContainer.addComponent(new IocContainer(childContainer));
- childContainer.setName(child.toString());
+ //childContainer.addComponent(new IocContainer(childContainer));
child.init(childContainer);
return child;
}
- public final void uninstallChild(Module child) {
- container.removeChildContainer(child.container);
+ public final void uninstallChild() {
+ container.removeChild();
}
/**
* @return this
*/
public final Module start() {
- container.start();
+ container.startComponents();
doStart();
return this;
}
@@ -100,7 +97,7 @@ public abstract class Module {
public final Module stop() {
try {
doStop();
- container.stop();
+ container.stopComponents();
} catch (Exception e) {
// ignore
}
@@ -113,39 +110,43 @@ public abstract class Module {
/**
* Implementation of this method must not contain conditional logic and just should contain several invocations of
- * {@link #addComponent(Object)}, {@link #addComponent(Object, Object)} or {@link #addAdapter(ComponentAdapter)}.
+ * {@link #addCoreSingleton(Object)}, {@link #addComponent(Object, Object)} or {@link #addAdapter(ComponentAdapter)}.
*/
protected abstract void configure();
- protected final void addComponent(Object component) {
- if (component instanceof Class) {
- container.as(Characteristics.CACHE).addComponent(component);
- } else {
- container.as(Characteristics.CACHE).addComponent(component.getClass().getCanonicalName() + "-" + component.toString(), component);
- }
+ protected final void addCoreSingleton(Object component) {
+ container.addSingleton(component);
}
- protected final void addComponent(Object componentKey, Object component) {
- container.as(Characteristics.CACHE).addComponent(componentKey, 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.addAdapter(componentAdapter);
+ container.addPicoAdapter(componentAdapter);
}
- public final <T> T getComponent(Class<T> componentType) {
- return container.getComponent(componentType);
+ public final <T> T getComponentByType(Class<T> componentType) {
+ return container.getComponentByType(componentType);
}
- public final <T> List<T> getComponents(Class<T> componentType) {
- return container.getComponents(componentType);
+ public final Object getComponentByKey(Object key) {
+ return container.getComponentByKey(key);
}
- /**
- * TODO should not be used and should be removed
- */
- public final MutablePicoContainer getContainer() {
- return container;
+ public final <T> List<T> getComponents(Class<T> componentType) {
+ return container.getComponentsByType(componentType);
}
+// /**
+// * TODO should not be used and should be removed
+// */
+// public final MutablePicoContainer getContainer() {
+// return container;
+// }
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
index 0ec164f7ca4..145d971387e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
@@ -77,7 +77,7 @@ public final class ProjectExtensionInstaller implements BatchComponent {
ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
!isDeactivatedCoverageExtension(extension, project, pluginKey) &&
!isMavenExtensionOnEmulatedMavenProject(extension, project)) {
- module.addComponent(extension);
+ module.addCoreSingleton(extension);
return extension;
}
return null;
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 c54b8d6d126..5381fc093ed 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
@@ -29,16 +29,21 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.rules.DefaultRulesManager;
+import org.sonar.api.utils.IocContainer;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.*;
import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.config.DeprecatedConfigurationProvider;
+import org.sonar.batch.config.ProjectSettings;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.batch.phases.Phases;
import org.sonar.batch.phases.PhasesTimeProfiler;
import org.sonar.core.components.DefaultModelFinder;
-import org.sonar.jpa.dao.*;
+import org.sonar.jpa.dao.DaoFacade;
+import org.sonar.jpa.dao.ProfilesDao;
+import org.sonar.jpa.dao.RulesDao;
import java.util.Arrays;
@@ -62,49 +67,52 @@ public class ProjectModule extends Module {
private void addProjectComponents() {
- ProjectDefinition projectDefinition = getComponent(ProjectTree.class).getProjectDefinition(project);
- addComponent(projectDefinition);
+ ProjectDefinition projectDefinition = getComponentByType(ProjectTree.class).getProjectDefinition(project);
+ addCoreSingleton(projectDefinition);
+ addCoreSingleton(project);
+ addCoreSingleton(project.getConfiguration());
+ addCoreSingleton(ProjectSettings.class);
+ addAdapter(new DeprecatedConfigurationProvider());
+ addCoreSingleton(IocContainer.class);
+
for (Object component : projectDefinition.getContainerExtensions()) {
- addComponent(component);
+ addCoreSingleton(component);
}
-
- addComponent(project);
- addComponent(project.getConfiguration());
- addComponent(DefaultProjectClasspath.class);
- addComponent(DefaultProjectFileSystem2.class);
- addComponent(DaoFacade.class);
- addComponent(RulesDao.class);
+ addCoreSingleton(DefaultProjectClasspath.class);
+ addCoreSingleton(DefaultProjectFileSystem2.class);
+ addCoreSingleton(DaoFacade.class);
+ addCoreSingleton(RulesDao.class);
if (!dryRun) {
// the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
- addComponent(getComponent(DefaultResourcePersister.class).getSnapshot(project));
+ addCoreSingleton(getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
}
- addComponent(TimeMachineConfiguration.class);
- addComponent(org.sonar.api.database.daos.MeasuresDao.class);
- addComponent(ProfilesDao.class);
- addComponent(DefaultRulesManager.class);
- addComponent(DefaultSensorContext.class);
- addComponent(Languages.class);
- addComponent(BatchExtensionDictionnary.class);
- addComponent(DefaultTimeMachine.class);
- addComponent(ViolationFilters.class);
- addComponent(ResourceFilters.class);
- addComponent(DefaultModelFinder.class);
- addComponent(ProfileLoader.class, DefaultProfileLoader.class);
+ addCoreSingleton(TimeMachineConfiguration.class);
+ addCoreSingleton(org.sonar.api.database.daos.MeasuresDao.class);
+ addCoreSingleton(ProfilesDao.class);
+ addCoreSingleton(DefaultRulesManager.class);
+ addCoreSingleton(DefaultSensorContext.class);
+ addCoreSingleton(Languages.class);
+ addCoreSingleton(BatchExtensionDictionnary.class);
+ addCoreSingleton(DefaultTimeMachine.class);
+ addCoreSingleton(ViolationFilters.class);
+ addCoreSingleton(ResourceFilters.class);
+ addCoreSingleton(DefaultModelFinder.class);
+ addCoreSingleton(DefaultProfileLoader.class);
addAdapter(new ProfileProvider());
}
private void addCoreComponents() {
- addComponent(EventBus.class);
- addComponent(Phases.class);
- addComponent(PhasesTimeProfiler.class);
+ addCoreSingleton(EventBus.class);
+ addCoreSingleton(Phases.class);
+ addCoreSingleton(PhasesTimeProfiler.class);
for (Class clazz : Phases.getPhaseClasses(dryRun)) {
- addComponent(clazz);
+ addCoreSingleton(clazz);
}
}
private void addProjectPluginExtensions() {
- ProjectExtensionInstaller installer = getComponent(ProjectExtensionInstaller.class);
+ ProjectExtensionInstaller installer = getComponentByType(ProjectExtensionInstaller.class);
installer.install(this, project);
}
@@ -124,22 +132,22 @@ public class ProjectModule extends Module {
*/
@Override
protected void doStart() {
- Language language = getComponent(Languages.class).get(project.getLanguageKey());
+ Language language = getComponentByType(Languages.class).get(project.getLanguageKey());
if (language == null) {
throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found");
}
project.setLanguage(language);
- DefaultIndex index = getComponent(DefaultIndex.class);
+ DefaultIndex index = getComponentByType(DefaultIndex.class);
index.setCurrentProject(project,
- getComponent(ResourceFilters.class),
- getComponent(ViolationFilters.class),
- getComponent(RulesProfile.class));
+ getComponentByType(ResourceFilters.class),
+ getComponentByType(ViolationFilters.class),
+ getComponentByType(RulesProfile.class));
// TODO See http://jira.codehaus.org/browse/SONAR-2126
// previously MavenProjectBuilder was responsible for creation of ProjectFileSystem
- project.setFileSystem(getComponent(ProjectFileSystem.class));
+ project.setFileSystem(getComponentByType(ProjectFileSystem.class));
- getComponent(Phases.class).execute(project);
+ getComponentByType(Phases.class).execute(project);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java
new file mode 100644
index 00000000000..9c86975cc77
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java
@@ -0,0 +1,60 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.config;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.core.config.ConfigurationUtils;
+
+import java.util.Map;
+
+/**
+ * @since 2.12
+ */
+public final class BatchSettings extends Settings {
+ private Configuration deprecatedConfiguration;
+ private ProjectReactor reactor;
+
+ public BatchSettings(PropertyDefinitions propertyDefinitions, ProjectReactor reactor, Configuration deprecatedConfiguration) {
+ super(propertyDefinitions);
+ this.reactor = reactor;
+ this.deprecatedConfiguration = deprecatedConfiguration;
+ load();
+ }
+
+ public BatchSettings load() {
+ clear();
+
+ // order is important -> bottom-up. The last one overrides all the others.
+ addProperties(reactor.getRoot().getProperties());
+ addEnvironmentVariables();
+ addSystemProperties();
+
+ updateDeprecatedCommonsConfiguration();
+
+ return this;
+ }
+
+ public void updateDeprecatedCommonsConfiguration() {
+ ConfigurationUtils.copyToCommonsConfiguration(properties, deprecatedConfiguration);
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java
new file mode 100644
index 00000000000..a770fa64adf
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.config;
+
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.database.configuration.Property;
+import org.sonar.core.config.ConfigurationUtils;
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+import java.util.List;
+
+/**
+ * @since 2.12
+ */
+public final class BatchSettingsEnhancer {
+
+ private DatabaseSessionFactory dbFactory;
+ private BatchSettings settings;
+ private ProjectReactor reactor;
+
+ public BatchSettingsEnhancer(DatabaseSessionFactory dbFactory, BatchSettings settings, ProjectReactor reactor) {
+ this.dbFactory = dbFactory;
+ this.settings = settings;
+ this.reactor = reactor;
+ }
+
+ public void start() {
+ String projectKey = reactor.getRoot().getKey();
+ setIfNotDefined(ConfigurationUtils.getProjectProperties(dbFactory, projectKey));
+ setIfNotDefined(ConfigurationUtils.getGlobalProperties(dbFactory));
+ settings.updateDeprecatedCommonsConfiguration();
+ }
+
+ private void setIfNotDefined(List<Property> dbProperties) {
+ for (Property dbProperty : dbProperties) {
+ if (!settings.hasKey(dbProperty.getKey())) {
+ settings.setProperty(dbProperty.getKey(), dbProperty.getValue());
+ }
+ }
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/DeprecatedConfigurationProvider.java b/sonar-batch/src/main/java/org/sonar/batch/config/DeprecatedConfigurationProvider.java
new file mode 100644
index 00000000000..636a5adde25
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/DeprecatedConfigurationProvider.java
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.config;
+
+import org.apache.commons.configuration.Configuration;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.resources.Project;
+
+public class DeprecatedConfigurationProvider extends ProviderAdapter {
+
+ public Configuration provide(Project project, ProjectSettings settings) {//NOSONAR the parameter ProjectSettings is declared to be sure that it is initialized
+ // configuration is valid because it has been updated by ProjectSettings
+ return project.getConfiguration();
+ }
+}
+
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
new file mode 100644
index 00000000000..4fcc837791b
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
@@ -0,0 +1,86 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.config;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.api.database.configuration.Property;
+import org.sonar.api.resources.Project;
+import org.sonar.core.config.ConfigurationUtils;
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+import java.util.List;
+
+/**
+ * @since 2.12
+ */
+public class ProjectSettings extends Settings {
+
+ private Configuration deprecatedCommonsConf;
+ private ProjectDefinition projectDefinition;
+ private DatabaseSessionFactory dbFactory;
+
+ public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, DatabaseSessionFactory dbFactory, Project project) {
+ super(definitions);
+ this.deprecatedCommonsConf = project.getConfiguration(); // Configuration is not a parameter to be sure that the project conf is used, not the global one
+ this.projectDefinition = projectDefinition;
+ this.dbFactory = dbFactory;
+ load();
+ }
+
+ public ProjectSettings load() {
+ clear();
+
+ // order is important -> bottom-up. The last one overrides all the others.
+ loadDatabaseGlobalSettings();
+ loadDatabaseProjectSettings(projectDefinition);
+ addProperties(projectDefinition.getProperties());
+ addEnvironmentVariables();
+ addSystemProperties();
+
+ updateDeprecatedCommonsConfiguration();
+
+ return this;
+ }
+
+ private void loadDatabaseProjectSettings(ProjectDefinition projectDef) {
+ if (projectDef.getParent() != null) {
+ loadDatabaseProjectSettings(projectDef.getParent());
+ }
+ List<Property> props = ConfigurationUtils.getProjectProperties(dbFactory, projectDef.getKey());
+ for (Property dbProperty : props) {
+ setProperty(dbProperty.getKey(), dbProperty.getValue());
+ }
+ }
+
+ private void loadDatabaseGlobalSettings() {
+ List<Property> props = ConfigurationUtils.getGlobalProperties(dbFactory);
+ for (Property dbProperty : props) {
+ setProperty(dbProperty.getKey(), dbProperty.getValue());
+ }
+ }
+
+ private void updateDeprecatedCommonsConfiguration() {
+ ConfigurationUtils.copyToCommonsConfiguration(properties, deprecatedCommonsConf);
+ }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java b/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java
index 2be1e1fc189..044038e17a8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java
@@ -21,12 +21,12 @@ package org.sonar.batch;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Test;
-import org.picocontainer.containers.TransientPicoContainer;
import org.sonar.api.batch.BatchExtensionDictionnary;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependedUpon;
import org.sonar.api.measures.*;
+import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -75,11 +75,9 @@ public class DecoratorsSelectorTest {
}
private BatchExtensionDictionnary newDictionnary(Object... extensions) {
- TransientPicoContainer ioc = new TransientPicoContainer();
- int index = 0;
+ ComponentContainer ioc = new ComponentContainer();
for (Object extension : extensions) {
- ioc.addComponent("" + index, extension);
- index++;
+ ioc.addSingleton(extension);
}
return new BatchExtensionDictionnary(ioc);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
index 48bdbe1f96d..4d2903e1e0a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
@@ -19,15 +19,9 @@
*/
package org.sonar.batch;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -35,30 +29,27 @@ import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.text.SimpleDateFormat;
import java.util.Date;
-public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
-
- private ProjectConfigurator configurator = null;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
- @Before
- public void before() {
- configurator = new ProjectConfigurator(getSession());
- }
+public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
@Test
- public void noExclusionPatterns() {
+ public void testNoExclusionPatterns() {
Project project = new Project("key");
- configurator.configure(project, new PropertiesConfiguration());
-
+ new ProjectConfigurator(getSession(), new Settings()).configure(project);
assertThat(project.getExclusionPatterns().length, is(0));
}
@Test
- public void manyExclusionPatterns() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*,foo,*/bar");
+ public void testManyExclusionPatterns() {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*,foo,*/bar");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), settings).configure(project);
assertThat(project.getExclusionPatterns().length, is(3));
assertThat(project.getExclusionPatterns()[0], is("**/*"));
@@ -73,11 +64,11 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
*/
@Test
public void trimExclusionPatterns() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " foo ");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getExclusionPatterns().length, is(1));
assertThat(project.getExclusionPatterns()[0], is("foo"));
@@ -85,11 +76,11 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
@Test
public void getLanguageFromConfiguration() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "foo");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getLanguageKey(), is("foo"));
}
@@ -97,7 +88,7 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
@Test
public void defaultLanguageIsJava() {
Project project = new Project("key");
- configurator.configure(project, new PropertiesConfiguration());
+ new ProjectConfigurator(getSession(), new Settings()).configure(project);
assertThat(project.getLanguageKey(), is(Java.KEY));
}
@@ -105,37 +96,35 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
@Test
public void analysisIsTodayByDefault() {
Project project = new Project("key");
- configurator.configure(project, new PropertiesConfiguration());
+ new ProjectConfigurator(getSession(), new Settings()).configure(project);
Date today = new Date();
assertTrue(today.getTime() - project.getAnalysisDate().getTime() < 1000);
}
@Test
public void analysisDateCouldBeExplicitlySet() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-01-30");
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-01-30");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), settings).configure(project);
assertEquals("30012005", new SimpleDateFormat("ddMMyyyy").format(project.getAnalysisDate()));
}
@Test(expected = RuntimeException.class)
public void failIfAnalyisDateIsNotValid() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005/30/01");
Project project = new Project("key");
- configurator.configure(project, configuration);
-
- project.getAnalysisDate();
+ new ProjectConfigurator(getSession(), configuration).configure(project);
}
@Test
public void sonarLightIsDeprecated() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty("sonar.light", "true");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
}
@@ -143,34 +132,34 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
@Test
public void defaultAnalysisTypeIsDynamic() {
Project project = new Project("key");
- configurator.configure(project, new PropertiesConfiguration());
+ new ProjectConfigurator(getSession(), new Settings()).configure(project);
assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
}
@Test
public void explicitDynamicAnalysis() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "true");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
}
@Test
public void explicitStaticAnalysis() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "false");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
}
@Test
public void explicitDynamicAnalysisReusingReports() {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "reuseReports");
Project project = new Project("key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.getAnalysisType(), is(Project.AnalysisType.REUSE_REPORTS));
}
@@ -190,11 +179,11 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
public void isLatestAnalysis() {
setupData("isLatestAnalysis");
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
Project project = new Project("my:key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.isLatestAnalysis(), is(true));
}
@@ -203,11 +192,11 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
public void isLatestAnalysisIfNeverAnalysed() {
setupData("isLatestAnalysisIfNeverAnalysed");
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
Project project = new Project("my:key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.isLatestAnalysis(), is(true));
}
@@ -216,11 +205,11 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
public void isNotLatestAnalysis() {
setupData("isNotLatestAnalysis");
- PropertiesConfiguration configuration = new PropertiesConfiguration();
+ Settings configuration = new Settings();
configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-12-25");
Project project = new Project("my:key");
- configurator.configure(project, configuration);
+ new ProjectConfigurator(getSession(), configuration).configure(project);
assertThat(project.isLatestAnalysis(), is(false));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
index 35fbd0c1bfb..093de7fab3c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
@@ -133,8 +133,4 @@ public class ProjectTreeTest extends AbstractDbUnitTestCase {
return new Project("org.example:" + artifactId).setPom(pom).setConfiguration(new PropertiesConfiguration());
}
-
- private ProjectConfigurator newConfigurator() {
- return new ProjectConfigurator(getSession());
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
index a52d5d829c3..913c3dc819b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
@@ -19,9 +19,9 @@
*/
package org.sonar.batch;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
import java.text.ParseException;
@@ -32,13 +32,13 @@ public class ServerMetadataTest {
@Test
public void testLoadProperties() throws ParseException {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.SERVER_ID, "123");
- conf.setProperty(CoreProperties.SERVER_VERSION, "2.2");
- conf.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
- conf.setProperty("sonar.host.url", "http://foo.com");
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.SERVER_ID, "123");
+ settings.setProperty(CoreProperties.SERVER_VERSION, "2.2");
+ settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
+ settings.setProperty("sonar.host.url", "http://foo.com");
- ServerMetadata server = new ServerMetadata(conf);
+ ServerMetadata server = new ServerMetadata(settings);
assertThat(server.getId(), is("123"));
assertThat(server.getVersion(), is("2.2"));
@@ -52,10 +52,10 @@ public class ServerMetadataTest {
*/
@Test
public void urlMustNotEndWithSlash() throws ParseException {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty("sonar.host.url", "http://localhost:80/");
+ Settings settings = new Settings();
+ settings.setProperty("sonar.host.url", "http://localhost:80/");
- ServerMetadata server = new ServerMetadata(conf);
+ ServerMetadata server = new ServerMetadata(settings);
assertThat(server.getURL(), is("http://localhost:80"));
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
index 10c19e6d415..c4c013d3632 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
@@ -19,14 +19,17 @@
*/
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;
@@ -36,51 +39,53 @@ 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 getExtensions() {
+ return Arrays.asList(classes);
+ }
+ }
+ );
+ return result;
+ }
+
@Test
public void shouldInstallExtensionsWithBatchInstantiationStrategy() {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
- when(pluginRepository.getPlugins()).thenReturn(Arrays.asList((Plugin) new SonarPlugin() {
- public List getExtensions() {
- return Arrays.asList(BatchService.class, ProjectService.class, ServerService.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.getComponent(BatchService.class), not(nullValue()));
- assertThat(module.getComponent(ProjectService.class), nullValue());
- assertThat(module.getComponent(ServerService.class), nullValue());
+ 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.getPlugins()).thenReturn(Arrays.asList((Plugin) new SonarPlugin(){
- public List getExtensions() {
- return Arrays.asList(BatchServiceProvider.class, ProjectServiceProvider.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.getComponent(BatchService.class), not(nullValue()));
- assertThat(module.getComponent(ProjectService.class), nullValue());
- assertThat(module.getComponent(ServerService.class), nullValue());
+ 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.getPlugins()).thenReturn(Arrays.asList((Plugin) new SonarPlugin(){
- public List getExtensions() {
- return Arrays.asList(InvalidCoverageExtension.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));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index 00b291a2279..40ed3add328 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -26,6 +26,7 @@ import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
import org.sonar.core.plugins.RemotePlugin;
import java.io.File;
@@ -57,7 +58,7 @@ public class BatchPluginRepositoryTest {
ArtifactDownloader downloader = mock(ArtifactDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar"));
- repository = new BatchPluginRepository(downloader, new PropertiesConfiguration());
+ repository = new BatchPluginRepository(downloader, new Settings());
repository.doStart(Arrays.asList(checkstyle));
@@ -77,7 +78,7 @@ public class BatchPluginRepositoryTest {
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.downloadPlugin(checkstyleExt)).thenReturn(copyFiles("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
- repository = new BatchPluginRepository(downloader, new PropertiesConfiguration());
+ repository = new BatchPluginRepository(downloader, new Settings());
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
@@ -97,7 +98,7 @@ public class BatchPluginRepositoryTest {
ArtifactDownloader downloader = mock(ArtifactDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar", "checkstyle-ext.xml"));
- repository = new BatchPluginRepository(downloader, new PropertiesConfiguration());
+ repository = new BatchPluginRepository(downloader, new Settings());
repository.doStart(Arrays.asList(checkstyle));
@@ -117,9 +118,9 @@ public class BatchPluginRepositoryTest {
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.downloadPlugin(checkstyleExt)).thenReturn(copyFiles("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
- repository = new BatchPluginRepository(downloader, conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
+ repository = new BatchPluginRepository(downloader, settings);
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
@@ -142,41 +143,41 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), new PropertiesConfiguration());
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), new Settings());
assertThat(repository.isAccepted("pmd"), Matchers.is(true));
}
@Test
public void whiteListShouldTakePrecedenceOverBlackList() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- conf.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd");
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd");
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), settings);
assertThat(repository.isAccepted("pmd"), Matchers.is(true));
}
@Test
public void corePluginShouldAlwaysBeInWhiteList() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), settings);
assertThat(repository.isAccepted("core"), Matchers.is(true));
}
@Test
public void corePluginShouldNeverBeInBlackList() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), settings);
assertThat(repository.isAccepted("core"), Matchers.is(true));
}
@Test
public void shouldCheckWhitelist() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), settings);
assertThat(repository.isAccepted("checkstyle"), Matchers.is(true));
assertThat(repository.isAccepted("pmd"), Matchers.is(true));
@@ -185,9 +186,9 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldCheckBlackListIfNoWhiteList() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- repository = new BatchPluginRepository(mock(ArtifactDownloader.class), conf);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ repository = new BatchPluginRepository(mock(ArtifactDownloader.class), settings);
assertThat(repository.isAccepted("checkstyle"), Matchers.is(false));
assertThat(repository.isAccepted("pmd"), Matchers.is(false));
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 5b278b0285d..a6acd28fd37 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,27 @@
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.hamcrest.core.Is;
import org.junit.Test;
+import org.sonar.api.config.Settings;
import static org.junit.Assert.assertThat;
public class DryRunTest {
@Test
- public void shouldReadConfiguration() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty("sonar.dryRun", "true");
- assertThat(new DryRun(conf).isEnabled(), Is.is(true));
+ public void shouldReadSettings() {
+ Settings settings = Settings.createForComponent(DryRun.class);
+ settings.setProperty("sonar.dryRun", true);
+ assertThat(new DryRun(settings).isEnabled(), Is.is(true));
- conf.setProperty("sonar.dryRun", "false");
- assertThat(new DryRun(conf).isEnabled(), Is.is(false));
+ settings.setProperty("sonar.dryRun", false);
+ assertThat(new DryRun(settings).isEnabled(), Is.is(false));
}
@Test
public void shouldNotEnableDryRunByDefault() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- assertThat(new DryRun(conf).isEnabled(), Is.is(false));
+ Settings settings = Settings.createForComponent(DryRun.class);
+ assertThat(new DryRun(settings).isEnabled(), Is.is(false));
}
}
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 60fc585dd0b..5d7accba6cc 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
@@ -22,6 +22,7 @@ package org.sonar.batch.bootstrap;
import org.hamcrest.Matchers;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
@@ -33,10 +34,10 @@ public class ModuleTest {
public void shouldInitModule() {
Module module = new FakeModule(FakeService.class).init();
- FakeService service = module.getComponent(FakeService.class);
+ FakeService service = module.getComponentByType(FakeService.class);
assertThat(service, not(nullValue()));
assertThat(service.started, is(false));
- assertThat(module.getContainer(), not(nullValue()));
+ assertThat(module.container, notNullValue());
}
@Test
@@ -44,7 +45,7 @@ public class ModuleTest {
Module module = new FakeModule(FakeService.class).init();
module.start();
- FakeService service = module.getComponent(FakeService.class);
+ FakeService service = module.getComponentByType(FakeService.class);
assertThat(service.started, is(true));
module.stop();
@@ -68,7 +69,7 @@ public class ModuleTest {
public void componentsShouldBeSingletons() {
Module module = new FakeModule(FakeService.class).init();
- assertThat(module.getComponent(FakeService.class) == module.getComponent(FakeService.class), is(true));
+ assertThat(module.getComponentByType(FakeService.class) == module.getComponentByType(FakeService.class), is(true));
}
@Test
@@ -78,16 +79,16 @@ public class ModuleTest {
Module child = parent.installChild(new FakeModule(ChildService.class));
- assertThat(parent.getComponent(ChildService.class), Matchers.nullValue());// child not accessible from parent
- assertThat(child.getComponent(FakeService.class), not(nullValue()));
- assertThat(child.getComponent(ChildService.class).started, is(false));
- assertThat(child.getComponent(ChildService.class).dependency, not(nullValue()));
+ 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()));
child.start();
- assertThat(child.getComponent(ChildService.class).started, is(true));
+ assertThat(child.getComponentByType(ChildService.class).started, is(true));
child.stop();
- assertThat(child.getComponent(ChildService.class).started, is(false));
+ assertThat(child.getComponentByType(ChildService.class).started, is(false));
}
public static class FakeModule extends Module {
@@ -100,7 +101,7 @@ public class ModuleTest {
@Override
protected void configure() {
for (Class component : components) {
- addComponent(component);
+ addCoreSingleton(component);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
index 9e9fcd60fa6..1148116b2e1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
@@ -70,9 +70,9 @@ public class ProjectExtensionInstallerTest {
installer.install(module, new Project("foo"));
- assertThat(module.getComponent(BatchService.class), nullValue());
- assertThat(module.getComponent(ProjectService.class), not(nullValue()));
- assertThat(module.getComponent(ServerService.class), nullValue());
+ assertThat(module.getComponentByType(BatchService.class), nullValue());
+ assertThat(module.getComponentByType(ProjectService.class), not(nullValue()));
+ assertThat(module.getComponentByType(ServerService.class), nullValue());
}
@Test
@@ -90,8 +90,8 @@ public class ProjectExtensionInstallerTest {
installer.install(module, new Project("foo"));
- assertThat(module.getComponent(MavenService.class), nullValue());
- assertThat(module.getComponent(BuildToolService.class), not(nullValue()));
+ assertThat(module.getComponentByType(MavenService.class), nullValue());
+ assertThat(module.getComponentByType(BuildToolService.class), not(nullValue()));
}