maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r618128 - in /maven/sandbox/branches/maven/MNG-3379: ./ maven-artifact-manager/ maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/ maven-core/ maven-core/src/main/java/org/apache/maven/
Date Mon, 04 Feb 2008 00:11:11 GMT
Author: brett
Date: Sun Feb  3 16:11:10 2008
New Revision: 618128

URL: http://svn.apache.org/viewvc?rev=618128&view=rev
Log:
[MNG-3379] initial implementation of parallel artifact resolution
Submitted by: Don Brown

Modified:
    maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/pom.xml
    maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
    maven/sandbox/branches/maven/MNG-3379/maven-core/pom.xml
    maven/sandbox/branches/maven/MNG-3379/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
    maven/sandbox/branches/maven/MNG-3379/pom.xml

Modified: maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/pom.xml?rev=618128&r1=618127&r2=618128&view=diff
==============================================================================
--- maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/pom.xml (original)
+++ maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/pom.xml Sun Feb  3 16:11:10
2008
@@ -55,6 +55,11 @@
       <artifactId>wagon-provider-api</artifactId>
     </dependency>
     <dependency>
+        <groupId>backport-util-concurrent</groupId>
+        <artifactId>backport-util-concurrent</artifactId>
+        <version>3.1</version>
+    </dependency>
+    <dependency>
       <groupId>easymock</groupId>
       <artifactId>easymock</artifactId>
       <version>1.2_Java1.3</version>

Modified: maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java?rev=618128&r1=618127&r2=618128&view=diff
==============================================================================
--- maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
(original)
+++ maven/sandbox/branches/maven/MNG-3379/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Sun Feb  3 16:11:10 2008
@@ -39,13 +39,12 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
+import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
 
 public class DefaultArtifactResolver
     extends AbstractLogEnabled
@@ -62,6 +61,13 @@
     protected ArtifactFactory artifactFactory;
 
     private ArtifactCollector artifactCollector;
+    private final ThreadPoolExecutor resolveArtifactPool;
+
+    public DefaultArtifactResolver()
+    {
+        super();
+        resolveArtifactPool = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS, new LinkedBlockingQueue());
+    }
 
     // ----------------------------------------------------------------------
     // Implementation
@@ -298,23 +304,37 @@
                                                               localRepository, remoteRepositories,
source, filter,
                                                               listeners );
 
-        List resolvedArtifacts = new ArrayList();
-        List missingArtifacts = new ArrayList();
+        List resolvedArtifacts = Collections.synchronizedList(new ArrayList());
+        List missingArtifacts = Collections.synchronizedList(new ArrayList());
+        CountDownLatch latch = new CountDownLatch(artifactResolutionResult.getArtifactResolutionNodes().size());
+        Map nodesByGroupId = new HashMap();
         for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator();
i.hasNext(); )
         {
             ResolutionNode node = (ResolutionNode) i.next();
-            try
+            List nodes = (List) nodesByGroupId.get(node.getArtifact().getGroupId());
+            if (nodes == null)
             {
-                resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository
);
-                resolvedArtifacts.add( node.getArtifact() );
+                nodes = new ArrayList();
+                nodesByGroupId.put(node.getArtifact().getGroupId(), nodes);
             }
-            catch ( ArtifactNotFoundException anfe )
-            {
-                getLogger().debug( anfe.getMessage(), anfe );
+            nodes.add(node);
+        }
 
-                missingArtifacts.add( node.getArtifact() );
+        try {
+            for (Iterator i = nodesByGroupId.values().iterator(); i.hasNext(); )
+            {
+                List nodes = (List) i.next();
+                resolveArtifactPool.execute(new ResolveArtifactTask(resolveArtifactPool,
latch, nodes, localRepository, resolvedArtifacts, missingArtifacts));
             }
-        }
+            latch.await();
+        } catch (InterruptedException e) {
+            throw new ArtifactResolutionException("Resolution interrupted", null, e);
+        } catch (RuntimeException ex) {
+            if (ex.getCause() instanceof ArtifactResolutionException)
+                throw (ArtifactResolutionException) ex.getCause();
+            else
+                throw ex;
+        } 
 
         if ( missingArtifacts.size() > 0 )
         {
@@ -340,6 +360,53 @@
     {
         return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP,
localRepository,
                                     remoteRepositories, source, null, listeners );
+    }
+
+    private class ResolveArtifactTask implements Runnable {
+        private List nodes;
+        private ArtifactRepository localRepository;
+        private List resolvedArtifacts;
+        private List missingArtifacts;
+        private CountDownLatch latch;
+        private ThreadPoolExecutor pool;
+
+        public ResolveArtifactTask(ThreadPoolExecutor pool, CountDownLatch latch, List nodes,
ArtifactRepository localRepository, List resolvedArtifacts, List missingArtifacts) {
+            this.nodes = nodes;
+            this.localRepository = localRepository;
+            this.resolvedArtifacts =  resolvedArtifacts;
+            this.missingArtifacts = missingArtifacts;
+            this.latch = latch;
+            this.pool = pool;
+        }
+
+        public void run() {
+            //getLogger().info("Size of nodes: "+nodes.size()+" on thread: "+Thread.currentThread().getId());
+            Iterator i = nodes.iterator();
+            ResolutionNode node = (ResolutionNode) i.next();
+            i.remove();
+            try {
+                resolveArtifact(node);
+                if (i.hasNext())
+                    pool.execute(new ResolveArtifactTask(pool, latch, nodes, localRepository,
resolvedArtifacts, missingArtifacts));
+            } catch (ArtifactResolutionException e) {
+                throw new RuntimeException(e);
+            }
+            latch.countDown();
+        }
+
+        private void resolveArtifact(ResolutionNode node) throws ArtifactResolutionException
{
+            try
+                {
+                    resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository
);
+                    resolvedArtifacts.add( node.getArtifact() );
+            }
+            catch ( ArtifactNotFoundException anfe )
+            {
+                getLogger().debug( anfe.getMessage(), anfe );
+
+                missingArtifacts.add( node.getArtifact() );
+            }
+        }
     }
 
 }

Modified: maven/sandbox/branches/maven/MNG-3379/maven-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven/MNG-3379/maven-core/pom.xml?rev=618128&r1=618127&r2=618128&view=diff
==============================================================================
--- maven/sandbox/branches/maven/MNG-3379/maven-core/pom.xml (original)
+++ maven/sandbox/branches/maven/MNG-3379/maven-core/pom.xml Sun Feb  3 16:11:10 2008
@@ -114,8 +114,24 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
-      <artifactId>wagon-http-lightweight</artifactId>
+      <artifactId>wagon-http</artifactId>
+      <classifier>shaded</classifier>
       <scope>runtime</scope>
+      <exclusions>
+        <!-- would be nice if the shading process could write out a new POM :) -->
+        <exclusion>
+          <groupId>commons-httpclient</groupId>
+          <artifactId>commons-httpclient</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>commons-codec</groupId>
+          <artifactId>commons-codec</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.reporting</groupId>

Modified: maven/sandbox/branches/maven/MNG-3379/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven/MNG-3379/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java?rev=618128&r1=618127&r2=618128&view=diff
==============================================================================
--- maven/sandbox/branches/maven/MNG-3379/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
(original)
+++ maven/sandbox/branches/maven/MNG-3379/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
Sun Feb  3 16:11:10 2008
@@ -65,8 +65,11 @@
         artifacts.add( "wagon-provider-api" );
         artifacts.add( "wagon-file" );
         artifacts.add( "wagon-http-lightweight" );
+        artifacts.add( "wagon-http" );
         artifacts.add( "wagon-ssh" );
         artifacts.add( "wagon-ssh-external" );
+        artifacts.add( "commons-httpclient" );
+        artifacts.add( "backport-util-concurrent" );
 
         return new ExclusionSetFilter( artifacts );
     }

Modified: maven/sandbox/branches/maven/MNG-3379/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/branches/maven/MNG-3379/pom.xml?rev=618128&r1=618127&r2=618128&view=diff
==============================================================================
--- maven/sandbox/branches/maven/MNG-3379/pom.xml (original)
+++ maven/sandbox/branches/maven/MNG-3379/pom.xml Sun Feb  3 16:11:10 2008
@@ -266,27 +266,28 @@
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-provider-api</artifactId>
-        <version>1.0-beta-2</version>
+        <version>1.0-rc1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ssh</artifactId>
-        <version>1.0-beta-2</version>
+        <version>1.0-rc1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ssh-external</artifactId>
-        <version>1.0-beta-2</version>
+        <version>1.0-rc1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-file</artifactId>
-        <version>1.0-beta-2</version>
+        <version>1.0-rc1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
-        <artifactId>wagon-http-lightweight</artifactId>
-        <version>1.0-beta-2</version>
+        <artifactId>wagon-http</artifactId>
+        <classifier>shaded</classifier>
+        <version>1.0-rc1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>easymock</groupId>



Mime
View raw message