geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r721777 - in /geronimo/gshell/trunk/gshell-support: gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/ gshell-artifact/src/main/java/org...
Date Sun, 30 Nov 2008 07:37:16 GMT
Author: jdillon
Date: Sat Nov 29 23:37:16 2008
New Revision: 721777

URL: http://svn.apache.org/viewvc?rev=721777&view=rev
Log:
Get the progress monitor working again

Added:
    geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
  (contents, props changed)
      - copied, changed from r721681, geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
Modified:
    geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferEvent.java
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferListener.java
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/monitor/ProgressSpinnerMonitor.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java?rev=721777&r1=721776&r2=721777&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
Sat Nov 29 23:37:16 2008
@@ -53,32 +53,7 @@
 
     public void setTransferListener(final TransferListener listener) {
         assert listener != null;
-
-        artifactManager.setDownloadMonitor(new org.apache.maven.wagon.events.TransferListener()
{
-            public void transferInitiated(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // ignore
-            }
-
-            public void transferStarted(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // TODO:
-            }
-
-            public void transferProgress(final org.apache.maven.wagon.events.TransferEvent
transferEvent, final byte[] buffer, final int length) {
-                // TODO:
-            }
-
-            public void transferCompleted(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // TODO:
-            }
-
-            public void transferError(final org.apache.maven.wagon.events.TransferEvent transferEvent)
{
-                // TODO:
-            }
-
-            public void debug(final String message) {
-                log.trace(message);
-            }
-        });
+        artifactManager.setDownloadMonitor(new TransferListenerAdapter(listener));
     }
 
     public Result resolve(final Request request) throws Failure {
@@ -149,6 +124,9 @@
         return result;
     }
 
+    /**
+     * Creates a GShell Artifact from a Maven Artifact.
+     */
     private Artifact createArtifact(final org.apache.maven.artifact.Artifact source) {
         assert source != null;
 
@@ -163,6 +141,9 @@
         return artifact;
     }
 
+    /**
+     * Creates a Maven Artifact from a GShell Artifact.
+     */
     private org.apache.maven.artifact.Artifact createArtifact(final Artifact source) {
         assert source != null;
 

Copied: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
(from r721681, geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java?p2=geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java&p1=geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java&r1=721681&r2=721777&rev=721777&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/ArtifactResolverImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
Sat Nov 29 23:37:16 2008
@@ -19,159 +19,87 @@
 
 package org.apache.geronimo.gshell.artifact.maven;
 
-import org.apache.geronimo.gshell.artifact.ArtifactResolver;
-import org.apache.geronimo.gshell.artifact.Artifact;
+import org.apache.geronimo.gshell.artifact.transfer.TransferEvent;
 import org.apache.geronimo.gshell.artifact.transfer.TransferListener;
-import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Set;
-import java.util.LinkedHashSet;
-
 /**
- * <a href="http://maven.apache.org">Apache Maven (maven-artifact)</a> based
{@link ArtifactResolver}.
+ * Adapts {@link TransferListener} to Maven Wagon's {@link org.apache.maven.wagon.events.TransferListener}.
  *
  * @version $Rev$ $Date$
  */
-public class ArtifactResolverImpl
-    implements ArtifactResolver
+public class TransferListenerAdapter
+    implements org.apache.maven.wagon.events.TransferListener
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final ArtifactManager artifactManager;
-
-    public ArtifactResolverImpl(final ArtifactManager artifactManager) {
-        assert artifactManager != null;
-        this.artifactManager = artifactManager;
-    }
+    private final TransferListener listener;
 
-    public void setTransferListener(final TransferListener listener) {
+    public TransferListenerAdapter(final TransferListener listener) {
         assert listener != null;
-
-        artifactManager.setDownloadMonitor(new org.apache.maven.wagon.events.TransferListener()
{
-            public void transferInitiated(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // ignore
-            }
-
-            public void transferStarted(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // TODO:
-            }
-
-            public void transferProgress(final org.apache.maven.wagon.events.TransferEvent
transferEvent, final byte[] buffer, final int length) {
-                // TODO:
-            }
-
-            public void transferCompleted(final org.apache.maven.wagon.events.TransferEvent
transferEvent) {
-                // TODO:
-            }
-
-            public void transferError(final org.apache.maven.wagon.events.TransferEvent transferEvent)
{
-                // TODO:
-            }
-
-            public void debug(final String message) {
-                log.trace(message);
-            }
-        });
+        this.listener = listener;
     }
 
-    public Result resolve(final Request request) throws Failure {
-        assert request != null;
-
-        ArtifactResolutionRequest _request = new ArtifactResolutionRequest();
-
-        if (request.artifact != null) {
-            log.debug("Artifact: {}", request.artifact);
+    public void transferInitiated(final org.apache.maven.wagon.events.TransferEvent source)
{
+        // ignore
+    }
 
-            _request.setArtifact(createArtifact(request.artifact));
-        }
+    public void transferStarted(final org.apache.maven.wagon.events.TransferEvent source)
{
+        listener.transferStarted(convert(source));
+    }
 
-        if (request.artifacts != null) {
-            Set<org.apache.maven.artifact.Artifact> artifacts = new LinkedHashSet<org.apache.maven.artifact.Artifact>();
+    public void transferProgress(final org.apache.maven.wagon.events.TransferEvent source,
final byte[] buffer, final int length) {
+        listener.transferProgress(convert(source, length));
+    }
 
-            log.debug("Dependencies:");
+    public void transferCompleted(final org.apache.maven.wagon.events.TransferEvent source)
{
+        listener.transferCompleted(convert(source));
+    }
 
-            for (Artifact source : request.artifacts) {
-                org.apache.maven.artifact.Artifact artifact = createArtifact(source);
-                log.debug("    {}", artifact);
-                artifacts.add(artifact);
-            }
+    public void transferError(final org.apache.maven.wagon.events.TransferEvent source) {
+        listener.transferFailed(convert(source));
+    }
 
-            _request.setArtifactDependencies(artifacts);
-        }
+    public void debug(final String message) {
+        log.trace(message);
+    }
 
-        AndArtifactFilter filter = new AndArtifactFilter();
-        _request.setFilter(filter);
+    private TransferEvent convert(final org.apache.maven.wagon.events.TransferEvent source,
final int length) {
+        assert source != null;
 
-        // Always filter for runtime scope
-        filter.add(new ScopeArtifactFilter(org.apache.maven.artifact.Artifact.SCOPE_RUNTIME));
+        return new TransferEvent()
+        {
+            public RequestType getRequestType() {
+                switch (source.getRequestType()) {
+                    case org.apache.maven.wagon.events.TransferEvent.REQUEST_GET:
+                        return RequestType.DOWNLOAD;
 
-        // Filter deps needed for use of maven-artifact
-        filter.add(new MavenArtifactDependenciesFilter());
-
-        if (request.filter != null) {
-            log.debug("Filter: {}", request.filter);
-            
-            filter.add(new ArtifactFilter() {
-                public boolean include(final org.apache.maven.artifact.Artifact source) {
-                    assert source != null;
-                    Artifact artifact = createArtifact(source);
-                    return request.filter.accept(artifact);
+                    case org.apache.maven.wagon.events.TransferEvent.REQUEST_PUT:
+                        return RequestType.UPLOAD;
                 }
-            });
-        }
-
-        Result result = new Result();
-        try {
-            ArtifactResolutionResult _result = artifactManager.resolve(_request);
-            result.artifacts = new LinkedHashSet<Artifact>();
-
-            log.debug("Resolved:");
-
-            for (org.apache.maven.artifact.Artifact source : _result.getArtifacts()) {
-                Artifact artifact = createArtifact(source);
-
-                log.debug("    {}", artifact);
-                
-                result.artifacts.add(artifact);
+                throw new InternalError();
             }
-        }
-        catch (ResolutionException e) {
-            throw new Failure(e);
-        }
 
-        return result;
-    }
+            public String getLocation() {
+                return source.getWagon().getRepository().getUrl() + "/" + source.getResource().getName();
+            }
 
-    private Artifact createArtifact(final org.apache.maven.artifact.Artifact source) {
-        assert source != null;
+            public long getContentLength() {
+                return source.getResource().getContentLength();
+            }
 
-        Artifact artifact = new Artifact();
-        artifact.setGroup(source.getGroupId());
-        artifact.setName(source.getArtifactId());
-        artifact.setVersion(source.getVersion());
-        artifact.setClassifier(source.getClassifier());
-        artifact.setType(source.getType());
-        artifact.setFile(source.getFile());
+            public long getLength() {
+                return length;
+            }
 
-        return artifact;
+            public Throwable getFailureCause() {
+                return source.getException();
+            }
+        };
     }
 
-    private org.apache.maven.artifact.Artifact createArtifact(final Artifact source) {
-        assert source != null;
-
-        ArtifactFactory factory = artifactManager.getArtifactFactory();
-
-        org.apache.maven.artifact.Artifact artifact = factory.createArtifact(source.getGroup(),
source.getName(), source.getVersion(), null, source.getType());
-
-        artifact.setFile(source.getFile());
-        
-        return artifact;
+    private TransferEvent convert(final org.apache.maven.wagon.events.TransferEvent source)
{
+        return convert(source, TransferEvent.UNKNOWN_LENGTH);
     }
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-support/gshell-artifact-maven/src/main/java/org/apache/geronimo/gshell/artifact/maven/TransferListenerAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferEvent.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferEvent.java?rev=721777&r1=721776&r2=721777&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferEvent.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferEvent.java
Sat Nov 29 23:37:16 2008
@@ -28,13 +28,27 @@
  */
 public interface TransferEvent
 {
-    enum Type {
+    /**
+     * Constant to be used when the content-length is not known.
+     */
+    int UNKNOWN_LENGTH = -1;
+
+    /**
+     * Transfer request type.
+     */
+    enum RequestType {
         UPLOAD, DOWNLOAD
     }
 
-    Type getType();
+    /**
+     * Transfer request type.
+     */
+    RequestType getRequestType();
 
-    URL getUrl();
+    /**
+     * Content location.
+     */
+    String getLocation();
 
     /**
      * The maximum length of the content.
@@ -46,5 +60,8 @@
      */
     long getLength();
 
-    Throwable getCause();
+    /**
+     * Failure cause.
+     */
+    Throwable getFailureCause();
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferListener.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferListener.java?rev=721777&r1=721776&r2=721777&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferListener.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/TransferListener.java
Sat Nov 29 23:37:16 2008
@@ -26,8 +26,6 @@
  */
 public interface TransferListener
 {
-    int UNKNOWN_LENGTH = -1;
-    
     void transferStarted(TransferEvent event);
 
     void transferProgress(TransferEvent event);

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/monitor/ProgressSpinnerMonitor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/monitor/ProgressSpinnerMonitor.java?rev=721777&r1=721776&r2=721777&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/monitor/ProgressSpinnerMonitor.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/transfer/monitor/ProgressSpinnerMonitor.java
Sat Nov 29 23:37:16 2008
@@ -70,10 +70,10 @@
 
         spinner.reset();
 
-        String type = event.getType() == TransferEvent.Type.UPLOAD ? "Uploading" : "Downloading";
-        URL url = event.getUrl();
+        String type = event.getRequestType() == TransferEvent.RequestType.UPLOAD ? "Uploading"
: "Downloading";
+        String location = event.getLocation();
 
-        String message = type + ": " + url;
+        String message = type + ": " + location;
 
         log.debug(message);
 
@@ -89,10 +89,10 @@
         String message;
 
         if (total >= 1024) {
-            message = complete / 1024 + "/" + (total == UNKNOWN_LENGTH ? "?" : total / 1024
+ "K");
+            message = complete / 1024 + "/" + (total == TransferEvent.UNKNOWN_LENGTH ? "?"
: total / 1024 + "K");
         }
         else {
-            message = complete + "/" + (total == UNKNOWN_LENGTH ? "?" : total + "b");
+            message = complete + "/" + (total == TransferEvent.UNKNOWN_LENGTH ? "?" : total
+ "b");
         }
 
         log.trace(message);
@@ -105,11 +105,11 @@
 
         super.transferCompleted(event);
 
-        long length = event.getLength();
-        String type = event.getType() == TransferEvent.Type.UPLOAD ? "Uploaded" : "Downloaded";
-        String bytes = length >= 1024 ? ( length / 1024 ) + "K" : length + "b";
+        long total = event.getContentLength();
+        String type = event.getRequestType() == TransferEvent.RequestType.UPLOAD ? "Uploaded"
: "Downloaded";
+        String bytes = total >= 1024 ? ( total / 1024 ) + "K" : total + "b";
 
-        // pad at end just incase, should really blank the reset of the line
+        // HACK: pad at end just incase, should really blank the reset of the line
         print(type + " " + bytes + "          ");
     }
 }
\ No newline at end of file



Mime
View raw message