]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3895 execute bootstrap extensions (liek ProjectBuilder) before initializing db
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 26 Oct 2012 08:44:32 +0000 (10:44 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 26 Oct 2012 09:01:33 +0000 (11:01 +0200)
73 files changed:
plugins/sonar-cobertura-plugin/pom.xml
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaMavenInitializer.java
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaMavenInitializerTest.java
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java
plugins/sonar-jacoco-plugin/pom.xml
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoItSensor.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoOverallSensor.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoSensor.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoUtils.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoConfiguration.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JacocoMavenInitializer.java
plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoMavenPluginHandlerTest.java
plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoSensorTest.java
plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JacocoConfigurationTest.java
plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JacocoMavenInitializerTest.java
plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefireSensor.java
pom.xml
sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRun.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/Module.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ModuleTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/InstantiationStrategy.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metrics.java
sonar-plugin-api/src/main/java/org/sonar/api/platform/ComponentContainer.java
sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/352_rename_java_coverage_property.rb [new file with mode: 0644]

index 7c6ff19eed3cee50a55e0ddb5c26f4aab0f85eb4..bd9c6d1e54eb5cb3d461d9d2ed19798872e559bd 100644 (file)
@@ -1,5 +1,6 @@
 <?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
index 4aac7eabe3c11438fd1e13dcb6b34a3ef49d4a06..473064784f3c101d0049f25e7914640098a42830 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.batch.maven.MavenPluginHandler;
 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.
@@ -37,9 +38,11 @@ import org.sonar.plugins.cobertura.api.CoberturaUtils;
 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) {
@@ -52,6 +55,7 @@ public class CoberturaMavenInitializer extends Initializer implements CoverageEx
   @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);
   }
index 222c2c5ac7741a72766b171d7f758dbd9f886bc6..6bdda1bf9da3ba566bd7c207fc01254010e498f4 100644 (file)
@@ -20,7 +20,6 @@
 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;
@@ -42,9 +41,11 @@ import java.util.List;
     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,
index e2dd02c0d018f5fac05b5aecb9f1cc405734a2b4..91c0347b3a6973287568353513e60298fa6b9a97 100644 (file)
@@ -29,13 +29,21 @@ import org.sonar.api.resources.JavaFile;
 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);
   }
index a16e3a5eb407eb8f99d2b179cb693c6e6b684b1e..1e3b4790cabac9dd4270340aab6a3635edca47d2 100644 (file)
@@ -25,11 +25,13 @@ import org.apache.maven.project.MavenProject;
 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;
@@ -54,7 +56,9 @@ public class CoberturaMavenInitializerTest {
   @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
index e813dc49d236dd9357b0a935e43bb2f3c95fcb9b..6129610d1834722280b62638483ba1ee63a420d1 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.api.resources.Resource;
 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;
@@ -62,7 +63,9 @@ public class CoberturaSensorTest {
   @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
index 4e4c5523ec8a410c236fe51634d367df10419486..5512d60ecd255d9f2fbfb21737b1b80223f248bf 100644 (file)
@@ -202,14 +202,6 @@ import java.util.List;
     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,
index e2b9328d31fcf0a2d7d7decb3bd408ce8bb8a62e..4dfb6d301aee41bd2006062dba8453e21682995b 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.resources.Qualifiers;
 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() {
index 32c08145b7add5451baebf7fa4c93d4412789d41..40f5e3afde63c6d16733d5fae14f87391bf2ecc5 100644 (file)
@@ -1,5 +1,6 @@
 <?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>
index a2bc48ebc2f77251a2f294b7c59341cffd024790..87355615f7703660d1d04cd917ef253920fb0876 100644 (file)
@@ -30,9 +30,6 @@ import org.sonar.api.resources.Project;
 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 {
@@ -43,8 +40,7 @@ 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) {
index 9f52d158361ed1a7ec0bcb084a3ed82b36670182..fc5c61f2ced848d84fae6029c0eb18d8f8263e00 100644 (file)
@@ -53,8 +53,7 @@ public class JaCoCoOverallSensor 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) {
index d6150513661b3750269fb7bf0bfab629d0aeedd0..a875b48740538864107fd516ce2afa04846b426f 100644 (file)
@@ -27,7 +27,7 @@ import java.util.List;
 
 public class JaCoCoPlugin extends SonarPlugin {
 
-  public List<Class<? extends BatchExtension>> getExtensions() {
+  public List<?> getExtensions() {
     return ImmutableList.of(
         JacocoConfiguration.class,
         JaCoCoAgentDownloader.class,
index 76b69f4001642fea54c9487c5f6120494b0a7b0c..085585dfb0b1df8a56521913b7a065c1af8af12b 100644 (file)
@@ -45,7 +45,8 @@ public class JaCoCoSensor implements Sensor, CoverageExtension {
   }
 
   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 {
index b2cfd231827e92e80d1474ef58c275c0fc4c5061..050a39a2fd9b904392df1296468d6455019fa91e 100644 (file)
@@ -33,6 +33,7 @@ public final class JaCoCoUtils {
   private JaCoCoUtils() {
   }
 
+  public static final String PLUGIN_KEY = "jacoco";
   public static final Logger LOG = LoggerFactory.getLogger(JaCoCoPlugin.class.getName());
 
 }
index a650f49f7363c1c3386157c1832537ce73308fa9..65854800198f3563addcc605b33d6c5c9ced571a 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.BatchExtension;
 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(
@@ -108,11 +109,17 @@ public class JacocoConfiguration implements BatchExtension {
   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() {
index 1f0cabd8e06f9a7b26edd8046abafba2fd7b52fa..e35dea775640596004dd8810d01658631e07c518 100644 (file)
@@ -31,14 +31,17 @@ import org.sonar.api.resources.Project;
 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();
   }
 
index 0dc3f3127a7ac17710b46d20f004f43c6f152d44..7b51c2d581138cea726dd6c30d60c6b0b76bcd6a 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.config.PropertyDefinitions;
 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;
 
@@ -46,7 +47,8 @@ public class JaCoCoMavenPluginHandlerTest {
   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);
   }
index 87f3314e54cee3cc1ae6319288c7427106a8e6b5..2701a4a9c428b7cb8f7d1d8bcf12c2e543b1f1c3 100644 (file)
@@ -91,6 +91,7 @@ public class JaCoCoSensorTest {
   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));
   }
index 2939ca6337b0d8bf17c2a00860a1c8047782f8e5..4889553a06437ea7c3a84e796a22a71a9bc50b71 100644 (file)
@@ -23,6 +23,7 @@ import org.junit.Before;
 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;
 
@@ -34,17 +35,18 @@ import static org.mockito.Mockito.when;
 
 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
@@ -59,23 +61,23 @@ public class JacocoConfigurationTest {
 
   @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_*"));
@@ -83,9 +85,9 @@ public class JacocoConfigurationTest {
 
   @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"));
index 4f8c02216a89ceab08b534ea7f79339c0f4a6ab8..d6acbbd61dfa2df8d3243c41fb780974fec68058 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.plugins.jacoco;
 
+import org.hamcrest.core.Is;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.InputFile;
@@ -28,20 +29,21 @@ import org.sonar.api.resources.ProjectFileSystem;
 
 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
@@ -59,8 +61,8 @@ public class JacocoMavenInitializerTest {
     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
@@ -70,16 +72,16 @@ public class JacocoMavenInitializerTest {
     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() {
index 72cb45d313575e94ee9e8b9a282f9d4a13032028..1456df4c2591913d39336dfcfb10c9c587d82ed1 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
 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;
@@ -41,7 +42,7 @@ public class SurefireSensor implements Sensor {
 
   @DependsUpon
   public Class dependsUponCoverageSensors() {
-    return AbstractCoverageExtension.class;
+    return CoverageExtension.class;
   }
 
   public boolean shouldExecuteOnProject(Project project) {
diff --git a/pom.xml b/pom.xml
index 124e36e4d88dbe7b85d3ae454b769e602c64f19e..9905d871c284db646f2c49e7a8623a518b5bd15c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -77,7 +77,7 @@
   </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>
index c99fd70d838b0f56cd57110e27bd943b40bfb347..6e13d83e527de1daf93b2a15b30ecbd054e77863 100644 (file)
@@ -22,14 +22,10 @@ package org.sonar.batch;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.apache.commons.lang.ObjectUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectBuilder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrap.ProjectFilter;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -40,21 +36,11 @@ public class ProjectTree {
 
   private List<Project> projects;
   private Map<ProjectDefinition, Project> projectsByDef;
-  private ProjectFilter projectFilter;
 
-  public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
-      ProjectConfigurator projectConfigurator,
-      ProjectFilter projectFilter,
-      /* Must be executed after ProjectBuilders */ProjectBuilder[] builders) {
-    this(projectReactor, projectConfigurator, projectFilter);
-  }
-
-  public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
-      ProjectConfigurator projectConfigurator,
-      ProjectFilter projectFilter) {
+  public ProjectTree(ProjectReactor projectReactor,
+                     ProjectConfigurator projectConfigurator) {
     this.projectReactor = projectReactor;
     this.configurator = projectConfigurator;
-    this.projectFilter = projectFilter;
   }
 
   ProjectTree(ProjectConfigurator configurator) {
@@ -87,21 +73,8 @@ public class ProjectTree {
     for (Project project : projects) {
       configurator.configure(project);
     }
-
-    applyExclusions();
   }
 
-  void applyExclusions() {
-    for (Iterator<Project> it = projects.iterator(); it.hasNext();) {
-      Project project = it.next();
-      if (projectFilter.isExcluded(project)) {
-        project.setExcluded(true);
-        LoggerFactory.getLogger(getClass()).info("Project {} excluded", project.getName());
-        project.removeFromParent();
-        it.remove();
-      }
-    }
-  }
 
   public List<Project> getProjects() {
     return projects;
index eca2765ecd05d68585dc679e3dab1de06ee8bb83..0ed7b77a24c7f999bfdb034d26a087438126ca66 100644 (file)
@@ -29,14 +29,16 @@ import java.util.Properties;
  */
 public class BatchDatabase extends DefaultDatabase {
 
-  public BatchDatabase(Settings settings) {
+  // the dependency on JdbcDriverHolder is required to be sure that the JDBC driver
+  // has been downloaded and injected into classloader
+  public BatchDatabase(Settings settings, JdbcDriverHolder jdbcDriverHolder) {
     super(settings);
   }
 
   @Override
   protected void doCompleteProperties(Properties properties) {
     // two connections are required : one for Hibernate and one for MyBatis
-    // Note that Hibernate will be remove soon
+    // Note that Hibernate will be removed soon
     properties.setProperty("sonar.jdbc.initialSize", "2");
     properties.setProperty("sonar.jdbc.maxActive", "2");
   }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionInstaller.java
deleted file mode 100644 (file)
index 75e595e..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.Extension;
-import org.sonar.api.ExtensionProvider;
-import org.sonar.api.Plugin;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metrics;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.Map;
-
-public final class BatchExtensionInstaller implements BatchComponent {
-
-  private BatchPluginRepository pluginRepository;
-  private EnvironmentInformation environment;
-  private DryRun dryRun;
-
-  public BatchExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun) {
-    this.pluginRepository = pluginRepository;
-    this.environment = environment;
-    this.dryRun = dryRun;
-  }
-
-  public void install(Module module) {
-    ListMultimap<PluginMetadata, Object> installedExtensionsByPlugin = ArrayListMultimap.create();
-    for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
-      PluginMetadata metadata = entry.getKey();
-      Plugin plugin = entry.getValue();
-      
-      module.addExtension(metadata, plugin);
-
-      for (Object extension : plugin.getExtensions()) {
-        if (installExtension(module, metadata, extension)) {
-          installedExtensionsByPlugin.put(metadata, extension);
-        } else {
-          module.declareExtension(metadata, extension);
-        }
-      }
-    }
-    for (Map.Entry<PluginMetadata, Object> entry : installedExtensionsByPlugin.entries()) {
-      PluginMetadata plugin = entry.getKey();
-      Object extension = entry.getValue();
-      if (isExtensionProvider(extension)) {
-        ExtensionProvider provider = (ExtensionProvider) module.getComponentByKey(extension);
-        installProvider(module, plugin, provider);
-      }
-    }
-    installMetrics(module);
-  }
-
-  static boolean isExtensionProvider(Object extension) {
-    return isType(extension, ExtensionProvider.class) || extension instanceof ExtensionProvider;
-  }
-
-  static boolean isType(Object extension, Class<? extends Extension> extensionClass) {
-    Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
-    return extensionClass.isAssignableFrom(clazz);
-  }
-
-  private void installMetrics(Module module) {
-    for (Metrics metrics : module.getComponents(Metrics.class)) {
-      for (Metric metric : metrics.getMetrics()) {
-        module.addCoreSingleton(metric);
-      }
-    }
-  }
-
-  private void installProvider(Module module, PluginMetadata plugin, ExtensionProvider provider) {
-    Object obj = provider.provide();
-    if (obj != null) {
-      if (obj instanceof Iterable) {
-        for (Object ext : (Iterable) obj) {
-          installExtension(module, plugin, ext);
-        }
-      } else {
-        installExtension(module, plugin, obj);
-      }
-    }
-  }
-
-  boolean installExtension(Module module, PluginMetadata plugin, Object extension) {
-    if (ExtensionUtils.isBatchExtension(extension) &&
-        ExtensionUtils.isSupportedEnvironment(extension, environment) &&
-        ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
-        ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_BATCH)) {
-      if (ExtensionUtils.isType(extension, CoverageExtension.class)) {
-        throw new IllegalArgumentException("Instantiation strategy " + InstantiationStrategy.PER_BATCH + " is not supported on CoverageExtension components: " + extension);
-      }
-      module.addExtension(plugin, extension);
-      return true;
-    }
-    return false;
-  }
-}
index b598f81a9ad1ee1f26bfe019c1e5987911a6b038..f7db951df26994c61a4e4cf105ff4b57ef3f6311 100644 (file)
 package org.sonar.batch.bootstrap;
 
 import org.sonar.api.Plugins;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
+import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.batch.DefaultFileLinesContextFactory;
 import org.sonar.batch.DefaultResourceCreationLock;
 import org.sonar.batch.ProjectConfigurator;
 import org.sonar.batch.ProjectTree;
-import org.sonar.batch.components.*;
-import org.sonar.batch.index.*;
+import org.sonar.batch.components.PastMeasuresLoader;
+import org.sonar.batch.components.PastSnapshotFinder;
+import org.sonar.batch.components.PastSnapshotFinderByDate;
+import org.sonar.batch.components.PastSnapshotFinderByDays;
+import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis;
+import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion;
+import org.sonar.batch.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.index.DefaultIndex;
+import org.sonar.batch.index.DefaultPersistenceManager;
+import org.sonar.batch.index.DefaultResourcePersister;
+import org.sonar.batch.index.DependencyPersister;
+import org.sonar.batch.index.EventPersister;
+import org.sonar.batch.index.LinkPersister;
+import org.sonar.batch.index.MeasurePersister;
+import org.sonar.batch.index.MemoryOptimizer;
+import org.sonar.batch.index.SourcePersister;
 import org.sonar.core.metric.CacheMetricFinder;
 import org.sonar.core.notification.DefaultNotificationManager;
 import org.sonar.core.rule.CacheRuleFinder;
@@ -41,66 +54,47 @@ import org.sonar.jpa.dao.MeasuresDao;
  */
 public class BatchModule extends Module {
 
-  private final boolean dryRun;
-
-  public BatchModule(boolean dryRun) {
-    this.dryRun = dryRun;
-  }
-
   @Override
   protected void configure() {
-    addCoreSingleton(ProjectTree.class);
-    addCoreSingleton(ProjectFilter.class);
-    addCoreSingleton(ProjectConfigurator.class);
-    addCoreSingleton(DefaultResourceCreationLock.class);
-    addCoreSingleton(DefaultIndex.class);
-    addCoreSingleton(DefaultFileLinesContextFactory.class);
-
-    if (dryRun) {
-      addCoreSingleton(ReadOnlyPersistenceManager.class);
-    } else {
-      addCoreSingleton(DefaultPersistenceManager.class);
-      addCoreSingleton(DependencyPersister.class);
-      addCoreSingleton(EventPersister.class);
-      addCoreSingleton(LinkPersister.class);
-      addCoreSingleton(MeasurePersister.class);
-      addCoreSingleton(MemoryOptimizer.class);
-      addCoreSingleton(DefaultResourcePersister.class);
-      addCoreSingleton(SourcePersister.class);
-    }
-
-    addCoreSingleton(Plugins.class);
-    addCoreSingleton(MeasuresDao.class);
-    addCoreSingleton(CacheRuleFinder.class);
-    addCoreSingleton(CacheMetricFinder.class);
-    addCoreSingleton(PastSnapshotFinderByDate.class);
-    addCoreSingleton(PastSnapshotFinderByDays.class);
-    addCoreSingleton(PastSnapshotFinderByPreviousAnalysis.class);
-    addCoreSingleton(PastSnapshotFinderByVersion.class);
-    addCoreSingleton(PastSnapshotFinderByPreviousVersion.class);
-    addCoreSingleton(PastMeasuresLoader.class);
-    addCoreSingleton(PastSnapshotFinder.class);
-    addCoreSingleton(DefaultNotificationManager.class);
-    addCoreSingleton(DefaultUserFinder.class);
-    addCoreSingleton(ResourceTypes.class);
-    addCoreMetrics();
+    container.addSingleton(ProjectTree.class);
+    container.addSingleton(ProjectConfigurator.class);
+    container.addSingleton(DefaultResourceCreationLock.class);
+    container.addSingleton(DefaultIndex.class);
+    container.addSingleton(DefaultFileLinesContextFactory.class);
+    container.addSingleton(DefaultPersistenceManager.class);
+    container.addSingleton(DependencyPersister.class);
+    container.addSingleton(EventPersister.class);
+    container.addSingleton(LinkPersister.class);
+    container.addSingleton(MeasurePersister.class);
+    container.addSingleton(MemoryOptimizer.class);
+    container.addSingleton(DefaultResourcePersister.class);
+    container.addSingleton(SourcePersister.class);
+    container.addSingleton(Plugins.class);
+    container.addSingleton(MeasuresDao.class);
+    container.addSingleton(CacheRuleFinder.class);
+    container.addSingleton(CacheMetricFinder.class);
+    container.addSingleton(PastSnapshotFinderByDate.class);
+    container.addSingleton(PastSnapshotFinderByDays.class);
+    container.addSingleton(PastSnapshotFinderByPreviousAnalysis.class);
+    container.addSingleton(PastSnapshotFinderByVersion.class);
+    container.addSingleton(PastSnapshotFinderByPreviousVersion.class);
+    container.addSingleton(PastMeasuresLoader.class);
+    container.addSingleton(PastSnapshotFinder.class);
+    container.addSingleton(DefaultNotificationManager.class);
+    container.addSingleton(DefaultUserFinder.class);
+    container.addSingleton(ResourceTypes.class);
+    container.addSingleton(MetricProvider.class);
     addBatchExtensions();
   }
 
   private void addBatchExtensions() {
-    BatchExtensionInstaller installer = getComponentByType(BatchExtensionInstaller.class);
-    installer.install(this);
-  }
-
-  void addCoreMetrics() {
-    for (Metric metric : CoreMetrics.getMetrics()) {
-      addCoreSingleton(metric);
-    }
+    ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class);
+    installer.install(container, InstantiationStrategy.BATCH);
   }
 
   @Override
   protected void doStart() {
-    ProjectTree projectTree = getComponentByType(ProjectTree.class);
+    ProjectTree projectTree = container.getComponentByType(ProjectTree.class);
     analyze(projectTree.getRootProject());
   }
 
@@ -109,7 +103,7 @@ public class BatchModule extends Module {
       analyze(subProject);
     }
 
-    Module projectComponents = installChild(new ProjectModule(project, dryRun));
+    Module projectComponents = installChild(new ProjectModule(project));
     try {
       projectComponents.start();
     } finally {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapExtensionExecutor.java
new file mode 100644 (file)
index 0000000..6fc42e4
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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();
+  }
+}
index f5bfb3eadd4c906de9891e29dfda0e85c18c974f..d7dedb1c1e1f0715e203046fd9204f9f63cd3086 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.batch.MavenPluginExecutor;
 import org.sonar.batch.RemoteServerMetadata;
 import org.sonar.batch.ServerMetadata;
 import org.sonar.batch.config.BatchDatabaseSettingsLoader;
-import org.sonar.batch.config.BatchSettings;
+import org.sonar.batch.config.BootstrapSettings;
 import org.sonar.batch.local.LocalDatabase;
 import org.sonar.core.config.Logback;
 import org.sonar.core.i18n.I18nManager;
@@ -41,8 +41,6 @@ import org.sonar.jpa.session.DatabaseSessionProvider;
 import org.sonar.jpa.session.DefaultDatabaseConnector;
 import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
 
-import java.net.URLClassLoader;
-
 /**
  * Level 1 components
  */
@@ -58,55 +56,51 @@ public class BootstrapModule extends Module {
 
   @Override
   protected void configure() {
-    addCoreSingleton(reactor);
-    addCoreSingleton(new PropertiesConfiguration());
-    addCoreSingleton(BatchSettings.class);
-    addCoreSingleton(DryRun.class);
-    addCoreSingleton(Logback.class);
-    addCoreSingleton(ServerMetadata.class);// registered here because used by BootstrapClassLoader
-    addCoreSingleton(TempDirectories.class);// registered here because used by BootstrapClassLoader
-    addCoreSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
-    addCoreSingleton(UriReader.class);// registered here because used by BootstrapClassLoader
-    addCoreSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
-    addCoreSingleton(JdbcDriverHolder.class);
-    addCoreSingleton(EmailSettings.class);
-    addCoreSingleton(I18nManager.class);
-    addCoreSingleton(RuleI18nManager.class);
-
-    URLClassLoader bootstrapClassLoader = getComponentByType(JdbcDriverHolder.class).getClassLoader();
-    // set as the current context classloader for hibernate, else it does not find the JDBC driver.
-    Thread.currentThread().setContextClassLoader(bootstrapClassLoader);
-
-    addCoreSingleton(RemoteServerMetadata.class);
+    container.addSingleton(reactor);
+    container.addSingleton(new PropertiesConfiguration());
+    container.addSingleton(BootstrapSettings.class);
+    container.addSingleton(BatchPluginRepository.class);
+    container.addSingleton(ExtensionInstaller.class);
+    container.addSingleton(DryRun.class);
+    container.addSingleton(Logback.class);
+    container.addSingleton(ServerMetadata.class);// registered here because used by BootstrapClassLoader
+    container.addSingleton(TempDirectories.class);// registered here because used by BootstrapClassLoader
+    container.addSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
+    container.addSingleton(UriReader.class);// registered here because used by BootstrapClassLoader
+    container.addSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
+    container.addSingleton(EmailSettings.class);
+    container.addSingleton(RemoteServerMetadata.class);
+    container.addSingleton(I18nManager.class);
+    container.addSingleton(RuleI18nManager.class);
+    for (Object component : boostrapperComponents) {
+      container.addSingleton(component);
+    }
+    container.addSingleton(BootstrapExtensionExecutor.class);
+    if (!isMavenPluginExecutorRegistered()) {
+      container.addSingleton(FakeMavenPluginExecutor.class);
+    }
+    addDatabaseComponents();
+  }
 
-    // local mode
-    addCoreSingleton(LocalMode.class);
-    addCoreSingleton(LocalDatabase.class);
+  private void addDatabaseComponents() {
+    container.addSingleton(JdbcDriverHolder.class);
+    container.addSingleton(LocalDatabase.class);
 
     // mybatis
-    addCoreSingleton(BatchDatabase.class);
-    addCoreSingleton(MyBatis.class);
-    addCoreSingleton(DatabaseVersion.class);
+    container.addSingleton(BatchDatabase.class);
+    container.addSingleton(MyBatis.class);
+    container.addSingleton(DatabaseVersion.class);
     for (Class daoClass : DaoUtils.getDaoClasses()) {
-      addCoreSingleton(daoClass);
+      container.addSingleton(daoClass);
     }
 
     // hibernate
-    addCoreSingleton(DefaultDatabaseConnector.class);
-    addCoreSingleton(ThreadLocalDatabaseSessionFactory.class);
-    addAdapter(new DatabaseSessionProvider());
-
-    addCoreSingleton(DatabaseBatchCompatibility.class);
-    for (Object component : boostrapperComponents) {
-      addCoreSingleton(component);
-    }
-    if (!isMavenPluginExecutorRegistered()) {
-      addCoreSingleton(FakeMavenPluginExecutor.class);
-    }
+    container.addSingleton(DefaultDatabaseConnector.class);
+    container.addSingleton(ThreadLocalDatabaseSessionFactory.class);
+    container.addPicoAdapter(new DatabaseSessionProvider());
 
-    addCoreSingleton(BatchPluginRepository.class);
-    addCoreSingleton(BatchExtensionInstaller.class);
-    addCoreSingleton(BatchDatabaseSettingsLoader.class);
+    container.addSingleton(DatabaseBatchCompatibility.class);
+    container.addSingleton(BatchDatabaseSettingsLoader.class);
   }
 
   boolean isMavenPluginExecutorRegistered() {
@@ -122,8 +116,7 @@ public class BootstrapModule extends Module {
 
   @Override
   protected void doStart() {
-    boolean dryRun = getComponentByType(DryRun.class).isEnabled();
-    Module batchComponents = installChild(new BatchModule(dryRun));
+    Module batchComponents = installChild(new BatchModule());
     batchComponents.start();
   }
 }
index 574ab37aa6abd75aa40519ff1eeb49c4279ae2ed..d0f6c97f9412913915edd11a49c526c3dbc2e2c6 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
+import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
 import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
 import org.sonar.api.config.Settings;
-import org.sonar.api.utils.Logs;
 
-@Property(key="sonar.dryRun", defaultValue = "false", name="Dry Run")
+@Property(key = "sonar.dryRun", defaultValue = "false", name = "Dry Run", type = PropertyType.BOOLEAN)
 public class DryRun implements BatchComponent {
   private boolean enabled;
 
   public DryRun(Settings settings) {
     enabled = settings.getBoolean("sonar.dryRun");
-    if (enabled) {
-      Logs.INFO.info("Dry run");
-    }
-  }
-
-  DryRun(boolean enabled) {
-    this.enabled = enabled;
   }
 
   public boolean isEnabled() {
     return enabled;
   }
+
+  public void start() {
+    if (enabled) {
+      LoggerFactory.getLogger(DryRun.class).info("Dry run");
+    }
+  }
 }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
new file mode 100644 (file)
index 0000000..0e31db3
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.batch.bootstrap;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.config.Settings;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.resources.Project;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Map;
+
+public class ExtensionInstaller implements BatchComponent {
+
+  private BatchPluginRepository pluginRepository;
+  private EnvironmentInformation environment;
+  private Settings settings;
+
+  public ExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, Settings settings) {
+    this.pluginRepository = pluginRepository;
+    this.environment = environment;
+    this.settings = settings;
+  }
+
+  public void install(ComponentContainer container, String instantiationStrategy) {
+    boolean dryRun = settings.getBoolean("sonar.dryRun");
+    for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
+      PluginMetadata metadata = entry.getKey();
+      Plugin plugin = entry.getValue();
+
+      container.addExtension(metadata, plugin);
+      for (Object extension : plugin.getExtensions()) {
+        installExtension(container, metadata, extension, dryRun, instantiationStrategy);
+      }
+    }
+
+    List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class);
+    for (ExtensionProvider provider : providers) {
+      executeProvider(container, instantiationStrategy, dryRun, provider);
+    }
+  }
+
+  private void executeProvider(ComponentContainer container, String instantiationStrategy, boolean dryRun, ExtensionProvider provider) {
+    Object obj = provider.provide();
+    if (obj instanceof Iterable) {
+      for (Object extension : (Iterable) obj) {
+        installExtension(container, null, extension, dryRun, instantiationStrategy);
+      }
+    } else {
+      installExtension(container, null, obj, dryRun, instantiationStrategy);
+    }
+  }
+
+  boolean installExtension(ComponentContainer container, @Nullable PluginMetadata plugin, Object extension, boolean dryRun, String instantiationStrategy) {
+    boolean installed;
+    if (ExtensionUtils.isBatchExtension(extension) &&
+      ExtensionUtils.supportsEnvironment(extension, environment) &&
+      (!dryRun || ExtensionUtils.supportsDryRun(extension)) &&
+      ExtensionUtils.isInstantiationStrategy(extension, instantiationStrategy) &&
+      !isMavenExtensionOnEmulatedMavenProject(extension, instantiationStrategy, container)) {
+
+      container.addExtension(plugin, extension);
+      installed = true;
+    } else {
+      container.declareExtension(plugin, extension);
+      installed = false;
+    }
+    return installed;
+  }
+
+  /**
+   * Special use-case: the extension point ProjectBuilder is used in a Maven environment to define some
+   * new sub-projects without pom.
+   * Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom.
+   */
+  static boolean isMavenExtensionOnEmulatedMavenProject(Object extension, String instantiationStrategy, ComponentContainer container) {
+    if (InstantiationStrategy.PROJECT.equals(instantiationStrategy) && ExtensionUtils.isMavenExtensionOnly(extension)) {
+      Project project = container.getComponentByType(Project.class);
+      return project!=null && project.getPom()==null;
+    }
+    return false;
+  }
+}
index da9c7ffc21400bb31af3a54f426d4eb4a7cecb55..901dad13ab62ca829e1e8d80b7459123f2887561 100644 (file)
@@ -28,28 +28,26 @@ import org.sonar.api.utils.AnnotationUtils;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
 import org.sonar.core.NotDryRun;
 
-public final class ExtensionUtils {
+final class ExtensionUtils {
 
   private ExtensionUtils() {
     // only static methods
   }
 
   static boolean isInstantiationStrategy(Object extension, String strategy) {
-    Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
-    InstantiationStrategy extStrategy = AnnotationUtils.getAnnotation(clazz, InstantiationStrategy.class);
-    if (extStrategy != null) {
-      return strategy.equals(extStrategy.value());
+    InstantiationStrategy annotation = AnnotationUtils.getAnnotation(extension, InstantiationStrategy.class);
+    if (annotation != null) {
+      return strategy.equals(annotation.value());
     }
-    return InstantiationStrategy.PER_PROJECT.equals(strategy);
+    return InstantiationStrategy.PROJECT.equals(strategy);
   }
 
   static boolean isBatchExtension(Object extension) {
     return isType(extension, BatchExtension.class);
   }
 
-  static boolean isSupportedEnvironment(Object extension, EnvironmentInformation environment) {
-    Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
-    SupportedEnvironment env = AnnotationUtils.getAnnotation(clazz, SupportedEnvironment.class);
+  static boolean supportsEnvironment(Object extension, EnvironmentInformation environment) {
+    SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
     if (env == null) {
       return true;
     }
@@ -61,13 +59,12 @@ public final class ExtensionUtils {
     return false;
   }
 
-  static boolean checkDryRun(Object extension, boolean dryRun) {
-    return !dryRun || AnnotationUtils.getAnnotation(extension, NotDryRun.class) == null;
+  static boolean supportsDryRun(Object extension) {
+    return AnnotationUtils.getAnnotation(extension, NotDryRun.class) == null;
   }
 
   static boolean isMavenExtensionOnly(Object extension) {
-    Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
-    SupportedEnvironment env = AnnotationUtils.getAnnotation(clazz, SupportedEnvironment.class);
+    SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
     return env!=null && env.value().length==1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]);
   }
 
index 1cdb7b9217cf83eeb50701cb481d714455bd3446..8de5ca9147d06a49fdc2bcc20b6e713439685930 100644 (file)
@@ -57,6 +57,11 @@ public class JdbcDriverHolder {
     return classLoader;
   }
 
+  public void start() {
+    // set as the current context classloader for hibernate, else it does not find the JDBC driver.
+    Thread.currentThread().setContextClassLoader(classLoader);
+  }
+
   /**
    * This method automatically invoked by PicoContainer and deregisters JDBC drivers, which were forgotten.
    * <p>
@@ -86,7 +91,7 @@ public class JdbcDriverHolder {
   private static class JdbcDriverClassLoader extends URLClassLoader {
 
     public JdbcDriverClassLoader(URL jdbcDriver, ClassLoader parent) {
-      super(new URL[] { jdbcDriver }, parent);
+      super(new URL[]{jdbcDriver}, parent);
     }
 
     public void clearReferencesJdbc() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/LocalMode.java
deleted file mode 100644 (file)
index 618a1e7..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import org.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");
-    }
-  }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java
new file mode 100644 (file)
index 0000000..d74c221
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.Lists;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.Metrics;
+
+import java.util.List;
+
+@InstantiationStrategy(InstantiationStrategy.BATCH)
+public class MetricProvider extends ExtensionProvider implements BatchExtension {
+
+  private Metrics[] factories;
+
+  public MetricProvider(Metrics[] factories) {
+    this.factories = factories;
+  }
+
+  public MetricProvider() {
+    this.factories = new Metrics[0];
+  }
+
+  public List<Metric> provide() {
+    LoggerFactory.getLogger(MetricProvider.class).debug("Load metrics");
+    List<Metric> metrics = Lists.newArrayList(CoreMetrics.getMetrics());
+    for (Metrics factory : factories) {
+      metrics.addAll(factory.getMetrics());
+    }
+    return metrics;
+  }
+}
index df51d635ce23e23b10ba6026419645a59f6e6502..b6d20d190e6378f3dc1992bda45274c90aab5142 100644 (file)
@@ -23,6 +23,8 @@ import org.picocontainer.ComponentAdapter;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.platform.PluginMetadata;
 
+import javax.annotation.Nullable;
+
 import java.util.List;
 
 /**
@@ -111,31 +113,4 @@ public abstract class Module {
    */
   protected abstract void configure();
 
-  protected final void addCoreSingleton(Object component) {
-    container.addSingleton(component);
-  }
-
-  protected final void declareExtension(PluginMetadata plugin, Object extension) {
-    container.declareExtension(plugin, extension);
-  }
-
-  protected final void addExtension(PluginMetadata plugin, Object extension) {
-    container.addExtension(plugin, extension);
-  }
-
-  protected final void addAdapter(ComponentAdapter<?> componentAdapter) {
-    container.addPicoAdapter(componentAdapter);
-  }
-
-  public final <T> T getComponentByType(Class<T> componentType) {
-    return container.getComponentByType(componentType);
-  }
-
-  public final Object getComponentByKey(Object key) {
-    return container.getComponentByKey(key);
-  }
-
-  public final <T> List<T> getComponents(Class<T> componentType) {
-    return container.getComponentsByType(componentType);
-  }
 }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExclusions.java
new file mode 100644 (file)
index 0000000..148fb35
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.batch.bootstrap;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+
+/**
+ * Exclude the sub-projects as defined by the properties sonar.skippedModules and sonar.includedModules
+ *
+ * @since 2.12
+ */
+@InstantiationStrategy(InstantiationStrategy.BOOTSTRAP)
+public class ProjectExclusions implements BatchComponent {
+
+  private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class);
+
+  private Settings settings;
+  private ProjectReactor reactor;
+
+  public ProjectExclusions(Settings settings, ProjectReactor reactor) {
+    this.settings = settings;
+    this.reactor = reactor;
+  }
+
+  public void start() {
+    LOG.debug("Apply project exclusions");
+    for (ProjectDefinition project : reactor.getProjects()) {
+      if (isExcluded(key(project), project == reactor.getRoot())) {
+        exclude(project);
+      }
+    }
+  }
+
+  private boolean isExcluded(String projectKey, boolean isRoot) {
+    String[] includedKeys = settings.getStringArray("sonar.includedModules");
+    boolean excluded = false;
+    if (!isRoot && includedKeys.length > 0) {
+      excluded = !ArrayUtils.contains(includedKeys, projectKey);
+    }
+    if (!excluded) {
+      String[] excludedKeys = settings.getStringArray("sonar.skippedModules");
+      excluded = ArrayUtils.contains(excludedKeys, projectKey);
+    }
+    if (excluded && isRoot) {
+      throw new IllegalArgumentException("The root project can't be excluded. Please check the parameters sonar.skippedModules and sonar.includedModules.");
+    }
+    return excluded;
+  }
+
+  private void exclude(ProjectDefinition project) {
+    LOG.info(String.format("Exclude project: %s [%s]", project.getName(), project.getKey()));
+    project.remove();
+  }
+
+  // TODO see http://jira.codehaus.org/browse/SONAR-2324
+  static String key(ProjectDefinition project) {
+    String key = project.getKey();
+    if (key.contains(":")) {
+      return StringUtils.substringAfter(key, ":");
+    }
+    return key;
+  }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java
deleted file mode 100644 (file)
index 108c803..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.ExtensionProvider;
-import org.sonar.api.Plugin;
-import org.sonar.api.batch.AbstractCoverageExtension;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.config.ProjectSettings;
-
-import java.util.List;
-import java.util.Map;
-
-public final class ProjectExtensionInstaller implements BatchComponent {
-
-  private BatchPluginRepository pluginRepository;
-  private EnvironmentInformation environment;
-  private DryRun dryRun;
-  private Project project;
-  private ProjectSettings settings;
-
-  public ProjectExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation environment, DryRun dryRun, Project project, ProjectSettings settings) {
-    this.pluginRepository = pluginRepository;
-    this.environment = environment;
-    this.dryRun = dryRun;
-    this.project = project;
-    this.settings = settings;
-  }
-
-  public void install(Module module) {
-    for (Map.Entry<String, Plugin> entry : pluginRepository.getPluginsByKey().entrySet()) {
-      for (Object extension : entry.getValue().getExtensions()) {
-        installExtension(module, extension, entry.getKey());
-      }
-    }
-    installExtensionProviders(module);
-  }
-
-  void installExtensionProviders(Module module) {
-    List<ExtensionProvider> providers = module.getComponents(ExtensionProvider.class);
-    for (ExtensionProvider provider : providers) {
-      Object obj = provider.provide();
-      if (obj instanceof Iterable) {
-        for (Object extension : (Iterable) obj) {
-          installExtension(module, extension, "");
-        }
-      } else {
-        installExtension(module, obj, "");
-      }
-    }
-  }
-
-  private Object installExtension(Module module, Object extension, String pluginKey) {
-    if (ExtensionUtils.isBatchExtension(extension) &&
-        ExtensionUtils.isSupportedEnvironment(extension, environment) &&
-        ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) &&
-        ExtensionUtils.checkDryRun(extension, dryRun.isEnabled()) &&
-        !isDeactivatedCoverageExtension(extension, pluginKey, project, settings) &&
-        !isMavenExtensionOnEmulatedMavenProject(extension, project)) {
-      module.addCoreSingleton(extension);
-      return extension;
-    }
-    return null;
-  }
-
-  /**
-   * Special use-case: the extension point ProjectBuilder is used in a Maven environment to define some
-   * new sub-projects without pom.
-   * Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom.
-   */
-  static boolean isMavenExtensionOnEmulatedMavenProject(Object extension, Project project) {
-    return ExtensionUtils.isMavenExtensionOnly(extension) && project.getPom() == null;
-  }
-
-  /**
-   * TODO this code is specific to Java projects and should be moved somewhere else
-   */
-  static boolean isDeactivatedCoverageExtension(Object extension, String pluginKey, Project project, Settings settings) {
-    if (!ExtensionUtils.isType(extension, CoverageExtension.class)) {
-      return false;
-    }
-
-    if (!project.getAnalysisType().isDynamic(true)) {
-      // not dynamic and not reuse reports
-      return true;
-    }
-
-    if (StringUtils.equals(project.getLanguageKey(), Java.KEY)) {
-      String[] selectedPluginKeys = settings.getStringArray(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY);
-      if (ArrayUtils.isEmpty(selectedPluginKeys)) {
-        selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN};
-      }
-      return !ArrayUtils.contains(selectedPluginKeys, pluginKey);
-    }
-    return false;
-  }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java
deleted file mode 100644 (file)
index 9727a74..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
-
-/**
- * Filter projects to analyze by using the properties sonar.skippedModules and sonar.includedModules
- *
- * @since 2.12
- */
-public class ProjectFilter {
-
-  private Settings settings;
-
-  public ProjectFilter(Settings settings) {
-    this.settings = settings;
-  }
-
-  public boolean isExcluded(Project project) {
-    Project p = project;
-    while (p != null) {
-      if (isExcludedModule(getArtifactId(p), p.isRoot())) {
-        return true;
-      }
-      p = p.getParent();
-    }
-    return false;
-  }
-
-  private boolean isExcludedModule(String artifactId, boolean isRoot) {
-    String[] includedArtifactIds = settings.getStringArray("sonar.includedModules");
-    boolean excluded = false;
-    if (!isRoot && includedArtifactIds.length > 0) {
-      excluded = !ArrayUtils.contains(includedArtifactIds, artifactId);
-    }
-    if (!excluded) {
-      String[] excludedArtifactIds = settings.getStringArray("sonar.skippedModules");
-      excluded = ArrayUtils.contains(excludedArtifactIds, artifactId);
-    }
-    if (excluded && isRoot) {
-      throw new IllegalArgumentException("The root module can't be skipped. Please check the parameter sonar.skippedModules.");
-    }
-    return excluded;
-  }
-
-  // TODO see http://jira.codehaus.org/browse/SONAR-2324
-  static String getArtifactId(Project project) {
-    String key = project.getKey();
-    if (StringUtils.isNotBlank(project.getBranch())) {
-      // remove branch part
-      key = StringUtils.removeEnd(project.getKey(), ":" + project.getBranch());
-    }
-    if (key.contains(":")) {
-      return StringUtils.substringAfter(key, ":");
-    }
-    return key;
-  }
-}
index 02cb458c4734436444b3fe25e5a33ff59c8a3ad9..13bde69f4dad60e025285e1a388c766343c57fc8 100644 (file)
@@ -22,12 +22,21 @@ package org.sonar.batch.bootstrap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.BatchExtensionDictionnary;
+import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 import org.sonar.api.utils.IocContainer;
-import org.sonar.batch.*;
+import org.sonar.batch.DefaultProfileLoader;
+import org.sonar.batch.DefaultProjectClasspath;
+import org.sonar.batch.DefaultProjectFileSystem2;
+import org.sonar.batch.DefaultSensorContext;
+import org.sonar.batch.DefaultTimeMachine;
+import org.sonar.batch.ProfileProvider;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
 import org.sonar.batch.components.TimeMachineConfiguration;
 import org.sonar.batch.config.ProjectSettings;
 import org.sonar.batch.config.UnsupportedProperties;
@@ -43,11 +52,9 @@ import org.sonar.jpa.dao.RulesDao;
 public class ProjectModule extends Module {
   private static final Logger LOG = LoggerFactory.getLogger(ProjectModule.class);
   private Project project;
-  private boolean dryRun;
 
-  public ProjectModule(Project project, boolean dryRun) {
+  public ProjectModule(Project project) {
     this.project = project;
-    this.dryRun = dryRun;
   }
 
   @Override
@@ -60,52 +67,50 @@ public class ProjectModule extends Module {
 
 
   private void addProjectComponents() {
-    ProjectDefinition projectDefinition = getComponentByType(ProjectTree.class).getProjectDefinition(project);
-    addCoreSingleton(projectDefinition);
-    addCoreSingleton(project);
-    addCoreSingleton(project.getConfiguration());
-    addCoreSingleton(ProjectSettings.class);
-    addCoreSingleton(UnsupportedProperties.class);
-    addCoreSingleton(IocContainer.class);
+    ProjectDefinition projectDefinition = container.getComponentByType(ProjectTree.class).getProjectDefinition(project);
+    container.addSingleton(projectDefinition);
+    container.addSingleton(project);
+    container.addSingleton(project.getConfiguration());
+    container.addSingleton(ProjectSettings.class);
+    container.addSingleton(UnsupportedProperties.class);
+    container.addSingleton(IocContainer.class);
 
     for (Object component : projectDefinition.getContainerExtensions()) {
-      addCoreSingleton(component);
+      container.addSingleton(component);
     }
-    addCoreSingleton(Languages.class);
-    addCoreSingleton(DefaultProjectClasspath.class);
-    addCoreSingleton(DefaultProjectFileSystem2.class);
-    addCoreSingleton(RulesDao.class);
+    container.addSingleton(Languages.class);
+    container.addSingleton(DefaultProjectClasspath.class);
+    container.addSingleton(DefaultProjectFileSystem2.class);
+    container.addSingleton(RulesDao.class);
 
-    if (!dryRun) {
-      // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
-      addCoreSingleton(getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
-    }
-    addCoreSingleton(TimeMachineConfiguration.class);
-    addCoreSingleton(org.sonar.api.database.daos.MeasuresDao.class);
-    addCoreSingleton(ProfilesDao.class);
-    addCoreSingleton(DefaultSensorContext.class);
-    addCoreSingleton(BatchExtensionDictionnary.class);
-    addCoreSingleton(DefaultTimeMachine.class);
-    addCoreSingleton(ViolationFilters.class);
-    addCoreSingleton(ResourceFilters.class);
-    addCoreSingleton(DefaultModelFinder.class);
-    addCoreSingleton(DefaultProfileLoader.class);
-    addAdapter(new ProfileProvider());
+    // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
+    container.addSingleton(container.getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
+
+    container.addSingleton(TimeMachineConfiguration.class);
+    container.addSingleton(org.sonar.api.database.daos.MeasuresDao.class);
+    container.addSingleton(ProfilesDao.class);
+    container.addSingleton(DefaultSensorContext.class);
+    container.addSingleton(BatchExtensionDictionnary.class);
+    container.addSingleton(DefaultTimeMachine.class);
+    container.addSingleton(ViolationFilters.class);
+    container.addSingleton(ResourceFilters.class);
+    container.addSingleton(DefaultModelFinder.class);
+    container.addSingleton(DefaultProfileLoader.class);
+    container.addPicoAdapter(new ProfileProvider());
   }
 
   private void addCoreComponents() {
-    addCoreSingleton(EventBus.class);
-    addCoreSingleton(Phases.class);
-    addCoreSingleton(PhasesTimeProfiler.class);
-    for (Class clazz : Phases.getPhaseClasses(dryRun)) {
-      addCoreSingleton(clazz);
+    container.addSingleton(EventBus.class);
+    container.addSingleton(Phases.class);
+    container.addSingleton(PhasesTimeProfiler.class);
+    for (Class clazz : Phases.getPhaseClasses()) {
+      container.addSingleton(clazz);
     }
   }
 
   private void addProjectPluginExtensions() {
-    addCoreSingleton(ProjectExtensionInstaller.class);
-    ProjectExtensionInstaller installer = getComponentByType(ProjectExtensionInstaller.class);
-    installer.install(this);
+    ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class);
+    installer.install(container, InstantiationStrategy.PROJECT);
   }
 
 
@@ -119,12 +124,12 @@ public class ProjectModule extends Module {
    */
   @Override
   protected void doStart() {
-    DefaultIndex index = getComponentByType(DefaultIndex.class);
+    DefaultIndex index = container.getComponentByType(DefaultIndex.class);
     index.setCurrentProject(project,
-      getComponentByType(ResourceFilters.class),
-      getComponentByType(ViolationFilters.class),
-      getComponentByType(RulesProfile.class));
+      container.getComponentByType(ResourceFilters.class),
+      container.getComponentByType(ViolationFilters.class),
+      container.getComponentByType(RulesProfile.class));
 
-    getComponentByType(Phases.class).execute(project);
+    container.getComponentByType(Phases.class).execute(project);
   }
 }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java
new file mode 100644 (file)
index 0000000..e287adb
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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;
index f47146f28eeb72f7cefd5e2e1a0a3a6ca6f140b6..1e907c30c0e87fc4b0d593ec92e0bc6073cfd2d9 100644 (file)
@@ -25,9 +25,11 @@ import java.util.List;
 
 /**
  * Describes order of projects.
+ * Used by sonar-runner 1.x. Gradle 1.0 already uses {#link org.sonar.api.batch.bootstrap.ProjectReactor}.
  * 
  * @since 2.6
  */
+@Deprecated
 public class Reactor {
 
   private ProjectDefinition root;
index 5f91446ddf7fa3cb57a10b80e9be42f3fb49afae..8a03eb01053c802276bfad76f1a899045668b612 100644 (file)
@@ -33,10 +33,10 @@ import java.util.List;
 public final class BatchDatabaseSettingsLoader {
 
   private PropertiesDao propertiesDao;
-  private BatchSettings settings;
+  private BootstrapSettings settings;
   private ProjectReactor reactor;
 
-  public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BatchSettings settings, ProjectReactor reactor) {
+  public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BootstrapSettings settings, ProjectReactor reactor) {
     this.propertiesDao = propertiesDao;
     this.settings = settings;
     this.reactor = reactor;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettings.java
deleted file mode 100644 (file)
index 5eb75bc..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.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);
-  }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
new file mode 100644 (file)
index 0000000..0d54743
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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);
+  }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/ReadOnlyPersistenceManager.java
deleted file mode 100644 (file)
index 1091375..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.index;
-
-import com.google.common.collect.Maps;
-import org.sonar.api.batch.Event;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectLink;
-import org.sonar.api.resources.Resource;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public final class ReadOnlyPersistenceManager implements PersistenceManager {
-
-  private Map<Resource, String> sources = Maps.newHashMap();
-
-  public void clear() {
-    sources.clear();
-  }
-
-  public void setDelayedMode(boolean b) {
-  }
-
-  public void dump() {
-  }
-
-  public void saveProject(Project project, Project parent) {
-  }
-
-  public Snapshot saveResource(Project project, Resource resource, Resource parent) {
-    return null;
-  }
-
-  public void setSource(Resource file, String source) {
-    sources.put(file, source);
-  }
-
-  public String getSource(Resource resource) {
-    return sources.get(resource);
-  }
-
-  public void saveMeasure(Resource resource, Measure measure) {
-  }
-
-  public Measure reloadMeasure(Measure measure) {
-    return measure;
-  }
-
-  public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) {
-  }
-
-  public void saveLink(Project project, ProjectLink link) {
-  }
-
-  public void deleteLink(Project project, String key) {
-  }
-
-  public List<Event> getEvents(Resource resource) {
-    return Collections.emptyList();
-  }
-
-  public void deleteEvent(Event event) {
-  }
-
-  public void saveEvent(Resource resource, Event event) {
-  }
-}
index 199541c12a04a7044e8b80c869078fecfef62562..be9b447ab8990ab4c593ba8cbb479afdcfeb68fb 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.database.DatabaseProperties;
 import org.sonar.api.platform.Server;
 import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrap.LocalMode;
+import org.sonar.batch.bootstrap.DryRun;
 import org.sonar.batch.bootstrap.TempDirectories;
 
 import java.io.File;
@@ -48,12 +48,12 @@ public class LocalDatabase implements BatchComponent {
   private static final String USER = "sonar";
   private static final String PASSWORD = "sonar";
 
-  private final LocalMode localMode;
+  private final DryRun localMode;
   private final Settings settings;
   private final Server server;
   private final TempDirectories tempDirectories;
 
-  public LocalDatabase(LocalMode localMode, Settings settings, Server server, TempDirectories tempDirectories) {
+  public LocalDatabase(DryRun localMode, Settings settings, Server server, TempDirectories tempDirectories) {
     this.localMode = localMode;
     this.settings = settings;
     this.server = server;
index e57e8e3fd8021150074ed800eabf77b5ad56712a..f90c60d348069bdeae9cadde48c15a6ceb7ac6e2 100644 (file)
@@ -32,14 +32,10 @@ import java.util.List;
 
 public final class Phases {
 
-  public static Collection<Class> getPhaseClasses(boolean dryRun) {
-    List<Class> classes = Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
+  public static Collection<Class> getPhaseClasses() {
+    return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
         PostJobsExecutor.class, SensorsExecutor.class,
-        InitializersExecutor.class, ProjectInitializer.class);
-    if (!dryRun) {
-      classes.add(UpdateStatusJob.class);
-    }
-    return classes;
+        InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
   }
 
   private EventBus eventBus;
index 7e5cabb7afc6dfd983aee49113c426cdd8efc907..38ea6b9ed943619704fcbc82afd3952b91599e77 100644 (file)
@@ -24,7 +24,6 @@ import org.sonar.api.resources.Language;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrap.DryRun;
 import org.sonar.core.resource.ResourceDao;
 import org.sonar.core.resource.ResourceDto;
 
@@ -34,12 +33,10 @@ import org.sonar.core.resource.ResourceDto;
 public class ProjectInitializer implements BatchComponent {
 
   private ResourceDao resourceDao;
-  private DryRun dryRun;
   private Languages languages;
 
-  public ProjectInitializer(ResourceDao resourceDao, DryRun dryRun, Languages languages) {
+  public ProjectInitializer(ResourceDao resourceDao, Languages languages) {
     this.resourceDao = resourceDao;
-    this.dryRun = dryRun;
     this.languages = languages;
   }
 
@@ -53,7 +50,7 @@ public class ProjectInitializer implements BatchComponent {
       throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found");
     }
     project.setLanguage(language);
-    if (!dryRun.isEnabled() && project.getId() != null) {
+    if (project.getId() != null) {
       ResourceDto dto = resourceDao.getResource(project.getId());
       dto.setLanguage(project.getLanguageKey());
       resourceDao.insertOrUpdate(dto);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
deleted file mode 100644 (file)
index 7230e87..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import com.google.common.collect.Maps;
-import org.junit.Test;
-import org.sonar.api.*;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.platform.PluginMetadata;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class BatchExtensionInstallerTest {
-
-  private static final PluginMetadata METADATA = mock(PluginMetadata.class);
-
-  private static Map<PluginMetadata, Plugin> newPlugin(final Class... classes) {
-    Map<PluginMetadata, Plugin> result = Maps.newHashMap();
-    result.put(METADATA,
-        new SonarPlugin() {
-          public List<Class> getExtensions() {
-            return Arrays.asList(classes);
-          }
-        }
-    );
-    return result;
-  }
-
-  @Test
-  public void shouldInstallExtensionsWithBatchInstantiationStrategy() {
-    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
-    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchService.class, ProjectService.class, ServerService.class));
-    Module module = new FakeModule().init();
-    BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
-    installer.install(module);
-
-    assertThat(module.getComponentByType(BatchService.class), not(nullValue()));
-    assertThat(module.getComponentByType(ProjectService.class), nullValue());
-    assertThat(module.getComponentByType(ServerService.class), nullValue());
-  }
-
-  @Test
-  public void shouldInstallProvidersWithBatchInstantiationStrategy() {
-    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
-    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchServiceProvider.class, ProjectServiceProvider.class));
-    Module module = new FakeModule().init();
-    BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
-    installer.install(module);
-
-    assertThat(module.getComponentByType(BatchService.class), not(nullValue()));
-    assertThat(module.getComponentByType(ProjectService.class), nullValue());
-    assertThat(module.getComponentByType(ServerService.class), nullValue());
-  }
-
-  @Test(expected = IllegalArgumentException.class)
-  public void shouldNotSupportCoverageExtensionsWithBatchInstantiationStrategy() {
-    // the reason is that CoverageExtensions currently depend on Project
-    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
-    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(InvalidCoverageExtension.class));
-    Module module = new FakeModule().init();
-    BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false));
-
-    installer.install(module);
-  }
-
-  public static class FakeModule extends Module {
-    @Override
-    protected void configure() {
-    }
-  }
-
-  @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-  public static class BatchService implements BatchExtension {
-
-  }
-
-  public static class ProjectService implements BatchExtension {
-
-  }
-
-  public static class ServerService implements ServerExtension {
-
-  }
-
-  @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-  public static class BatchServiceProvider extends ExtensionProvider implements BatchExtension {
-
-    @Override
-    public Object provide() {
-      return Arrays.<Object> asList(BatchService.class, ServerService.class);
-    }
-  }
-
-  public static class ProjectServiceProvider extends ExtensionProvider implements BatchExtension {
-    @Override
-    public Object provide() {
-      return ProjectService.class;
-    }
-  }
-
-  @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-  public static class InvalidCoverageExtension implements CoverageExtension {
-    // strategy PER_BATCH is not allowed
-  }
-}
index 52b421efeb9a7b13542a30319d6e873a302170d6..f0b514fff0f80b4bc18308b34c5af8d6bf3b40f2 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
-import org.hamcrest.core.Is;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class DryRunTest {
+  Settings settings = new Settings();
 
   @Test
-  public void shouldReadSettings() {
-    Settings settings = Settings.createForComponent(DryRun.class);
-    settings.setProperty("sonar.dryRun", true);
-    assertThat(new DryRun(settings).isEnabled(), Is.is(true));
+  public void should_be_disabled() {
+    DryRun dryRun = new DryRun(settings);
+    dryRun.start();
 
-    settings.setProperty("sonar.dryRun", false);
-    assertThat(new DryRun(settings).isEnabled(), Is.is(false));
+    assertThat(dryRun.isEnabled()).isFalse();
   }
 
   @Test
-  public void shouldNotEnableDryRunByDefault() {
-    Settings settings = Settings.createForComponent(DryRun.class);
-    assertThat(new DryRun(settings).isEnabled(), Is.is(false));
+  public void should_enable() {
+    settings.setProperty("sonar.dryRun", "true");
+
+    DryRun dryRun = new DryRun(settings);
+    dryRun.start();
+
+    assertThat(dryRun.isEnabled()).isTrue();
   }
 }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
new file mode 100644 (file)
index 0000000..1f65e53
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+* Sonar, open source software quality management tool.
+* Copyright (C) 2008-2012 SonarSource
+* mailto:contact AT sonarsource DOT com
+*
+* Sonar is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or (at your option) any later version.
+*
+* Sonar is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Sonar; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+*/
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.Maps;
+import org.junit.Test;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.SonarPlugin;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.SupportedEnvironment;
+import org.sonar.api.config.Settings;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ExtensionInstallerTest {
+
+  private static final PluginMetadata METADATA = mock(PluginMetadata.class);
+
+  private static Map<PluginMetadata, Plugin> newPlugin(final Class... classes) {
+    Map<PluginMetadata, Plugin> result = Maps.newHashMap();
+    result.put(METADATA,
+      new SonarPlugin() {
+        public List<Class> getExtensions() {
+          return Arrays.asList(classes);
+        }
+      }
+    );
+    return result;
+  }
+
+  @Test
+  public void shouldInstallExtensionsWithBatchInstantiationStrategy() {
+    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchService.class, ProjectService.class, ServerService.class));
+    ComponentContainer container = new ComponentContainer();
+    ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+    installer.install(container, InstantiationStrategy.BATCH);
+
+    assertThat(container.getComponentByType(BatchService.class)).isNotNull();
+    assertThat(container.getComponentByType(ProjectService.class)).isNull();
+    assertThat(container.getComponentByType(ServerService.class)).isNull();
+  }
+
+  @Test
+  public void shouldInstallProvidersWithBatchInstantiationStrategy() {
+    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(BatchServiceProvider.class, ProjectServiceProvider.class));
+    ComponentContainer container = new ComponentContainer();
+    ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+    installer.install(container, InstantiationStrategy.BATCH);
+
+    assertThat(container.getComponentByType(BatchService.class)).isNotNull();
+    assertThat(container.getComponentByType(ProjectService.class)).isNull();
+    assertThat(container.getComponentByType(ServerService.class)).isNull();
+  }
+
+
+  @Test
+  public void shouldNotInstallPluginsOnNonSupportedEnvironment() {
+    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
+    when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(MavenService.class, BuildToolService.class));
+
+    ComponentContainer container = new ComponentContainer();
+    ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+
+    installer.install(container, InstantiationStrategy.PROJECT);
+
+    assertThat(container.getComponentByType(MavenService.class)).isNull();
+    assertThat(container.getComponentByType(BuildToolService.class)).isNotNull();
+  }
+
+  @InstantiationStrategy(InstantiationStrategy.BATCH)
+  public static class BatchService implements BatchExtension {
+
+  }
+
+  public static class ProjectService implements BatchExtension {
+
+  }
+
+  public static class ServerService implements ServerExtension {
+
+  }
+
+  @InstantiationStrategy(InstantiationStrategy.BATCH)
+  public static class BatchServiceProvider extends ExtensionProvider implements BatchExtension {
+
+    @Override
+    public Object provide() {
+      return Arrays.<Object>asList(BatchService.class, ServerService.class);
+    }
+  }
+
+  public static class ProjectServiceProvider extends ExtensionProvider implements BatchExtension {
+    @Override
+    public Object provide() {
+      return ProjectService.class;
+    }
+  }
+
+  @SupportedEnvironment("maven")
+  public static class MavenService implements BatchExtension {
+
+  }
+
+  @SupportedEnvironment({"maven", "ant", "gradle"})
+  public static class BuildToolService implements BatchExtension {
+
+  }
+
+}
index a6d34d3a3a591195c3f6c403bca2d06f76934ad8..ef85fb296c45d22d465ff7be19ff60206dd5d741 100644 (file)
@@ -34,22 +34,22 @@ public class ExtensionUtilsTest {
 
   @Test
   public void shouldBeBatchInstantiationStrategy() {
-    assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_BATCH), is(true));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_BATCH), is(true));
-    assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_BATCH), is(false));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_BATCH), is(false));
-    assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_BATCH), is(false));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_BATCH), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.BATCH), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.BATCH), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.BATCH), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.BATCH), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.BATCH), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.BATCH), is(false));
   }
 
   @Test
   public void shouldBeProjectInstantiationStrategy() {
-    assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PER_PROJECT), is(false));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PER_PROJECT), is(false));
-    assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PER_PROJECT), is(true));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PER_PROJECT), is(true));
-    assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PER_PROJECT), is(true));
-    assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PER_PROJECT), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(BatchService.class, InstantiationStrategy.PROJECT), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new BatchService(), InstantiationStrategy.PROJECT), is(false));
+    assertThat(ExtensionUtils.isInstantiationStrategy(ProjectService.class, InstantiationStrategy.PROJECT), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new ProjectService(), InstantiationStrategy.PROJECT), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(DefaultService.class, InstantiationStrategy.PROJECT), is(true));
+    assertThat(ExtensionUtils.isInstantiationStrategy(new DefaultService(), InstantiationStrategy.PROJECT), is(true));
   }
 
   @Test
@@ -63,11 +63,11 @@ public class ExtensionUtilsTest {
 
   @Test
   public void shouldCheckEnvironment() {
-    assertThat(ExtensionUtils.isSupportedEnvironment(new MavenService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
-    assertThat(ExtensionUtils.isSupportedEnvironment(new BuildToolService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
-    assertThat(ExtensionUtils.isSupportedEnvironment(new DefaultService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+    assertThat(ExtensionUtils.supportsEnvironment(new MavenService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+    assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
+    assertThat(ExtensionUtils.supportsEnvironment(new DefaultService(), new EnvironmentInformation("maven", "2.2.1")), is(true));
 
-    assertThat(ExtensionUtils.isSupportedEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1")), is(false));
+    assertThat(ExtensionUtils.supportsEnvironment(new BuildToolService(), new EnvironmentInformation("eclipse", "0.1")), is(false));
   }
 
   @Test
@@ -76,24 +76,24 @@ public class ExtensionUtilsTest {
     assertThat(ExtensionUtils.isMavenExtensionOnly(BuildToolService.class), is(false));
   }
 
-  @Test
-  public void shouldCheckDryRun() {
-    assertThat(ExtensionUtils.checkDryRun(BatchService.class, true), is(true));
-    assertThat(ExtensionUtils.checkDryRun(PersistentService.class, true), is(false));
-  }
-
-  @Test
-  public void shouldNotCheckDryRun() {
-    assertThat(ExtensionUtils.checkDryRun(BatchService.class, false), is(true));
-    assertThat(ExtensionUtils.checkDryRun(PersistentService.class, false), is(true));
-  }
-
-  @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+//  @Test
+//  public void shouldCheckDryRun() {
+//    assertThat(ExtensionUtils.supportsDryRun(BatchService.class, true), is(true));
+//    assertThat(ExtensionUtils.supportsDryRun(PersistentService.class, true), is(false));
+//  }
+//
+//  @Test
+//  public void shouldNotCheckDryRun() {
+//    assertThat(ExtensionUtils.supportsDryRun(BatchService.class, false), is(true));
+//    assertThat(ExtensionUtils.supportsDryRun(PersistentService.class, false), is(true));
+//  }
+
+  @InstantiationStrategy(InstantiationStrategy.BATCH)
   public static class BatchService implements BatchExtension {
 
   }
 
-  @InstantiationStrategy(InstantiationStrategy.PER_PROJECT)
+  @InstantiationStrategy(InstantiationStrategy.PROJECT)
   public static class ProjectService implements BatchExtension {
 
   }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/LocalModeTest.java
deleted file mode 100644 (file)
index e409d67..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-
-import 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();
-  }
-}
index ae134ec1e9501847b914a8e986a10b392b692ee4..96250202acc41eaf86a7355241b1649b63c93e9c 100644 (file)
@@ -1,22 +1,22 @@
 /*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
+* Sonar, open source software quality management tool.
+* Copyright (C) 2008-2012 SonarSource
+* mailto:contact AT sonarsource DOT com
+*
+* Sonar is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or (at your option) any later version.
+*
+* Sonar is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Sonar; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+*/
 package org.sonar.batch.bootstrap;
 
 import org.hamcrest.Matchers;
@@ -34,7 +34,7 @@ public class ModuleTest {
   public void shouldInitModule() {
     Module module = new FakeModule(FakeService.class).init();
 
-    FakeService service = module.getComponentByType(FakeService.class);
+    FakeService service = module.container.getComponentByType(FakeService.class);
     assertThat(service, not(nullValue()));
     assertThat(service.started, is(false));
     assertThat(module.container, notNullValue());
@@ -45,7 +45,7 @@ public class ModuleTest {
     Module module = new FakeModule(FakeService.class).init();
     module.start();
 
-    FakeService service = module.getComponentByType(FakeService.class);
+    FakeService service = module.container.getComponentByType(FakeService.class);
     assertThat(service.started, is(true));
 
     module.stop();
@@ -69,7 +69,7 @@ public class ModuleTest {
   public void componentsShouldBeSingletons() {
     Module module = new FakeModule(FakeService.class).init();
 
-    assertThat(module.getComponentByType(FakeService.class) == module.getComponentByType(FakeService.class), is(true));
+    assertThat(module.container.getComponentByType(FakeService.class) == module.container.getComponentByType(FakeService.class), is(true));
   }
 
   @Test
@@ -79,16 +79,16 @@ public class ModuleTest {
 
     Module child = parent.installChild(new FakeModule(ChildService.class));
 
-    assertThat(parent.getComponentByType(ChildService.class), Matchers.nullValue());// child not accessible from parent
-    assertThat(child.getComponentByType(FakeService.class), not(nullValue()));
-    assertThat(child.getComponentByType(ChildService.class).started, is(false));
-    assertThat(child.getComponentByType(ChildService.class).dependency, not(nullValue()));
+    assertThat(parent.container.getComponentByType(ChildService.class), Matchers.nullValue());// child not accessible from parent
+    assertThat(child.container.getComponentByType(FakeService.class), not(nullValue()));
+    assertThat(child.container.getComponentByType(ChildService.class).started, is(false));
+    assertThat(child.container.getComponentByType(ChildService.class).dependency, not(nullValue()));
 
     child.start();
-    assertThat(child.getComponentByType(ChildService.class).started, is(true));
+    assertThat(child.container.getComponentByType(ChildService.class).started, is(true));
 
     child.stop();
-    assertThat(child.getComponentByType(ChildService.class).started, is(false));
+    assertThat(child.container.getComponentByType(ChildService.class).started, is(false));
   }
 
   public static class FakeModule extends Module {
@@ -101,7 +101,7 @@ public class ModuleTest {
     @Override
     protected void configure() {
       for (Class component : components) {
-        addCoreSingleton(component);
+        container.addSingleton(component);
       }
     }
 
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExclusionsTest.java
new file mode 100644 (file)
index 0000000..8270a05
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.batch.bootstrap;
+
+import org.junit.Test;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+
+public class ProjectExclusionsTest {
+
+  ProjectReactor newReactor(String rootKey, String... moduleKeys) {
+    ProjectDefinition root = ProjectDefinition.create().setKey(rootKey);
+    for (String moduleKey : moduleKeys) {
+      ProjectDefinition module = ProjectDefinition.create().setKey(moduleKey);
+      root.addSubProject(module);
+    }
+    return new ProjectReactor(root);
+  }
+
+  @Test
+  public void testSkippedModules() {
+    Settings settings = new Settings();
+    settings.setProperty("sonar.skippedModules", "sub1,sub3");
+
+    ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+
+    ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+    exclusions.start();
+
+    assertThat(reactor.getProject("root")).isNotNull();
+    assertThat(reactor.getProject("sub1")).isNull();
+    assertThat(reactor.getProject("sub2")).isNotNull();
+  }
+
+  @Test
+  public void testNoSkippedModules() {
+    Settings settings = new Settings();
+    ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+    ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+    exclusions.start();
+
+    assertThat(reactor.getProject("root")).isNotNull();
+    assertThat(reactor.getProject("sub1")).isNotNull();
+    assertThat(reactor.getProject("sub2")).isNotNull();
+  }
+
+  @Test
+  public void testIncludedModules() {
+    Settings settings = new Settings();
+    settings.setProperty("sonar.includedModules", "sub1");
+    ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+    ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+    exclusions.start();
+
+    assertThat(reactor.getProject("root")).isNotNull();
+    assertThat(reactor.getProject("sub1")).isNotNull();
+    assertThat(reactor.getProject("sub2")).isNull();
+  }
+
+  @Test
+  public void shouldBeExcludedIfParentIsExcluded() {
+    ProjectDefinition sub11 = ProjectDefinition.create().setKey("sub11");
+    ProjectDefinition sub1 = ProjectDefinition.create().setKey("sub1").addSubProject(sub11);
+    ProjectDefinition root = ProjectDefinition.create().setKey("root").addSubProject(sub1);
+
+    Settings settings = new Settings();
+    settings.setProperty("sonar.skippedModules", "sub1");
+
+    ProjectReactor reactor = new ProjectReactor(root);
+    ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+    exclusions.start();
+
+
+    assertThat(reactor.getProject("root")).isNotNull();
+    assertThat(reactor.getProject("sub1")).isNull();
+    assertThat(reactor.getProject("sub11")).isNull();
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void shouldFailIfExcludingRoot() {
+    Settings settings = new Settings();
+    settings.setProperty("sonar.skippedModules", "sub1,root");
+
+    ProjectReactor reactor = newReactor("root", "sub1", "sub2");
+    ProjectExclusions exclusions = new ProjectExclusions(settings, reactor);
+    exclusions.start();
+
+  }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
deleted file mode 100644 (file)
index 5690e94..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.sonar.api.BatchExtension;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.Extension;
-import org.sonar.api.Plugin;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.SonarPlugin;
-import org.sonar.api.batch.CoverageExtension;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ProjectExtensionInstallerTest {
-
-  @Test
-  public void shouldBeMavenExtensionOnEmulatedMavenProject() {
-    Project mavenProject = new Project("foo").setPom(new MavenProject());
-    Project otherProject = new Project("bar");
-    assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(MavenService.class, mavenProject), is(false));
-    assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(MavenService.class, otherProject), is(true));
-
-    // this service is not for Maven only
-    assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(BuildToolService.class, mavenProject), is(false));
-    assertThat(ProjectExtensionInstaller.isMavenExtensionOnEmulatedMavenProject(BuildToolService.class, otherProject), is(false));
-  }
-
-  @Test
-  public void shouldInstallExtensionsWithProjectInstantiationStrategy() {
-    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
-    Map<String, Plugin> pluginsMap = Maps.newHashMap();
-    pluginsMap.put("fooPlugin", new SonarPlugin() {
-      public List<Class<? extends Extension>> getExtensions() {
-        return ImmutableList.of(BatchService.class, ProjectService.class, ServerService.class);
-      }
-    });
-    when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
-    Module module = new FakeModule().init();
-    ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null);
-
-    installer.install(module);
-
-    assertThat(module.getComponentByType(BatchService.class), nullValue());
-    assertThat(module.getComponentByType(ProjectService.class), not(nullValue()));
-    assertThat(module.getComponentByType(ServerService.class), nullValue());
-  }
-
-  @Test
-  public void shouldNotInstallPluginsOnNonSupportedEnvironment() {
-    BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
-    Map<String, Plugin> pluginsMap = Maps.newHashMap();
-    pluginsMap.put("fooPlugin", new SonarPlugin() {
-      public List<Class<? extends BatchExtension>> getExtensions() {
-        return ImmutableList.of(MavenService.class, BuildToolService.class);
-      }
-    });
-    when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
-    Module module = new FakeModule().init();
-    ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false), new Project("foo"), null);
-
-    installer.install(module);
-
-    assertThat(module.getComponentByType(MavenService.class), nullValue());
-    assertThat(module.getComponentByType(BuildToolService.class), not(nullValue()));
-  }
-
-  private static Project newJavaProject() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty("sonar.language", Java.KEY);
-    Project project = new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
-    return project;
-  }
-
-  private static Project newGroovyProject() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-        configuration.setProperty("sonar.language", "grvy");
-    return new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
-  }
-
-  @Test
-  public void shouldRegisterCustomCoverageExtension() {
-    Settings conf = new Settings();
-    conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "clover,phpunit");
-
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "cobertura", newJavaProject(), conf), is(true));
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "clover", newJavaProject(), conf), is(false));
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "phpunit", newJavaProject(), conf), is(false));
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "other", newJavaProject(), conf), is(true));
-  }
-
-  @Test
-  public void shouldNotCheckCoverageExtensionsOnNonJavaProjects() {
-    Settings conf = new Settings();
-    conf.setProperty(CoreProperties.CORE_COVERAGE_PLUGIN_PROPERTY, "cobertura");
-
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newGroovyProject(), conf), is(false));
-    assertThat(ProjectExtensionInstaller.isDeactivatedCoverageExtension(FakeCoverageExtension.class, "groovy", newJavaProject(), conf), is(true));
-
-  }
-
-  @SupportedEnvironment("maven")
-  public static class MavenService implements BatchExtension {
-
-  }
-
-  @SupportedEnvironment({"maven", "ant", "gradle"})
-  public static class BuildToolService implements BatchExtension {
-
-  }
-
-  @InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-  public static class BatchService implements BatchExtension {
-
-  }
-
-  public static class ProjectService implements BatchExtension {
-
-  }
-
-  public static class ServerService implements ServerExtension {
-
-  }
-
-  public static class FakeCoverageExtension implements CoverageExtension {
-
-  }
-
-  public static class FakeModule extends Module {
-    @Override
-    protected void configure() {
-    }
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java
deleted file mode 100644 (file)
index 3e5cb64..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.bootstrap;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
-
-public class ProjectFilterTest {
-
-  private Project root = new Project("root");
-
-  @Test
-  public void testSkippedModules() {
-    Settings settings = new Settings();
-    settings.setProperty("sonar.skippedModules", "foo,bar");
-
-    ProjectFilter filter = new ProjectFilter(settings);
-    assertTrue(filter.isExcluded(new Project("foo").setParent(root)));
-    assertFalse(filter.isExcluded(new Project("other").setParent(root)));
-  }
-
-  @Test
-  public void testNoSkippedModules() {
-    Settings settings = new Settings();
-    ProjectFilter filter = new ProjectFilter(settings);
-
-    assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
-    assertFalse(filter.isExcluded(root));
-  }
-
-  @Test
-  public void testIncludedModules() {
-    Settings settings = new Settings();
-    settings.setProperty("sonar.includedModules", "foo");
-    ProjectFilter filter = new ProjectFilter(settings);
-
-    assertFalse(filter.isExcluded(new Project("foo").setParent(root)));
-    assertTrue(filter.isExcluded(new Project("bar").setParent(root)));
-  }
-
-  @Test
-  public void includingRootShouldBeOptional() {
-    Settings settings = new Settings();
-    settings.setProperty("sonar.includedModules", "foo,bar");
-    ProjectFilter filter = new ProjectFilter(settings);
-
-    assertFalse(filter.isExcluded(root));
-  }
-
-  @Test
-  public void shouldBeExcludedIfParentIsExcluded() {
-    Settings settings = new Settings();
-    settings.setProperty("sonar.skippedModules", "parent");
-
-    Project parent = new Project("parent").setParent(root);
-    Project child = new Project("child").setParent(parent);
-
-    ProjectFilter filter = new ProjectFilter(settings);
-    assertTrue(filter.isExcluded(parent));
-    assertTrue(filter.isExcluded(child));
-  }
-
-  @Test(expected = IllegalArgumentException.class)
-  public void shouldFailIfExcludingRoot() {
-    Settings settings = new Settings();
-    settings.setProperty("sonar.skippedModules", "foo,root");
-
-    ProjectFilter filter = new ProjectFilter(settings);
-
-    filter.isExcluded(root);
-  }
-
-  @Test
-  public void testGetArtifactId() {
-    assertThat(ProjectFilter.getArtifactId(new Project("org:foo")), is("foo"));
-    assertThat(ProjectFilter.getArtifactId(new Project("foo")), is("foo"));
-    assertThat(ProjectFilter.getArtifactId(new Project("org:foo:1.x").setBranch("1.x")), is("foo"));
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/config/BatchSettingsTest.java
deleted file mode 100644 (file)
index f001afb..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.batch.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"));
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java
new file mode 100644 (file)
index 0000000..1d68dfa
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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"));
+  }
+}
index 3d67d1a985bec0d24f15f18e728d1da6de0e01ab..0e4d0157a7ad521f111ddb1911c9f7a2647610eb 100644 (file)
@@ -28,11 +28,7 @@ public class PhasesTest {
 
   @Test
   public void shouldDefinePhaseClasses() {
-    assertThat(Phases.getPhaseClasses(false).size(), greaterThan(4));
+    assertThat(Phases.getPhaseClasses().size(), greaterThan(4));
   }
 
-  @Test
-  public void someComponentsShouldBeDisabledOnDryRun() {
-    assertThat(Phases.getPhaseClasses(false).size(), greaterThan(Phases.getPhaseClasses(true).size()));
-  }
 }
index 91c13431ca18795e2efccf16daae177e2d8366f1..793723d6af005c375254c7d87306f7f47aa1d5c0 100644 (file)
@@ -35,7 +35,7 @@ import java.util.List;
  */
 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
index 207f9270e834a99da52924617519266b425608e2..5c27bbed51c6b66709d9cd1f8da891a13e0e80cf 100644 (file)
@@ -179,6 +179,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('334');
 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;
index 1e86dd8947f4437fbf036b884b50fa3495c1deea..ba1bc4331877bc4f84c993bbe71df3c74ec7ddce 100644 (file)
@@ -137,7 +137,6 @@ public interface CoreProperties {
   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";
index 2c4de8854eb4e10bb23ec14a97c0f73ac45c9e22..a5619a1bdd4dec79da72f995c22ff183aff4428a 100644 (file)
@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
 
 /**
  * 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)
@@ -34,13 +34,32 @@ public @interface InstantiationStrategy {
 
   /**
    * 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();
 }
index 7de741cc6c96f0439a500bf502b3c77517cae405..078d5f335a843191f00d120b545169e96dfd0d3c 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.api.batch.InstantiationStrategy;
  *
  * @since 2.9
  */
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BOOTSTRAP)
 public abstract class ProjectBuilder implements BatchExtension {
 
   private ProjectReactor reactor;
index d9d4d2f49ca15db6e168618d0a0c56f6eb07cb5f..fa03621d73305fe16abc8b3bba70a74ea84534ab 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.api.batch.bootstrap;
 
 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;
@@ -35,7 +34,7 @@ import java.util.Properties;
  *
  * @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";
@@ -59,9 +58,9 @@ public final class ProjectDefinition implements BatchComponent {
 
   /**
    * @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) {
@@ -96,7 +95,7 @@ public final class ProjectDefinition implements BatchComponent {
 
   /**
    * Copies specified properties into this object.
-   * 
+   *
    * @since 2.12
    */
   public ProjectDefinition setProperties(Properties properties) {
@@ -350,6 +349,14 @@ public final class ProjectDefinition implements BatchComponent {
     return parent;
   }
 
+  public void remove() {
+    if (parent != null) {
+      parent.subProjects.remove(this);
+      parent = null;
+      subProjects.clear();
+    }
+  }
+
   private void setParent(ProjectDefinition parent) {
     this.parent = parent;
   }
@@ -368,4 +375,27 @@ public final class ProjectDefinition implements BatchComponent {
     }
     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;
+  }
 }
index b5e238bd3be31e1b0d97525ae796a2827d839edf..caad3cc3d12c2fe06fe0bc10945c79641436a6d2 100644 (file)
  */
 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;
@@ -56,4 +54,13 @@ public final class ProjectReactor implements BatchComponent {
   public ProjectDefinition getRoot() {
     return root;
   }
+
+  public ProjectDefinition getProject(String key) {
+    for (ProjectDefinition p : getProjects()) {
+      if (key.equals(p.getKey())) {
+        return p;
+      }
+    }
+    return null;
+  }
 }
index c51106adb2577ad6cd7797ac821385b27e3d55ee..e60d3cd90a100f04cd642b1af32b5bee4900ab24 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 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.*;
 
@@ -34,6 +35,7 @@ import javax.persistence.*;
  */
 @Table(name = "metrics")
 @Entity(name = "Metric")
+@InstantiationStrategy(InstantiationStrategy.BATCH)
 public class Metric implements ServerExtension, BatchExtension {
 
   /**
index fe0170eac4eaa4802834a9bb72ab90fbf733c297..f22181642ef504e57190e7017d1f7e10cff50b74 100644 (file)
@@ -28,7 +28,7 @@ import java.util.List;
 /**
  * @since 1.10
  */
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BATCH)
 public interface Metrics extends BatchExtension, ServerExtension {
   List<Metric> getMetrics();
 }
index 23abc99ae1d504cac1086110ce67f77b90fdf773..c95e320ac921561e1c35d25855309ca95157140b 100644 (file)
@@ -30,6 +30,8 @@ import org.sonar.api.BatchComponent;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.config.PropertyDefinitions;
 
+import javax.annotation.Nullable;
+
 /**
  * @since 2.12
  */
@@ -90,18 +92,18 @@ public class ComponentContainer implements BatchComponent, ServerComponent {
    */
   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) {
index 6fcbc654fadb325a3096e1bb22d88f6226e42d23..0acd4c40798b6c7bb30a14945fe2af77ebb9b875 100644 (file)
@@ -22,10 +22,11 @@ package org.sonar.api.platform;
 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);
index 88fb6f72379f5dd7f94aac566cca6ee22de2f8c7..d02fa97a17aa118c1b4d27c560e41a308168b8c0 100644 (file)
@@ -36,7 +36,7 @@ import java.util.List;
  */
 @Beta
 @Immutable
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+@InstantiationStrategy(InstantiationStrategy.BATCH)
 public final class ResourceTypeTree implements BatchExtension, ServerExtension {
 
   private List<ResourceType> types;
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/352_rename_java_coverage_property.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/352_rename_java_coverage_property.rb
new file mode 100644 (file)
index 0000000..a8eb934
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# 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