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 DefaultMaven.java
Date Wed, 16 Mar 2005 03:39:54 GMT
brett       2005/03/15 19:39:54

  Modified:    maven-core/src/main/java/org/apache/maven/artifact
                        MavenMetadataSource.java
               maven-core/src/main/java/org/apache/maven/project
                        DefaultMavenProjectBuilder.java
                        MavenProjectBuilder.java
               maven-core/src/main/java/org/apache/maven DefaultMaven.java
  Log:
  cache POMs within the reactor
  
  Revision  Changes    Path
  1.19      +41 -24    maven-components/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java
  
  Index: MavenMetadataSource.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- MavenMetadataSource.java	9 Mar 2005 05:48:30 -0000	1.18
  +++ MavenMetadataSource.java	16 Mar 2005 03:39:54 -0000	1.19
  @@ -29,8 +29,6 @@
   import org.apache.maven.project.MavenProjectBuilder;
   
   import java.io.FileReader;
  -import java.util.HashSet;
  -import java.util.Iterator;
   import java.util.List;
   import java.util.Set;
   
  @@ -57,6 +55,7 @@
       {
           // there is code in plexus that uses this (though it shouldn't) so we
           // need to be able to not have a project builder
  +        // TODO: remove, then remove those null checks
           this.artifactResolver = artifactResolver;
           this.mavenProjectBuilder = null;
       }
  @@ -70,39 +69,57 @@
       public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories
)
           throws ArtifactMetadataRetrievalException
       {
  -        Set artifacts;
  -        Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
  -                                                                    artifact.getVersion(),
artifact.getScope(), "pom",
  -                                                                    "pom", null );
           try
           {
  -            artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository
);
  +            List dependencies = null;
   
  -            // [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
  -            // post-processing and inheritance calculation before retrieving the 
  -            // associated artifacts. This should improve consistency.
               if ( mavenProjectBuilder != null )
               {
  -                MavenProject project = mavenProjectBuilder.build( metadataArtifact.getFile(),
localRepository );
  -                artifacts =
  -                    artifactFactory.createArtifacts( project.getDependencies(), localRepository,
artifact.getScope() );
  +                MavenProject project = mavenProjectBuilder.getCachedProject( artifact.getGroupId(),
  +                                                                             artifact.getArtifactId(),
  +                                                                             artifact.getVersion()
);
  +                if ( project != null )
  +                {
  +                    dependencies = project.getDependencies();
  +                }
               }
  -            else
  +
  +            if ( dependencies == null )
               {
  -                Model model = reader.read( new FileReader( metadataArtifact.getFile() )
);
  -                artifacts =
  -                    artifactFactory.createArtifacts( model.getDependencies(), localRepository,
artifact.getScope() );
  +                Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(),
  +                                                                            artifact.getArtifactId(),
  +                                                                            artifact.getVersion(),
artifact.getScope(),
  +                                                                            "pom", "pom",
null );
  +
  +                artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository
);
  +
  +                // [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
  +                // post-processing and inheritance calculation before retrieving the
  +                // associated artifacts. This should improve consistency.
  +                try
  +                {
  +                    if ( mavenProjectBuilder != null )
  +                    {
  +                        MavenProject p = mavenProjectBuilder.build( metadataArtifact.getFile(),
localRepository );
  +                        dependencies = p.getDependencies();
  +                    }
  +                    else
  +                    {
  +                        Model model = reader.read( new FileReader( metadataArtifact.getFile()
) );
  +                        dependencies = model.getDependencies();
  +                    }
  +                }
  +                catch ( Exception e )
  +                {
  +                    throw new ArtifactMetadataRetrievalException(
  +                        "Cannot read artifact source: " + metadataArtifact.getPath(), e
);
  +                }
               }
  +            return artifactFactory.createArtifacts( dependencies, localRepository, artifact.getScope()
);
           }
           catch ( ArtifactResolutionException e )
           {
               throw new ArtifactMetadataRetrievalException( "Error while resolving metadata
artifact", e );
           }
  -        catch ( Exception e )
  -        {
  -            throw new ArtifactMetadataRetrievalException( "Cannot read artifact source:
" + metadataArtifact.getPath(),
  -                                                          e );
  -        }
  -        return artifacts;
       }
   }
  
  
  
  1.46      +27 -8     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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- DefaultMavenProjectBuilder.java	15 Mar 2005 21:41:04 -0000	1.45
  +++ DefaultMavenProjectBuilder.java	16 Mar 2005 03:39:54 -0000	1.46
  @@ -82,11 +82,13 @@
       private ModelDefaultsInjector modelDefaultsInjector;
   
       private ModelInterpolator modelInterpolator;
  -    
  +
       private UserModelBuilder userModelBuilder;
  -    
  +
       private ArtifactRepositoryFactory artifactRepositoryFactory;
   
  +    private final Map projectCache = new HashMap();
  +
       public void initialize()
       {
           modelReader = new MavenXpp3Reader();
  @@ -155,6 +157,9 @@
           project.setParent( parentProject );
           project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(),
localRepository, null ) );
   
  +        projectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(),
project.getVersion() ),
  +                          project );
  +
           // ----------------------------------------------------------------------
           // Typically when the project builder is being used from maven proper
           // the transitive dependencies will not be resolved here because this
  @@ -233,18 +238,22 @@
   
               aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories()
) );
   
  -            File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories,
localRepository );
  -
  -            MavenProject parent = assembleLineage( parentPom, localRepository, lineage,
  -                                                   aggregatedRemoteWagonRepositories );
  +            MavenProject parent = getCachedProject( parentModel.getGroupId(), parentModel.getArtifactId(),
  +                                                    parentModel.getVersion() );
  +            if ( parent == null )
  +            {
  +                File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories,
localRepository );
   
  +                parent = assembleLineage( parentPom, localRepository, lineage, aggregatedRemoteWagonRepositories
);
  +            }
               project.setParent( parent );
           }
   
           return project;
       }
   
  -    private List buildArtifactRepositories( List repositories ) throws ProjectBuildingException
  +    private List buildArtifactRepositories( List repositories )
  +        throws ProjectBuildingException
       {
           UserModel userModel = null;
   
  @@ -256,7 +265,7 @@
           {
               throw new ProjectBuildingException( "Cannot read user-model.", e );
           }
  -        
  +
           List repos = new ArrayList();
           for ( Iterator i = repositories.iterator(); i.hasNext(); )
           {
  @@ -387,6 +396,16 @@
           return sortedProjects;
       }
   
  +    public MavenProject getCachedProject( String groupId, String artifactId, String version
)
  +    {
  +        return (MavenProject) projectCache.get( createCacheKey( groupId, artifactId, version
) );
  +    }
  +
  +    private static String createCacheKey( String groupId, String artifactId, String version
)
  +    {
  +        return groupId + ":" + artifactId + ":" + version;
  +    }
  +
       public MavenProject buildSuperProject( ArtifactRepository localRepository )
           throws ProjectBuildingException
       {
  
  
  
  1.10      +2 -0      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MavenProjectBuilder.java	10 Mar 2005 23:01:35 -0000	1.9
  +++ MavenProjectBuilder.java	16 Mar 2005 03:39:54 -0000	1.10
  @@ -43,4 +43,6 @@
   
       List getSortedProjects( List projects )
           throws CycleDetectedException;
  +
  +    MavenProject getCachedProject( String groupId, String artifactId, String version );
   }
  
  
  
  1.33      +2 -17     maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
  
  Index: DefaultMaven.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- DefaultMaven.java	16 Mar 2005 01:43:09 -0000	1.32
  +++ DefaultMaven.java	16 Mar 2005 03:39:54 -0000	1.33
  @@ -130,22 +130,7 @@
   
                   try
                   {
  -                    List goals;
  -                    if ( "pom".equals( project.getPackaging() ) )
  -                    {
  -                        goals = new ArrayList();
  -
  -                        // TODO: not required if discovered and cached
  -                        goals.add( "pom:install" );
  -
  -                        goals.addAll( request.getGoals() );
  -                    }
  -                    else
  -                    {
  -                        goals = request.getGoals();
  -                    }
  -
  -                    MavenExecutionResponse response = processProject( request, project,
dispatcher, goals );
  +                    MavenExecutionResponse response = processProject( request, project,
dispatcher, request.getGoals() );
                       if ( response.isExecutionFailure() )
                       {
                           return response;
  
  
  

Mime
View raw message