]> source.dussan.org Git - sonarqube.git/commitdiff
Use default value for property "project.build.directory"
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 25 Jan 2011 13:56:59 +0000 (16:56 +0300)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 25 Jan 2011 13:56:59 +0000 (16:56 +0300)
sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java
sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java

index af82ba42faf5b9cf376685a6bb8f0b5a486aaad9..f1b05d90df29a71e1972f9caa1eba692b4b564a8 100644 (file)
@@ -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);
index b9336e43deb63ce4a1f86a515ffb2202b11eaf53..b46e2abb42bbda3d16982a8f6330abc4649b3f23 100644 (file)
@@ -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();
   }