diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 12:25:05 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 12:25:16 +0200 |
commit | 5e5916cd83e20df7331bb3534e82f3845951b160 (patch) | |
tree | ecd59c3f473109fd75050ace9d78dd924cdaab75 /sonar-batch/src/main | |
parent | c073a325c80ef5d4c0d805b2545dd6be40b1892e (diff) | |
download | sonarqube-5e5916cd83e20df7331bb3534e82f3845951b160.tar.gz sonarqube-5e5916cd83e20df7331bb3534e82f3845951b160.zip |
SONAR-2468 new extension point org.sonar.api.bootstrap.ProjectBuilder
Diffstat (limited to 'sonar-batch/src/main')
12 files changed, 146 insertions, 161 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/Batch.java index 685b56faf65..2461b865064 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/Batch.java @@ -20,15 +20,46 @@ package org.sonar.batch; import org.apache.commons.configuration.Configuration; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.bootstrap.BootstrapModule; import org.sonar.batch.bootstrap.Module; +import org.sonar.batch.bootstrapper.Reactor; public final class Batch { private Module bootstrapModule; + /** + * @deprecated since 2.9. Replaced by the factory method. + */ + @Deprecated public Batch(Configuration configuration, Object... bootstrapperComponents) { - this.bootstrapModule = new BootstrapModule(configuration, bootstrapperComponents).init(); + this.bootstrapModule = new BootstrapModule(extractProjectReactor(bootstrapperComponents), configuration, bootstrapperComponents).init(); + } + + static ProjectReactor extractProjectReactor(Object[] components) { + Reactor deprecatedReactor = null; + for (Object component : components) { + if (component instanceof ProjectReactor) { + return (ProjectReactor) component; + } + if (component instanceof Reactor) { + deprecatedReactor = (Reactor) component; + } + } + + if (deprecatedReactor == null) { + throw new IllegalArgumentException("Project reactor is not defined"); + } + return deprecatedReactor.toProjectReactor(); + } + + private Batch(ProjectReactor reactor, Configuration configuration, Object... bootstrapperComponents) { + this.bootstrapModule = new BootstrapModule(reactor, configuration, bootstrapperComponents).init(); + } + + public static Batch create(ProjectReactor projectReactor, Configuration configuration, Object... bootstrapperComponents) { + return new Batch(projectReactor, configuration, bootstrapperComponents); } /** diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java index 978acf4b5d5..0009ec85645 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java @@ -22,8 +22,8 @@ package org.sonar.batch; import com.google.common.collect.Lists; import org.apache.maven.project.MavenProject; import org.sonar.api.batch.ProjectClasspath; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.batch.bootstrapper.ProjectDefinition; import java.io.File; import java.util.List; diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java index 90e8ec2e658..baa4e2394ec 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectFileSystem2.java @@ -23,11 +23,11 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import org.apache.commons.io.FileUtils; import org.apache.maven.project.MavenProject; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.resources.DefaultProjectFileSystem; import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.utils.SonarException; -import org.sonar.batch.bootstrapper.ProjectDefinition; import java.io.File; import java.io.IOException; diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java index b50f882ba58..be0ac861cd7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java @@ -21,19 +21,18 @@ package org.sonar.batch; import com.google.common.collect.Maps; import org.apache.maven.project.MavenProject; -import org.sonar.api.CoreProperties; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.utils.SonarException; -import org.sonar.batch.bootstrapper.ProjectDefinition; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Properties; public final class MavenProjectConverter { private MavenProjectConverter() { + // only static methods } public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { @@ -52,7 +51,7 @@ public final class MavenProjectConverter { for (Object moduleId : pom.getModules()) { File modulePath = new File(pom.getBasedir(), (String) moduleId); MavenProject module = paths.get(modulePath.getCanonicalPath()); - defs.get(pom).addModule(defs.get(module)); + defs.get(pom).addSubProject(defs.get(module)); } } } catch (IOException e) { @@ -66,23 +65,12 @@ public final class MavenProjectConverter { * Visibility has been relaxed for tests. */ static ProjectDefinition convert(MavenProject pom) { - Properties properties = new Properties(); - String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); - setProperty(properties, CoreProperties.PROJECT_KEY_PROPERTY, key); - setProperty(properties, CoreProperties.PROJECT_VERSION_PROPERTY, pom.getVersion()); - setProperty(properties, CoreProperties.PROJECT_NAME_PROPERTY, pom.getName()); - setProperty(properties, CoreProperties.PROJECT_DESCRIPTION_PROPERTY, pom.getDescription()); - properties.putAll(pom.getModel().getProperties()); - - ProjectDefinition def = new ProjectDefinition(pom.getBasedir(), null, properties); // TODO work directory ? - def.addContainerExtension(pom); - return def; - } - - private static void setProperty(Properties properties, String key, String value) { - if (value != null) { - properties.setProperty(key, value); - } + return new ProjectDefinition(pom.getBasedir(), null, pom.getModel().getProperties()) // TODO work directory ? + .setKey(key) + .setVersion(pom.getVersion()) + .setName(pom.getName()) + .setDescription(pom.getDescription()) + .addContainerExtension(pom); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 1761431ce7f..061348d4c66 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -22,33 +22,43 @@ package org.sonar.batch; import org.apache.commons.configuration.*; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; +import org.apache.maven.project.MavenProject; import org.sonar.api.CoreProperties; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.utils.SonarException; -import org.sonar.batch.bootstrapper.ProjectDefinition; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -public class ProjectBuilder { +public class ProjectConfigurator { private DatabaseSession databaseSession; - public ProjectBuilder(DatabaseSession databaseSession) { + public ProjectConfigurator(DatabaseSession databaseSession) { this.databaseSession = databaseSession; } - public Project create(ProjectDefinition project) { - Configuration configuration = getStartupConfiguration(project); - return new Project(loadProjectKey(project), loadProjectBranch(configuration), loadProjectName(project)) - .setDescription(project.getProperties().getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, "")) + public Project create(ProjectDefinition definition) { + Configuration configuration = getStartupConfiguration(definition); + Project project = new Project(definition.getKey(), loadProjectBranch(configuration), definition.getName()) + .setDescription(StringUtils.defaultString(definition.getDescription(), "")) .setPackaging("jar"); + // For backward compatibility we must set POM and actual packaging + for (Object component : definition.getContainerExtensions()) { + if (component instanceof MavenProject) { + MavenProject pom = (MavenProject) component; + project.setPom(pom); + project.setPackaging(pom.getPackaging()); + } + } + return project; } Configuration getStartupConfiguration(ProjectDefinition project) { @@ -59,24 +69,6 @@ public class ProjectBuilder { return configuration; } - private String getPropertyOrDie(ProjectDefinition project, String key) { - String value = project.getProperties().getProperty(key); - if (StringUtils.isBlank(value)) { - throw new SonarException("Property '" + key + "' must be specified"); - } - return value; - } - - String loadProjectKey(ProjectDefinition projectDefinition) { - return getPropertyOrDie(projectDefinition, CoreProperties.PROJECT_KEY_PROPERTY); - } - - String loadProjectName(ProjectDefinition projectDefinition) { - return projectDefinition.getProperties().getProperty( - CoreProperties.PROJECT_NAME_PROPERTY, - "Unnamed - " + loadProjectKey(projectDefinition)); - } - String loadProjectBranch(Configuration configuration) { return configuration.getString(CoreProperties.PROJECT_BRANCH_PROPERTY); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java index 1ea52bc5738..6f848ce7e37 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java @@ -23,84 +23,68 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; -import org.apache.maven.project.MavenProject; import org.slf4j.LoggerFactory; +import org.sonar.api.batch.bootstrap.ProjectBuilder; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; -import org.sonar.batch.bootstrapper.ProjectDefinition; -import org.sonar.batch.bootstrapper.Reactor; import java.io.IOException; import java.util.*; public class ProjectTree { - private ProjectBuilder projectBuilder; + private ProjectConfigurator configurator; + private ProjectReactor projectReactor; + private List<Project> projects; - private List<ProjectDefinition> definitions; - private Map<ProjectDefinition, Project> projectsMap; - - public ProjectTree(Reactor sonarReactor, DatabaseSession databaseSession) { - this.projectBuilder = new ProjectBuilder(databaseSession); - definitions = Lists.newArrayList(); - for (ProjectDefinition project : sonarReactor.getSortedProjects()) { - collectProjects(project, definitions); - } + private Map<ProjectDefinition, Project> projectsByDef; + + public ProjectTree(ProjectReactor projectReactor, DatabaseSession databaseSession, /* Must be executed after ProjectBuilders */ ProjectBuilder[] builders) { + this(projectReactor, databaseSession); } - /** - * for unit tests - */ - protected ProjectTree(ProjectBuilder projectBuilder, List<MavenProject> poms) { - this.projectBuilder = projectBuilder; - definitions = Lists.newArrayList(); - collectProjects(MavenProjectConverter.convert(poms, poms.get(0)), definitions); + public ProjectTree(ProjectReactor projectReactor, DatabaseSession databaseSession) { + configurator = new ProjectConfigurator(databaseSession); + this.projectReactor = projectReactor; } - /** - * for unit tests - */ - protected ProjectTree(List<Project> projects) { - this.projects = new ArrayList<Project>(projects); + ProjectTree(ProjectConfigurator configurator) { + this.configurator = configurator; } - /** - * Populates list of projects from hierarchy. - */ - private static void collectProjects(ProjectDefinition root, List<ProjectDefinition> collected) { - collected.add(root); - for (ProjectDefinition module : root.getModules()) { - collectProjects(module, collected); - } + public void start() throws IOException { + doStart(projectReactor.getProjects()); } - public void start() throws IOException { + void doStart(List<ProjectDefinition> definitions) { projects = Lists.newArrayList(); - projectsMap = Maps.newHashMap(); + projectsByDef = Maps.newHashMap(); for (ProjectDefinition def : definitions) { - Project project = projectBuilder.create(def); - projectsMap.put(def, project); + Project project = configurator.create(def); + projectsByDef.put(def, project); projects.add(project); } - for (Map.Entry<ProjectDefinition, Project> entry : projectsMap.entrySet()) { + for (Map.Entry<ProjectDefinition, Project> entry : projectsByDef.entrySet()) { ProjectDefinition def = entry.getKey(); Project project = entry.getValue(); - for (ProjectDefinition module : def.getModules()) { - projectsMap.get(module).setParent(project); + for (ProjectDefinition module : def.getSubProjects()) { + projectsByDef.get(module).setParent(project); } } // Configure - for (Map.Entry<ProjectDefinition, Project> entry : projectsMap.entrySet()) { - projectBuilder.configure(entry.getValue(), entry.getKey()); + for (Map.Entry<ProjectDefinition, Project> entry : projectsByDef.entrySet()) { + configurator.configure(entry.getValue(), entry.getKey()); } - applyModuleExclusions(); + applyExclusions(); } - void applyModuleExclusions() { + void applyExclusions() { for (Project project : projects) { String[] excludedArtifactIds = project.getConfiguration().getStringArray("sonar.skippedModules"); String[] includedArtifactIds = project.getConfiguration().getStringArray("sonar.includedModules"); @@ -131,7 +115,7 @@ public class ProjectTree { } } - for (Iterator<Project> it = projects.iterator(); it.hasNext();) { + for (Iterator<Project> it = projects.iterator(); it.hasNext(); ) { Project project = it.next(); if (project.isExcluded()) { LoggerFactory.getLogger(getClass()).info("Module {} is excluded from analysis", project.getName()); @@ -183,7 +167,7 @@ public class ProjectTree { } public ProjectDefinition getProjectDefinition(Project project) { - for (Map.Entry<ProjectDefinition, Project> entry : projectsMap.entrySet()) { + for (Map.Entry<ProjectDefinition, Project> entry : projectsByDef.entrySet()) { if (ObjectUtils.equals(entry.getValue(), project)) { return entry.getKey(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index fc9c344412a..10546623f32 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -21,6 +21,7 @@ package org.sonar.batch.bootstrap; import org.apache.commons.configuration.Configuration; import org.sonar.api.Plugin; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.HttpDownloader; import org.sonar.batch.FakeMavenPluginExecutor; import org.sonar.batch.MavenPluginExecutor; @@ -39,14 +40,17 @@ public class BootstrapModule extends Module { private Configuration configuration; private Object[] boostrapperComponents; + private ProjectReactor reactor; - public BootstrapModule(Configuration configuration, Object... boostrapperComponents) { + public BootstrapModule(ProjectReactor reactor, Configuration configuration, Object... boostrapperComponents) { + this.reactor = reactor; this.configuration = configuration; this.boostrapperComponents = boostrapperComponents; } @Override protected void configure() { + addComponent(reactor); addComponent(configuration); addComponent(ServerMetadata.class);// registered here because used by BootstrapClassLoader addComponent(TempDirectories.class);// registered here because used by BootstrapClassLoader diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java index a7907b6b08e..6214d8d4e53 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java @@ -60,6 +60,12 @@ public final class ExtensionUtils { return false; } + static boolean isMavenExtensionOnly(Object extension) { + Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass()); + SupportedEnvironment env = AnnotationUtils.getClassAnnotation(clazz, SupportedEnvironment.class); + return env!=null && env.value().length==1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]); + } + static boolean isType(Object extension, Class<? extends Extension> extensionClass) { Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass()); return extensionClass.isAssignableFrom(clazz); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java index bfb924cf7b4..49debff0d19 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectExtensionInstaller.java @@ -50,7 +50,6 @@ public final class ProjectExtensionInstaller implements BatchComponent { installExtension(module, extension, project, entry.getKey()); } } - installExtensionProviders(module, project); } @@ -72,7 +71,8 @@ public final class ProjectExtensionInstaller implements BatchComponent { if (ExtensionUtils.isBatchExtension(extension) && ExtensionUtils.isSupportedEnvironment(extension, environment) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT) && - !isDeactivatedCoverageExtension(extension, project, pluginKey)) { + !isDeactivatedCoverageExtension(extension, project, pluginKey) && + !isMavenExtensionOnEmulatedMavenProject(extension, project)) { module.addComponent(extension); return extension; @@ -80,6 +80,10 @@ public final class ProjectExtensionInstaller implements BatchComponent { return null; } + boolean isMavenExtensionOnEmulatedMavenProject(Object extension, Project project) { + return ExtensionUtils.isMavenExtensionOnly(extension) && project.getPom() == null; + } + /** * TODO this code is specific to Java projects and should be moved somewhere else */ diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java index 26c3609cbaf..7f1827a9808 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java @@ -19,10 +19,10 @@ */ package org.sonar.batch.bootstrap; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchExtensionDictionnary; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; @@ -34,7 +34,6 @@ import org.sonar.api.resources.ProjectFileSystem; import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.utils.SonarException; import org.sonar.batch.*; -import org.sonar.batch.bootstrapper.ProjectDefinition; import org.sonar.batch.components.PastViolationsLoader; import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.events.EventBus; @@ -69,18 +68,12 @@ public class ProjectModule extends Module { addComponent(projectDefinition); for (Object component : projectDefinition.getContainerExtensions()) { addComponent(component); - if (component instanceof MavenProject) { - // For backward compatibility we must set POM and actual packaging - MavenProject pom = (MavenProject) component; - project.setPom(pom); - project.setPackaging(pom.getPackaging()); - } } addComponent(project); + addComponent(project.getConfiguration()); addComponent(DefaultProjectClasspath.class); addComponent(DefaultProjectFileSystem2.class); - addComponent(project.getConfiguration()); addComponent(DaoFacade.class); addComponent(RulesDao.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java index 907f30940ac..e24d078f172 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java @@ -19,11 +19,8 @@ */ package org.sonar.batch.bootstrapper; -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; - import java.io.File; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -32,66 +29,44 @@ import java.util.Properties; * We assume that project is just a set of configuration properties and directories. * * @since 2.6 + * @deprecated since 2.9. Move into org.sonar.api.batch.bootstrap */ +@Deprecated public class ProjectDefinition { - private static final String PROJECT_SOURCES_PROPERTY = "sonar.sources"; - private static final String PROJECT_TESTS_PROPERTY = "sonar.tests"; - private static final String PROJECT_BINARIES_PROPERTY = "sonar.binaries"; - private static final String PROJECT_LIBRARIES_PROPERTY = "sonar.libraries"; - - private static final char SEPARATOR = ','; - - private File baseDir; - private File workDir; - private Properties properties; - private List<ProjectDefinition> modules = Lists.newArrayList(); - - private List<Object> containerExtensions = Lists.newArrayList(); + private org.sonar.api.batch.bootstrap.ProjectDefinition target = null; + private List<ProjectDefinition> children = new ArrayList<ProjectDefinition>(); /** * @param baseDir project base directory * @param properties project properties */ public ProjectDefinition(File baseDir, File workDir, Properties properties) { - this.baseDir = baseDir; - this.workDir = workDir; - this.properties = properties; + target = new org.sonar.api.batch.bootstrap.ProjectDefinition(baseDir, workDir, properties); } public File getBaseDir() { - return baseDir; + return target.getBaseDir(); } public File getWorkDir() { - return workDir; + return target.getWorkDir(); } public Properties getProperties() { - return properties; - } - - private void appendProperty(String key, String value) { - String newValue = properties.getProperty(key, "") + SEPARATOR + value; - properties.put(key, newValue); + return target.getProperties(); } public List<String> getSourceDirs() { - String sources = properties.getProperty(PROJECT_SOURCES_PROPERTY, ""); - return Arrays.asList(StringUtils.split(sources, SEPARATOR)); + return target.getSourceDirs(); } - /** - * @param path path to directory with main sources. - * It can be absolute or relative to project directory. - */ public void addSourceDir(String path) { - appendProperty(PROJECT_SOURCES_PROPERTY, path); + target.addSourceDir(path); } public List<String> getTestDirs() { - String sources = properties.getProperty(PROJECT_TESTS_PROPERTY, ""); - return Arrays.asList(StringUtils.split(sources, SEPARATOR)); + return target.getTestDirs(); } /** @@ -99,12 +74,11 @@ public class ProjectDefinition { * It can be absolute or relative to project directory. */ public void addTestDir(String path) { - appendProperty(PROJECT_TESTS_PROPERTY, path); + target.addTestDir(path); } public List<String> getBinaries() { - String sources = properties.getProperty(PROJECT_BINARIES_PROPERTY, ""); - return Arrays.asList(StringUtils.split(sources, SEPARATOR)); + return target.getBinaries(); } /** @@ -113,12 +87,11 @@ public class ProjectDefinition { * @TODO currently Sonar supports only one such directory due to dependency on MavenProject */ public void addBinaryDir(String path) { - appendProperty(PROJECT_BINARIES_PROPERTY, path); + target.addBinaryDir(path); } public List<String> getLibraries() { - String sources = properties.getProperty(PROJECT_LIBRARIES_PROPERTY, ""); - return Arrays.asList(StringUtils.split(sources, SEPARATOR)); + return target.getLibraries(); } /** @@ -126,7 +99,7 @@ public class ProjectDefinition { * It can be absolute or relative to project directory. */ public void addLibrary(String path) { - appendProperty(PROJECT_LIBRARIES_PROPERTY, path); + target.addLibrary(path); } /** @@ -135,27 +108,32 @@ public class ProjectDefinition { * @since 2.8 */ public void addContainerExtension(Object extension) { - containerExtensions.add(extension); + target.addContainerExtension(extension); } /** * @since 2.8 */ public List<Object> getContainerExtensions() { - return containerExtensions; + return target.getContainerExtensions(); } /** * @since 2.8 */ public void addModule(ProjectDefinition projectDefinition) { - modules.add(projectDefinition); + target.addSubProject(projectDefinition.toNewProjectDefinition()); + children.add(projectDefinition); } /** * @since 2.8 */ public List<ProjectDefinition> getModules() { - return modules; + return children; + } + + public org.sonar.api.batch.bootstrap.ProjectDefinition toNewProjectDefinition() { + return target; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java index 2df674053f9..9301cd0ce48 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java @@ -19,7 +19,8 @@ */ package org.sonar.batch.bootstrapper; -import java.util.Collections; +import org.sonar.api.batch.bootstrap.ProjectReactor; + import java.util.List; /** @@ -29,18 +30,22 @@ import java.util.List; */ public class Reactor { - private List<ProjectDefinition> projects; + private ProjectDefinition root; - public Reactor(ProjectDefinition project) { - this.projects = Collections.singletonList(project); + public Reactor(ProjectDefinition root) { + this.root = root; } public Reactor(List<ProjectDefinition> sortedProjects) { - this.projects = sortedProjects; + throw new IllegalArgumentException("This constructor is not supported anymore"); } public List<ProjectDefinition> getSortedProjects() { - return projects; + throw new IllegalArgumentException("The method getSortedProjects() is not supported anymore"); + } + + public ProjectReactor toProjectReactor() { + return new ProjectReactor(root.toNewProjectDefinition()); } } |