]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5181 Move parsing of sonar-project.properties files to SQ Runner
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 3 Apr 2014 10:19:31 +0000 (12:19 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 3 Apr 2014 15:10:11 +0000 (17:10 +0200)
43 files changed:
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
sonar-batch/src/main/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilder.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapContainerTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/build/report.txt [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sources/Fake.java [new file with mode: 0644]

index 52e3ad64ef3a1e1721c03d66883453b83019fb55..7464af12e338b03e5001413e28dbe07297424239 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.UriReader;
 import org.sonar.api.utils.internal.TempFolderCleaner;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
 import org.sonar.batch.components.PastMeasuresLoader;
 import org.sonar.batch.components.PastSnapshotFinder;
 import org.sonar.batch.components.PastSnapshotFinderByDate;
@@ -36,6 +37,7 @@ import org.sonar.batch.components.PastSnapshotFinderByDays;
 import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis;
 import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion;
 import org.sonar.batch.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.scan.DeprecatedProjectReactorBuilder;
 import org.sonar.batch.scan.ProjectReactorBuilder;
 import org.sonar.core.config.Logback;
 import org.sonar.core.i18n.DefaultI18n;
@@ -97,7 +99,20 @@ public class BootstrapContainer extends ComponentContainer {
       UriReader.class,
       new FileCacheProvider(),
       System2.INSTANCE,
-      ProjectReactorBuilder.class);
+      projectReactorBuilder());
+  }
+
+  private Class<? extends ProjectReactorBuilder> projectReactorBuilder() {
+    if (isRunnerPre2_4()) {
+      return DeprecatedProjectReactorBuilder.class;
+    }
+    return ProjectReactorBuilder.class;
+  }
+
+  private boolean isRunnerPre2_4() {
+    EnvironmentInformation env = this.getComponentByType(EnvironmentInformation.class);
+    // Starting from SQ Runner 2.4 the key is "SonarQubeRunner"
+    return env != null && "SonarRunner".equals(env.getKey());
   }
 
   private void addDatabaseComponents() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilder.java
new file mode 100644 (file)
index 0000000..a0c3f5d
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.batch.bootstrap.BootstrapSettings;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+/**
+ * Class that creates a project definition based on a set of properties. This class is intended to work with
+ * SQ Runner <= 2.3. Starting from SQ Runner 2.4 loading of sonar-project.properties file should not be done by
+ * the core.
+ * @deprecated since 4.3 should be removed when we will require SQ Runner 2.4+
+ */
+@Deprecated
+public class DeprecatedProjectReactorBuilder extends ProjectReactorBuilder {
+
+  private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
+
+  public DeprecatedProjectReactorBuilder(BootstrapSettings settings) {
+    super(settings);
+  }
+
+  @Override
+  protected ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
+    final File baseDir;
+    if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
+      baseDir = resolvePath(parentProject.getBaseDir(), moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR));
+      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);
+    }
+
+    setModuleKeyAndNameIfNotDefined(moduleProps, moduleId, parentProject.getKey());
+
+    // and finish
+    checkMandatoryProperties(moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
+    validateDirectories(moduleProps, baseDir, moduleId);
+
+    mergeParentProperties(moduleProps, parentProject.getProperties());
+
+    return defineProject(moduleProps, parentProject);
+  }
+
+  /**
+   * @return baseDir
+   */
+  private File loadPropsFile(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
+    File propertyFile = resolvePath(parentProject.getBaseDir(), moduleProps.getProperty(PROPERTY_PROJECT_CONFIG_FILE));
+    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 = resolvePath(propertyFile.getParentFile(), moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR));
+      } 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 = resolvePath(propertyFile.getParentFile(), moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR));
+        setProjectBaseDir(overwrittenBaseDir, moduleProps, moduleId);
+      }
+    }
+  }
+
+}
index 17db4e4850af592e6bdb7c3e52aab4742ee8be3a..0dae4d31c28592d97597919f12adf2dfaedad1d3 100644 (file)
@@ -59,9 +59,8 @@ public class ProjectReactorBuilder {
    */
   private static final String MODULE_KEY_PROPERTY = "sonar.moduleKey";
 
-  private static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir";
+  protected static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir";
   private static final String PROPERTY_PROJECT_BUILDDIR = "sonar.projectBuildDir";
-  private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
   private static final String PROPERTY_MODULES = "sonar.modules";
 
   /**
@@ -91,7 +90,7 @@ public class ProjectReactorBuilder {
   /**
    * 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 = {MODULE_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY};
+  protected static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {MODULE_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY};
 
   /**
    * Properties that must not be passed from the parent project to its children.
@@ -115,7 +114,7 @@ public class ProjectReactorBuilder {
     return new ProjectReactor(rootProject);
   }
 
-  private ProjectDefinition defineProject(Properties properties, ProjectDefinition parent) {
+  protected 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);
@@ -207,24 +206,14 @@ public class ProjectReactorBuilder {
     }
   }
 
-  private ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
+  protected ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
     final File baseDir;
     if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
-      baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
+      baseDir = resolvePath(parentProject.getBaseDir(), moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR));
       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);
     }
 
     setModuleKeyAndNameIfNotDefined(moduleProps, moduleId, parentProject.getKey());
@@ -238,43 +227,6 @@ public class ProjectReactorBuilder {
     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();
@@ -320,7 +272,7 @@ public class ProjectReactorBuilder {
     }
   }
 
-  private static void setProjectBaseDir(File baseDir, Properties childProps, String moduleId) {
+  protected 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());
     }
@@ -344,7 +296,7 @@ public class ProjectReactorBuilder {
     }
   }
 
-  private static void validateDirectories(Properties props, File baseDir, String projectId) {
+  protected 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
 
@@ -407,7 +359,7 @@ public class ProjectReactorBuilder {
     // SONARPLUGINS-2295
     String[] sourceDirs = getListFromProperty(properties, PROPERTY_SOURCES);
     for (String path : sourceDirs) {
-      File sourceFolder = getFileFromPath(path, project.getBaseDir());
+      File sourceFolder = resolvePath(project.getBaseDir(), path);
       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.",
@@ -471,7 +423,7 @@ public class ProjectReactorBuilder {
   @VisibleForTesting
   protected static void checkExistenceOfDirectories(String moduleRef, File baseDir, String[] sourceDirs, String propName) {
     for (String path : sourceDirs) {
-      File sourceFolder = getFileFromPath(path, baseDir);
+      File sourceFolder = resolvePath(baseDir, path);
       if (!sourceFolder.isDirectory()) {
         LOG.error("Invalid value of " + propName + " for " + moduleRef);
         throw new IllegalStateException("The folder '" + path + "' does not exist for '" + moduleRef +
@@ -508,7 +460,7 @@ public class ProjectReactorBuilder {
     return files;
   }
 
-  private static File resolvePath(File baseDir, String path) {
+  protected static File resolvePath(File baseDir, String path) {
     File file = new File(path);
     if (!file.isAbsolute()) {
       try {
@@ -520,18 +472,6 @@ public class ProjectReactorBuilder {
     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.
    *
index 21806c54efe698788eed373d4a631eb682c572e3..cb611c8ae668decfbf9068355d8aa1e1c54da1f7 100644 (file)
@@ -27,6 +27,9 @@ import org.sonar.api.Plugin;
 import org.sonar.api.SonarPlugin;
 import org.sonar.api.platform.PluginMetadata;
 import org.sonar.api.utils.TempFolder;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.batch.scan.DeprecatedProjectReactorBuilder;
+import org.sonar.batch.scan.ProjectReactorBuilder;
 import org.sonar.core.config.Logback;
 
 import java.util.Arrays;
@@ -75,6 +78,30 @@ public class BootstrapContainerTest {
     assertThat(container.getComponentsByType(Plugin.class)).containsOnly(plugin);
   }
 
+  @Test
+  public void should_add_project_reactor_builder_by_default() {
+    BootstrapContainer container = BootstrapContainer.create(Lists.newArrayList());
+    container.add(new BootstrapProperties(Collections.<String, String>emptyMap()));
+    container.doBeforeStart();
+
+    assertThat(container.getComponentByType(ProjectReactorBuilder.class)).isNotNull().isInstanceOf(ProjectReactorBuilder.class);
+
+    container = BootstrapContainer.create(Lists.newArrayList(new EnvironmentInformation("SonarQubeRunner", "2.4")));
+    container.add(new BootstrapProperties(Collections.<String, String>emptyMap()));
+    container.doBeforeStart();
+
+    assertThat(container.getComponentByType(ProjectReactorBuilder.class)).isNotNull().isInstanceOf(ProjectReactorBuilder.class);
+  }
+
+  @Test
+  public void should_add_deprecated_project_reactor_builder_if_old_runner() {
+    BootstrapContainer container = BootstrapContainer.create(Lists.newArrayList(new EnvironmentInformation("SonarRunner", "2.3")));
+    container.add(new BootstrapProperties(Collections.<String, String>emptyMap()));
+    container.doBeforeStart();
+
+    assertThat(container.getComponentByType(DeprecatedProjectReactorBuilder.class)).isNotNull().isInstanceOf(DeprecatedProjectReactorBuilder.class);
+  }
+
   public static class Foo implements BatchExtension {
 
   }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java
new file mode 100644 (file)
index 0000000..a5fa0ef
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.collect.Maps;
+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.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.BootstrapSettings;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DeprecatedProjectReactorBuilderTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @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();
+  }
+
+  @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 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");
+  }
+
+  private ProjectDefinition loadProjectDefinition(String projectFolder) throws IOException {
+    Map<String, String> props = Maps.<String, String>newHashMap();
+    Properties runnerProps = ProjectReactorBuilder.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
+    for (final String name : runnerProps.stringPropertyNames()) {
+      props.put(name, runnerProps.getProperty(name));
+    }
+    props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
+    BootstrapProperties bootstrapProps = new BootstrapProperties(props);
+    ProjectReactor projectReactor = new DeprecatedProjectReactorBuilder(new BootstrapSettings(bootstrapProps)).execute();
+    return projectReactor.getRoot();
+  }
+
+}
index da0e9626c1c77e9382802c99829c3c9d1453fc5d..dfea7822a7ae5e4ac13175e2c1cde4ce31a65f2e 100644 (file)
@@ -152,57 +152,6 @@ public class ProjectReactorBuilderTest {
       .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();
-  }
-
   // SONAR-4876
   @Test
   public void shouldDefineMultiModuleProjectWithModuleKey() throws IOException {
@@ -222,57 +171,6 @@ public class ProjectReactorBuilderTest {
     assertThat(module2.getKey()).isEqualTo("com.foo.project.module2");
   }
 
-  @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 {
@@ -312,28 +210,6 @@ public class ProjectReactorBuilderTest {
     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);
@@ -343,16 +219,6 @@ public class ProjectReactorBuilderTest {
     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);
@@ -505,7 +371,7 @@ public class ProjectReactorBuilderTest {
 
   @Test
   public void shouldGetRelativeFile() {
-    assertThat(ProjectReactorBuilder.getFileFromPath("shouldGetFile/foo.properties", TestUtils.getResource(this.getClass(), "/")))
+    assertThat(ProjectReactorBuilder.resolvePath(TestUtils.getResource(this.getClass(), "/"), "shouldGetFile/foo.properties"))
       .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
   }
 
@@ -513,7 +379,7 @@ public class ProjectReactorBuilderTest {
   public void shouldGetAbsoluteFile() {
     File file = TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties");
 
-    assertThat(ProjectReactorBuilder.getFileFromPath(file.getAbsolutePath(), TestUtils.getResource(this.getClass(), "/")))
+    assertThat(ProjectReactorBuilder.resolvePath(TestUtils.getResource(this.getClass(), "/"), file.getAbsolutePath()))
       .isEqualTo(file);
   }
 
@@ -662,6 +528,15 @@ public class ProjectReactorBuilderTest {
     assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
   }
 
+  @Test
+  public void shouldDefineProjectWithBuildDir() throws IOException {
+    ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-build-dir");
+    File buildDir = rootProject.getBuildDir();
+    assertThat(buildDir).isDirectory().exists();
+    assertThat(new File(buildDir, "report.txt")).isFile().exists();
+    assertThat(buildDir.getName()).isEqualTo("build");
+  }
+
   private Properties loadPropsFromFile(String filePath) throws IOException {
     Properties props = new Properties();
     FileInputStream fileInputStream = null;
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties
new file mode 100644 (file)
index 0000000..ec642a9
--- /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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties
new file mode 100644 (file)
index 0000000..2f16886
--- /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/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java
new file mode 100644 (file)
index 0000000..b2e6462
--- /dev/null
@@ -0,0 +1 @@
+Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/DeprecatedProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/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/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties
deleted file mode 100644 (file)
index 7bace22..0000000
+++ /dev/null
@@ -1 +0,0 @@
-# Mandatory properties for module1 are all inferred from the module ID
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties
deleted file mode 100644 (file)
index d25a9e9..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties
deleted file mode 100644 (file)
index 4744284..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties
deleted file mode 100644 (file)
index ec642a9..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties
deleted file mode 100644 (file)
index d25a9e9..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties
deleted file mode 100644 (file)
index 2f16886..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties
deleted file mode 100644 (file)
index c50d50b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties
deleted file mode 100644 (file)
index c1640b1..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties
deleted file mode 100644 (file)
index 460d349..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-sonar.projectKey=com.foo.project.module1
-sonar.projectName=Foo Module 1
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java
deleted file mode 100644 (file)
index b2e6462..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties
deleted file mode 100644 (file)
index e246f8c..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-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/ProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties
deleted file mode 100644 (file)
index e246f8c..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-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/ProjectReactorBuilderTest/simple-project-with-build-dir/build/report.txt b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/build/report.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..35b3399
--- /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.projectBuildDir=build
+
+sonar.sources=sources
+
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sources/Fake.java
new file mode 100644 (file)
index 0000000..b272235
--- /dev/null
@@ -0,0 +1,3 @@
+package org.sonar.runner.batch.ProjectReactorBuilderTest.simple
+
+Fake