From 82e4778aaf039f21d1869011b84984d820712ddb Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 17 May 2011 19:30:31 +0400 Subject: [PATCH] Fix association between Project and ProjectDefinition --- .../java/org/sonar/batch/ProjectBatch.java | 2 +- .../java/org/sonar/batch/ProjectTree.java | 39 +++++++------------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java index 7a6ea61b454..2216a49c1b5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java @@ -104,7 +104,7 @@ public class ProjectBatch { @Override protected void configure() { - ProjectDefinition projectDefinition = getComponent(ProjectTree.class).getProjectDefinition(project.getKey()); + ProjectDefinition projectDefinition = getComponent(ProjectTree.class).getProjectDefinition(project); addComponent(projectDefinition); for (Object component : projectDefinition.getContainerExtensions()) { addComponent(component); 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 54b97fb2b6f..1ea52bc5738 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java @@ -21,10 +21,10 @@ package org.sonar.batch; 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.CoreProperties; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Project; import org.sonar.batch.bootstrapper.ProjectDefinition; @@ -35,9 +35,10 @@ import java.util.*; public class ProjectTree { - private List projects; private ProjectBuilder projectBuilder; + private List projects; private List definitions; + private Map projectsMap; public ProjectTree(Reactor sonarReactor, DatabaseSession databaseSession) { this.projectBuilder = new ProjectBuilder(databaseSession); @@ -75,24 +76,24 @@ public class ProjectTree { public void start() throws IOException { projects = Lists.newArrayList(); - Map map = Maps.newHashMap(); + projectsMap = Maps.newHashMap(); for (ProjectDefinition def : definitions) { Project project = projectBuilder.create(def); - map.put(def, project); + projectsMap.put(def, project); projects.add(project); } - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : projectsMap.entrySet()) { ProjectDefinition def = entry.getKey(); Project project = entry.getValue(); for (ProjectDefinition module : def.getModules()) { - map.get(module).setParent(project); + projectsMap.get(module).setParent(project); } } // Configure - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : projectsMap.entrySet()) { projectBuilder.configure(entry.getValue(), entry.getKey()); } @@ -181,26 +182,12 @@ public class ProjectTree { throw new IllegalStateException("Can not find the root project from the list of Maven modules"); } - private String getProjectKey(ProjectDefinition def) { - String key = def.getProperties().getProperty(CoreProperties.PROJECT_KEY_PROPERTY); - String branch = def.getProperties().getProperty(CoreProperties.PROJECT_BRANCH_PROPERTY); - if (StringUtils.isNotBlank(branch)) { - return key + ":" + branch; - } else { - return key; - } - } - - public ProjectDefinition getProjectDefinition(String key) { - for (ProjectDefinition def : definitions) { - if (StringUtils.equals(key, getProjectKey(def))) { - return def; + public ProjectDefinition getProjectDefinition(Project project) { + for (Map.Entry entry : projectsMap.entrySet()) { + if (ObjectUtils.equals(entry.getValue(), project)) { + return entry.getKey(); } } - return null; - } - - public List getProjectExtensions(String key) { - return getProjectDefinition(key).getContainerExtensions(); + throw new IllegalStateException("Can not find ProjectDefinition for " + project); } } -- 2.39.5