geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r657545 - in /geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact: ./ monitor/
Date Sun, 18 May 2008 11:46:20 GMT
Author: jdillon
Date: Sun May 18 04:46:19 2008
New Revision: 657545

URL: http://svn.apache.org/viewvc?rev=657545&view=rev
Log:
Some support for download monitoring muck

Added:
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinner.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinnerMonitor.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/TransferListenerSupport.java
      - copied, changed from r657378, geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
Modified:
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
    geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/DefaultArtifactManager.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java?rev=657545&r1=657544&r2=657545&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
Sun May 18 04:46:19 2008
@@ -25,6 +25,7 @@
 import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.UnknownRepositoryLayoutException;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.wagon.events.TransferListener;
 
 import java.util.List;
 import java.io.File;
@@ -52,5 +53,7 @@
 
     ArtifactFactory getArtifactFactory();
 
+    void setDownloadMonitor(TransferListener listener);
+
     ArtifactResolutionResult resolve(ArtifactResolutionRequest request);
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/DefaultArtifactManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/DefaultArtifactManager.java?rev=657545&r1=657544&r2=657545&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/DefaultArtifactManager.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/DefaultArtifactManager.java
Sun May 18 04:46:19 2008
@@ -30,6 +30,7 @@
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.wagon.events.TransferListener;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.slf4j.Logger;
@@ -41,7 +42,7 @@
 import java.util.List;
 
 /**
- * ???
+ * Default implementation of the {@link ArtifactManager} component.
  *
  * @version $Rev$ $Date$
  */
@@ -114,6 +115,12 @@
         return artifactFactory;
     }
 
+    public void setDownloadMonitor(final TransferListener listener) {
+        assert listener != null;
+
+        wagonManager.setDownloadMonitor(listener);
+    }
+    
     public ArtifactResolutionResult resolve(final ArtifactResolutionRequest request) {
         assert request != null;
 

Added: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinner.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinner.java?rev=657545&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinner.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinner.java
Sun May 18 04:46:19 2008
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.artifact.monitor;
+
+/**
+ * Provides a fancy text-based progress spinner w/optional informative message.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProgressSpinner
+{
+    private static final String CARRIAGE_RETURN = "\r";
+
+    private static final String MESSAGE_PAD = " ";
+
+    private final Style style;
+
+    private int state = 0;
+
+    public ProgressSpinner(final Style style) {
+        assert style != null;
+
+        this.style = style;
+    }
+
+    public ProgressSpinner() {
+        this(new DefaultStyle());
+    }
+
+    public void reset() {
+        state = 0;
+    }
+    
+    public String spin() {
+        return spin(null);
+    }
+
+    public String spin(final String message) {
+        // message may be null
+        
+        StringBuffer buff = new StringBuffer();
+
+        String[] elements = style.getElements();
+        buff.append(style.getPrefix());
+        buff.append(elements[state]);
+        buff.append(style.getSuffix());
+
+        if (message != null) {
+            buff.append(MESSAGE_PAD);
+            buff.append(message);
+        }
+
+        buff.append(CARRIAGE_RETURN);
+
+        state++;
+        if (state >= elements.length) {
+            state = 0;
+        }
+
+        return buff.toString();
+    }
+
+    //
+    // Style
+    //
+
+    public static interface Style
+    {
+        String getPrefix();
+
+        String[] getElements();
+
+        String getSuffix();
+    }
+
+    //
+    // Default Style
+    //
+    
+    public static class DefaultStyle
+        implements Style
+    {
+        private static final String[] ELEMENTS = {
+            "|",
+            "/",
+            "-",
+            "\\",
+        };
+
+        public String getPrefix() {
+            return "(";
+        }
+
+        public String[] getElements() {
+            return ELEMENTS;
+        }
+
+        public String getSuffix() {
+            return ")";
+        }
+    }
+
+    public static class BounceStyle
+        extends DefaultStyle
+    {
+        private static final String[] ELEMENTS = {
+            "*    ",
+            " *   ",
+            "  *  ",
+            "   * ",
+            "    *",
+            "   * ",
+            "  *  ",
+            " *   ",
+            "*    "
+        };
+
+        public String[] getElements() {
+            return ELEMENTS;
+        }
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinnerMonitor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinnerMonitor.java?rev=657545&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinnerMonitor.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/ProgressSpinnerMonitor.java
Sun May 18 04:46:19 2008
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.artifact.monitor;
+
+import static org.apache.maven.wagon.WagonConstants.UNKNOWN_LENGTH;
+import org.apache.maven.wagon.events.TransferEvent;
+import static org.apache.maven.wagon.events.TransferEvent.REQUEST_PUT;
+
+/**
+ * A download monitor providing a simple spinning progress interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProgressSpinnerMonitor
+    extends TransferListenerSupport
+{
+    private long complete;
+
+    private ProgressSpinner spinner = new ProgressSpinner();
+
+    //
+    // FIXME: Need to abstract the actualy IO here... But IO is not accessible ATM
+    //
+
+    public void transferInitiated(TransferEvent event) {
+        complete = 0;
+
+        spinner.reset();
+
+        String message = event.getRequestType() == REQUEST_PUT ? "Uploading" : "Downloading";
+
+        String url = event.getWagon().getRepository().getUrl();
+
+        System.out.println(message + ": " + url + "/" + event.getResource().getName());
+    }
+
+    public void transferProgress(final TransferEvent event, final byte[] buffer, final int
length) {
+        long total = event.getResource().getContentLength();
+        complete += length;
+
+        String message;
+
+        if (total >= 1024) {
+            message = complete / 1024 + "/" + (total == UNKNOWN_LENGTH ? "?" : total / 1024
+ "K");
+        }
+        else {
+            message = complete + "/" + (total == UNKNOWN_LENGTH ? "?" : total + "b");
+        }
+
+        System.out.print(spinner.spin(message));
+    }
+
+    public void transferCompleted(final TransferEvent event) {
+        long length = event.getResource().getContentLength();
+
+        if (length != UNKNOWN_LENGTH) {
+            String type = (event.getRequestType() == REQUEST_PUT ? "uploaded" : "downloaded");
+            String l = length >= 1024 ? (length / 1024) + "K" : length + "b";
+            
+            System.out.println(l + " " + type);
+        }
+    }
+}
\ No newline at end of file

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

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

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

Copied: geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/TransferListenerSupport.java
(from r657378, geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/TransferListenerSupport.java?p2=geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/TransferListenerSupport.java&p1=geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java&r1=657378&r2=657545&rev=657545&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/ArtifactManager.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-artifact/src/main/java/org/apache/geronimo/gshell/artifact/monitor/TransferListenerSupport.java
Sun May 18 04:46:19 2008
@@ -17,40 +17,47 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.artifact;
+package org.apache.geronimo.gshell.artifact.monitor;
 
-import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.InvalidRepositoryException;
-import org.apache.maven.artifact.UnknownRepositoryLayoutException;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-
-import java.util.List;
-import java.io.File;
-import java.net.URL;
-import java.net.MalformedURLException;
+import org.apache.maven.wagon.events.TransferListener;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Support for Wagon {@link TransferListener} implementations.
  *
  * @version $Rev$ $Date$
  */
-public interface ArtifactManager
+public class TransferListenerSupport
+    implements TransferListener
 {
-    ArtifactRepository getLocalRepository();
+    protected final Logger log = LoggerFactory.getLogger(getClass());
 
-    void setLocalRepository(ArtifactRepository repository);
+    public void transferInitiated(final TransferEvent event) {
+    }
 
-    void setLocalRepository(File dir) throws MalformedURLException, InvalidRepositoryException;
+    public void transferStarted(final TransferEvent event) {
+    }
 
-    List<ArtifactRepository> getRemoteRepositories();
-
-    void addRemoteRepository(ArtifactRepository repository);
-
-    void addRemoteRepository(String id, URL url) throws UnknownRepositoryLayoutException;
-
-    ArtifactFactory getArtifactFactory();
-
-    ArtifactResolutionResult resolve(ArtifactResolutionRequest request);
+    public void transferProgress(final TransferEvent event, final byte[] buffer, final int
length) {
+    }
+
+    public void transferCompleted(final TransferEvent event) {
+    }
+
+    public void transferError(final TransferEvent event) {
+        assert event != null;
+
+        Throwable cause = event.getException();
+        assert cause != null;
+        
+        log.error("Transfer failure: " + cause, cause);
+    }
+
+    public void debug(final String message) {
+        assert message != null;
+        
+        log.debug(message);
+    }
 }
\ No newline at end of file



Mime
View raw message