]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Refactor package names
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 13 Sep 2012 14:49:00 +0000 (16:49 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 13 Sep 2012 14:49:00 +0000 (16:49 +0200)
79 files changed:
src/main/java/org/sonar/runner/BootstrapClassLoader.java
src/main/java/org/sonar/runner/Runner.java
src/main/java/org/sonar/runner/batch/Launcher.java [deleted file]
src/main/java/org/sonar/runner/batch/SonarProjectBuilder.java [deleted file]
src/main/java/org/sonar/runner/batch/SonarRunnerUtils.java [deleted file]
src/main/java/org/sonar/runner/batch/package-info.java [deleted file]
src/main/java/org/sonar/runner/internal/batch/Launcher.java [new file with mode: 0644]
src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java [new file with mode: 0644]
src/main/java/org/sonar/runner/internal/batch/SonarRunnerUtils.java [new file with mode: 0644]
src/main/java/org/sonar/runner/internal/batch/package-info.java [new file with mode: 0644]
src/test/java/org/sonar/runner/BootstrapClassLoaderTest.java
src/test/java/org/sonar/runner/batch/LauncherTest.java [deleted file]
src/test/java/org/sonar/runner/batch/SonarProjectBuilderTest.java [deleted file]
src/test/java/org/sonar/runner/batch/SonarRunnerUtilsTest.java [deleted file]
src/test/java/org/sonar/runner/internal/batch/LauncherTest.java [new file with mode: 0644]
src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java [new file with mode: 0644]
src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/any-file.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-unexisting-file/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldGetFile/foo.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib1.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib2.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib1.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib2.txt [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties [deleted file]
src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sources/Fake.java [deleted file]
src/test/resources/org/sonar/runner/batch/SonarRunnerUtilsTest/shouldGetList/foo.properties [deleted file]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-basedir/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/any-file.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-unexisting-file/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldGetFile/foo.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib1.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib2.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/libs/lib1.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/libs/lib2.txt [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/sources/Fake.java [new file with mode: 0644]
src/test/resources/org/sonar/runner/internal/batch/SonarRunnerUtilsTest/shouldGetList/foo.properties [new file with mode: 0644]

index 307fc9c8126899325b3091726e40a29f06002753..8cb7f39a7e152f36798cb959bbbf84bb651e7155 100644 (file)
@@ -56,7 +56,7 @@ class BootstrapClassLoader extends URLClassLoader {
    * @return true, if class can be loaded from parent ClassLoader
    */
   boolean canLoadFromParent(String name) {
-    if (name.startsWith("org.sonar.runner.") && !name.startsWith("org.sonar.runner.batch.")) {
+    if (name.startsWith("org.sonar.runner.") && !name.startsWith("org.sonar.runner.internal.batch.")) {
       return true;
     }
     for (String pkg : unmaskedPackages) {
index b0a22087adccb0467d9840b0e0e1d881dd07259d..78a261d38f9577e7ff9b8333e8dee1a847f68868 100644 (file)
@@ -255,7 +255,7 @@ public final class Runner {
     ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
     try {
       Thread.currentThread().setContextClassLoader(sonarClassLoader);
-      Class<?> launcherClass = sonarClassLoader.findClass("org.sonar.runner.batch.Launcher");
+      Class<?> launcherClass = sonarClassLoader.findClass("org.sonar.runner.internal.batch.Launcher");
       Constructor<?> constructor = launcherClass.getConstructor(Properties.class, List.class);
       Object launcher = constructor.newInstance(getProperties(), containerExtensions);
       Method method = launcherClass.getMethod("execute");
diff --git a/src/main/java/org/sonar/runner/batch/Launcher.java b/src/main/java/org/sonar/runner/batch/Launcher.java
deleted file mode 100644 (file)
index 97f31da..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-package org.sonar.runner.batch;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.configuration.*;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.utils.SonarException;
-import org.sonar.batch.Batch;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.runner.Runner;
-
-import java.io.InputStream;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Contrary to {@link org.sonar.runner.Runner}, this class is executed within the classloader
- * provided by the server. It contains the installed plugins and the same version of sonar-batch as the server.
- */
-public class Launcher {
-
-  private Properties propertiesFromRunner;
-  private List<Object> containerExtensions;
-
-  public Launcher(Properties properties, List<Object> containerExtensions) {
-    this.propertiesFromRunner = properties;
-    this.containerExtensions = containerExtensions;
-  }
-
-  /**
-   * Main entry point.
-   */
-  public void execute() {
-    ProjectDefinition project = SonarProjectBuilder.create(propertiesFromRunner).generateProjectDefinition();
-    Configuration initialConfiguration = getInitialConfiguration(project);
-    initLogging(initialConfiguration);
-    executeBatch(project, initialConfiguration);
-  }
-
-  private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) {
-    setContainerExtensionsOnProject(project);
-    String envKey = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
-    String envVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
-    Batch batch = Batch.create(new ProjectReactor(project), initialConfiguration, new EnvironmentInformation(envKey, envVersion));
-    batch.execute();
-  }
-
-  private void setContainerExtensionsOnProject(ProjectDefinition projectDefinition) {
-    for (Object extension : containerExtensions) {
-      projectDefinition.addContainerExtension(extension);
-    }
-    for (ProjectDefinition module : projectDefinition.getSubProjects()) {
-      setContainerExtensionsOnProject(module);
-    }
-  }
-
-  private void initLogging(Configuration initialConfiguration) {
-    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
-    JoranConfigurator jc = new JoranConfigurator();
-    jc.setContext(context);
-    context.reset();
-    InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml");
-    System.setProperty("ROOT_LOGGER_LEVEL", isDebug() ? "DEBUG" : "INFO");
-    context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(initialConfiguration));// since 2.14. Ignored on previous versions.
-    context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(initialConfiguration));// since 2.14. Ignored on previous versions.
-    try {
-      jc.doConfigure(input);
-
-    } catch (JoranException e) {
-      throw new SonarException("can not initialize logging", e);
-
-    } finally {
-      IOUtils.closeQuietly(input);
-    }
-  }
-
-  @VisibleForTesting
-  protected boolean isDebug() {
-    return Boolean.parseBoolean(propertiesFromRunner.getProperty(Runner.PROPERTY_VERBOSE, propertiesFromRunner.getProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "false")));
-  }
-
-  @VisibleForTesting
-  protected static String getSqlLevel(Configuration config) {
-    boolean showSql = config.getBoolean("sonar.showSql", false);
-    return showSql ? "DEBUG" : "WARN";
-  }
-
-  @VisibleForTesting
-  protected static String getSqlResultsLevel(Configuration config) {
-    boolean showSql = config.getBoolean("sonar.showSqlResults", false);
-    return showSql ? "DEBUG" : "WARN";
-  }
-
-  private Configuration getInitialConfiguration(ProjectDefinition project) {
-    CompositeConfiguration configuration = new CompositeConfiguration();
-    configuration.addConfiguration(new SystemConfiguration());
-    configuration.addConfiguration(new EnvironmentConfiguration());
-    configuration.addConfiguration(new MapConfiguration(project.getProperties()));
-    return configuration;
-  }
-
-}
diff --git a/src/main/java/org/sonar/runner/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/batch/SonarProjectBuilder.java
deleted file mode 100644 (file)
index 2861d09..0000000
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-
-package org.sonar.runner.batch;
-
-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.WildcardFileFilter;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.runner.RunnerException;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.IOException;
-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.
- * 
- * @since 1.5
- */
-public final class SonarProjectBuilder {
-
-  private static final Logger LOG = LoggerFactory.getLogger(SonarProjectBuilder.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.
-   */
-  private static final String[] MANDATORY_PROPERTIES_FOR_PROJECT = {PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION,
-    PROPERTY_SOURCES};
-
-  /**
-   * 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 Properties properties;
-
-  private SonarProjectBuilder(Properties properties) {
-    this.properties = properties;
-  }
-
-  public static SonarProjectBuilder create(Properties properties) {
-    return new SonarProjectBuilder(properties);
-  }
-
-  public ProjectDefinition generateProjectDefinition() {
-    ProjectDefinition rootProject = defineProject(properties);
-    defineChildren(rootProject);
-    cleanAndCheckProjectDefinitions(rootProject);
-    return rootProject;
-  }
-
-  private ProjectDefinition defineProject(Properties properties) {
-    checkMandatoryProperties("root project", properties, MANDATORY_PROPERTIES_FOR_PROJECT);
-    File baseDir = new File(properties.getProperty(PROPERTY_PROJECT_BASEDIR));
-    ProjectDefinition definition = ProjectDefinition.create((Properties) properties.clone())
-        .setBaseDir(baseDir)
-        .setWorkDir(initWorkDir(baseDir));
-    return definition;
-  }
-
-  @VisibleForTesting
-  protected File initWorkDir(File baseDir) {
-    String workDir = properties.getProperty(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());
-  }
-
-  private void defineChildren(ProjectDefinition parentProject) {
-    Properties parentProps = parentProject.getProperties();
-    if (parentProps.containsKey(PROPERTY_MODULES)) {
-      for (String module : SonarRunnerUtils.getListFromProperty(parentProps, PROPERTY_MODULES)) {
-        Properties moduleProps = extractModuleProperties(module, parentProps);
-        ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, module);
-        // check the unicity of the child key
-        checkUnicityOfChildKey(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) {
-    setProjectKeyIfNotDefined(moduleProps, moduleId);
-
-    if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
-      File baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
-      setProjectBaseDir(baseDir, moduleProps, moduleId);
-      tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
-    } else if (moduleProps.containsKey(PROPERTY_PROJECT_CONFIG_FILE)) {
-      loadPropsFile(parentProject, moduleProps, moduleId);
-    } else {
-      File baseDir = new File(parentProject.getBaseDir(), moduleId);
-      setProjectBaseDir(baseDir, moduleProps, moduleId);
-      tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
-    }
-
-    // and finish
-    checkMandatoryProperties(moduleId, moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
-    mergeParentProperties(moduleProps, parentProject.getProperties());
-
-    prefixProjectKeyWithParentKey(moduleProps, parentProject.getKey());
-
-    return defineProject(moduleProps);
-  }
-
-  protected void 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);
-    } else {
-      throw new RunnerException("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 RunnerException("Impossible to read the property file: " + propertyFile.getAbsolutePath(), e);
-    } finally {
-      IOUtils.closeQuietly(fileInputStream);
-    }
-    return propsFromFile;
-  }
-
-  @VisibleForTesting
-  protected static void setProjectKeyIfNotDefined(Properties childProps, String moduleId) {
-    if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
-      childProps.put(PROPERTY_PROJECT_KEY, moduleId);
-    }
-  }
-
-  @VisibleForTesting
-  protected static void checkUnicityOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
-    for (ProjectDefinition definition : parentProject.getSubProjects()) {
-      if (definition.getKey().equals(childProject.getKey())) {
-        throw new RunnerException("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 RunnerException("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath());
-    }
-    childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath());
-  }
-
-  @VisibleForTesting
-  protected static void checkMandatoryProperties(String moduleId, 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);
-      }
-    }
-    if (missing.length() != 0) {
-      String projectKey = props.getProperty(PROPERTY_PROJECT_KEY);
-      throw new RunnerException("You must define the following mandatory properties for '" + (projectKey == null ? moduleId : projectKey) + "': " + missing);
-    }
-  }
-
-  @VisibleForTesting
-  protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) {
-    if (project.getSubProjects().isEmpty()) {
-      cleanAndCheckModuleProperties(project);
-    } else {
-      cleanAggregatorProjectProperties(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 = SonarRunnerUtils.getListFromProperty(properties, PROPERTY_SOURCES);
-    checkExistenceOfDirectories(project.getKey(), project.getBaseDir(), sourceDirs);
-
-    // And we need to resolve patterns that may have been used in "sonar.libraries"
-    List<String> libPaths = Lists.newArrayList();
-    for (String pattern : SonarRunnerUtils.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 cleanAggregatorProjectProperties(ProjectDefinition project) {
-    Properties properties = project.getProperties();
-
-    // "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(SonarRunnerUtils.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(SonarRunnerUtils.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 projectKey, File baseDir, String[] sourceDirs) {
-    for (String path : sourceDirs) {
-      File sourceFolder = getFileFromPath(path, baseDir);
-      if (!sourceFolder.isDirectory()) {
-        throw new RunnerException("The folder '" + path + "' does not exist for '" + projectKey +
-          "' project (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);
-    }
-    FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(filePattern));
-    File dir = resolvePath(baseDir, dirPath);
-    File[] files = dir.listFiles(fileFilter);
-    if (files == null || files.length == 0) {
-      throw new RunnerException("No files matching pattern \"" + filePattern + "\" in directory \"" + dir + "\"");
-    }
-    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 RunnerException("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;
-  }
-
-}
diff --git a/src/main/java/org/sonar/runner/batch/SonarRunnerUtils.java b/src/main/java/org/sonar/runner/batch/SonarRunnerUtils.java
deleted file mode 100644 (file)
index b4a4842..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-package org.sonar.runner.batch;
-
-import org.apache.commons.lang.StringUtils;
-
-import java.util.Properties;
-
-/**
- * Public utility that can be used by consumers of the Sonar Runner.
- */
-public final class SonarRunnerUtils {
-
-  private SonarRunnerUtils() {
-    // only static methods
-  }
-
-  /**
-   * 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, ...)
-   *
-   */
-  public static String[] getListFromProperty(Properties properties, String key) {
-    return StringUtils.stripAll(StringUtils.split(properties.getProperty(key, ""), ','));
-  }
-
-}
diff --git a/src/main/java/org/sonar/runner/batch/package-info.java b/src/main/java/org/sonar/runner/batch/package-info.java
deleted file mode 100644 (file)
index cbeee96..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-/**
- * Internal package that creates the project definition and launches the analyses based on it.
- * Should not be used by consumers.
- */
-package org.sonar.runner.batch;
\ No newline at end of file
diff --git a/src/main/java/org/sonar/runner/internal/batch/Launcher.java b/src/main/java/org/sonar/runner/internal/batch/Launcher.java
new file mode 100644 (file)
index 0000000..cb689bf
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+package org.sonar.runner.internal.batch;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.configuration.*;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.utils.SonarException;
+import org.sonar.batch.Batch;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.runner.Runner;
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Contrary to {@link org.sonar.runner.Runner}, this class is executed within the classloader
+ * provided by the server. It contains the installed plugins and the same version of sonar-batch as the server.
+ */
+public class Launcher {
+
+  private Properties propertiesFromRunner;
+  private List<Object> containerExtensions;
+
+  public Launcher(Properties properties, List<Object> containerExtensions) {
+    this.propertiesFromRunner = properties;
+    this.containerExtensions = containerExtensions;
+  }
+
+  /**
+   * Main entry point.
+   */
+  public void execute() {
+    ProjectDefinition project = SonarProjectBuilder.create(propertiesFromRunner).generateProjectDefinition();
+    Configuration initialConfiguration = getInitialConfiguration(project);
+    initLogging(initialConfiguration);
+    executeBatch(project, initialConfiguration);
+  }
+
+  private void executeBatch(ProjectDefinition project, Configuration initialConfiguration) {
+    setContainerExtensionsOnProject(project);
+    String envKey = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY);
+    String envVersion = propertiesFromRunner.getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION);
+    Batch batch = Batch.create(new ProjectReactor(project), initialConfiguration, new EnvironmentInformation(envKey, envVersion));
+    batch.execute();
+  }
+
+  private void setContainerExtensionsOnProject(ProjectDefinition projectDefinition) {
+    for (Object extension : containerExtensions) {
+      projectDefinition.addContainerExtension(extension);
+    }
+    for (ProjectDefinition module : projectDefinition.getSubProjects()) {
+      setContainerExtensionsOnProject(module);
+    }
+  }
+
+  private void initLogging(Configuration initialConfiguration) {
+    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+    JoranConfigurator jc = new JoranConfigurator();
+    jc.setContext(context);
+    context.reset();
+    InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml");
+    System.setProperty("ROOT_LOGGER_LEVEL", isDebug() ? "DEBUG" : "INFO");
+    context.putProperty("SQL_LOGGER_LEVEL", getSqlLevel(initialConfiguration));// since 2.14. Ignored on previous versions.
+    context.putProperty("SQL_RESULTS_LOGGER_LEVEL", getSqlResultsLevel(initialConfiguration));// since 2.14. Ignored on previous versions.
+    try {
+      jc.doConfigure(input);
+
+    } catch (JoranException e) {
+      throw new SonarException("can not initialize logging", e);
+
+    } finally {
+      IOUtils.closeQuietly(input);
+    }
+  }
+
+  @VisibleForTesting
+  protected boolean isDebug() {
+    return Boolean.parseBoolean(propertiesFromRunner.getProperty(Runner.PROPERTY_VERBOSE, propertiesFromRunner.getProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "false")));
+  }
+
+  @VisibleForTesting
+  protected static String getSqlLevel(Configuration config) {
+    boolean showSql = config.getBoolean("sonar.showSql", false);
+    return showSql ? "DEBUG" : "WARN";
+  }
+
+  @VisibleForTesting
+  protected static String getSqlResultsLevel(Configuration config) {
+    boolean showSql = config.getBoolean("sonar.showSqlResults", false);
+    return showSql ? "DEBUG" : "WARN";
+  }
+
+  private Configuration getInitialConfiguration(ProjectDefinition project) {
+    CompositeConfiguration configuration = new CompositeConfiguration();
+    configuration.addConfiguration(new SystemConfiguration());
+    configuration.addConfiguration(new EnvironmentConfiguration());
+    configuration.addConfiguration(new MapConfiguration(project.getProperties()));
+    return configuration;
+  }
+
+}
diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java b/src/main/java/org/sonar/runner/internal/batch/SonarProjectBuilder.java
new file mode 100644 (file)
index 0000000..e4cd483
--- /dev/null
@@ -0,0 +1,451 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+
+package org.sonar.runner.internal.batch;
+
+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.WildcardFileFilter;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.runner.RunnerException;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+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.
+ * 
+ * @since 1.5
+ */
+public final class SonarProjectBuilder {
+
+  private static final Logger LOG = LoggerFactory.getLogger(SonarProjectBuilder.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.
+   */
+  private static final String[] MANDATORY_PROPERTIES_FOR_PROJECT = {PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION,
+    PROPERTY_SOURCES};
+
+  /**
+   * 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 Properties properties;
+
+  private SonarProjectBuilder(Properties properties) {
+    this.properties = properties;
+  }
+
+  public static SonarProjectBuilder create(Properties properties) {
+    return new SonarProjectBuilder(properties);
+  }
+
+  public ProjectDefinition generateProjectDefinition() {
+    ProjectDefinition rootProject = defineProject(properties);
+    defineChildren(rootProject);
+    cleanAndCheckProjectDefinitions(rootProject);
+    return rootProject;
+  }
+
+  private ProjectDefinition defineProject(Properties properties) {
+    checkMandatoryProperties("root project", properties, MANDATORY_PROPERTIES_FOR_PROJECT);
+    File baseDir = new File(properties.getProperty(PROPERTY_PROJECT_BASEDIR));
+    ProjectDefinition definition = ProjectDefinition.create((Properties) properties.clone())
+        .setBaseDir(baseDir)
+        .setWorkDir(initWorkDir(baseDir));
+    return definition;
+  }
+
+  @VisibleForTesting
+  protected File initWorkDir(File baseDir) {
+    String workDir = properties.getProperty(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());
+  }
+
+  private void defineChildren(ProjectDefinition parentProject) {
+    Properties parentProps = parentProject.getProperties();
+    if (parentProps.containsKey(PROPERTY_MODULES)) {
+      for (String module : SonarRunnerUtils.getListFromProperty(parentProps, PROPERTY_MODULES)) {
+        Properties moduleProps = extractModuleProperties(module, parentProps);
+        ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, module);
+        // check the unicity of the child key
+        checkUnicityOfChildKey(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) {
+    setProjectKeyIfNotDefined(moduleProps, moduleId);
+
+    if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
+      File baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
+      setProjectBaseDir(baseDir, moduleProps, moduleId);
+      tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+    } else if (moduleProps.containsKey(PROPERTY_PROJECT_CONFIG_FILE)) {
+      loadPropsFile(parentProject, moduleProps, moduleId);
+    } else {
+      File baseDir = new File(parentProject.getBaseDir(), moduleId);
+      setProjectBaseDir(baseDir, moduleProps, moduleId);
+      tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId);
+    }
+
+    // and finish
+    checkMandatoryProperties(moduleId, moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
+    mergeParentProperties(moduleProps, parentProject.getProperties());
+
+    prefixProjectKeyWithParentKey(moduleProps, parentProject.getKey());
+
+    return defineProject(moduleProps);
+  }
+
+  protected void 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);
+    } else {
+      throw new RunnerException("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 RunnerException("Impossible to read the property file: " + propertyFile.getAbsolutePath(), e);
+    } finally {
+      IOUtils.closeQuietly(fileInputStream);
+    }
+    return propsFromFile;
+  }
+
+  @VisibleForTesting
+  protected static void setProjectKeyIfNotDefined(Properties childProps, String moduleId) {
+    if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
+      childProps.put(PROPERTY_PROJECT_KEY, moduleId);
+    }
+  }
+
+  @VisibleForTesting
+  protected static void checkUnicityOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
+    for (ProjectDefinition definition : parentProject.getSubProjects()) {
+      if (definition.getKey().equals(childProject.getKey())) {
+        throw new RunnerException("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 RunnerException("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath());
+    }
+    childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath());
+  }
+
+  @VisibleForTesting
+  protected static void checkMandatoryProperties(String moduleId, 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);
+      }
+    }
+    if (missing.length() != 0) {
+      String projectKey = props.getProperty(PROPERTY_PROJECT_KEY);
+      throw new RunnerException("You must define the following mandatory properties for '" + (projectKey == null ? moduleId : projectKey) + "': " + missing);
+    }
+  }
+
+  @VisibleForTesting
+  protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) {
+    if (project.getSubProjects().isEmpty()) {
+      cleanAndCheckModuleProperties(project);
+    } else {
+      cleanAggregatorProjectProperties(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 = SonarRunnerUtils.getListFromProperty(properties, PROPERTY_SOURCES);
+    checkExistenceOfDirectories(project.getKey(), project.getBaseDir(), sourceDirs);
+
+    // And we need to resolve patterns that may have been used in "sonar.libraries"
+    List<String> libPaths = Lists.newArrayList();
+    for (String pattern : SonarRunnerUtils.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 cleanAggregatorProjectProperties(ProjectDefinition project) {
+    Properties properties = project.getProperties();
+
+    // "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(SonarRunnerUtils.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(SonarRunnerUtils.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 projectKey, File baseDir, String[] sourceDirs) {
+    for (String path : sourceDirs) {
+      File sourceFolder = getFileFromPath(path, baseDir);
+      if (!sourceFolder.isDirectory()) {
+        throw new RunnerException("The folder '" + path + "' does not exist for '" + projectKey +
+          "' project (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);
+    }
+    FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(filePattern));
+    File dir = resolvePath(baseDir, dirPath);
+    File[] files = dir.listFiles(fileFilter);
+    if (files == null || files.length == 0) {
+      throw new RunnerException("No files matching pattern \"" + filePattern + "\" in directory \"" + dir + "\"");
+    }
+    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 RunnerException("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;
+  }
+
+}
diff --git a/src/main/java/org/sonar/runner/internal/batch/SonarRunnerUtils.java b/src/main/java/org/sonar/runner/internal/batch/SonarRunnerUtils.java
new file mode 100644 (file)
index 0000000..3f4725b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+package org.sonar.runner.internal.batch;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Properties;
+
+/**
+ * Public utility that can be used by consumers of the Sonar Runner.
+ */
+public final class SonarRunnerUtils {
+
+  private SonarRunnerUtils() {
+    // only static methods
+  }
+
+  /**
+   * 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, ...)
+   *
+   */
+  public static String[] getListFromProperty(Properties properties, String key) {
+    return StringUtils.stripAll(StringUtils.split(properties.getProperty(key, ""), ','));
+  }
+
+}
diff --git a/src/main/java/org/sonar/runner/internal/batch/package-info.java b/src/main/java/org/sonar/runner/internal/batch/package-info.java
new file mode 100644 (file)
index 0000000..cd9bbf4
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+/**
+ * Internal package that creates the project definition and launches the analyses based on it.
+ * Should not be used by consumers.
+ */
+package org.sonar.runner.internal.batch;
\ No newline at end of file
index 935297e093e7863d042a746fcaf157ce3752fbcc..ad513c37c39fe1aae31710e01cf4bec0f3180d95 100644 (file)
@@ -33,7 +33,7 @@ public class BootstrapClassLoaderTest {
   @Test
   public void should_restrict_loading_from_parent() throws Exception {
     BootstrapClassLoader classLoader = new BootstrapClassLoader(getClass().getClassLoader(), "org.apache.ant");
-    assertThat(classLoader.canLoadFromParent("org.sonar.runner.batch.Launcher")).isFalse();
+    assertThat(classLoader.canLoadFromParent("org.sonar.runner.internal.batch.Launcher")).isFalse();
     assertThat(classLoader.canLoadFromParent("org.sonar.runner.Runner")).isTrue();
     assertThat(classLoader.canLoadFromParent("org.objectweb.asm.ClassVisitor")).isFalse();
     assertThat(classLoader.canLoadFromParent("org.apache.ant.project.Project")).isTrue();
diff --git a/src/test/java/org/sonar/runner/batch/LauncherTest.java b/src/test/java/org/sonar/runner/batch/LauncherTest.java
deleted file mode 100644 (file)
index 54c1a92..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-package org.sonar.runner.batch;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.junit.Test;
-import org.sonar.runner.Runner;
-
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LauncherTest {
-
-  @Test
-  public void testGetSqlLevel() throws Exception {
-    Configuration conf = new BaseConfiguration();
-
-    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
-
-    conf.setProperty("sonar.showSql", "true");
-    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("DEBUG");
-
-    conf.setProperty("sonar.showSql", "false");
-    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
-  }
-
-  @Test
-  public void testGetSqlResultsLevel() throws Exception {
-    Configuration conf = new BaseConfiguration();
-
-    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
-
-    conf.setProperty("sonar.showSqlResults", "true");
-    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("DEBUG");
-
-    conf.setProperty("sonar.showSqlResults", "false");
-    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
-  }
-
-  @Test
-  public void shouldDetermineVerboseMode() {
-    Properties properties = new Properties();
-    Launcher launcher = new Launcher(properties, Lists.newArrayList());
-    assertThat(launcher.isDebug()).isFalse();
-    properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
-    assertThat(launcher.isDebug()).isTrue();
-  }
-
-  @Test
-  public void shouldSupportDeprecatedDebugProperty() {
-    Properties properties = new Properties();
-    Launcher launcher = new Launcher(properties, Lists.newArrayList());
-    properties.setProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "true");
-    assertThat(launcher.isDebug()).isTrue();
-  }
-
-}
diff --git a/src/test/java/org/sonar/runner/batch/SonarProjectBuilderTest.java b/src/test/java/org/sonar/runner/batch/SonarProjectBuilderTest.java
deleted file mode 100644 (file)
index cb8b1f0..0000000
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-package org.sonar.runner.batch;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.runner.RunnerException;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class SonarProjectBuilderTest {
-
-  @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.getTestDirs()).contains("tests");
-    assertThat(projectDefinition.getBinaries()).contains("target/classes");
-    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.getTestDirs()).contains("tests");
-    assertThat(projectDefinition.getBinaries()).contains("target/classes");
-    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(RunnerException.class);
-    thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' 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 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: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()).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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
-    assertThat(rootProject.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-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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
-    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-  }
-
-  @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()).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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
-    assertThat(rootProject.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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
-    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-  }
-
-  @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(RunnerException.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(RunnerException.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 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 = SonarProjectBuilder.extractModuleProperties("bar", props);
-    assertThat(moduleProps.size()).isEqualTo(0);
-
-    moduleProps = SonarProjectBuilder.extractModuleProperties("foo", props);
-    assertThat(moduleProps.size()).isEqualTo(1);
-    assertThat(moduleProps.get("sources")).isEqualTo("src/main/java");
-
-    moduleProps = SonarProjectBuilder.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(RunnerException.class);
-    thrown.expectMessage("You must define the following mandatory properties for 'foo': foo2, foo3");
-
-    SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1", "foo2", "foo3"});
-  }
-
-  @Test
-  public void shouldNotFailIfMandatoryPropertiesArePresent() {
-    Properties props = new Properties();
-    props.setProperty("foo1", "bla");
-    props.setProperty("foo4", "bla");
-
-    SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1"});
-
-    // No exception should be thrown
-  }
-
-  @Test
-  public void shouldFilterFiles() throws Exception {
-    File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
-    assertThat(SonarProjectBuilder.getLibraries(baseDir, "in*.txt").length).isEqualTo(1);
-    assertThat(SonarProjectBuilder.getLibraries(baseDir, "*.txt").length).isEqualTo(2);
-    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/in*.txt").length).isEqualTo(1);
-    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/*.txt").length).isEqualTo(2);
-  }
-
-  @Test
-  public void shouldWorkWithAbsolutePath() throws Exception {
-    File baseDir = new File("not-exists");
-    String absolutePattern = TestUtils.getResource(this.getClass(), "shouldFilterFiles").getAbsolutePath() + "/in*.txt";
-    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), absolutePattern).length).isEqualTo(1);
-  }
-
-  @Test
-  public void shouldThrowExceptionWhenNoFilesMatchingPattern() throws Exception {
-    File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
-
-    thrown.expect(RunnerException.class);
-    thrown.expectMessage("No files matching pattern \"*.jar\" in directory");
-
-    SonarProjectBuilder.getLibraries(baseDir, "*.jar");
-  }
-
-  @Test
-  public void shouldGetRelativeFile() {
-    assertThat(SonarProjectBuilder.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(SonarProjectBuilder.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");
-
-    SonarProjectBuilder.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 shouldInitWorkDir() {
-    SonarProjectBuilder builder = SonarProjectBuilder.create(new Properties());
-    File baseDir = new File("target/tmp/baseDir");
-
-    File workDir = builder.initWorkDir(baseDir);
-
-    assertThat(workDir).isEqualTo(new File(baseDir, ".sonar"));
-  }
-
-  @Test
-  public void shouldInitWorkDirWithCustomRelativeFolder() {
-    Properties properties = new Properties();
-    properties.put("sonar.working.directory", ".foo");
-    SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
-    File baseDir = new File("target/tmp/baseDir");
-
-    File workDir = builder.initWorkDir(baseDir);
-
-    assertThat(workDir).isEqualTo(new File(baseDir, ".foo"));
-  }
-
-  @Test
-  public void shouldInitWorkDirWithCustomAbsoluteFolder() {
-    Properties properties = new Properties();
-    properties.put("sonar.working.directory", new File("src").getAbsolutePath());
-    SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
-    File baseDir = new File("target/tmp/baseDir");
-
-    File workDir = builder.initWorkDir(baseDir);
-
-    assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile());
-  }
-
-  @Test
-  public void shouldReturnPrefixedKey() {
-    Properties props = new Properties();
-    props.put("sonar.projectKey", "my-module-key");
-
-    SonarProjectBuilder.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(props);
-
-    Properties props1 = new Properties();
-    props1.put("sonar.projectKey", "mod1");
-    root.addSubProject(ProjectDefinition.create(props1));
-
-    // Check unicity of a new module: OK
-    Properties props2 = new Properties();
-    props2.put("sonar.projectKey", "mod2");
-    ProjectDefinition mod2 = ProjectDefinition.create(props2);
-    SonarProjectBuilder.checkUnicityOfChildKey(mod2, root);
-
-    // Now, add it and check again
-    root.addSubProject(mod2);
-
-    thrown.expect(RunnerException.class);
-    thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
-
-    SonarProjectBuilder.checkUnicityOfChildKey(mod2, root);
-  }
-
-  @Test
-  public void shouldSetProjectKeyIfNotPresent() {
-    Properties props = new Properties();
-    props.put("sonar.projectVersion", "1.0");
-
-    // should be set
-    SonarProjectBuilder.setProjectKeyIfNotDefined(props, "foo");
-    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
-
-    // but not this 2nd time
-    SonarProjectBuilder.setProjectKeyIfNotDefined(props, "bar");
-    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
-  }
-
-  @Test
-  public void shouldFailToLoadPropertiesFile() throws Exception {
-    thrown.expect(RunnerException.class);
-    thrown.expectMessage("Impossible to read the property file");
-
-    SonarProjectBuilder.toProperties(new File("foo.properties"));
-  }
-
-  private ProjectDefinition loadProjectDefinition(String projectFolder) throws FileNotFoundException, IOException {
-    Properties props = SonarProjectBuilder.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
-    props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
-    ProjectDefinition projectDefinition = SonarProjectBuilder.create(props)
-        .generateProjectDefinition();
-    return projectDefinition;
-  }
-
-}
diff --git a/src/test/java/org/sonar/runner/batch/SonarRunnerUtilsTest.java b/src/test/java/org/sonar/runner/batch/SonarRunnerUtilsTest.java
deleted file mode 100644 (file)
index 0d368bf..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar Standalone Runner
- * Copyright (C) 2011 SonarSource
- * dev@sonar.codehaus.org
- *
- * This program 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.
- *
- * This program 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  02
- */
-package org.sonar.runner.batch;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.sonar.test.TestUtils;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class SonarRunnerUtilsTest {
-
-  @Test
-  public void shouldGetList() {
-    Properties props = new Properties();
-
-    props.put("prop", "  foo  ,  bar  , \n\ntoto,tutu");
-    assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
-  }
-
-  @Test
-  public void shouldGetListFromFile() throws IOException {
-    String filePath = "shouldGetList/foo.properties";
-    Properties props = loadPropsFromFile(filePath);
-
-    assertThat(SonarRunnerUtils.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;
-  }
-
-}
diff --git a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
new file mode 100644 (file)
index 0000000..979a517
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+package org.sonar.runner.internal.batch;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.junit.Test;
+import org.sonar.runner.Runner;
+
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class LauncherTest {
+
+  @Test
+  public void testGetSqlLevel() throws Exception {
+    Configuration conf = new BaseConfiguration();
+
+    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
+
+    conf.setProperty("sonar.showSql", "true");
+    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("DEBUG");
+
+    conf.setProperty("sonar.showSql", "false");
+    assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
+  }
+
+  @Test
+  public void testGetSqlResultsLevel() throws Exception {
+    Configuration conf = new BaseConfiguration();
+
+    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
+
+    conf.setProperty("sonar.showSqlResults", "true");
+    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("DEBUG");
+
+    conf.setProperty("sonar.showSqlResults", "false");
+    assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
+  }
+
+  @Test
+  public void shouldDetermineVerboseMode() {
+    Properties properties = new Properties();
+    Launcher launcher = new Launcher(properties, Lists.newArrayList());
+    assertThat(launcher.isDebug()).isFalse();
+    properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
+    assertThat(launcher.isDebug()).isTrue();
+  }
+
+  @Test
+  public void shouldSupportDeprecatedDebugProperty() {
+    Properties properties = new Properties();
+    Launcher launcher = new Launcher(properties, Lists.newArrayList());
+    properties.setProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "true");
+    assertThat(launcher.isDebug()).isTrue();
+  }
+
+}
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
new file mode 100644 (file)
index 0000000..aa8209f
--- /dev/null
@@ -0,0 +1,438 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+package org.sonar.runner.internal.batch;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.runner.RunnerException;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SonarProjectBuilderTest {
+
+  @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.getTestDirs()).contains("tests");
+    assertThat(projectDefinition.getBinaries()).contains("target/classes");
+    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.getTestDirs()).contains("tests");
+    assertThat(projectDefinition.getBinaries()).contains("target/classes");
+    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(RunnerException.class);
+    thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' 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 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: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()).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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.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-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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+  }
+
+  @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()).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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.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(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
+    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
+  }
+
+  @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(RunnerException.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(RunnerException.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 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 = SonarProjectBuilder.extractModuleProperties("bar", props);
+    assertThat(moduleProps.size()).isEqualTo(0);
+
+    moduleProps = SonarProjectBuilder.extractModuleProperties("foo", props);
+    assertThat(moduleProps.size()).isEqualTo(1);
+    assertThat(moduleProps.get("sources")).isEqualTo("src/main/java");
+
+    moduleProps = SonarProjectBuilder.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(RunnerException.class);
+    thrown.expectMessage("You must define the following mandatory properties for 'foo': foo2, foo3");
+
+    SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1", "foo2", "foo3"});
+  }
+
+  @Test
+  public void shouldNotFailIfMandatoryPropertiesArePresent() {
+    Properties props = new Properties();
+    props.setProperty("foo1", "bla");
+    props.setProperty("foo4", "bla");
+
+    SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1"});
+
+    // No exception should be thrown
+  }
+
+  @Test
+  public void shouldFilterFiles() throws Exception {
+    File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
+    assertThat(SonarProjectBuilder.getLibraries(baseDir, "in*.txt").length).isEqualTo(1);
+    assertThat(SonarProjectBuilder.getLibraries(baseDir, "*.txt").length).isEqualTo(2);
+    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/in*.txt").length).isEqualTo(1);
+    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/*.txt").length).isEqualTo(2);
+  }
+
+  @Test
+  public void shouldWorkWithAbsolutePath() throws Exception {
+    File baseDir = new File("not-exists");
+    String absolutePattern = TestUtils.getResource(this.getClass(), "shouldFilterFiles").getAbsolutePath() + "/in*.txt";
+    assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), absolutePattern).length).isEqualTo(1);
+  }
+
+  @Test
+  public void shouldThrowExceptionWhenNoFilesMatchingPattern() throws Exception {
+    File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
+
+    thrown.expect(RunnerException.class);
+    thrown.expectMessage("No files matching pattern \"*.jar\" in directory");
+
+    SonarProjectBuilder.getLibraries(baseDir, "*.jar");
+  }
+
+  @Test
+  public void shouldGetRelativeFile() {
+    assertThat(SonarProjectBuilder.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(SonarProjectBuilder.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");
+
+    SonarProjectBuilder.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 shouldInitWorkDir() {
+    SonarProjectBuilder builder = SonarProjectBuilder.create(new Properties());
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File(baseDir, ".sonar"));
+  }
+
+  @Test
+  public void shouldInitWorkDirWithCustomRelativeFolder() {
+    Properties properties = new Properties();
+    properties.put("sonar.working.directory", ".foo");
+    SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File(baseDir, ".foo"));
+  }
+
+  @Test
+  public void shouldInitWorkDirWithCustomAbsoluteFolder() {
+    Properties properties = new Properties();
+    properties.put("sonar.working.directory", new File("src").getAbsolutePath());
+    SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
+    File baseDir = new File("target/tmp/baseDir");
+
+    File workDir = builder.initWorkDir(baseDir);
+
+    assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile());
+  }
+
+  @Test
+  public void shouldReturnPrefixedKey() {
+    Properties props = new Properties();
+    props.put("sonar.projectKey", "my-module-key");
+
+    SonarProjectBuilder.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(props);
+
+    Properties props1 = new Properties();
+    props1.put("sonar.projectKey", "mod1");
+    root.addSubProject(ProjectDefinition.create(props1));
+
+    // Check unicity of a new module: OK
+    Properties props2 = new Properties();
+    props2.put("sonar.projectKey", "mod2");
+    ProjectDefinition mod2 = ProjectDefinition.create(props2);
+    SonarProjectBuilder.checkUnicityOfChildKey(mod2, root);
+
+    // Now, add it and check again
+    root.addSubProject(mod2);
+
+    thrown.expect(RunnerException.class);
+    thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
+
+    SonarProjectBuilder.checkUnicityOfChildKey(mod2, root);
+  }
+
+  @Test
+  public void shouldSetProjectKeyIfNotPresent() {
+    Properties props = new Properties();
+    props.put("sonar.projectVersion", "1.0");
+
+    // should be set
+    SonarProjectBuilder.setProjectKeyIfNotDefined(props, "foo");
+    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+
+    // but not this 2nd time
+    SonarProjectBuilder.setProjectKeyIfNotDefined(props, "bar");
+    assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+  }
+
+  @Test
+  public void shouldFailToLoadPropertiesFile() throws Exception {
+    thrown.expect(RunnerException.class);
+    thrown.expectMessage("Impossible to read the property file");
+
+    SonarProjectBuilder.toProperties(new File("foo.properties"));
+  }
+
+  private ProjectDefinition loadProjectDefinition(String projectFolder) throws FileNotFoundException, IOException {
+    Properties props = SonarProjectBuilder.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
+    props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
+    ProjectDefinition projectDefinition = SonarProjectBuilder.create(props)
+        .generateProjectDefinition();
+    return projectDefinition;
+  }
+
+}
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java
new file mode 100644 (file)
index 0000000..bb19b64
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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  02
+ */
+package org.sonar.runner.internal.batch;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.test.TestUtils;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SonarRunnerUtilsTest {
+
+  @Test
+  public void shouldGetList() {
+    Properties props = new Properties();
+
+    props.put("prop", "  foo  ,  bar  , \n\ntoto,tutu");
+    assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
+  }
+
+  @Test
+  public void shouldGetListFromFile() throws IOException {
+    String filePath = "shouldGetList/foo.properties";
+    Properties props = loadPropsFromFile(filePath);
+
+    assertThat(SonarRunnerUtils.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;
+  }
+
+}
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties
deleted file mode 100644 (file)
index 4e29926..0000000
+++ /dev/null
@@ -1,20 +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
-
-module1.sonar.projectKey=com.foo.project.module1
-module1.sonar.projectName=Foo Module 1
-
-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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-basedir/sonar-project.properties
deleted file mode 100644 (file)
index 615f5c7..0000000
+++ /dev/null
@@ -1,14 +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.projectBaseDir=modules/module1
-module1.sonar.projectKey=com.foo.project.module1
-module1.sonar.projectName=Foo Module 1
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/any-file.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-configfile/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties
deleted file mode 100644 (file)
index 67fbf34..0000000
+++ /dev/null
@@ -1,13 +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.projectKey=com.foo.project.module1
-module1.sonar.projectName=Foo Module 1
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/multi-module-with-unexisting-file/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldGetFile/foo.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/shouldGetFile/foo.properties
deleted file mode 100644 (file)
index 8fbb104..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-prop=  foo, bar, \
-toto,\
-\
-tutu,
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib1.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib1.txt
deleted file mode 100644 (file)
index 81d4e95..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lib1
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib2.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib2.txt
deleted file mode 100644 (file)
index 7dacac0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lib2
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties
deleted file mode 100644 (file)
index acf3c83..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
-
-# Those are the deprecated properties
-sources=sources
-tests=tests
-binaries=target/classes
-libraries=libs/*.txt
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties
deleted file mode 100644 (file)
index 0b83b11..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-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/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib1.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib1.txt
deleted file mode 100644 (file)
index 81d4e95..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lib1
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib2.txt b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/libs/lib2.txt
deleted file mode 100644 (file)
index 7dacac0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lib2
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties
deleted file mode 100644 (file)
index ea8a1b5..0000000
+++ /dev/null
@@ -1,9 +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.libraries=libs/*.txt
diff --git a/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sources/Fake.java b/src/test/resources/org/sonar/runner/batch/SonarProjectBuilderTest/simple-project/sources/Fake.java
deleted file mode 100644 (file)
index 5967658..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Fake
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/batch/SonarRunnerUtilsTest/shouldGetList/foo.properties b/src/test/resources/org/sonar/runner/batch/SonarRunnerUtilsTest/shouldGetList/foo.properties
deleted file mode 100644 (file)
index 8fbb104..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-prop=  foo, bar, \
-toto,\
-\
-tutu,
\ No newline at end of file
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties
new file mode 100644 (file)
index 0000000..4e29926
--- /dev/null
@@ -0,0 +1,20 @@
+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
+
+module1.sonar.projectKey=com.foo.project.module1
+module1.sonar.projectName=Foo Module 1
+
+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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-definitions-in-each-module/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/any-file.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-configfile/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/multi-module-with-unexisting-file/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/exclude.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldFilterFiles/include.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/shouldGetFile/foo.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib1.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/libs/lib2.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sonar-project.properties
new file mode 100644 (file)
index 0000000..acf3c83
--- /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
+
+# Those are the deprecated properties
+sources=sources
+tests=tests
+binaries=target/classes
+libraries=libs/*.txt
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-deprecated-props/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/libs/lib1.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/libs/lib2.txt b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/sonar-project.properties
new file mode 100644 (file)
index 0000000..ea8a1b5
--- /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=sources
+sonar.tests=tests
+sonar.binaries=target/classes
+sonar.libraries=libs/*.txt
diff --git a/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/simple-project/sources/Fake.java b/src/test/resources/org/sonar/runner/internal/batch/SonarProjectBuilderTest/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/src/test/resources/org/sonar/runner/internal/batch/SonarRunnerUtilsTest/shouldGetList/foo.properties b/src/test/resources/org/sonar/runner/internal/batch/SonarRunnerUtilsTest/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