diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-01-25 16:56:59 +0300 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-01-25 16:56:59 +0300 |
commit | 8bc595e68b9eb635570c358091527836ac798802 (patch) | |
tree | ab79d62de724630bf4b4072b38c59adc7915a390 /sonar-batch | |
parent | 0effb8e5016195ace8a295d44eaa245e265ff0b7 (diff) | |
download | sonarqube-8bc595e68b9eb635570c358091527836ac798802.tar.gz sonarqube-8bc595e68b9eb635570c358091527836ac798802.zip |
Use default value for property "project.build.directory"
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java | 2 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java | 69 |
2 files changed, 44 insertions, 27 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java index af82ba42faf..f1b05d90df2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java @@ -78,7 +78,7 @@ public class InMemoryPomCreator { pom.setArtifacts(Collections.EMPTY_SET); // Configure fake directories - String buildDirectory = getPropertyOrDie(properties, "project.build.directory"); + String buildDirectory = properties.getProperty("project.build.directory", project.getBaseDir().getAbsolutePath() + "/target"); pom.getBuild().setDirectory(buildDirectory); String buildOutputDirectory = properties.getProperty("project.build.outputDirectory", buildDirectory + "/classes"); pom.getBuild().setOutputDirectory(buildOutputDirectory); diff --git a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java index b9336e43deb..b46e2abb42b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java @@ -45,12 +45,8 @@ public class InMemoryPomCreatorTest { } @Test - public void shouldCreate() throws Exception { - createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "target"); - properties.setProperty("sonar.projectBinaries", "junit.jar"); - - project.addSourceDir("src"); - project.addTestDir("test"); + public void minimal() { + createRequiredProperties(); MavenProject pom = create(); @@ -58,45 +54,73 @@ public class InMemoryPomCreatorTest { assertThat(pom.getGroupId(), is("org.example")); assertThat(pom.getArtifactId(), is("example")); assertThat(pom.getProperties(), is(project.getProperties())); - assertThat(pom.getBuild().getDirectory(), is("target")); - assertThat(pom.getBuild().getOutputDirectory(), is("target/classes")); - assertThat(pom.getReporting().getOutputDirectory(), is("target/site")); + } + + @Test + public void sourceDirectories() { + createRequiredProperties(); + properties.setProperty("sonar.projectBinaries", "junit.jar"); + project.addSourceDir("src"); + project.addTestDir("test"); + + MavenProject pom = create(); assertThat(pom.getCompileSourceRoots().size(), is(1)); assertThat((String) pom.getCompileSourceRoots().get(0), is("src")); assertThat(pom.getTestCompileSourceRoots().size(), is(1)); assertThat((String) pom.getTestCompileSourceRoots().get(0), is("test")); + } + + @Test + public void classpath() throws Exception { + createRequiredProperties(); + properties.setProperty("sonar.projectBinaries", "junit.jar"); + + MavenProject pom = create(); assertThat(pom.getCompileClasspathElements().size(), is(1)); assertThat((String) pom.getCompileClasspathElements().get(0), is("junit.jar")); } @Test + public void standardDirectoriesLayout() { + createRequiredProperties(); + + MavenProject pom = create(); + + assertThat(pom.getBasedir(), is(project.getBaseDir())); + String buildDirectory = new File(project.getBaseDir(), "/target").getAbsolutePath(); + assertThat(pom.getBuild().getDirectory(), is(buildDirectory)); + assertThat(pom.getBuild().getOutputDirectory(), is(buildDirectory + "/classes")); + assertThat(pom.getReporting().getOutputDirectory(), is(buildDirectory + "/site")); + } + + @Test public void nonStandardDirectoriesLayout() { - createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "build"); - properties.setProperty("project.build.outputDirectory", "bin"); - properties.setProperty("project.reporting.outputDirectory", "build/reports"); + createRequiredProperties(); + properties.setProperty("project.build.directory", "build"); + properties.setProperty("project.build.outputDirectory", "classes"); + properties.setProperty("project.reporting.outputDirectory", "reports"); MavenProject pom = create(); assertThat(pom.getBuild().getDirectory(), is("build")); - assertThat(pom.getBuild().getOutputDirectory(), is("bin")); - assertThat(pom.getReporting().getOutputDirectory(), is("build/reports")); + assertThat(pom.getBuild().getOutputDirectory(), is("classes")); + assertThat(pom.getReporting().getOutputDirectory(), is("reports")); } @Test public void shouldNotFailIfNoBinaries() throws Exception { - createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "build"); + createRequiredProperties(); MavenProject pom = create(); assertThat(pom.getCompileClasspathElements().size(), is(0)); } - private void createRequiredProperties(String key, String version, String buildDirectory) { - properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, key); - properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, version); - properties.setProperty("project.build.directory", buildDirectory); + private void createRequiredProperties() { + properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example"); + properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0-SNAPSHOT"); } @Test(expected = SonarException.class) @@ -110,13 +134,6 @@ public class InMemoryPomCreatorTest { create(); } - @Test(expected = SonarException.class) - public void shouldFailWhenBuildDirectoryNotSpecified() { - properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example"); - properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "0.1"); - create(); - } - private MavenProject create() { return new InMemoryPomCreator(project).create(); } |