diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-06-06 14:27:49 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-06-06 14:28:04 +0200 |
commit | d346d2313443339ded7b86bca7765a7ee850a8bb (patch) | |
tree | 9ee28f020559465a003f952ed538d3a6ddd68802 /sonar-plugin-api/src/test/java | |
parent | 00d12c9382a8c4161455e2203b9b074b15278111 (diff) | |
download | sonarqube-d346d2313443339ded7b86bca7765a7ee850a8bb.tar.gz sonarqube-d346d2313443339ded7b86bca7765a7ee850a8bb.zip |
Allow the extension ProjectBuilder to change the source directories of root module
Diffstat (limited to 'sonar-plugin-api/src/test/java')
3 files changed, 36 insertions, 19 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 4a5d80b899f..af6ae6d93b8 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 @@ -35,7 +35,7 @@ public class ProjectBuilderTest { @Test public void shouldChangeProject() { // this reactor is created and injected by Sonar - ProjectReactor projectReactor = new ProjectReactor(new ProjectDefinition(new File("."), new File("."), new Properties())); + ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create()); ProjectBuilder builder = new ProjectBuilderSample(projectReactor, new PropertiesConfiguration()); builder.start(); @@ -65,11 +65,13 @@ public class ProjectBuilderTest { // add sub-project File baseDir = new File(root.getBaseDir(), "path/to/subproject"); - ProjectDefinition subProject = new ProjectDefinition(baseDir, new File(baseDir, "target/.sonar"), new Properties()); + ProjectDefinition subProject = ProjectDefinition.create(); + subProject.setBaseDir(baseDir); + subProject.setWorkDir(new File(baseDir, "target/.sonar")); subProject.setKey("groupId:subProjectId"); subProject.setVersion(root.getVersion()); subProject.setName("Sub Project"); - subProject.setSourceDir("src"); + subProject.setSourceDirs("src"); root.addSubProject(subProject); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java index ed13c6a719c..93b9bcdfefa 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java @@ -19,6 +19,7 @@ */ package org.sonar.api.batch.bootstrap; +import org.hamcrest.CoreMatchers; import org.junit.Test; import org.sonar.api.CoreProperties; @@ -29,19 +30,20 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.hasItem; public class ProjectDefinitionTest { @Test public void shouldSetKey() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition def = ProjectDefinition.create(); def.setKey("mykey"); assertThat(def.getKey(), is("mykey")); } @Test public void shouldSetOptionalFields() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition def = ProjectDefinition.create(); def.setName("myname"); def.setDescription("desc"); assertThat(def.getName(), is("myname")); @@ -50,7 +52,7 @@ public class ProjectDefinitionTest { @Test public void shouldSupportDefaultName() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition def = ProjectDefinition.create(); def.setKey("myKey"); assertThat(def.getName(), is("Unnamed - myKey")); } @@ -58,13 +60,14 @@ public class ProjectDefinitionTest { public void shouldGetKeyFromProperties() { Properties props = new Properties(); props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), props); + ProjectDefinition def = ProjectDefinition.create(); + def.setProperties(props); assertThat(def.getKey(), is("foo")); } @Test public void testDefaultValues() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition def = ProjectDefinition.create(); assertThat(def.getSourceDirs().size(), is(0)); assertThat(def.getTestDirs().size(), is(0)); assertThat(def.getBinaries().size(), is(0)); @@ -72,8 +75,8 @@ public class ProjectDefinitionTest { } @Test - public void shouldAddDirectories() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + public void shouldAddDirectoriesAsPath() { + ProjectDefinition def = ProjectDefinition.create(); def.addSourceDirs("src/main/java", "src/main/java2"); def.addTestDirs("src/test/java"); def.addTestDirs("src/test/java2"); @@ -89,8 +92,20 @@ public class ProjectDefinitionTest { } @Test + public void shouldAddDirectories() { + ProjectDefinition def = ProjectDefinition.create(); + def.addSourceDirs(new File("src/main/java"), new File("src/main/java2")); + def.addTestDirs(new File("src/test/java"), new File("src/test/java2")); + def.addBinaryDir(new File("target/classes")); + + assertThat(def.getSourceDirs().size(), is(2)); + assertThat(def.getTestDirs().size(), CoreMatchers.is(2)); + assertThat(def.getBinaries().size(), CoreMatchers.is(1)); + } + + @Test public void shouldAddFiles() { - ProjectDefinition def = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition def = ProjectDefinition.create(); def.addSourceFiles("src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); def.addTestFiles("src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); @@ -101,8 +116,8 @@ public class ProjectDefinitionTest { @Test public void shouldManageRelationships() { - ProjectDefinition root = new ProjectDefinition(new File("."), new File("."), new Properties()); - ProjectDefinition child = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition root = ProjectDefinition.create(); + ProjectDefinition child = ProjectDefinition.create(); root.addSubProject(child); assertThat(root.getSubProjects().size(), is(1)); @@ -114,7 +129,7 @@ public class ProjectDefinitionTest { @Test public void shouldResetSourceDirs() { - ProjectDefinition root = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition root = ProjectDefinition.create(); root.addSourceDirs("src", "src2/main"); assertThat(root.getSourceDirs().size(), is(2)); @@ -124,7 +139,7 @@ public class ProjectDefinitionTest { @Test public void shouldResetTestDirs() { - ProjectDefinition root = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition root = ProjectDefinition.create(); root.addTestDirs("src", "src2/test"); assertThat(root.getTestDirs().size(), is(2)); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java index 4385cb1455a..59035cd4dd4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java @@ -31,8 +31,8 @@ public class ProjectReactorTest { @Test public void shouldSupportMultipleProjects() { - ProjectDefinition root = new ProjectDefinition(new File("."), new File("."), new Properties()); - ProjectDefinition child = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition root = ProjectDefinition.create(); + ProjectDefinition child = ProjectDefinition.create(); root.addSubProject(child); ProjectReactor reactor = new ProjectReactor(root); @@ -42,8 +42,8 @@ public class ProjectReactorTest { @Test(expected = IllegalArgumentException.class) public void shouldFailIfNotRoot() { - ProjectDefinition root = new ProjectDefinition(new File("."), new File("."), new Properties()); - ProjectDefinition child = new ProjectDefinition(new File("."), new File("."), new Properties()); + ProjectDefinition root = ProjectDefinition.create(); + ProjectDefinition child = ProjectDefinition.create(); root.addSubProject(child); new ProjectReactor(child); |