maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raf...@apache.org
Subject svn commit: r667224 - in /maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype: common/DefaultArchetypeArtifactManager.java downloader/DefaultDownloader.java old/DefaultOldArchetype.java
Date Thu, 12 Jun 2008 20:41:07 GMT
Author: rafale
Date: Thu Jun 12 13:41:07 2008
New Revision: 667224

URL: http://svn.apache.org/viewvc?rev=667224&view=rev
Log:
Fix archetype-165
Updated the downloading process using a cache.
It seems the ArtifactResolver can't resolve 2 times 
the same artifact in a session.

Modified:
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java?rev=667224&r1=667223&r2=667224&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
(original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
Thu Jun 12 13:41:07 2008
@@ -47,6 +47,8 @@
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
@@ -72,6 +74,8 @@
      * @plexus.requirement
      */
     private RepositoryMetadataManager repositoryMetadataManager;
+    
+    private Map archetypeCache = new TreeMap();
 
     public File getArchetypeFile (
         final String groupId,
@@ -85,15 +89,28 @@
     {
         try
         {
-            return
-                downloader.download (
+            File archetype = getArchetype(
                     groupId,
                     artifactId,
-                    version,
-                    archetypeRepository,
-                    localRepository,
-                    repositories
-                );
+                    version);
+            if (archetype==null)
+            {
+                archetype = 
+                    downloader.download (
+                        groupId,
+                        artifactId,
+                        version,
+                        archetypeRepository,
+                        localRepository,
+                        repositories
+                    );
+                setArchetype(
+                        groupId,
+                        artifactId,
+                        version,
+                        archetype);
+            }
+            return archetype;
         }
         catch ( DownloadNotFoundException ex )
         {
@@ -307,17 +324,29 @@
     {
         try
         {
-            File archetypeFile =
-                downloader.download (
+            File archetype = getArchetype(
                     archetypeGroupId,
                     archetypeArtifactId,
-                    archetypeVersion,
-                    archetypeRepository,
-                    localRepository,
-                    remoteRepositories
-                );
+                    archetypeVersion);
+            if (archetype==null)
+            {
+                archetype = 
+                    downloader.download (
+                        archetypeGroupId,
+                        archetypeArtifactId,
+                        archetypeVersion,
+                        archetypeRepository,
+                        localRepository,
+                        remoteRepositories
+                    );
+                setArchetype(
+                        archetypeGroupId,
+                        archetypeArtifactId,
+                        archetypeVersion,
+                        archetype);
+            }
 
-            return archetypeFile.exists ();
+            return archetype.exists ();
         }
         catch ( DownloadException e )
         {
@@ -478,6 +507,30 @@
         }
     }
 
+    private File getArchetype(String archetypeGroupId,
+            String archetypeArtifactId, 
+            String archetypeVersion) {
+        String key = archetypeGroupId+":"+archetypeArtifactId+":"+archetypeVersion;
+        if (archetypeCache.containsKey(key))
+        {
+            getLogger().debug("Found archetype "+key+" in cache: "+archetypeCache.get(key));
+            return (File) archetypeCache.get(key);
+        }
+        else
+        {
+            getLogger().debug("Not found archetype "+key+" in cache");
+            return null;
+        }
+    }
+
+    private void setArchetype(String archetypeGroupId, 
+            String archetypeArtifactId,
+            String archetypeVersion,
+            File archetype) {
+        String key = archetypeGroupId+":"+archetypeArtifactId+":"+archetypeVersion;
+        archetypeCache.put(key, archetype);
+    }
+
     private Reader getArchetypeDescriptorReader ( ZipFile zipFile )
     throws IOException
     {

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java?rev=667224&r1=667223&r2=667224&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
(original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
Thu Jun 12 13:41:07 2008
@@ -52,7 +52,7 @@
         ArtifactRepository localRepo = localRepository;
         try
         {
-            artifactResolver.resolveAlways( artifact, repositories, localRepo );
+            artifactResolver.resolve( artifact, repositories, localRepo );
         }
         catch ( ArtifactResolutionException e )
         {
@@ -76,7 +76,7 @@
         Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version,
Artifact.SCOPE_RUNTIME, "jar" );
         try
         {
-            artifactResolver.resolveAlways( artifact, remoteRepositories, localRepository
);
+            artifactResolver.resolve( artifact, remoteRepositories, localRepository );
         }
         catch ( ArtifactResolutionException e )
         {

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java?rev=667224&r1=667223&r2=667224&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
(original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
Thu Jun 12 13:41:07 2008
@@ -20,15 +20,14 @@
 import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptorBuilder;
 import org.apache.maven.archetype.old.descriptor.TemplateDescriptor;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.archetype.common.ArchetypeArtifactManager;
+import org.apache.maven.archetype.exception.UnknownArchetype;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Resource;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.archetype.downloader.DownloadException;
-import org.apache.maven.archetype.downloader.DownloadNotFoundException;
-import org.apache.maven.archetype.downloader.Downloader;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -89,10 +88,8 @@
      */
     private VelocityComponent velocity;
 
-    /**
-     * @plexus.requirement
-     */
-    private Downloader downloader;
+    /** @plexus.requirement */
+    private ArchetypeArtifactManager archetypeArtifactManager;
 
     // ----------------------------------------------------------------------
     // Implementation
@@ -105,7 +102,7 @@
     public void createArchetype( String archetypeGroupId,
                                  String archetypeArtifactId,
                                  String archetypeVersion,
-                          ArtifactRepository archetypeRepository,
+                                 ArtifactRepository archetypeRepository,
                                  ArtifactRepository localRepository,
                                  List remoteRepositories,
                                  Map parameters )
@@ -119,17 +116,14 @@
 
         try
         {
-            archetype = downloader.downloadOld( archetypeGroupId, archetypeArtifactId, archetypeVersion,
archetypeRepository, localRepository,
-                                             remoteRepositories );
+            archetype = archetypeArtifactManager.getArchetypeFile( 
+                archetypeGroupId, archetypeArtifactId, archetypeVersion, 
+                archetypeRepository, localRepository, remoteRepositories );
         }
-        catch ( DownloadException e )
+        catch ( UnknownArchetype e )
         {
             throw new ArchetypeDescriptorException( "Error attempting to download archetype.",
e );
         }
-        catch ( DownloadNotFoundException e )
-        {
-            throw new ArchetypeNotFoundException( "OldArchetype does not exist.", e );
-        }
 
         // ---------------------------------------------------------------------
         // Get Logger and display all parameters used



Mime
View raw message