diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 7082ec534a..3bfe0bcf71 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -25,7 +25,6 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Repository; @@ -42,9 +41,6 @@ import org.apache.maven.project.validation.ModelValidator; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.dag.CycleDetectedException; -import org.codehaus.plexus.util.dag.DAG; -import org.codehaus.plexus.util.dag.TopologicalSorter; import java.io.File; import java.io.FileNotFoundException; @@ -336,75 +332,6 @@ public class DefaultMavenProjectBuilder return artifact.getFile(); } - /** - * Sort a list of projects. - * - */ - public List getSortedProjects( List projects ) - throws CycleDetectedException - { - DAG dag = new DAG(); - - Map projectMap = new HashMap(); - - for ( Iterator i = projects.iterator(); i.hasNext(); ) - { - MavenProject project = (MavenProject) i.next(); - - String artifactId = project.getArtifactId(); - - dag.addVertex( artifactId ); - - projectMap.put( artifactId, project ); - } - - for ( Iterator i = projects.iterator(); i.hasNext(); ) - { - MavenProject project = (MavenProject) i.next(); - - String artifactId = project.getArtifactId(); - - for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); ) - { - Dependency dependency = (Dependency) j.next(); - - String dependencyArtifactId = dependency.getArtifactId(); - - if ( dag.getVertex( dependencyArtifactId ) != null ) - { - dag.addEdge( artifactId, dependencyArtifactId ); - } - } - - MavenProject parent = project.getParent(); - if ( parent != null ) - { - if ( dag.getVertex( parent.getArtifactId() ) != null ) - { - dag.addEdge( artifactId, parent.getArtifactId() ); - } - } - } - - List sortedProjects = new ArrayList(); - - for ( Iterator i = TopologicalSorter.sort( dag ).iterator(); i.hasNext(); ) - { - String artifactId = (String) i.next(); - - sortedProjects.add( projectMap.get( artifactId ) ); - } - - return sortedProjects; - } - public MavenProject getCachedProject( String groupId, String artifactId, String version ) { return (MavenProject) projectCache.get( createCacheKey( groupId, artifactId, version ) ); diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 6a37d3d263..a2c3c3e35f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Build; import org.apache.maven.model.CiManagement; import org.apache.maven.model.Contributor; +import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Developer; import org.apache.maven.model.DistributionManagement; @@ -33,12 +34,17 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Reports; import org.apache.maven.model.Scm; +import org.codehaus.plexus.util.dag.CycleDetectedException; +import org.codehaus.plexus.util.dag.DAG; +import org.codehaus.plexus.util.dag.TopologicalSorter; import java.io.File; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -569,5 +575,74 @@ public class MavenProject { this.collectedProjects = collectedProjects; } + + /** + * Sort a list of projects. + * + */ + public static List getSortedProjects( List projects ) + throws CycleDetectedException + { + DAG dag = new DAG(); + + Map projectMap = new HashMap(); + + for ( Iterator i = projects.iterator(); i.hasNext(); ) + { + MavenProject project = (MavenProject) i.next(); + + String artifactId = project.getArtifactId(); + + dag.addVertex( artifactId ); + + projectMap.put( artifactId, project ); + } + + for ( Iterator i = projects.iterator(); i.hasNext(); ) + { + MavenProject project = (MavenProject) i.next(); + + String artifactId = project.getArtifactId(); + + for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); ) + { + Dependency dependency = (Dependency) j.next(); + + String dependencyArtifactId = dependency.getArtifactId(); + + if ( dag.getVertex( dependencyArtifactId ) != null ) + { + dag.addEdge( artifactId, dependencyArtifactId ); + } + } + + MavenProject parent = project.getParent(); + if ( parent != null ) + { + if ( dag.getVertex( parent.getArtifactId() ) != null ) + { + dag.addEdge( artifactId, parent.getArtifactId() ); + } + } + } + + List sortedProjects = new ArrayList(); + + for ( Iterator i = TopologicalSorter.sort( dag ).iterator(); i.hasNext(); ) + { + String artifactId = (String) i.next(); + + sortedProjects.add( projectMap.get( artifactId ) ); + } + + return sortedProjects; + } } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index b9b5fd08c2..c6392f9c44 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -18,10 +18,8 @@ package org.apache.maven.project; */ import org.apache.maven.artifact.repository.ArtifactRepository; -import org.codehaus.plexus.util.dag.CycleDetectedException; import java.io.File; -import java.util.List; public interface MavenProjectBuilder { @@ -36,10 +34,5 @@ public interface MavenProjectBuilder MavenProject buildSuperProject( ArtifactRepository localRepository ) throws ProjectBuildingException; - // take this out - - List getSortedProjects( List projects ) - throws CycleDetectedException; - MavenProject getCachedProject( String groupId, String artifactId, String version ); }