maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/project DefaultMavenProjectBuilder.java MavenProject.java MavenProjectBuilder.java
Date Wed, 16 Mar 2005 04:21:03 GMT
brett       2005/03/15 20:21:03

  Modified:    maven-core/src/main/java/org/apache/maven/project
                        DefaultMavenProjectBuilder.java MavenProject.java
                        MavenProjectBuilder.java
  Log:
  project sorting can be a static method
  
  Revision  Changes    Path
  1.49      +0 -73     maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
  
  Index: DefaultMavenProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- DefaultMavenProjectBuilder.java	16 Mar 2005 04:18:06 -0000	1.48
  +++ DefaultMavenProjectBuilder.java	16 Mar 2005 04:21:03 -0000	1.49
  @@ -25,7 +25,6 @@
   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.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 @@
           return artifact.getFile();
       }
   
  -    /**
  -     * Sort a list of projects.
  -     * <ul>
  -     * <li>collect all the vertices for the projects that we want to build.</li>
  -     * <li>iterate through the deps of each project and if that dep is within
  -     * the set of projects we want to build then add an edge, otherwise throw
  -     * the edge away because that dependency is not within the set of projects
  -     * we are trying to build. we assume a closed set.</li>
  -     * <li>do a topo sort on the graph that remains.</li>
  -     * </ul>
  -     */
  -    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
) );
  
  
  
  1.29      +75 -0     maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
  
  Index: MavenProject.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- MavenProject.java	15 Mar 2005 23:36:27 -0000	1.28
  +++ MavenProject.java	16 Mar 2005 04:21:03 -0000	1.29
  @@ -21,6 +21,7 @@
   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.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 @@
       {
           this.collectedProjects = collectedProjects;
       }
  +
  +    /**
  +     * Sort a list of projects.
  +     * <ul>
  +     * <li>collect all the vertices for the projects that we want to build.</li>
  +     * <li>iterate through the deps of each project and if that dep is within
  +     * the set of projects we want to build then add an edge, otherwise throw
  +     * the edge away because that dependency is not within the set of projects
  +     * we are trying to build. we assume a closed set.</li>
  +     * <li>do a topo sort on the graph that remains.</li>
  +     * </ul>
  +     */
  +    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;
  +    }
   }
   
  
  
  
  1.12      +0 -7      maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
  
  Index: MavenProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MavenProjectBuilder.java	16 Mar 2005 04:18:06 -0000	1.11
  +++ MavenProjectBuilder.java	16 Mar 2005 04:21:03 -0000	1.12
  @@ -18,10 +18,8 @@
    */
   
   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 @@
       MavenProject buildSuperProject( ArtifactRepository localRepository )
           throws ProjectBuildingException;
   
  -    // take this out
  -
  -    List getSortedProjects( List projects )
  -        throws CycleDetectedException;
  -
       MavenProject getCachedProject( String groupId, String artifactId, String version );
   }
  
  
  

Mime
View raw message