<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
+ <artifactId>sonar-java-plugin</artifactId>
+ <type>sonar-plugin</type>
+ <version>${sonarJava.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- TODO http://jira.codehaus.org/browse/SONAR-2011
We need following dependency, otherwise we will receive compilation error
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.plugins.cobertura.api.CoberturaUtils;
+import org.sonar.plugins.java.api.JavaSettings;
/**
* Provides {@link CoberturaMavenPluginHandler} and configures correct path to report.
public class CoberturaMavenInitializer extends Initializer implements CoverageExtension, DependsUponMavenPlugin {
private CoberturaMavenPluginHandler handler;
+ private JavaSettings javaSettings;
- public CoberturaMavenInitializer(CoberturaMavenPluginHandler handler) {
+ public CoberturaMavenInitializer(CoberturaMavenPluginHandler handler, JavaSettings javaSettings) {
this.handler = handler;
+ this.javaSettings = javaSettings;
}
public MavenPluginHandler getMavenPluginHandler(Project project) {
@Override
public boolean shouldExecuteOnProject(Project project) {
return Java.KEY.equals(project.getLanguageKey())
+ && CoberturaPlugin.PLUGIN_KEY.equals(javaSettings.getEnabledCoveragePlugin())
&& !project.getFileSystem().mainFiles(Java.KEY).isEmpty()
&& project.getAnalysisType().isDynamic(true);
}
package org.sonar.plugins.cobertura;
import com.google.common.collect.ImmutableList;
-import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
import org.sonar.api.Properties;
import org.sonar.api.Property;
description = "Maximum memory to pass to JVM of Cobertura processes",
project = true,
global = true)})
-public class CoberturaPlugin extends SonarPlugin {
+public final class CoberturaPlugin extends SonarPlugin {
- public List<Class<? extends BatchExtension>> getExtensions() {
+ static final String PLUGIN_KEY = "cobertura";
+
+ public List<?> getExtensions() {
return ImmutableList.of(
CoberturaSensor.class,
CoberturaMavenPluginHandler.class,
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.plugins.cobertura.api.AbstractCoberturaParser;
+import org.sonar.plugins.java.api.JavaSettings;
import java.io.File;
public class CoberturaSensor implements Sensor, CoverageExtension {
+ private JavaSettings javaSettings;
+
+ public CoberturaSensor(JavaSettings javaSettings) {
+ this.javaSettings = javaSettings;
+ }
+
public boolean shouldExecuteOnProject(Project project) {
return Java.KEY.equals(project.getLanguageKey())
+ && CoberturaPlugin.PLUGIN_KEY.equals(javaSettings.getEnabledCoveragePlugin())
&& !project.getFileSystem().mainFiles(Java.KEY).isEmpty()
&& project.getAnalysisType().isDynamic(true);
}
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
import org.sonar.api.resources.InputFile;
import org.sonar.api.resources.InputFileUtils;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.test.MavenTestUtils;
+import org.sonar.plugins.java.api.JavaSettings;
import java.io.File;
import java.util.ArrayList;
@Before
public void setUp() {
project = mock(Project.class);
- initializer = new CoberturaMavenInitializer(new CoberturaMavenPluginHandler(null));
+ JavaSettings javaSettings = mock(JavaSettings.class);
+ when(javaSettings.getEnabledCoveragePlugin()).thenReturn("cobertura");
+ initializer = new CoberturaMavenInitializer(new CoberturaMavenPluginHandler(new Settings()), javaSettings);
}
@Test
import org.sonar.api.resources.Scopes;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.test.IsResource;
+import org.sonar.plugins.java.api.JavaSettings;
import java.io.File;
import java.net.URISyntaxException;
@Before
public void setUp() {
context = mock(SensorContext.class);
- sensor = new CoberturaSensor();
+ JavaSettings javaSettings = mock(JavaSettings.class);
+ when(javaSettings.getEnabledCoveragePlugin()).thenReturn("cobertura");
+ sensor = new CoberturaSensor(javaSettings);
}
@Test
global = true,
multiValues = true,
category = CoreProperties.CATEGORY_EXCLUSIONS),
- @Property(
- key = CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY,
- defaultValue = "jacoco",
- name = "Code coverage plugin",
- description = "Key of the code coverage plugin to use.",
- project = true,
- global = true,
- category = CoreProperties.CATEGORY_CODE_COVERAGE),
@Property(
key = CoreProperties.CORE_IMPORT_SOURCES_PROPERTY,
defaultValue = "" + CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE,
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BATCH)
public final class DefaultResourceTypes extends ExtensionProvider implements BatchExtension, ServerExtension {
@Override
public ResourceTypeTree provide() {
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
+ <artifactId>sonar-java-plugin</artifactId>
+ <type>sonar-plugin</type>
+ <version>${sonarJava.version}</version>
+ <scope>provided</scope>
+ </dependency>
<!-- Would be provided by environment -->
<dependency>
<groupId>org.apache.ant</groupId>
import java.util.Collection;
/**
- * Note that this class can't extend {@link org.sonar.api.batch.AbstractCoverageExtension}, because in this case this extension will be
- * disabled under Sonar 2.3, if JaCoCo is not defined as the default code coverage plugin.
- *
* @author Evgeny Mandrikov
*/
public class JaCoCoItSensor implements Sensor {
}
public boolean shouldExecuteOnProject(Project project) {
- return StringUtils.isNotBlank(configuration.getItReportPath())
- && project.getAnalysisType().isDynamic(true);
+ return StringUtils.isNotBlank(configuration.getItReportPath()) && project.getAnalysisType().isDynamic(true);
}
public void analyse(Project project, SensorContext context) {
}
public boolean shouldExecuteOnProject(Project project) {
- return StringUtils.isNotBlank(configuration.getItReportPath())
- && project.getAnalysisType().isDynamic(true);
+ return StringUtils.isNotBlank(configuration.getItReportPath()) && project.getAnalysisType().isDynamic(true);
}
public void analyse(Project project, SensorContext context) {
public class JaCoCoPlugin extends SonarPlugin {
- public List<Class<? extends BatchExtension>> getExtensions() {
+ public List<?> getExtensions() {
return ImmutableList.of(
JacocoConfiguration.class,
JaCoCoAgentDownloader.class,
}
public boolean shouldExecuteOnProject(Project project) {
- return Java.KEY.equals(project.getLanguageKey());
+ return Java.KEY.equals(project.getLanguageKey())
+ && project.getAnalysisType().isDynamic(true);
}
class UnitTestsAnalyzer extends AbstractAnalyzer {
private JaCoCoUtils() {
}
+ public static final String PLUGIN_KEY = "jacoco";
public static final Logger LOG = LoggerFactory.getLogger(JaCoCoPlugin.class.getName());
}
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.config.Settings;
+import org.sonar.plugins.java.api.JavaSettings;
@Properties({
@Property(
public static final String ANT_TARGETS_DEFAULT_VALUE = "";
private Settings settings;
+ private JavaSettings javaSettings;
private JaCoCoAgentDownloader downloader;
- public JacocoConfiguration(Settings settings, JaCoCoAgentDownloader downloader) {
+ public JacocoConfiguration(Settings settings, JaCoCoAgentDownloader downloader, JavaSettings javaSettings) {
this.settings = settings;
this.downloader = downloader;
+ this.javaSettings = javaSettings;
+ }
+
+ public boolean isEnabled() {
+ return JaCoCoUtils.PLUGIN_KEY.equals(javaSettings.getEnabledCoveragePlugin());
}
public String getReportPath() {
public class JacocoMavenInitializer extends Initializer implements CoverageExtension, DependsUponMavenPlugin {
private JaCoCoMavenPluginHandler handler;
+ private JacocoConfiguration configuration;
- public JacocoMavenInitializer(JaCoCoMavenPluginHandler handler) {
+ public JacocoMavenInitializer(JaCoCoMavenPluginHandler handler, JacocoConfiguration configuration) {
this.handler = handler;
+ this.configuration = configuration;
}
@Override
public boolean shouldExecuteOnProject(Project project) {
- return project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)
+ return configuration.isEnabled()
+ && project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)
&& !project.getFileSystem().testFiles(Java.KEY).isEmpty();
}
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;
+import org.sonar.plugins.java.api.JavaSettings;
import java.io.File;
public void setUp() throws Exception {
JaCoCoAgentDownloader downloader = mock(JaCoCoAgentDownloader.class);
when(downloader.getAgentJarFile()).thenReturn(new File("jacocoagent.jar"));
- configuration = spy(new JacocoConfiguration(new Settings(new PropertyDefinitions(JacocoConfiguration.class)), downloader));
+ Settings settings = new Settings(new PropertyDefinitions(JacocoConfiguration.class));
+ configuration = spy(new JacocoConfiguration(settings, downloader, new JavaSettings(settings)));
handler = new JaCoCoMavenPluginHandler(configuration);
}
public void shouldExecuteOnProject() {
Project project = mock(Project.class);
when(project.getLanguageKey()).thenReturn(Java.KEY);
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
assertThat(sensor.shouldExecuteOnProject(project), is(true));
}
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
+import org.sonar.plugins.java.api.JavaSettings;
import java.io.File;
public class JacocoConfigurationTest {
- private Settings configuration;
+ private Settings settings;
private JacocoConfiguration jacocoConfiguration;
+ private JavaSettings javaSettings;
@Before
public void setUp() {
JaCoCoAgentDownloader downloader = mock(JaCoCoAgentDownloader.class);
when(downloader.getAgentJarFile()).thenReturn(new File("jacocoagent.jar"));
+ javaSettings = mock(JavaSettings.class);
+ settings = new Settings(new PropertyDefinitions(JacocoConfiguration.class));
- configuration = new Settings(new PropertyDefinitions(JacocoConfiguration.class));
-
- jacocoConfiguration = new JacocoConfiguration(configuration, downloader);
+ jacocoConfiguration = new JacocoConfiguration(settings, downloader, javaSettings);
}
@Test
@Test
public void shouldReturnAntTargets() {
- configuration.setProperty(JacocoConfiguration.ANT_TARGETS_PROPERTY, "test");
+ settings.setProperty(JacocoConfiguration.ANT_TARGETS_PROPERTY, "test");
assertThat(jacocoConfiguration.getAntTargets(), is(new String[]{"test"}));
- configuration.setProperty(JacocoConfiguration.ANT_TARGETS_PROPERTY, "test1,test2");
+ settings.setProperty(JacocoConfiguration.ANT_TARGETS_PROPERTY, "test1,test2");
assertThat(jacocoConfiguration.getAntTargets(), is(new String[]{"test1", "test2"}));
}
@Test
public void shouldReturnItReportPath() {
- configuration.setProperty(JacocoConfiguration.IT_REPORT_PATH_PROPERTY, "target/it-jacoco.exec");
+ settings.setProperty(JacocoConfiguration.IT_REPORT_PATH_PROPERTY, "target/it-jacoco.exec");
assertThat(jacocoConfiguration.getItReportPath(), is("target/it-jacoco.exec"));
}
@Test
public void shouldSetDestfile() {
- configuration.setProperty(JacocoConfiguration.REPORT_PATH_PROPERTY, "jacoco.exec");
+ settings.setProperty(JacocoConfiguration.REPORT_PATH_PROPERTY, "jacoco.exec");
assertThat(jacocoConfiguration.getReportPath(), is("jacoco.exec"));
assertThat(jacocoConfiguration.getJvmArgument(), is("-javaagent:jacocoagent.jar=destfile=jacoco.exec,excludes=*_javassist_*"));
@Test
public void shouldSetIncludesAndExcludes() {
- configuration.setProperty(JacocoConfiguration.INCLUDES_PROPERTY, "org.sonar.*");
- configuration.setProperty(JacocoConfiguration.EXCLUDES_PROPERTY, "org.sonar.api.*");
- configuration.setProperty(JacocoConfiguration.EXCLCLASSLOADER_PROPERTY, "sun.reflect.DelegatingClassLoader");
+ settings.setProperty(JacocoConfiguration.INCLUDES_PROPERTY, "org.sonar.*");
+ settings.setProperty(JacocoConfiguration.EXCLUDES_PROPERTY, "org.sonar.api.*");
+ settings.setProperty(JacocoConfiguration.EXCLCLASSLOADER_PROPERTY, "sun.reflect.DelegatingClassLoader");
assertThat(jacocoConfiguration.getJvmArgument(),
is("-javaagent:jacocoagent.jar=destfile=target/jacoco.exec,includes=org.sonar.*,excludes=org.sonar.api.*,exclclassloader=sun.reflect.DelegatingClassLoader"));
*/
package org.sonar.plugins.jacoco;
+import org.hamcrest.core.Is;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.InputFile;
import java.util.Collections;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.*;
public class JacocoMavenInitializerTest {
private JaCoCoMavenPluginHandler mavenPluginHandler;
private JacocoMavenInitializer initializer;
+ private JacocoConfiguration jacocoSettings;
@Before
public void setUp() {
mavenPluginHandler = mock(JaCoCoMavenPluginHandler.class);
- initializer = new JacocoMavenInitializer(mavenPluginHandler);
+ jacocoSettings = mock(JacocoConfiguration.class);
+ when(jacocoSettings.isEnabled()).thenReturn(true);
+ initializer = new JacocoMavenInitializer(mavenPluginHandler, jacocoSettings);
}
@Test
when(project.getFileSystem().testFiles(Java.KEY)).thenReturn(Collections.singletonList(inputFile));
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
- assertThat(initializer.shouldExecuteOnProject(project), is(true));
- assertThat(initializer.getMavenPluginHandler(project), instanceOf(JaCoCoMavenPluginHandler.class));
+ assertThat(initializer.shouldExecuteOnProject(project)).isTrue();
+ assertThat(initializer.getMavenPluginHandler(project)).isInstanceOf(JaCoCoMavenPluginHandler.class);
}
@Test
when(project.getFileSystem().testFiles(Java.KEY)).thenReturn(Collections.singletonList(inputFile));
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
- assertThat(initializer.shouldExecuteOnProject(project), is(false));
+ assertThat(initializer.shouldExecuteOnProject(project)).isFalse();
}
@Test
public void shouldNotExecuteMavenWhenNoTests() {
Project project = mockProject();
- when(project.getFileSystem().hasTestFiles(argThat(is(Java.INSTANCE)))).thenReturn(false);
+ when(project.getFileSystem().hasTestFiles(argThat(Is.is(Java.INSTANCE)))).thenReturn(false);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
- assertThat(initializer.shouldExecuteOnProject(project), is(false));
+ assertThat(initializer.shouldExecuteOnProject(project)).isFalse();
}
private Project mockProject() {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.batch.CoverageExtension;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
@DependsUpon
public Class dependsUponCoverageSensors() {
- return AbstractCoverageExtension.class;
+ return CoverageExtension.class;
}
public boolean shouldExecuteOnProject(Project project) {
</prerequisites>
<properties>
- <sonarJava.version>1.0</sonarJava.version>
+ <sonarJava.version>1.1-SNAPSHOT</sonarJava.version>
<h2.version>1.3.167</h2.version>
<jetty.version>6.1.25</jetty.version>
<sonar.skippedModules>sonar-gwt-api,sonar-core-gwt</sonar.skippedModules>
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;
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) {
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;
*/
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");
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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;
- }
-}
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;
*/
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());
}
analyze(subProject);
}
- Module projectComponents = installChild(new ProjectModule(project, dryRun));
+ Module projectComponents = installChild(new ProjectModule(project));
try {
projectComponents.start();
} finally {
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.bootstrap;
+
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.platform.ComponentContainer;
+
+public class BootstrapExtensionExecutor {
+
+ private ComponentContainer container;
+ private ExtensionInstaller installer;
+
+ public BootstrapExtensionExecutor(ComponentContainer container, ExtensionInstaller installer) {
+ this.container = container;
+ this.installer = installer;
+ }
+
+ public void start() {
+ 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();
+ }
+}
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;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
-import java.net.URLClassLoader;
-
/**
* Level 1 components
*/
@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() {
@Override
protected void doStart() {
- boolean dryRun = getComponentByType(DryRun.class).isEnabled();
- Module batchComponents = installChild(new BatchModule(dryRun));
+ Module batchComponents = installChild(new BatchModule());
batchComponents.start();
}
}
*/
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");
+ }
+ }
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.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;
+ }
+}
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;
}
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]);
}
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>
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() {
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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;
-
-/**
- * @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 LocalMode(Settings settings) {
- enabled = settings.getBoolean("sonar.local");
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void start() {
- if (enabled) {
- LOG.info("Local Mode");
- }
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.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;
+ }
+}
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.PluginMetadata;
+import javax.annotation.Nullable;
+
import java.util.List;
/**
*/
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);
- }
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.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;
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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;
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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;
- }
-}
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;
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
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);
}
*/
@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);
}
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.bootstrap;
+
+import javax.annotation.ParametersAreNonnullByDefault;
/**
* 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;
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;
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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;
-
-/**
- * @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);
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.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;
+
+/**
+ * @since 2.12
+ */
+public final class BootstrapSettings extends Settings {
+ private Configuration deprecatedConfiguration;
+ private ProjectReactor reactor;
+
+ public BootstrapSettings(PropertyDefinitions propertyDefinitions, ProjectReactor reactor, Configuration deprecatedConfiguration) {
+ super(propertyDefinitions);
+ this.reactor = reactor;
+ this.deprecatedConfiguration = deprecatedConfiguration;
+ load();
+ }
+
+ public BootstrapSettings 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);
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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) {
- }
-}
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;
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;
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;
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;
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;
}
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);
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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
- }
-}
*/
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();
}
}
--- /dev/null
+/*
+* Sonar, open source software quality management tool.
+* Copyright (C) 2008-2012 SonarSource
+* mailto:contact AT sonarsource DOT com
+*
+* Sonar is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or (at your option) any later version.
+*
+* Sonar is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Sonar; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+*/
+package org.sonar.batch.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 {
+
+ }
+
+}
@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
@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
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 {
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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();
- }
-}
/*
- * 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;
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());
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();
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
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 {
@Override
protected void configure() {
for (Class component : components) {
- addCoreSingleton(component);
+ container.addSingleton(component);
}
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.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();
+
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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() {
- }
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.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"));
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.config;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.junit.Test;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.PropertyDefinitions;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class BatchSettingsTest {
-
- @Test
- public void shouldLoadBuildModel() {
- // this is the project as defined in the build tool
- ProjectDefinition project = ProjectDefinition.create();
- project.setProperty("foo", "bar");
-
- ProjectReactor reactor = new ProjectReactor(project);
- BatchSettings settings = new BatchSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
-
- assertThat(settings.getString("foo"), is("bar"));
- }
-
- @Test
- public void environmentShouldOverrideBuildModel() {
- ProjectDefinition project = ProjectDefinition.create();
- project.setProperty("BatchSettingsTest.testEnv", "build");
- System.setProperty("BatchSettingsTest.testEnv", "env");
-
- ProjectReactor reactor = new ProjectReactor(project);
- BatchSettings settings = new BatchSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
-
- assertThat(settings.getString("BatchSettingsTest.testEnv"), is("env"));
- }
-
- @Test
- public void shouldForwardToCommonsConfiguration() {
- ProjectDefinition project = ProjectDefinition.create();
- project.setProperty("foo", "bar");
-
- ProjectReactor reactor = new ProjectReactor(project);
- BaseConfiguration deprecatedConfiguration = new BaseConfiguration();
- new BatchSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
-
- assertThat(deprecatedConfiguration.getString("foo"), is("bar"));
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.config;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.junit.Test;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.PropertyDefinitions;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BootstrapSettingsTest {
+
+ @Test
+ public void shouldLoadBuildModel() {
+ // this is the project as defined in the build tool
+ ProjectDefinition project = ProjectDefinition.create();
+ project.setProperty("foo", "bar");
+
+ ProjectReactor reactor = new ProjectReactor(project);
+ BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
+
+ assertThat(settings.getString("foo"), is("bar"));
+ }
+
+ @Test
+ public void environmentShouldOverrideBuildModel() {
+ ProjectDefinition project = ProjectDefinition.create();
+ project.setProperty("BootstrapSettingsTest.testEnv", "build");
+ System.setProperty("BootstrapSettingsTest.testEnv", "env");
+
+ ProjectReactor reactor = new ProjectReactor(project);
+ BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
+
+ assertThat(settings.getString("BootstrapSettingsTest.testEnv"), is("env"));
+ }
+
+ @Test
+ public void shouldForwardToCommonsConfiguration() {
+ ProjectDefinition project = ProjectDefinition.create();
+ project.setProperty("foo", "bar");
+
+ ProjectReactor reactor = new ProjectReactor(project);
+ BaseConfiguration deprecatedConfiguration = new BaseConfiguration();
+ new BootstrapSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
+
+ assertThat(deprecatedConfiguration.getString("foo"), is("bar"));
+ }
+}
@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()));
- }
}
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 351;
+ public static final int LAST_VERSION = 352;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('335');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('350');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('351');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('352');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
String CORE_PLUGIN = "core";
String CORE_VIOLATION_LOCALE_PROPERTY = "sonar.violationLocale";
String CORE_VIOLATION_LOCALE_DEFAULT_VALUE = "en";
- String CORE_COVERAGE_PLUGIN_PROPERTY = "sonar.core.codeCoveragePlugin";
String CORE_IMPORT_SOURCES_PROPERTY = "sonar.importSources";
boolean CORE_IMPORT_SOURCES_DEFAULT_VALUE = true;
String CORE_SKIPPED_MODULES_PROPERTY = "sonar.skippedModules";
/**
* Define instantiation strategy of batch extensions. If an extension is not annotated, then default value
- * is {@link org.sonar.api.batch.InstantiationStrategy#PER_PROJECT}.
+ * is {@link org.sonar.api.batch.InstantiationStrategy#PROJECT}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
/**
* Shared extension. Lifecycle is the full analysis.
+ * @deprecated replaced by the constant {@link org.sonar.api.batch.InstantiationStrategy.BATCH} since version 3.4
*/
+ @Deprecated
String PER_BATCH = "PER_BATCH";
/**
* Created and initialized for each project and sub-project (a project is a module in Maven terminology).
+ * @deprecated replaced by the constant {@link org.sonar.api.batch.InstantiationStrategy.PROJECT} since version 3.4
*/
+ @Deprecated
String PER_PROJECT = "PER_PROJECT";
+ /**
+ * @since 3.4
+ */
+ String BOOTSTRAP = "BOOTSTRAP";
+
+ /**
+ * @since 3.4
+ */
+ String BATCH = "PER_BATCH";
+
+ /**
+ * @since 3.4
+ */
+ String PROJECT = "PER_PROJECT";
+
String value();
}
*
* @since 2.9
*/
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BOOTSTRAP)
public abstract class ProjectBuilder implements BatchExtension {
private ProjectReactor reactor;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
import java.io.File;
*
* @since 2.9
*/
-public final class ProjectDefinition implements BatchComponent {
+public final class ProjectDefinition {
public static final String SOURCE_DIRS_PROPERTY = "sonar.sources";
public static final String SOURCE_FILES_PROPERTY = "sonar.sourceFiles";
/**
* @deprecated in 2.12, because it uses external object to represent internal state.
- * To ensure backward-compatibility with Ant task this method cannot clone properties,
- * so other callers must explicitly make clone of properties before passing into this method.
- * Thus better to use {@link #create()} with combination of other methods like {@link #setProperties(Properties)} and {@link #setProperty(String, String)}.
+ * To ensure backward-compatibility with Ant task this method cannot clone properties,
+ * so other callers must explicitly make clone of properties before passing into this method.
+ * Thus better to use {@link #create()} with combination of other methods like {@link #setProperties(Properties)} and {@link #setProperty(String, String)}.
*/
@Deprecated
public static ProjectDefinition create(Properties properties) {
/**
* Copies specified properties into this object.
- *
+ *
* @since 2.12
*/
public ProjectDefinition setProperties(Properties properties) {
return parent;
}
+ public void remove() {
+ if (parent != null) {
+ parent.subProjects.remove(this);
+ parent = null;
+ subProjects.clear();
+ }
+ }
+
private void setParent(ProjectDefinition parent) {
this.parent = parent;
}
}
return result;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProjectDefinition that = (ProjectDefinition) o;
+ String key = getKey();
+ if (key != null ? !key.equals(that.getKey()) : that.getKey() != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ String key = getKey();
+ return key != null ? key.hashCode() : 0;
+ }
}
*/
package org.sonar.api.batch.bootstrap;
-import org.sonar.api.BatchComponent;
-
import java.util.ArrayList;
import java.util.List;
/**
* @since 2.9
*/
-public final class ProjectReactor implements BatchComponent {
+public final class ProjectReactor {
private ProjectDefinition root;
public ProjectReactor(ProjectDefinition root) {
- if (root.getParent()!=null) {
+ if (root.getParent() != null) {
throw new IllegalArgumentException("Not a root project: " + root);
}
this.root = root;
public ProjectDefinition getRoot() {
return root;
}
+
+ public ProjectDefinition getProject(String key) {
+ for (ProjectDefinition p : getProjects()) {
+ if (key.equals(p.getKey())) {
+ return p;
+ }
+ }
+ return null;
+ }
}
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
+import org.sonar.api.batch.InstantiationStrategy;
import javax.persistence.*;
*/
@Table(name = "metrics")
@Entity(name = "Metric")
+@InstantiationStrategy(InstantiationStrategy.BATCH)
public class Metric implements ServerExtension, BatchExtension {
/**
/**
* @since 1.10
*/
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BATCH)
public interface Metrics extends BatchExtension, ServerExtension {
List<Metric> getMetrics();
}
import org.sonar.api.ServerComponent;
import org.sonar.api.config.PropertyDefinitions;
+import javax.annotation.Nullable;
+
/**
* @since 2.12
*/
*/
public final ComponentContainer addComponent(Object component, boolean singleton) {
pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(getComponentKey(component), component);
- propertyDefinitions.addComponent(component);
+ declareExtension(null, component);
return this;
}
- public final ComponentContainer addExtension(PluginMetadata plugin, Object extension) {
+ public final ComponentContainer addExtension(@Nullable PluginMetadata plugin, Object extension) {
pico.as(Characteristics.CACHE).addComponent(getComponentKey(extension), extension);
declareExtension(plugin, extension);
return this;
}
- public final void declareExtension(PluginMetadata plugin, Object extension) {
- propertyDefinitions.addComponent(extension, plugin.getName());
+ public final void declareExtension(@Nullable PluginMetadata plugin, Object extension) {
+ propertyDefinitions.addComponent(extension, plugin!=null ? plugin.getName() : "");
}
public final ComponentContainer addPicoAdapter(ComponentAdapter adapter) {
import org.sonar.api.BatchComponent;
import org.sonar.api.Plugin;
import org.sonar.api.Property;
+import org.sonar.api.ServerComponent;
import java.util.Collection;
-public interface PluginRepository extends BatchComponent {
+public interface PluginRepository extends BatchComponent, ServerComponent {
Collection<Plugin> getPlugins();
Plugin getPlugin(String key);
*/
@Beta
@Immutable
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BATCH)
public final class ResourceTypeTree implements BatchExtension, ServerExtension {
private List<ResourceType> types;
--- /dev/null
+#
+# Sonar, open source software quality management tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 3.4
+#
+class RenameJavaCoverageProperty < ActiveRecord::Migration
+
+ class Property < ActiveRecord::Base
+ end
+
+ def self.up
+ Property.update_all({:prop_key=> 'sonar.java.coveragePlugin'}, ['prop_key=?', 'sonar.core.codeCoveragePlugin'])
+ end
+end