diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 15:51:05 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 15:51:05 +0200 |
commit | 72ee9bc51b7f9e9f582b00df215d29ae3b4a698a (patch) | |
tree | 10599f25afdd109435a95a0c0d883592486b9e4e | |
parent | 78f121539257fda264f929a4d596e3919eaafdcc (diff) | |
download | sonarqube-72ee9bc51b7f9e9f582b00df215d29ae3b4a698a.tar.gz sonarqube-72ee9bc51b7f9e9f582b00df215d29ae3b4a698a.zip |
SONAR-2468 add a better sample of ProjectBuilder
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java | 39 |
1 files changed, 32 insertions, 7 deletions
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 a4f6811cde3..4a5d80b899f 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,6 +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 java.io.File; @@ -26,27 +28,50 @@ import java.util.Properties; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.hasItem; public class ProjectBuilderTest { @Test - public void shouldBuild() { - FakeProjectBuilder builder = new FakeProjectBuilder(new ProjectReactor(new ProjectDefinition(new File("."), new File("."), new Properties()))); + public void shouldChangeProject() { + // this reactor is created and injected by Sonar + ProjectReactor projectReactor = new ProjectReactor(new ProjectDefinition(new File("."), new File("."), new Properties())); + + ProjectBuilder builder = new ProjectBuilderSample(projectReactor, new PropertiesConfiguration()); builder.start(); - assertThat(builder.built, is(true)); + assertThat(projectReactor.getProjects().size(), is(2)); + ProjectDefinition root = projectReactor.getRoot(); + assertThat(root.getName(), is("Name changed by plugin")); + assertThat(root.getSubProjects().size(), is(1)); + assertThat(root.getSubProjects().get(0).getSourceDirs(), hasItem("src")); } - private static class FakeProjectBuilder extends ProjectBuilder { - private boolean built=false; + final static class ProjectBuilderSample extends ProjectBuilder { + private Configuration conf; - FakeProjectBuilder(final ProjectReactor reactor) { + public ProjectBuilderSample(ProjectReactor reactor, Configuration conf) { super(reactor); + + // A real implementation should for example use the configuration + this.conf = conf; } @Override protected void build(ProjectReactor reactor) { - built=true; + // change name of root project + ProjectDefinition root = reactor.getRoot(); + root.setName("Name changed by plugin"); + + // add sub-project + File baseDir = new File(root.getBaseDir(), "path/to/subproject"); + ProjectDefinition subProject = new ProjectDefinition(baseDir, new File(baseDir, "target/.sonar"), new Properties()); + subProject.setKey("groupId:subProjectId"); + subProject.setVersion(root.getVersion()); + subProject.setName("Sub Project"); + subProject.setSourceDir("src"); + root.addSubProject(subProject); } } + } |