]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4433 New ProjectBootstrapper extension point
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 24 Jun 2013 09:53:07 +0000 (11:53 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 24 Jun 2013 10:09:16 +0000 (12:09 +0200)
72 files changed:
plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenBatchPlugin.java
plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBootstrapper.java [new file with mode: 0644]
plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java
plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java [deleted file]
plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/package-info.java [new file with mode: 0644]
plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/MavenProjectConverterTest.java
plugins/sonar-maven-batch-plugin/src/test/java/org/sonar/plugins/maven/SonarMavenProjectBuilderTest.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java
sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/java/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module1/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module2/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/modules/module1/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/any-file.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/module1/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-basedir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-file/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/module1/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/module1/src/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/exclude.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/include.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetFile/foo.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetList/foo.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib1.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib2.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/lib/Fake.class [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-source-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib1.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib2.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sources/Fake.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBootstrapper.java [new file with mode: 0644]

index aac1e709fbf2f8fb711972f14384880fb82ff412..a86881c603656866cbf3ddef92319a6db7c0287c 100644 (file)
@@ -27,6 +27,6 @@ import java.util.List;
 public final class MavenBatchPlugin extends SonarPlugin {
 
   public List getExtensions() {
-    return ImmutableList.of(SonarMavenProjectBuilder.class, RealMavenPluginExecutor.class, MavenProjectConverter.class);
+    return ImmutableList.of(MavenProjectBootstrapper.class, RealMavenPluginExecutor.class, MavenProjectConverter.class);
   }
 }
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBootstrapper.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectBootstrapper.java
new file mode 100644 (file)
index 0000000..48fbdb9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.plugins.maven;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.sonar.api.batch.SupportedEnvironment;
+import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+
+import java.util.List;
+
+@SupportedEnvironment("maven")
+public class MavenProjectBootstrapper extends ProjectBootstrapper {
+
+  private MavenSession session;
+  private MavenProjectConverter mavenProjectConverter;
+
+  public MavenProjectBootstrapper(MavenSession session, MavenProjectConverter mavenProjectConverter) {
+    this.session = session;
+    this.mavenProjectConverter = mavenProjectConverter;
+  }
+
+  @Override
+  public ProjectReactor bootstrap() {
+    // Don't use session.getTopLevelProject or session.getProjects to keep compatibility with Maven 2
+    List<MavenProject> sortedProjects = session.getSortedProjects();
+    MavenProject topLevelProject = null;
+    for (MavenProject project : sortedProjects) {
+      if (project.isExecutionRoot()) {
+        topLevelProject = project;
+        break;
+      }
+    }
+    return new ProjectReactor(mavenProjectConverter.configure(sortedProjects, topLevelProject));
+  }
+
+}
index 3e5a900e2a595e614ae0de87c680524ecaa1ea46..c6ac61c728d3d07aee4d94ad59782a0362a1bf45 100644 (file)
@@ -29,11 +29,10 @@ import org.apache.maven.model.CiManagement;
 import org.apache.maven.model.IssueManagement;
 import org.apache.maven.model.Scm;
 import org.apache.maven.project.MavenProject;
-import org.sonar.api.BatchExtension;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.maven.MavenUtils;
+import org.sonar.api.task.TaskExtension;
 import org.sonar.api.utils.SonarException;
 import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
 import org.sonar.java.api.JavaUtils;
@@ -44,19 +43,12 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public class MavenProjectConverter implements BatchExtension {
+public class MavenProjectConverter implements TaskExtension {
 
   private static final String UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE = "Unable to determine structure of project." +
     " Probably you use Maven Advanced Reactor Options, which is not supported by Sonar and should not be used.";
 
-  public ProjectDefinition convert(List<MavenProject> poms, MavenProject root) {
-    ProjectDefinition def = ProjectDefinition.create();
-    configure(def, poms, root);
-    return def;
-  }
-
-  public void configure(ProjectDefinition rootProjectDefinition, List<MavenProject> poms, MavenProject root) {
+  public ProjectDefinition configure(List<MavenProject> poms, MavenProject root) {
     // projects by canonical path to pom.xml
     Map<String, MavenProject> paths = Maps.newHashMap();
     Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap();
@@ -64,7 +56,7 @@ public class MavenProjectConverter implements BatchExtension {
     try {
       for (MavenProject pom : poms) {
         paths.put(pom.getFile().getCanonicalPath(), pom);
-        ProjectDefinition def = pom == root ? rootProjectDefinition : ProjectDefinition.create();
+        ProjectDefinition def = ProjectDefinition.create();
         merge(pom, def);
         defs.put(pom, def);
       }
@@ -95,6 +87,7 @@ public class MavenProjectConverter implements BatchExtension {
     if (rootProject == null) {
       throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE);
     }
+    return rootProject;
   }
 
   private static MavenProject findMavenProject(final File modulePath, Map<String, MavenProject> paths) throws IOException {
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/SonarMavenProjectBuilder.java
deleted file mode 100644 (file)
index d2a648f..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.plugins.maven;
-
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.project.MavenProject;
-import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.batch.bootstrap.ProjectBuilder;
-import org.sonar.api.batch.bootstrap.ProjectBuilderContext;
-
-import java.util.List;
-
-@SupportedEnvironment("maven")
-public class SonarMavenProjectBuilder extends ProjectBuilder {
-
-  private MavenSession session;
-  private MavenProjectConverter mavenProjectConverter;
-
-  public SonarMavenProjectBuilder(MavenSession session, MavenProjectConverter mavenProjectConverter) {
-    this.session = session;
-    this.mavenProjectConverter = mavenProjectConverter;
-  }
-
-  @Override
-  public void build(ProjectBuilderContext context) {
-    // Don't use session.getTopLevelProject or session.getProjects to keep compatibility with Maven 2
-    List<MavenProject> sortedProjects = session.getSortedProjects();
-    MavenProject topLevelProject = null;
-    for (MavenProject project : sortedProjects) {
-      if (project.isExecutionRoot()) {
-        topLevelProject = project;
-        break;
-      }
-    }
-    mavenProjectConverter.configure(context.getProjectReactor().getRoot(), sortedProjects, topLevelProject);
-  }
-
-}
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/package-info.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/package-info.java
new file mode 100644 (file)
index 0000000..2ba97cb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * This package is a part of bootstrap process, so we should take care about backward compatibility.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.plugins.maven;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 604a9bf82c19f6f044057e1d806f5e6b07611ede..4c25ec45c40aa82bbbf797efa05ea15e1c58e933 100644 (file)
@@ -64,7 +64,7 @@ public class MavenProjectConverterTest {
     root.getModules().add("module/pom.xml");
 
     try {
-      mavenProjectConverter.convert(Arrays.asList(root), root);
+      mavenProjectConverter.configure(Arrays.asList(root), root);
       fail();
     } catch (IllegalStateException e) {
       assertThat(e.getMessage(), containsString("Advanced Reactor Options"));
@@ -84,7 +84,7 @@ public class MavenProjectConverterTest {
     module.setFile(new File(basedir, "module/pom.xml"));
     module.getBuild().setDirectory("target");
     module.getBuild().setOutputDirectory("target/classes");
-    ProjectDefinition project = mavenProjectConverter.convert(Arrays.asList(root, module), root);
+    ProjectDefinition project = mavenProjectConverter.configure(Arrays.asList(root, module), root);
 
     assertThat(project.getSubProjects().size(), is(1));
   }
@@ -124,7 +124,7 @@ public class MavenProjectConverterTest {
     MavenProject module1 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false);
     MavenProject module2 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(parent, module1, module2), parent);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(parent, module1, module2), parent);
 
     assertThat(rootDef.getSubProjects().size(), Is.is(2));
     assertThat(rootDef.getKey(), Is.is("org.test:parent"));
@@ -145,7 +145,7 @@ public class MavenProjectConverterTest {
     MavenProject module1 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false);
     MavenProject module2 = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(parent, module1, module2), parent);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(parent, module1, module2), parent);
 
     assertThat(rootDef.getSubProjects().size(), is(2));
     assertThat(rootDef.getKey(), is("org.test:parent"));
@@ -165,7 +165,7 @@ public class MavenProjectConverterTest {
     MavenProject parent = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true);
     MavenProject module = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(parent, module), parent);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(parent, module), parent);
 
     assertThat(rootDef.getSubProjects().size(), Is.is(1));
     assertThat(rootDef.getKey(), Is.is("org.test:parent"));
@@ -184,7 +184,7 @@ public class MavenProjectConverterTest {
     File rootDir = TestUtils.getResource("/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/");
     MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(pom), pom);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(pom), pom);
 
     assertThat(rootDef.getKey(), is("org.test:parent"));
     assertThat(rootDef.getSubProjects().size(), is(0));
@@ -196,7 +196,7 @@ public class MavenProjectConverterTest {
   public void shouldConvertLinksToProperties() throws Exception {
     MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinks/pom.xml", true);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(pom), pom);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(pom), pom);
 
     Properties props = rootDef.getProperties();
     assertThat(props.getProperty(CoreProperties.LINKS_HOME_PAGE)).isEqualTo("http://home.com");
@@ -210,7 +210,7 @@ public class MavenProjectConverterTest {
   public void shouldNotConvertLinksToPropertiesIfPropertyAlreadyDefined() throws Exception {
     MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml", true);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(pom), pom);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(pom), pom);
 
     Properties props = rootDef.getProperties();
 
@@ -228,7 +228,7 @@ public class MavenProjectConverterTest {
   public void shouldLoadSourceEncoding() throws Exception {
     MavenProject pom = loadPom("/org/sonar/plugins/maven/MavenProjectConverterTest/sourceEncoding/pom.xml", true);
 
-    ProjectDefinition rootDef = mavenProjectConverter.convert(Arrays.asList(pom), pom);
+    ProjectDefinition rootDef = mavenProjectConverter.configure(Arrays.asList(pom), pom);
 
     assertThat(rootDef.getProperties().getProperty(CoreProperties.ENCODING_PROPERTY)).isEqualTo("Shift_JIS");
   }
index d631b60e617894ff68844d0a5308b28bb3892ea0..f99b4e32b474663078dce48de6728a8776391a13 100644 (file)
@@ -23,14 +23,13 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.project.MavenProject;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.batch.bootstrap.ProjectBuilderContext;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
 
 import java.util.Arrays;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -46,17 +45,14 @@ public class SonarMavenProjectBuilderTest {
     when(session.getSortedProjects()).thenReturn(Arrays.asList(rootProject));
 
     MavenProjectConverter mavenProjectConverter = mock(MavenProjectConverter.class);
-    SonarMavenProjectBuilder builder = new SonarMavenProjectBuilder(session, mavenProjectConverter);
+    ProjectDefinition projectDefinition = ProjectDefinition.create();
+    when(mavenProjectConverter.configure(any(List.class), any(MavenProject.class))).thenReturn(projectDefinition);
+    MavenProjectBootstrapper builder = new MavenProjectBootstrapper(session, mavenProjectConverter);
 
-    ProjectBuilderContext context = mock(ProjectBuilderContext.class);
-    ProjectDefinition root = ProjectDefinition.create();
-    ProjectReactor reactor = new ProjectReactor(root);
-    when(context.getProjectReactor()).thenReturn(reactor);
-
-    builder.build(context);
+    assertThat(builder.bootstrap().getRoot()).isEqualTo(projectDefinition);
 
     ArgumentCaptor<List> argument = ArgumentCaptor.forClass(List.class);
-    verify(mavenProjectConverter).configure(eq(root), argument.capture(), eq(rootProject));
+    verify(mavenProjectConverter).configure(argument.capture(), eq(rootProject));
     assertThat(argument.getValue()).contains(rootProject);
   }
 
@@ -72,17 +68,14 @@ public class SonarMavenProjectBuilderTest {
     when(session.getSortedProjects()).thenReturn(Arrays.asList(module1, module2, rootProject));
 
     MavenProjectConverter mavenProjectConverter = mock(MavenProjectConverter.class);
-    SonarMavenProjectBuilder builder = new SonarMavenProjectBuilder(session, mavenProjectConverter);
-
-    ProjectBuilderContext context = mock(ProjectBuilderContext.class);
-    ProjectDefinition root = ProjectDefinition.create();
-    ProjectReactor reactor = new ProjectReactor(root);
-    when(context.getProjectReactor()).thenReturn(reactor);
+    ProjectDefinition projectDefinition = ProjectDefinition.create();
+    when(mavenProjectConverter.configure(any(List.class), any(MavenProject.class))).thenReturn(projectDefinition);
+    MavenProjectBootstrapper builder = new MavenProjectBootstrapper(session, mavenProjectConverter);
 
-    builder.build(context);
+    assertThat(builder.bootstrap().getRoot()).isEqualTo(projectDefinition);
 
     ArgumentCaptor<List> argument = ArgumentCaptor.forClass(List.class);
-    verify(mavenProjectConverter).configure(eq(root), argument.capture(), eq(rootProject));
+    verify(mavenProjectConverter).configure(argument.capture(), eq(rootProject));
     assertThat(argument.getValue()).contains(module1, module2, rootProject);
   }
 
index 5503d5f03defcebe1f60d8ed582cb0b00c7d22a3..94b362d04e7018618887828839183d06de2d85ee 100644 (file)
@@ -39,6 +39,10 @@ public final class Batch {
   private LoggingConfiguration logging;
   private List<Object> components;
   private Map<String, String> bootstrapProperties = Maps.newHashMap();
+  /**
+   * @deprecated since 3.7
+   */
+  @Deprecated
   private ProjectReactor projectReactor;
 
   private Batch(Builder builder) {
@@ -50,8 +54,10 @@ public final class Batch {
     if (builder.bootstrapProperties != null) {
       bootstrapProperties.putAll(builder.bootstrapProperties);
     } else {
-      // For backward compatibility, previously all properties were set in root project
-      bootstrapProperties.putAll(Maps.fromProperties(builder.projectReactor.getRoot().getProperties()));
+      if (builder.projectReactor != null) {
+        // For backward compatibility, previously all properties were set in root project
+        bootstrapProperties.putAll(Maps.fromProperties(builder.projectReactor.getRoot().getProperties()));
+      }
     }
     projectReactor = builder.projectReactor;
     if (builder.isEnableLoggingConfiguration()) {
@@ -92,6 +98,10 @@ public final class Batch {
 
   public static final class Builder {
     private Map<String, String> bootstrapProperties;
+    /**
+     * @deprecated since 3.7
+     */
+    @Deprecated
     private ProjectReactor projectReactor;
     private EnvironmentInformation environment;
     private List<Object> components = Lists.newArrayList();
@@ -100,6 +110,10 @@ public final class Batch {
     private Builder() {
     }
 
+    /**
+     * @deprecated since 3.7
+     */
+    @Deprecated
     public Builder setProjectReactor(ProjectReactor projectReactor) {
       this.projectReactor = projectReactor;
       return this;
@@ -115,11 +129,20 @@ public final class Batch {
       return this;
     }
 
+    /**
+     * @deprecated since 3.7 use {@link #setBootstrapProperties(Map)}
+     */
+    @Deprecated
     public Builder setGlobalProperties(Map<String, String> globalProperties) {
       this.bootstrapProperties = globalProperties;
       return this;
     }
 
+    public Builder setBootstrapProperties(Map<String, String> bootstrapProperties) {
+      this.bootstrapProperties = bootstrapProperties;
+      return this;
+    }
+
     public Builder addComponents(Object... components) {
       Collections.addAll(this.components, components);
       return this;
index 75b1dd4af93a623d93767034c282cdbcea647ff7..5fdce9f98803b6e05defd933be888c4fd34c65ba 100644 (file)
@@ -21,5 +21,8 @@
 /**
  * This package is a part of bootstrap process, so we should take care about backward compatibility.
  */
+@ParametersAreNonnullByDefault
 package org.sonar.batch.bootstrapper;
 
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java
new file mode 100644 (file)
index 0000000..711fe00
--- /dev/null
@@ -0,0 +1,544 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.FileFileFilter;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+/**
+ * Class that creates a Sonar project definition based on a set of properties.
+ */
+class DefaultProjectBootstrapper extends ProjectBootstrapper {
+
+  private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectBootstrapper.class);
+
+  private static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir";
+  private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
+  private static final String PROPERTY_PROJECT_KEY = "sonar.projectKey";
+  private static final String PROPERTY_PROJECT_NAME = "sonar.projectName";
+  private static final String PROPERTY_PROJECT_DESCRIPTION = "sonar.projectDescription";
+  private static final String PROPERTY_PROJECT_VERSION = "sonar.projectVersion";
+  private static final String PROPERTY_MODULES = "sonar.modules";
+
+  /**
+   * New properties, to be consistent with Sonar naming conventions
+   *
+   * @since 1.5
+   */
+  private static final String PROPERTY_SOURCES = "sonar.sources";
+  private static final String PROPERTY_TESTS = "sonar.tests";
+  private static final String PROPERTY_BINARIES = "sonar.binaries";
+  private static final String PROPERTY_LIBRARIES = "sonar.libraries";
+
+  /**
+   * Old deprecated properties, replaced by the same ones preceded by "sonar."
+   */
+  private static final String PROPERTY_OLD_SOURCES = "sources";
+  private static final String PROPERTY_OLD_TESTS = "tests";
+  private static final String PROPERTY_OLD_BINARIES = "binaries";
+  private static final String PROPERTY_OLD_LIBRARIES = "libraries";
+  private static final Map<String, String> DEPRECATED_PROPS_TO_NEW_PROPS = new HashMap<String, String>() {
+    {
+      put(PROPERTY_OLD_SOURCES, PROPERTY_SOURCES);
+      put(PROPERTY_OLD_TESTS, PROPERTY_TESTS);
+      put(PROPERTY_OLD_BINARIES, PROPERTY_BINARIES);
+      put(PROPERTY_OLD_LIBRARIES, PROPERTY_LIBRARIES);
+    }
+  };
+
+  /**
+   * @since 1.4
+   */
+  private static final String PROPERTY_WORK_DIRECTORY = "sonar.working.directory";
+  private static final String DEF_VALUE_WORK_DIRECTORY = ".sonar";
+
+  /**
+   * Array of all mandatory properties required for a project without child.
+   */
+  private static final String[] MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT = {
+    PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION
+  };
+
+  /**
+   * Array of all mandatory properties required for a project with children.
+   */
+  private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION};
+
+  /**
+   * Array of all mandatory properties required for a child project before its properties get merged with its parent ones.
+   */
+  private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME};
+
+  /**
+   * Properties that must not be passed from the parent project to its children.
+   */
+  private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, PROPERTY_MODULES, PROPERTY_PROJECT_DESCRIPTION);
+
+  private Settings settings;
+  private File rootProjectWorkDir;
+
+  DefaultProjectBootstrapper(Settings settings) {
+    this.settings = settings;
+  }
+
+  @Override
+  public ProjectReactor bootstrap() {
+    Properties bootstrapProperties = new Properties();
+    bootstrapProperties.putAll(settings.getProperties());
+    ProjectDefinition rootProject = defineProject(bootstrapProperties, null);
+    rootProjectWorkDir = rootProject.getWorkDir();
+    defineChildren(rootProject);
+    cleanAndCheckProjectDefinitions(rootProject);
+    return new ProjectReactor(rootProject);
+  }
+
+  private ProjectDefinition defineProject(Properties properties, ProjectDefinition parent) {
+    File baseDir = new File(properties.getProperty(PROPERTY_PROJECT_BASEDIR));
+    if (properties.containsKey(PROPERTY_MODULES)) {
+      checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT);
+    } else {
+      checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT);
+    }
+    File workDir;
+    if (parent == null) {
+      validateDirectories(properties, baseDir, properties.getProperty(PROPERTY_PROJECT_KEY));
+      workDir = initRootProjectWorkDir(baseDir);
+    } else {
+      workDir = initModuleWorkDir(properties);
+    }
+
+    ProjectDefinition definition = ProjectDefinition.create().setProperties(properties)
+        .setBaseDir(baseDir)
+        .setWorkDir(workDir);
+    return definition;
+  }
+
+  @VisibleForTesting
+  protected File initRootProjectWorkDir(File baseDir) {
+    String workDir = settings.getString(PROPERTY_WORK_DIRECTORY);
+    if (StringUtils.isBlank(workDir)) {
+      return new File(baseDir, DEF_VALUE_WORK_DIRECTORY);
+    }
+
+    File customWorkDir = new File(workDir);
+    if (customWorkDir.isAbsolute()) {
+      return customWorkDir;
+    }
+    return new File(baseDir, customWorkDir.getPath());
+  }
+
+  @VisibleForTesting
+  protected File initModuleWorkDir(Properties properties) {
+    String cleanKey = StringUtils.deleteWhitespace(properties.getProperty(PROPERTY_PROJECT_KEY));
+    cleanKey = StringUtils.replace(cleanKey, ":", "_");
+    return new File(rootProjectWorkDir, cleanKey);
+  }
+
+  private void defineChildren(ProjectDefinition parentProject) {
+    Properties parentProps = parentProject.getProperties();
+    if (parentProps.containsKey(PROPERTY_MODULES)) {
+      for (String module : getListFromProperty(parentProps, PROPERTY_MODULES)) {
+        Properties moduleProps = extractModuleProperties(module, parentProps);
+        ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, module);
+        // check the uniqueness of the child key
+        checkUniquenessOfChildKey(childProject, parentProject);
+        // the child project may have children as well
+        defineChildren(childProject);
+        // and finally add this child project to its parent
+        parentProject.addSubProject(childProject);
+      }
+    }
+  }
+
+  private ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
+    setProjectKeyAndNameIfNotDefined(moduleProps, moduleId);
+
+    final File baseDir;
+    if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
+      baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
+      setProjectBaseDir(baseDir, moduleProps, moduleId);
+      try {
+        if (!parentProject.getBaseDir().getCanonicalFile().equals(baseDir.getCanonicalFile())) {
+          tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+        }
+      } catch (IOException e) {
+        throw new IllegalStateException("Error when resolving baseDir", e);
+      }
+    } else if (moduleProps.containsKey(PROPERTY_PROJECT_CONFIG_FILE)) {
+      baseDir = loadPropsFile(parentProject, moduleProps, moduleId);
+    } else {
+      baseDir = new File(parentProject.getBaseDir(), moduleId);
+      setProjectBaseDir(baseDir, moduleProps, moduleId);
+      tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+    }
+
+    // and finish
+    checkMandatoryProperties(moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
+    validateDirectories(moduleProps, baseDir, moduleId);
+
+    mergeParentProperties(moduleProps, parentProject.getProperties());
+
+    prefixProjectKeyWithParentKey(moduleProps, parentProject.getKey());
+
+    return defineProject(moduleProps, parentProject);
+  }
+
+  /**
+   * @return baseDir
+   */
+  protected File loadPropsFile(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
+    File propertyFile = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_CONFIG_FILE), parentProject.getBaseDir());
+    if (propertyFile.isFile()) {
+      Properties propsFromFile = toProperties(propertyFile);
+      for (Entry<Object, Object> entry : propsFromFile.entrySet()) {
+        moduleProps.put(entry.getKey(), entry.getValue());
+      }
+      File baseDir = null;
+      if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
+        baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), propertyFile.getParentFile());
+      } else {
+        baseDir = propertyFile.getParentFile();
+      }
+      setProjectBaseDir(baseDir, moduleProps, moduleId);
+      return baseDir;
+    } else {
+      throw new IllegalStateException("The properties file of the module '" + moduleId + "' does not exist: " + propertyFile.getAbsolutePath());
+    }
+  }
+
+  private void tryToFindAndLoadPropsFile(File baseDir, Properties moduleProps, String moduleId) {
+    File propertyFile = new File(baseDir, "sonar-project.properties");
+    if (propertyFile.isFile()) {
+      Properties propsFromFile = toProperties(propertyFile);
+      for (Entry<Object, Object> entry : propsFromFile.entrySet()) {
+        moduleProps.put(entry.getKey(), entry.getValue());
+      }
+      if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
+        File overwrittenBaseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), propertyFile.getParentFile());
+        setProjectBaseDir(overwrittenBaseDir, moduleProps, moduleId);
+      }
+    }
+  }
+
+  @VisibleForTesting
+  protected static Properties toProperties(File propertyFile) {
+    Properties propsFromFile = new Properties();
+    FileInputStream fileInputStream = null;
+    try {
+      fileInputStream = new FileInputStream(propertyFile);
+      propsFromFile.load(fileInputStream);
+    } catch (IOException e) {
+      throw new IllegalStateException("Impossible to read the property file: " + propertyFile.getAbsolutePath(), e);
+    } finally {
+      IOUtils.closeQuietly(fileInputStream);
+    }
+    return propsFromFile;
+  }
+
+  @VisibleForTesting
+  protected static void setProjectKeyAndNameIfNotDefined(Properties childProps, String moduleId) {
+    if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
+      childProps.put(PROPERTY_PROJECT_KEY, moduleId);
+    }
+    if (!childProps.containsKey(PROPERTY_PROJECT_NAME)) {
+      childProps.put(PROPERTY_PROJECT_NAME, moduleId);
+    }
+  }
+
+  @VisibleForTesting
+  protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
+    for (ProjectDefinition definition : parentProject.getSubProjects()) {
+      if (definition.getKey().equals(childProject.getKey())) {
+        throw new IllegalStateException("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey());
+      }
+    }
+  }
+
+  @VisibleForTesting
+  protected static void prefixProjectKeyWithParentKey(Properties childProps, String parentKey) {
+    String childKey = childProps.getProperty(PROPERTY_PROJECT_KEY);
+    childProps.put(PROPERTY_PROJECT_KEY, parentKey + ":" + childKey);
+  }
+
+  private static void setProjectBaseDir(File baseDir, Properties childProps, String moduleId) {
+    if (!baseDir.isDirectory()) {
+      throw new IllegalStateException("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath());
+    }
+    childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath());
+  }
+
+  @VisibleForTesting
+  protected static void checkMandatoryProperties(Properties props, String[] mandatoryProps) {
+    replaceDeprecatedProperties(props);
+    StringBuilder missing = new StringBuilder();
+    for (String mandatoryProperty : mandatoryProps) {
+      if (!props.containsKey(mandatoryProperty)) {
+        if (missing.length() > 0) {
+          missing.append(", ");
+        }
+        missing.append(mandatoryProperty);
+      }
+    }
+    String projectKey = props.getProperty(PROPERTY_PROJECT_KEY);
+    if (missing.length() != 0) {
+      throw new IllegalStateException("You must define the following mandatory properties for '" + (projectKey == null ? "Unknown" : projectKey) + "': " + missing);
+    }
+  }
+
+  private static void validateDirectories(Properties props, File baseDir, String projectId) {
+    if (!props.containsKey(PROPERTY_MODULES)) {
+      // SONARPLUGINS-2285 Not an aggregator project so we can validate that paths are correct if defined
+
+      // We need to resolve patterns that may have been used in "sonar.libraries"
+      for (String pattern : getListFromProperty(props, PROPERTY_LIBRARIES)) {
+        File[] files = getLibraries(baseDir, pattern);
+        if (files == null || files.length == 0) {
+          LOG.error("Invalid value of " + PROPERTY_LIBRARIES + " for " + projectId);
+          throw new IllegalStateException("No files nor directories matching '" + pattern + "' in directory " + baseDir);
+        }
+      }
+
+      // Check sonar.tests
+      String[] testDirs = getListFromProperty(props, PROPERTY_TESTS);
+      checkExistenceOfDirectories(projectId, baseDir, testDirs, PROPERTY_TESTS);
+
+      // Check sonar.binaries
+      String[] binDirs = getListFromProperty(props, PROPERTY_BINARIES);
+      checkExistenceOfDirectories(projectId, baseDir, binDirs, PROPERTY_BINARIES);
+    }
+  }
+
+  @VisibleForTesting
+  protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) {
+    if (project.getSubProjects().isEmpty()) {
+      cleanAndCheckModuleProperties(project);
+    } else {
+      cleanAndCheckAggregatorProjectProperties(project);
+
+      // clean modules properties as well
+      for (ProjectDefinition module : project.getSubProjects()) {
+        cleanAndCheckProjectDefinitions(module);
+      }
+    }
+  }
+
+  @VisibleForTesting
+  protected static void cleanAndCheckModuleProperties(ProjectDefinition project) {
+    Properties properties = project.getProperties();
+
+    // We need to check the existence of source directories
+    String[] sourceDirs = getListFromProperty(properties, PROPERTY_SOURCES);
+    checkExistenceOfDirectories(project.getKey(), project.getBaseDir(), sourceDirs, PROPERTY_SOURCES);
+
+    // And we need to resolve patterns that may have been used in "sonar.libraries"
+    List<String> libPaths = Lists.newArrayList();
+    for (String pattern : getListFromProperty(properties, PROPERTY_LIBRARIES)) {
+      for (File file : getLibraries(project.getBaseDir(), pattern)) {
+        libPaths.add(file.getAbsolutePath());
+      }
+    }
+    properties.remove(PROPERTY_LIBRARIES);
+    properties.put(PROPERTY_LIBRARIES, StringUtils.join(libPaths, ","));
+  }
+
+  @VisibleForTesting
+  protected static void cleanAndCheckAggregatorProjectProperties(ProjectDefinition project) {
+    Properties properties = project.getProperties();
+
+    // SONARPLUGINS-2295
+    String[] sourceDirs = getListFromProperty(properties, PROPERTY_SOURCES);
+    for (String path : sourceDirs) {
+      File sourceFolder = getFileFromPath(path, project.getBaseDir());
+      if (sourceFolder.isDirectory()) {
+        LOG.warn("/!\\ A multi-module project can't have source folders, so '{}' won't be used for the analysis. " +
+          "If you want to analyse files of this folder, you should create another sub-module and move them inside it.",
+            sourceFolder.toString());
+      }
+    }
+
+    // "aggregator" project must not have the following properties:
+    properties.remove(PROPERTY_SOURCES);
+    properties.remove(PROPERTY_TESTS);
+    properties.remove(PROPERTY_BINARIES);
+    properties.remove(PROPERTY_LIBRARIES);
+
+    // and they don't need properties related to their modules either
+    Properties clone = (Properties) properties.clone();
+    List<String> moduleIds = Lists.newArrayList(getListFromProperty(properties, PROPERTY_MODULES));
+    for (Entry<Object, Object> entry : clone.entrySet()) {
+      String key = (String) entry.getKey();
+      if (isKeyPrefixedByModuleId(key, moduleIds)) {
+        properties.remove(key);
+      }
+    }
+  }
+
+  /**
+   * Replaces the deprecated properties by the new ones, and logs a message to warn the users.
+   */
+  @VisibleForTesting
+  protected static void replaceDeprecatedProperties(Properties props) {
+    for (Entry<String, String> entry : DEPRECATED_PROPS_TO_NEW_PROPS.entrySet()) {
+      String key = entry.getKey();
+      if (props.containsKey(key)) {
+        String newKey = entry.getValue();
+        LOG.warn("/!\\ The '{}' property is deprecated and is replaced by '{}'. Don't forget to update your files.", key, newKey);
+        String value = props.getProperty(key);
+        props.remove(key);
+        props.put(newKey, value);
+      }
+    }
+
+  }
+
+  @VisibleForTesting
+  protected static void mergeParentProperties(Properties childProps, Properties parentProps) {
+    List<String> moduleIds = Lists.newArrayList(getListFromProperty(parentProps, PROPERTY_MODULES));
+    for (Map.Entry<Object, Object> entry : parentProps.entrySet()) {
+      String key = (String) entry.getKey();
+      if (!childProps.containsKey(key)
+        && !NON_HERITED_PROPERTIES_FOR_CHILD.contains(key)
+        && !isKeyPrefixedByModuleId(key, moduleIds)) {
+        childProps.put(entry.getKey(), entry.getValue());
+      }
+    }
+  }
+
+  private static boolean isKeyPrefixedByModuleId(String key, List<String> moduleIds) {
+    for (String moduleId : moduleIds) {
+      if (key.startsWith(moduleId + ".")) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @VisibleForTesting
+  protected static Properties extractModuleProperties(String module, Properties properties) {
+    Properties moduleProps = new Properties();
+    String propertyPrefix = module + ".";
+    int prefixLength = propertyPrefix.length();
+    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+      String key = (String) entry.getKey();
+      if (key.startsWith(propertyPrefix)) {
+        moduleProps.put(key.substring(prefixLength), entry.getValue());
+      }
+    }
+    return moduleProps;
+  }
+
+  @VisibleForTesting
+  protected static void checkExistenceOfDirectories(String moduleRef, File baseDir, String[] sourceDirs, String propName) {
+    for (String path : sourceDirs) {
+      File sourceFolder = getFileFromPath(path, baseDir);
+      if (!sourceFolder.isDirectory()) {
+        LOG.error("Invalid value of " + propName + " for " + moduleRef);
+        throw new IllegalStateException("The folder '" + path + "' does not exist for '" + moduleRef +
+          "' (base directory = " + baseDir.getAbsolutePath() + ")");
+      }
+    }
+
+  }
+
+  /**
+   * Returns files matching specified pattern.
+   */
+  @VisibleForTesting
+  protected static File[] getLibraries(File baseDir, String pattern) {
+    final int i = Math.max(pattern.lastIndexOf('/'), pattern.lastIndexOf('\\'));
+    final String dirPath, filePattern;
+    if (i == -1) {
+      dirPath = ".";
+      filePattern = pattern;
+    } else {
+      dirPath = pattern.substring(0, i);
+      filePattern = pattern.substring(i + 1);
+    }
+    List<IOFileFilter> filters = new ArrayList<IOFileFilter>();
+    if (pattern.indexOf('*') >= 0) {
+      filters.add(FileFileFilter.FILE);
+    }
+    filters.add(new WildcardFileFilter(filePattern));
+    File dir = resolvePath(baseDir, dirPath);
+    File[] files = dir.listFiles((FileFilter) new AndFileFilter(filters));
+    if (files == null) {
+      files = new File[0];
+    }
+    return files;
+  }
+
+  private static File resolvePath(File baseDir, String path) {
+    File file = new File(path);
+    if (!file.isAbsolute()) {
+      try {
+        file = new File(baseDir, path).getCanonicalFile();
+      } catch (IOException e) {
+        throw new IllegalStateException("Unable to resolve path \"" + path + "\"", e);
+      }
+    }
+    return file;
+  }
+
+  /**
+   * Returns the file denoted by the given path, may this path be relative to "baseDir" or absolute.
+   */
+  @VisibleForTesting
+  protected static File getFileFromPath(String path, File baseDir) {
+    File propertyFile = new File(path.trim());
+    if (!propertyFile.isAbsolute()) {
+      propertyFile = new File(baseDir, propertyFile.getPath());
+    }
+    return propertyFile;
+  }
+
+  /**
+   * Transforms a comma-separated list String property in to a array of trimmed strings.
+   *
+   * This works even if they are separated by whitespace characters (space char, EOL, ...)
+   *
+   */
+  static String[] getListFromProperty(Properties properties, String key) {
+    return StringUtils.stripAll(StringUtils.split(properties.getProperty(key, ""), ','));
+  }
+
+}
index 06030f10f2aaeb9ed2ac389bdca570171e2a758b..234fe0f1813e3c0c9615e85d7e76673859845c53 100644 (file)
@@ -23,9 +23,12 @@ import com.google.common.annotations.VisibleForTesting;
 import org.sonar.api.BatchExtension;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.resources.Project;
+import org.sonar.api.utils.SonarException;
 import org.sonar.batch.DefaultFileLinesContextFactory;
 import org.sonar.batch.DefaultResourceCreationLock;
 import org.sonar.batch.ProjectConfigurator;
@@ -76,6 +79,7 @@ public class ProjectScanContainer extends ComponentContainer {
 
   @Override
   protected void doBeforeStart() {
+    projectBootstrap();
     addBatchComponents();
     fixMavenExecutor();
     addBatchExtensions();
@@ -85,6 +89,26 @@ public class ProjectScanContainer extends ComponentContainer {
     }
   }
 
+  private void projectBootstrap() {
+    // Old versions of bootstrappers used to pass project reactor as an extension
+    // so check if it is already present in parent container
+    ProjectReactor reactor = getComponentByType(ProjectReactor.class);
+    if (reactor == null) {
+      // OK, not present, so look for a custom ProjectBootstrapper
+      ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class);
+      if (bootstrapper == null) {
+        // Use default SonarRunner project bootstrapper
+        Settings settings = getComponentByType(Settings.class);
+        bootstrapper = new DefaultProjectBootstrapper(settings);
+      }
+      reactor = bootstrapper.bootstrap();
+      if (reactor == null) {
+        throw new SonarException(bootstrapper + " has returned null as ProjectReactor");
+      }
+      add(reactor);
+    }
+  }
+
   private void addBatchComponents() {
     add(
         DefaultResourceCreationLock.class,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java
new file mode 100644 (file)
index 0000000..3b1c641
--- /dev/null
@@ -0,0 +1,662 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultProjectBootstrapperTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void shouldDefineSimpleProject() throws IOException {
+    ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");
+
+    assertThat(projectDefinition.getKey()).isEqualTo("com.foo.project");
+    assertThat(projectDefinition.getName()).isEqualTo("Foo Project");
+    assertThat(projectDefinition.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project");
+    assertThat(projectDefinition.getSourceDirs()).contains("sources");
+    assertThat(projectDefinition.getLibraries()).contains(TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath(),
+        TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
+  }
+
+  @Test
+  public void shouldDefineSimpleProjectWithDeprecatedProperties() throws IOException {
+    ProjectDefinition projectDefinition = loadProjectDefinition("simple-project-with-deprecated-props");
+
+    assertThat(projectDefinition.getSourceDirs()).contains("sources");
+    assertThat(projectDefinition.getLibraries()).contains(
+        TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath(),
+        TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath());
+  }
+
+  @Test
+  public void shouldFailIfUnexistingSourceDirectory() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = "
+      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
+
+    loadProjectDefinition("simple-project-with-unexisting-source-dir");
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithDefinitionsAllInRootProject() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-all-in-root");
+
+    // CHECK ROOT
+    assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
+    assertThat(rootProject.getName()).isEqualTo("Foo Project");
+    assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
+    // root project must not contain some properties - even if they are defined in the root properties file
+    assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
+    assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
+    assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
+    // and module properties must have been cleaned
+    assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+    // Check baseDir and workDir
+    assertThat(rootProject.getBaseDir().getCanonicalFile())
+        .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
+    assertThat(rootProject.getWorkDir().getCanonicalFile())
+        .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
+
+    // CHECK MODULES
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(2);
+
+    // Module 1
+    ProjectDefinition module1 = modules.get(0);
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
+    assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
+    assertThat(module1.getName()).isEqualTo("module1");
+    assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    // Description should not be inherited from parent if not set
+    assertThat(module1.getDescription()).isNull();
+    assertThat(module1.getSourceDirs()).contains("sources");
+    assertThat(module1.getTestDirs()).contains("tests");
+    assertThat(module1.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+    // Check baseDir and workDir
+    assertThat(module1.getBaseDir().getCanonicalFile())
+        .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
+    assertThat(module1.getWorkDir().getCanonicalFile())
+        .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
+
+    // Module 2
+    ProjectDefinition module2 = modules.get(1);
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
+    assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
+    assertThat(module2.getName()).isEqualTo("Foo Module 2");
+    assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
+    assertThat(module2.getSourceDirs()).contains("src");
+    assertThat(module2.getTestDirs()).contains("tests");
+    assertThat(module2.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+    // Check baseDir and workDir
+    assertThat(module2.getBaseDir().getCanonicalFile())
+        .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
+    assertThat(module2.getWorkDir().getCanonicalFile())
+        .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithDefinitionsAllInEachModule() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module");
+
+    // CHECK ROOT
+    assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
+    assertThat(rootProject.getName()).isEqualTo("Foo Project");
+    assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
+    // root project must not contain some properties - even if they are defined in the root properties file
+    assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
+    assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
+    assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
+    // and module properties must have been cleaned
+    assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+
+    // CHECK MODULES
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(2);
+
+    // Module 1
+    ProjectDefinition module1 = modules.get(0);
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module1"));
+    assertThat(module1.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
+    assertThat(module1.getName()).isEqualTo("Foo Module 1");
+    assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    // Description should not be inherited from parent if not set
+    assertThat(module1.getDescription()).isEqualTo("Description of Module 1");
+    assertThat(module1.getSourceDirs()).contains("sources");
+    assertThat(module1.getTestDirs()).contains("tests");
+    assertThat(module1.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+
+    // Module 2
+    ProjectDefinition module2 = modules.get(1);
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module2/newBaseDir"));
+    assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
+    assertThat(module2.getName()).isEqualTo("Foo Module 2");
+    assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
+    assertThat(module2.getSourceDirs()).contains("src");
+    assertThat(module2.getTestDirs()).contains("tests");
+    assertThat(module2.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithDefinitionsModule1Inherited() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module-inherited");
+
+    // CHECK ROOT
+    assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
+    assertThat(rootProject.getName()).isEqualTo("Foo Project");
+    assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
+    // root project must not contain some properties - even if they are defined in the root properties file
+    assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
+    assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
+    assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
+    // and module properties must have been cleaned
+    assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+
+    // CHECK MODULES
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(2);
+
+    // Module 1
+    ProjectDefinition module1 = modules.get(0);
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/module1"));
+    assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
+    assertThat(module1.getName()).isEqualTo("module1");
+    assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    // Description should not be inherited from parent if not set
+    assertThat(module1.getDescription()).isNull();
+    assertThat(module1.getSourceDirs()).contains("sources");
+    assertThat(module1.getTestDirs()).contains("tests");
+    assertThat(module1.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+
+    // Module 2
+    ProjectDefinition module2 = modules.get(1);
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/module2/newBaseDir"));
+    assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
+    assertThat(module2.getName()).isEqualTo("Foo Module 2");
+    assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
+    assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
+    assertThat(module2.getSourceDirs()).contains("src");
+    assertThat(module2.getTestDirs()).contains("tests");
+    assertThat(module2.getBinaries()).contains("target/classes");
+    // and module properties must have been cleaned
+    assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+  }
+
+  // SONARPLUGINS-2421
+  @Test
+  public void shouldDefineMultiLanguageProjectWithDefinitionsAllInRootProject() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-language-definitions-all-in-root");
+
+    // CHECK ROOT
+    assertThat(rootProject.getKey()).isEqualTo("example");
+    assertThat(rootProject.getName()).isEqualTo("Example");
+    assertThat(rootProject.getVersion()).isEqualTo("1.0");
+
+    // CHECK MODULES
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(2);
+
+    // Module 1
+    ProjectDefinition module1 = modules.get(0);
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+    assertThat(module1.getSourceDirs()).contains("src/main/java");
+    // and module properties must have been cleaned
+    assertThat(module1.getWorkDir().getCanonicalFile())
+        .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
+
+    // Module 2
+    ProjectDefinition module2 = modules.get(1);
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+    assertThat(module2.getSourceDirs()).contains("src/main/groovy");
+    // and module properties must have been cleaned
+    assertThat(module2.getWorkDir().getCanonicalFile())
+        .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithBaseDir() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-basedir");
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(1);
+    assertThat(modules.get(0).getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithConfigFile() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-configfile");
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(1);
+    ProjectDefinition module = modules.get(0);
+    assertThat(module.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
+    // verify the base directory that has been changed in this config file
+    assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile/any-folder"));
+  }
+
+  @Test
+  public void shouldDefineMultiModuleProjectWithConfigFileAndOverwrittenBasedir() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-configfile-and-overwritten-basedir");
+    List<ProjectDefinition> modules = rootProject.getSubProjects();
+    assertThat(modules.size()).isEqualTo(1);
+    ProjectDefinition module = modules.get(0);
+    assertThat(module.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
+    // verify the base directory that has been changed in this config file
+    assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile-and-overwritten-basedir/any-folder"));
+  }
+
+  @Test
+  public void shouldFailIfUnexistingModuleBaseDir() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The base directory of the module 'module1' does not exist: "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1");
+
+    loadProjectDefinition("multi-module-with-unexisting-basedir");
+  }
+
+  @Test
+  public void shouldFailIfUnexistingModuleFile() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The properties file of the module 'module1' does not exist: "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-file").getAbsolutePath() + File.separator + "any-folder"
+      + File.separator + "any-file.properties");
+
+    loadProjectDefinition("multi-module-with-unexisting-file");
+  }
+
+  @Test
+  public void shouldFailIfUnexistingSourceFolderInheritedInMultimodule() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)");
+
+    loadProjectDefinition("multi-module-with-unexisting-source-dir");
+  }
+
+  @Test
+  public void shouldNotFailIfUnexistingTestBinLibFolderInheritedInMultimodule() throws IOException {
+    loadProjectDefinition("multi-module-with-unexisting-test-bin-lib-dir");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnexistingTestFolder() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'tests' does not exist for 'com.foo.project' (base directory = "
+      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath());
+
+    loadProjectDefinition("simple-project-with-unexisting-test-dir");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnexistingBinaryFolder() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'bin' does not exist for 'com.foo.project' (base directory = "
+      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-binary").getAbsolutePath());
+
+    loadProjectDefinition("simple-project-with-unexisting-binary");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnmatchingLibFolder() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("No files nor directories matching 'libs/*.txt' in directory "
+      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-lib").getAbsolutePath());
+
+    loadProjectDefinition("simple-project-with-unexisting-lib");
+  }
+
+  @Test
+  public void shouldGetLibDirectory() throws IOException {
+    ProjectDefinition def = loadProjectDefinition("simple-project-with-lib-dir");
+    assertThat(def.getLibraries()).hasSize(1);
+    File libDir = new File(def.getLibraries().get(0));
+    assertThat(libDir).isDirectory().exists();
+    assertThat(libDir.getName()).isEqualTo("lib");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnexistingTestFolderOnModule() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)");
+
+    loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnexistingBinaryFolderOnModule() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The folder 'bin' does not exist for 'module1' (base directory = "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-binary-dir").getAbsolutePath() + File.separator + "module1)");
+
+    loadProjectDefinition("multi-module-with-explicit-unexisting-binary-dir");
+  }
+
+  @Test
+  public void shouldFailIfExplicitUnmatchingLibFolderOnModule() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("No files nor directories matching 'lib/*.jar' in directory "
+      + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-lib").getAbsolutePath() + File.separator + "module1");
+
+    loadProjectDefinition("multi-module-with-explicit-unexisting-lib");
+  }
+
+  @Test
+  public void shouldExtractModuleProperties() {
+    Properties props = new Properties();
+    props.setProperty("sources", "src/main/java");
+    props.setProperty("tests", "src/test/java");
+    props.setProperty("foo.sources", "src/main/java");
+    props.setProperty("foobar.tests", "src/test/java");
+    props.setProperty("foobar.binaries", "target/classes");
+
+    Properties moduleProps = DefaultProjectBootstrapper.extractModuleProperties("bar", props);
+    assertThat(moduleProps.size()).isEqualTo(0);
+
+    moduleProps = DefaultProjectBootstrapper.extractModuleProperties("foo", props);
+    assertThat(moduleProps.size()).isEqualTo(1);
+    assertThat(moduleProps.get("sources")).isEqualTo("src/main/java");
+
+    moduleProps = DefaultProjectBootstrapper.extractModuleProperties("foobar", props);
+    assertThat(moduleProps.size()).isEqualTo(2);
+    assertThat(moduleProps.get("tests")).isEqualTo("src/test/java");
+    assertThat(moduleProps.get("binaries")).isEqualTo("target/classes");
+  }
+
+  @Test
+  public void shouldFailIfMandatoryPropertiesAreNotPresent() {
+    Properties props = new Properties();
+    props.setProperty("foo1", "bla");
+    props.setProperty("foo4", "bla");
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3");
+
+    DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
+  }
+
+  @Test
+  public void shouldFailIfMandatoryPropertiesAreNotPresentButWithProjectKey() {
+    Properties props = new Properties();
+    props.setProperty("foo1", "bla");
+    props.setProperty("sonar.projectKey", "my-project");
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3");
+
+    DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
+  }
+
+  @Test
+  public void shouldNotFailIfMandatoryPropertiesArePresent() {
+    Properties props = new Properties();
+    props.setProperty("foo1", "bla");
+    props.setProperty("foo4", "bla");
+
+    DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1"});
+
+    // No exception should be thrown
+  }
+
+  @Test
+  public void shouldFilterFiles() throws Exception {
+    File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
+    assertThat(DefaultProjectBootstrapper.getLibraries(baseDir, "in*.txt")).hasSize(1);
+    assertThat(DefaultProjectBootstrapper.getLibraries(baseDir, "*.txt")).hasSize(2);
+    assertThat(DefaultProjectBootstrapper.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/in*.txt")).hasSize(1);
+    assertThat(DefaultProjectBootstrapper.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/*.txt")).hasSize(2);
+  }
+
+  @Test
+  public void shouldWorkWithAbsolutePath() throws Exception {
+    File baseDir = new File("not-exists");
+    String absolutePattern = TestUtils.getResource(this.getClass(), "shouldFilterFiles").getAbsolutePath() + "/in*.txt";
+    assertThat(DefaultProjectBootstrapper.getLibraries(baseDir.getParentFile(), absolutePattern)).hasSize(1);
+  }
+
+  @Test
+  public void shouldGetRelativeFile() {
+    assertThat(DefaultProjectBootstrapper.getFileFromPath("shouldGetFile/foo.properties", TestUtils.getResource(this.getClass(), "/")))
+        .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
+  }
+
+  @Test
+  public void shouldGetAbsoluteFile() {
+    File file = TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties");
+
+    assertThat(DefaultProjectBootstrapper.getFileFromPath(file.getAbsolutePath(), TestUtils.getResource(this.getClass(), "/")))
+        .isEqualTo(file);
+  }
+
+  @Test
+  public void shouldMergeParentProperties() {
+    Properties parentProps = new Properties();
+    parentProps.setProperty("toBeMergeProps", "fooParent");
+    parentProps.setProperty("existingChildProp", "barParent");
+    parentProps.setProperty("sonar.modules", "mod1,mod2");
+    parentProps.setProperty("sonar.projectDescription", "Desc from Parent");
+    parentProps.setProperty("mod1.sonar.projectDescription", "Desc for Mod1");
+    parentProps.setProperty("mod2.sonar.projectkey", "Key for Mod2");
+
+    Properties childProps = new Properties();
+    childProps.setProperty("existingChildProp", "barChild");
+    childProps.setProperty("otherProp", "tutuChild");
+
+    DefaultProjectBootstrapper.mergeParentProperties(childProps, parentProps);
+
+    assertThat(childProps.size()).isEqualTo(3);
+    assertThat(childProps.getProperty("toBeMergeProps")).isEqualTo("fooParent");
+    assertThat(childProps.getProperty("existingChildProp")).isEqualTo("barChild");
+    assertThat(childProps.getProperty("otherProp")).isEqualTo("tutuChild");
+    assertThat(childProps.getProperty("sonar.modules")).isNull();
+    assertThat(childProps.getProperty("sonar.projectDescription")).isNull();
+    assertThat(childProps.getProperty("mod1.sonar.projectDescription")).isNull();
+    assertThat(childProps.getProperty("mod2.sonar.projectkey")).isNull();
+  }
+
+  @Test
+  public void shouldInitRootWorkDir() {
+    DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new Settings());
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initRootProjectWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File(baseDir, ".sonar"));
+  }
+
+  @Test
+  public void shouldInitWorkDirWithCustomRelativeFolder() {
+    Settings settings = new Settings();
+    settings.setProperty("sonar.working.directory", ".foo");
+    DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(settings);
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initRootProjectWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File(baseDir, ".foo"));
+  }
+
+  @Test
+  public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
+    Settings settings = new Settings();
+    settings.setProperty("sonar.working.directory", new File("src").getAbsolutePath());
+    DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(settings);
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initRootProjectWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile());
+  }
+
+  @Test
+  public void shouldReturnPrefixedKey() {
+    Properties props = new Properties();
+    props.put("sonar.projectKey", "my-module-key");
+
+    DefaultProjectBootstrapper.prefixProjectKeyWithParentKey(props, "my-parent-key");
+    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("my-parent-key:my-module-key");
+  }
+
+  @Test
+  public void shouldFailIf2ModulesWithSameKey() {
+    Properties props = new Properties();
+    props.put("sonar.projectKey", "root");
+    ProjectDefinition root = ProjectDefinition.create().setProperties(props);
+
+    Properties props1 = new Properties();
+    props1.put("sonar.projectKey", "mod1");
+    root.addSubProject(ProjectDefinition.create().setProperties(props1));
+
+    // Check uniqueness of a new module: OK
+    Properties props2 = new Properties();
+    props2.put("sonar.projectKey", "mod2");
+    ProjectDefinition mod2 = ProjectDefinition.create().setProperties(props2);
+    DefaultProjectBootstrapper.checkUniquenessOfChildKey(mod2, root);
+
+    // Now, add it and check again
+    root.addSubProject(mod2);
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
+
+    DefaultProjectBootstrapper.checkUniquenessOfChildKey(mod2, root);
+  }
+
+  @Test
+  public void shouldSetProjectKeyIfNotPresent() {
+    Properties props = new Properties();
+    props.put("sonar.projectVersion", "1.0");
+
+    // should be set
+    DefaultProjectBootstrapper.setProjectKeyAndNameIfNotDefined(props, "foo");
+    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+    assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
+
+    // but not this 2nd time
+    DefaultProjectBootstrapper.setProjectKeyAndNameIfNotDefined(props, "bar");
+    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+    assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
+  }
+
+  @Test
+  public void shouldFailToLoadPropertiesFile() throws Exception {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("Impossible to read the property file");
+
+    DefaultProjectBootstrapper.toProperties(new File("foo.properties"));
+  }
+
+  private ProjectDefinition loadProjectDefinition(String projectFolder) throws IOException {
+    Settings settings = new Settings();
+    settings.addProperties(DefaultProjectBootstrapper.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties")));
+    settings.setProperty("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
+    ProjectReactor projectReactor = new DefaultProjectBootstrapper(settings).bootstrap();
+    return projectReactor.getRoot();
+  }
+
+  public Map<String, String> toMap(Properties props) {
+    Map<String, String> result = new HashMap<String, String>();
+    for (Map.Entry<Object, Object> entry : props.entrySet()) {
+      result.put(entry.getKey().toString(), entry.getValue().toString());
+    }
+    return result;
+  }
+
+  @Test
+  public void shouldGetList() {
+    Properties props = new Properties();
+
+    props.put("prop", "  foo  ,  bar  , \n\ntoto,tutu");
+    assertThat(DefaultProjectBootstrapper.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+  }
+
+  //
+  // @Test
+  // public void test_props() {
+  // Properties p1 = new Properties();
+  // p1.setProperty("foo", "bar");
+  // Properties p2 = new Properties();
+  // p2.putAll(p1);
+  // assertThat(p2.getProperty("foo")).isEqualTo("bar");
+  // }
+
+  @Test
+  public void shouldGetListFromFile() throws IOException {
+    String filePath = "shouldGetList/foo.properties";
+    Properties props = loadPropsFromFile(filePath);
+
+    assertThat(DefaultProjectBootstrapper.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+  }
+
+  private Properties loadPropsFromFile(String filePath) throws IOException {
+    Properties props = new Properties();
+    FileInputStream fileInputStream = null;
+    try {
+      fileInputStream = new FileInputStream(TestUtils.getResource(this.getClass(), filePath));
+      props.load(fileInputStream);
+    } finally {
+      IOUtils.closeQuietly(fileInputStream);
+    }
+    return props;
+  }
+
+}
index 54e3e12ee9a63f0ca282d1f369deadfd8f62cb27..cc78d8d21e4617071923acd2754322e92a5c64b4 100644 (file)
  */
 package org.sonar.batch.scan;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.BatchExtension;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.ServerExtension;
 import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.ComponentContainer;
 import org.sonar.api.task.TaskExtension;
@@ -33,13 +37,22 @@ import org.sonar.batch.scan.maven.MavenPluginExecutor;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class ProjectScanContainerTest {
 
+  private ProjectBootstrapper projectBootstrapper;
+
+  @Before
+  public void prepare() {
+    projectBootstrapper = mock(ProjectBootstrapper.class);
+    when(projectBootstrapper.bootstrap()).thenReturn(new ProjectReactor(ProjectDefinition.create()));
+  }
+
   @Test
   public void should_add_fake_maven_executor_on_non_maven_env() {
     ProjectScanContainer container = new ProjectScanContainer(new ComponentContainer());
-    container.add(mock(ExtensionInstaller.class));
+    container.add(mock(ExtensionInstaller.class), projectBootstrapper);
     container.doBeforeStart();
 
     assertThat(container.getComponentByType(MavenPluginExecutor.class)).isNotNull();
@@ -48,7 +61,7 @@ public class ProjectScanContainerTest {
   @Test
   public void should_use_maven_executor_provided_by_maven() {
     ProjectScanContainer container = new ProjectScanContainer(new ComponentContainer());
-    container.add(mock(ExtensionInstaller.class));
+    container.add(mock(ExtensionInstaller.class), projectBootstrapper);
     MavenPluginExecutor mavenPluginExecutor = mock(MavenPluginExecutor.class);
     container.add(mavenPluginExecutor);
     container.doBeforeStart();
@@ -63,7 +76,7 @@ public class ProjectScanContainerTest {
     Settings settings = new Settings();
     parentContainer.add(settings);
     ProjectScanContainer container = new ProjectScanContainer(parentContainer);
-    container.add(mock(ExtensionInstaller.class));
+    container.add(mock(ExtensionInstaller.class), projectBootstrapper);
     container.doBeforeStart();
 
     assertThat(container.getComponentsByType(PhasesSumUpTimeProfiler.class)).hasSize(0);
@@ -71,7 +84,7 @@ public class ProjectScanContainerTest {
     settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, "true");
 
     container = new ProjectScanContainer(parentContainer);
-    container.add(mock(ExtensionInstaller.class));
+    container.add(mock(ExtensionInstaller.class), projectBootstrapper);
     container.doBeforeStart();
 
     assertThat(container.getComponentsByType(PhasesSumUpTimeProfiler.class)).hasSize(1);
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/sonar-project.properties
new file mode 100644 (file)
index 0000000..53aacb5
--- /dev/null
@@ -0,0 +1,13 @@
+sonar.projectKey=example
+sonar.projectName=Example
+sonar.projectVersion=1.0
+
+sonar.modules=java-module,groovy-module
+
+java-module.sonar.language=java
+java-module.sonar.projectBaseDir=.
+java-module.sonar.sources=src/main/java
+
+groovy-module.sonar.language=groovy
+groovy-module.sonar.projectBaseDir=.
+groovy-module.sonar.sources=src/main/groovy
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/java/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-language-definitions-all-in-root/src/main/java/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module2/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/module2/src/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-all-in-root/sonar-project.properties
new file mode 100644 (file)
index 0000000..0f06d31
--- /dev/null
@@ -0,0 +1,19 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1,\
+              module2
+
+# Mandatory properties for module1 are all inferred from the module ID
+
+module2.sonar.projectKey=com.foo.project.module2
+module2.sonar.projectName=Foo Module 2
+# redefine some properties
+module2.sonar.projectDescription=Description of Module 2
+module2.sonar.sources=src
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties
new file mode 100644 (file)
index 0000000..7bace22
--- /dev/null
@@ -0,0 +1 @@
+# Mandatory properties for module1 are all inferred from the module ID
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties
new file mode 100644 (file)
index 0000000..d25a9e9
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=com.foo.project.module2
+sonar.projectName=Foo Module 2
+# redefine some properties
+sonar.projectBaseDir=newBaseDir
+sonar.projectDescription=Description of Module 2
+sonar.sources=src
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties
new file mode 100644 (file)
index 0000000..4744284
--- /dev/null
@@ -0,0 +1,11 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1,\
+              module2
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sonar-project.properties
new file mode 100644 (file)
index 0000000..0138e27
--- /dev/null
@@ -0,0 +1,4 @@
+sonar.projectKey=com.foo.project.module1
+sonar.projectName=Foo Module 1
+sonar.projectDescription=Description of Module 1
+sonar.sources=sources
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/module2/sonar-project.properties
new file mode 100644 (file)
index 0000000..d25a9e9
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=com.foo.project.module2
+sonar.projectName=Foo Module 2
+# redefine some properties
+sonar.projectBaseDir=newBaseDir
+sonar.projectDescription=Description of Module 2
+sonar.sources=src
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-definitions-in-each-module/sonar-project.properties
new file mode 100644 (file)
index 0000000..df58736
--- /dev/null
@@ -0,0 +1,10 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1,\
+              module2
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/modules/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/modules/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-basedir/sonar-project.properties
new file mode 100644 (file)
index 0000000..615f5c7
--- /dev/null
@@ -0,0 +1,14 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1
+
+module1.sonar.projectBaseDir=modules/module1
+module1.sonar.projectKey=com.foo.project.module1
+module1.sonar.projectName=Foo Module 1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties
new file mode 100644 (file)
index 0000000..c50d50b
--- /dev/null
@@ -0,0 +1,5 @@
+sonar.projectKey=com.foo.project.module1
+sonar.projectName=Foo Module 1
+
+# and specify a different baseDir
+sonar.projectBaseDir=..
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties
new file mode 100644 (file)
index 0000000..c1640b1
--- /dev/null
@@ -0,0 +1,12 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1
+
+module1.sonar.projectConfigFile=any-folder/generated/any-file.properties
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/any-file.properties
new file mode 100644 (file)
index 0000000..460d349
--- /dev/null
@@ -0,0 +1,2 @@
+sonar.projectKey=com.foo.project.module1
+sonar.projectName=Foo Module 1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/any-folder/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-configfile/sonar-project.properties
new file mode 100644 (file)
index 0000000..e246f8c
--- /dev/null
@@ -0,0 +1,12 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1
+
+module1.sonar.projectConfigFile=any-folder/any-file.properties
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..8007363
--- /dev/null
@@ -0,0 +1,9 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=src
+
+sonar.modules=module1
+module1.sonar.binaries=bin
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties
new file mode 100644 (file)
index 0000000..d97a18b
--- /dev/null
@@ -0,0 +1,9 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=src
+
+sonar.modules=module1
+module1.sonar.libraries=lib/*.jar
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/module1/src/Fake.java
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-explicit-unexisting-test-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..09cb220
--- /dev/null
@@ -0,0 +1,9 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=src
+
+sonar.modules=module1
+module1.sonar.tests=tests
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-basedir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-basedir/sonar-project.properties
new file mode 100644 (file)
index 0000000..67fbf34
--- /dev/null
@@ -0,0 +1,13 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1
+
+module1.sonar.projectKey=com.foo.project.module1
+module1.sonar.projectName=Foo Module 1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-file/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-file/sonar-project.properties
new file mode 100644 (file)
index 0000000..e246f8c
--- /dev/null
@@ -0,0 +1,12 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+
+sonar.modules=module1
+
+module1.sonar.projectConfigFile=any-folder/any-file.properties
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/module1/src/Fake.java
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-source-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..04ea08a
--- /dev/null
@@ -0,0 +1,8 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=unexisting-source-dir
+
+sonar.modules=module1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/module1/src/Fake.java
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/multi-module-with-unexisting-test-bin-lib-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..59b68b3
--- /dev/null
@@ -0,0 +1,11 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=src
+sonar.tests=tests
+sonar.binaries=bin
+sonar.libraries=lib/*.jar
+
+sonar.modules=module1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/exclude.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/exclude.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/include.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldFilterFiles/include.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetFile/foo.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetFile/foo.properties
new file mode 100644 (file)
index 0000000..8fbb104
--- /dev/null
@@ -0,0 +1,4 @@
+prop=  foo, bar, \
+toto,\
+\
+tutu,
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetList/foo.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/shouldGetList/foo.properties
new file mode 100644 (file)
index 0000000..8fbb104
--- /dev/null
@@ -0,0 +1,4 @@
+prop=  foo, bar, \
+toto,\
+\
+tutu,
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib1.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib1.txt
new file mode 100644 (file)
index 0000000..81d4e95
--- /dev/null
@@ -0,0 +1 @@
+lib1
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib2.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/libs/lib2.txt
new file mode 100644 (file)
index 0000000..7dacac0
--- /dev/null
@@ -0,0 +1 @@
+lib2
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sonar-project.properties
new file mode 100644 (file)
index 0000000..1b2b596
--- /dev/null
@@ -0,0 +1,8 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+# Those are the deprecated properties
+sources=sources
+libraries=libs/*.txt
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-deprecated-props/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/lib/Fake.class b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/lib/Fake.class
new file mode 100644 (file)
index 0000000..bf2c3a0
--- /dev/null
@@ -0,0 +1,3 @@
+package org.sonar.runner.batch.ProjectReactorBuilderTest.simple
+
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..0cada50
--- /dev/null
@@ -0,0 +1,7 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.libraries=lib
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-lib-dir/sources/Fake.java
new file mode 100644 (file)
index 0000000..bf2c3a0
--- /dev/null
@@ -0,0 +1,3 @@
+package org.sonar.runner.batch.ProjectReactorBuilderTest.simple
+
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sonar-project.properties
new file mode 100644 (file)
index 0000000..55d1ddf
--- /dev/null
@@ -0,0 +1,7 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.binaries=bin
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-binary/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sonar-project.properties
new file mode 100644 (file)
index 0000000..69ccd8d
--- /dev/null
@@ -0,0 +1,7 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.libraries=libs/*.txt
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-lib/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-source-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-source-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..0b83b11
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=unexisting-source-dir
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..a4fac8e
--- /dev/null
@@ -0,0 +1,7 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.tests=tests
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-unexisting-test-dir/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib1.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib1.txt
new file mode 100644 (file)
index 0000000..81d4e95
--- /dev/null
@@ -0,0 +1 @@
+lib1
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib2.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/libs/lib2.txt
new file mode 100644 (file)
index 0000000..7dacac0
--- /dev/null
@@ -0,0 +1 @@
+lib2
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sonar-project.properties
new file mode 100644 (file)
index 0000000..69ccd8d
--- /dev/null
@@ -0,0 +1,7 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=sources
+sonar.libraries=libs/*.txt
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project/sources/Fake.java
new file mode 100644 (file)
index 0000000..5967658
--- /dev/null
@@ -0,0 +1 @@
+Fake
\ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBootstrapper.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBootstrapper.java
new file mode 100644 (file)
index 0000000..bc90921
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.bootstrap;
+
+import org.sonar.api.task.TaskExtension;
+
+/**
+ * This extension point allows to define project structure at runtime. It is executed once during task startup.
+ * Some use-cases :
+ * <ul>
+ *   <li>Maven bootstraper create project structure from pom.xml</li>
+ *   <li>Sonar Runner bootstraper create project structure from sonar-runner.properties</li>
+ * </ul>
+ * Only one ProjectBootstrapper is allowed per environement.
+ *
+ * @since 3.7
+ */
+public abstract class ProjectBootstrapper implements TaskExtension {
+
+  protected ProjectBootstrapper() {
+  }
+
+  /**
+   * Implement this method to create project reactor
+   */
+  public abstract ProjectReactor bootstrap();
+
+}