Caching of models. This model is not the one returned in the MavenProject so no danger of other components modifying it.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@699873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-09-28 18:20:13 +00:00
parent a14e0aa39f
commit c208511348
2 changed files with 106 additions and 7 deletions

94
c.patch Normal file
View File

@ -0,0 +1,94 @@
Index: maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
===================================================================
--- maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java (revision 697955)
+++ maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java (working copy)
@@ -46,11 +46,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
/**
* Default implementation of the project builder.
@@ -72,6 +68,8 @@
private RepositoryHelper repositoryHelper;
+ private HashMap<String, PomClassicDomainModel> cache = new HashMap<String, PomClassicDomainModel>();
+
/**
* Default constructor
*/
@@ -139,6 +137,12 @@
}
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
+ if(cache.containsKey(domainModel.getId()))
+ {
+ // System.out.println("CACHE: " + domainModel.getId());
+ return createMavenProject(cache.get(domainModel.getId()), projectBuilderConfiguration);
+ }
+
domainModel.setProjectDirectory( projectDirectory );
List<DomainModel> domainModels = new ArrayList<DomainModel>();
@@ -181,12 +185,21 @@
transformer,
importModels,
properties ) );
+ transformedDomainModel.setParentFile(parentFile);
+ cache.put(domainModel.getId(), transformedDomainModel);
+ //System.out.println("CACHE SIZE = " + cache.size());
+ return createMavenProject(transformedDomainModel, projectBuilderConfiguration);
+ }
+
+
+ private MavenProject createMavenProject(PomClassicDomainModel domainModel, ProjectBuilderConfiguration config)
+ throws IOException
+ {
try
{
- MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
- mavenTools, null,
- projectBuilderConfiguration );
- mavenProject.setParentFile( parentFile );
+ MavenProject mavenProject = new MavenProject( domainModel.getModel(), artifactFactory, mavenTools, null,
+ config );
+ mavenProject.setParentFile( domainModel.getParentFile() );
return mavenProject;
}
catch ( InvalidRepositoryException e )
@@ -240,7 +253,7 @@
Artifact artifactParent =
artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
- artifactResolver.resolve( artifactParent );
+ // artifactParent = artifactResolver.resolve( artifactParent );
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
@@ -249,17 +262,12 @@
": Child ID = " + domainModel.getModel().getId() );
return domainModels;
}
- else
- {
- // logger.info("Adding pom to hierarchy: Group Id = " + parent.getGroupId() + ", Artifact Id ="
- // + parent.getArtifactId() + ", Version = " + parent.getVersion() + ", File" + artifactParent.getFile());
- }
-
+ cache.put(parentDomainModel.getId(), parentDomainModel);
domainModels.add( parentDomainModel );
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver ) );
return domainModels;
}
-
+
/**
* Returns list of domain model parents of the specified domain model. The parent domain models are part
*

View File

@ -50,12 +50,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be
@ -79,6 +74,8 @@ public class DefaultRepositoryHelper
private MavenXpp3Reader modelReader;
private static HashMap<String, Model> cache = new HashMap<String, Model>();
private Logger getLogger()
{
return logger;
@ -116,7 +113,15 @@ public class DefaultRepositoryHelper
File file = projectArtifact.getFile();
artifact.setFile( file );
legacy_model = readModelLegacy( projectId, file, false );
if(cache.containsKey(projectId))
{
legacy_model = cache.get(projectId);
}
else
{
legacy_model = readModelLegacy( projectId, file, false );
cache.put(projectId, legacy_model);
}
String downloadUrl = null;