aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-06-11 15:17:11 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-06-11 15:17:11 +0200
commitd099e513e4066280677117e130df54a4ef66c3b5 (patch)
tree4c9887ed4a95c515905a49b78e0ae7addfb0107e /sonar-plugin-api
parenta384ced603ce00b9f6f9590d345808dd933e730b (diff)
downloadsonarqube-d099e513e4066280677117e130df54a4ef66c3b5.tar.gz
sonarqube-d099e513e4066280677117e130df54a4ef66c3b5.zip
SONAR-4386 Refactor ProjectBuilder extension
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java24
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java17
2 files changed, 27 insertions, 14 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
index 7f874f07619..b3adf46ad6d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
@@ -37,15 +37,31 @@ import org.sonar.api.batch.InstantiationStrategy;
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public abstract class ProjectBuilder implements BatchExtension {
- private ProjectReactor reactor;
-
+ /**
+ * Don't inject ProjectReactor as it may not be available
+ * @deprecated since 3.7 use {@link #ProjectBuilder()}
+ */
+ @Deprecated
protected ProjectBuilder(final ProjectReactor reactor) {
- this.reactor = reactor;
}
- public final void start() {
+ /**
+ * @since 3.7
+ */
+ protected ProjectBuilder() {
+ }
+
+ /**
+ * This method was introduced to relax visibility of {@link #build(ProjectReactor)}
+ * @since 3.7
+ */
+ public final void doBuild(ProjectReactor reactor) {
build(reactor);
}
+ /**
+ * This method will be called by Sonar core to let you a chance to change project reactor structure.
+ * @param reactor
+ */
protected abstract void build(ProjectReactor reactor);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java
index 9def3de0aa8..2ae474e3866 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java
@@ -19,9 +19,8 @@
*/
package org.sonar.api.batch.bootstrap;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
+import org.sonar.api.config.Settings;
import java.io.File;
@@ -33,11 +32,11 @@ public class ProjectBuilderTest {
@Test
public void shouldChangeProject() {
- // this reactor is created and injected by Sonar
+ // this reactor is created and provided by Sonar
ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
- ProjectBuilder builder = new ProjectBuilderSample(projectReactor, new PropertiesConfiguration());
- builder.start();
+ ProjectBuilder builder = new ProjectBuilderSample(new Settings());
+ builder.doBuild(projectReactor);
assertThat(projectReactor.getProjects().size(), is(2));
ProjectDefinition root = projectReactor.getRoot();
@@ -47,12 +46,10 @@ public class ProjectBuilderTest {
}
final static class ProjectBuilderSample extends ProjectBuilder {
- private Configuration conf;
+ private Settings conf;
- public ProjectBuilderSample(ProjectReactor reactor, Configuration conf) {
- super(reactor);
-
- // A real implementation should for example use the configuration
+ public ProjectBuilderSample(Settings conf) {
+ // A real implementation should for example use the settings
this.conf = conf;
}