diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-07 11:48:04 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-07 11:48:04 +0200 |
commit | 93570072a1c3f1e4e90a20d2bfbaefae60528376 (patch) | |
tree | 2ad86299fef06c6beaed69e5b76d4010977af009 /sonar-batch | |
parent | 83f27436880ed453c4c367e8c39625e09982a624 (diff) | |
download | sonarqube-93570072a1c3f1e4e90a20d2bfbaefae60528376.tar.gz sonarqube-93570072a1c3f1e4e90a20d2bfbaefae60528376.zip |
SONAR-2469 extensions annotated with @InstantiationStrategy(BATCH) should access project configuration
Diffstat (limited to 'sonar-batch')
5 files changed, 31 insertions, 21 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfiguration.java index f89e9d644fa..55b92b57998 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfiguration.java @@ -20,6 +20,8 @@ package org.sonar.batch; import org.apache.commons.configuration.*; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; @@ -28,25 +30,27 @@ import java.util.Properties; public class ProjectConfiguration extends CompositeConfiguration { private PropertiesConfiguration runtimeConfiguration; - // FIXME remove - public ProjectConfiguration(DatabaseSession session, Project project) { - this(session, project, project.getPom().getProperties()); + /** + * Used during batch startup + */ + public ProjectConfiguration(DatabaseSession session, ProjectReactor projectReactor) { + this(session, projectReactor.getRoot()); } - - public ProjectConfiguration(DatabaseSession session, Project project, Properties properties) { + + public ProjectConfiguration(DatabaseSession session, ProjectDefinition project) { runtimeConfiguration = new PropertiesConfiguration(); addConfiguration(runtimeConfiguration); loadSystemSettings(); loadProjectDatabaseSettings(session, project); - addConfiguration(new MapConfiguration(properties)); + addConfiguration(new MapConfiguration(project.getProperties())); loadGlobalDatabaseSettings(session); } - private void loadProjectDatabaseSettings(DatabaseSession session, Project project) { + private void loadProjectDatabaseSettings(DatabaseSession session, ProjectDefinition project) { addConfiguration(new ResourceDatabaseConfiguration(session, project.getKey())); - Project parent = project.getParent(); + ProjectDefinition parent = project.getParent(); while (parent != null && parent.getKey() != null) { addConfiguration(new ResourceDatabaseConfiguration(session, parent.getKey())); parent = parent.getParent(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 061348d4c66..6659aa5618f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -74,7 +74,7 @@ public class ProjectConfigurator { } public void configure(Project project, ProjectDefinition def) { - ProjectConfiguration projectConfiguration = new ProjectConfiguration(databaseSession, project, def.getProperties()); + ProjectConfiguration projectConfiguration = new ProjectConfiguration(databaseSession, def); configure(project, projectConfiguration); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java index 08931556821..4fae72f95e1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java @@ -25,6 +25,7 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; import org.sonar.api.utils.ServerHttpClient; import org.sonar.batch.DefaultResourceCreationLock; +import org.sonar.batch.ProjectConfiguration; import org.sonar.batch.ProjectTree; import org.sonar.batch.components.*; import org.sonar.batch.index.*; @@ -45,6 +46,7 @@ public class BatchModule extends Module { @Override protected void configure() { + addComponent(ProjectConfiguration.class); addComponent(ProjectTree.class); addComponent(DefaultResourceCreationLock.class); addComponent(DefaultIndex.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index 6d0a84372b5..2c925b71674 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -50,7 +50,7 @@ public class BootstrapModule extends Module { @Override protected void configure() { addComponent(reactor); - addComponent(configuration); + addComponent(configuration);// this configuration does not access database addComponent(DryRun.class); addComponent(ServerMetadata.class);// registered here because used by BootstrapClassLoader addComponent(TempDirectories.class);// registered here because used by BootstrapClassLoader diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfigurationTest.java index 632fbc8e0ca..523a084e905 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfigurationTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfigurationTest.java @@ -21,8 +21,11 @@ package org.sonar.batch; import org.apache.maven.project.MavenProject; import org.junit.Test; -import org.sonar.jpa.test.AbstractDbUnitTestCase; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.resources.Project; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; @@ -71,17 +74,17 @@ public class ProjectConfigurationTest extends AbstractDbUnitTestCase { @Test public void mavenSettingsLoadedBeforeGlobalSettings() { setupData("global-properties"); - Project project = newProject(); - project.getPom().getProperties().put("key1", "maven1"); + ProjectDefinition project = newProject(); + project.setProperty("maven.foo", "bar"); ProjectConfiguration config = new ProjectConfiguration(getSession(), project); - assertThat(config.getString("key1"), is("maven1")); + assertThat(config.getString("maven.foo"), is("bar")); } @Test public void projectSettingsLoadedBeforeMavenSettings() { setupData("project-properties"); - Project project = newProject(); - project.getPom().getProperties().put("key1", "maven1"); + ProjectDefinition project = newProject(); + project.setProperty("key1", "maven1"); ProjectConfiguration config = new ProjectConfiguration(getSession(), project); assertThat(config.getString("key1"), is("overriden_value1")); } @@ -105,13 +108,14 @@ public class ProjectConfigurationTest extends AbstractDbUnitTestCase { assertThat(config.getString("key1"), is("new1")); } - private Project newProject() { - return new Project("mygroup:myproject").setPom(new MavenProject()); + private ProjectDefinition newProject() { + return ProjectDefinition.create().setKey("mygroup:myproject"); } - private Project newModule() { - Project module = new Project("mygroup:mymodule").setPom(new MavenProject()); - module.setParent(newProject()); + private ProjectDefinition newModule() { + ProjectDefinition module = ProjectDefinition.create().setKey("mygroup:mymodule"); + ProjectDefinition project = newProject(); + project.addSubProject(module); return module; } } |