maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager DefaultWagonManager.java WagonManager.java
Date Thu, 10 Feb 2005 07:09:57 GMT
brett       2005/02/09 23:09:57

  Modified:    maven-core/src/main/java/org/apache/maven/cli MavenCli.java
               maven-artifact/src/main/java/org/apache/maven/artifact/manager
                        DefaultWagonManager.java WagonManager.java
  Added:       maven-core/src/main/java/org/apache/maven/cli
                        ConsoleDownloadMonitor.java
  Log:
  *very* quick download monitor. Instantiation and output to be reviewed later
  
  Revision  Changes    Path
  1.9       +8 -1      maven-components/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
  
  Index: MavenCli.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MavenCli.java	8 Feb 2005 04:39:37 -0000	1.8
  +++ MavenCli.java	10 Feb 2005 07:09:57 -0000	1.9
  @@ -27,6 +27,7 @@
   import org.apache.maven.Maven;
   import org.apache.maven.MavenConstants;
   import org.apache.maven.artifact.repository.ArtifactRepository;
  +import org.apache.maven.artifact.manager.WagonManager;
   import org.apache.maven.execution.MavenExecutionRequest;
   import org.apache.maven.execution.MavenExecutionResponse;
   import org.apache.maven.execution.initialize.MavenInitializingExecutionRequest;
  @@ -129,6 +130,12 @@
   
           ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
           embedder.start( classWorld );
  +
  +        // TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like
the right place.
  +        WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
  +        wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
  +
  +
           Maven maven = (Maven) embedder.lookup( Maven.ROLE );
   
           // ----------------------------------------------------------------------
  
  
  
  1.1                  maven-components/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java
  
  Index: ConsoleDownloadMonitor.java
  ===================================================================
  package org.apache.maven.cli;
  
  /* ====================================================================
   *   Copyright 2001-2005 The Apache Software Foundation.
   *
   *   Licensed 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.
   * ====================================================================
   */
  
  import org.apache.maven.wagon.events.TransferEvent;
  import org.apache.maven.wagon.events.TransferListener;
  import org.codehaus.plexus.logging.AbstractLogEnabled;
  
  /**
   * Console download progress meter.
   *
   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   * @version $Id: ConsoleDownloadMonitor.java,v 1.1 2005/02/10 07:09:57 brett Exp $
   */
  public class ConsoleDownloadMonitor
      extends AbstractLogEnabled
      implements TransferListener
  {
      private long complete;
  
      public void transferStarted( TransferEvent transferEvent )
      {
          System.out.println( "Downloading: " + transferEvent.getResource().getName() );
          complete = 0;
      }
  
      public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length
)
      {
          long total = transferEvent.getResource().getContentLength();
          complete += length;
          // TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()?
          System.out.print( ( complete / 1024 ) + "/" + ( total == 0 ? "?" : ( total / 1024
) + "K" ) + "\r" );
      }
  
      public void transferCompleted( TransferEvent transferEvent )
      {
          long total = transferEvent.getResource().getContentLength();
          System.out.println( ( total / 1024 ) + "K downloaded" );
      }
  
      public void transferError( TransferEvent transferEvent )
      {
          getLogger().error( transferEvent.getException().getMessage() );
      }
  
      public void debug( String message )
      {
          getLogger().debug( message );
      }
  }
  
  
  
  
  
  
  1.9       +17 -0     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
  
  Index: DefaultWagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultWagonManager.java	8 Feb 2005 07:48:08 -0000	1.8
  +++ DefaultWagonManager.java	10 Feb 2005 07:09:57 -0000	1.9
  @@ -26,6 +26,7 @@
   import org.apache.maven.wagon.TransferFailedException;
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
  +import org.apache.maven.wagon.events.TransferListener;
   import org.apache.maven.wagon.authentication.AuthenticationException;
   import org.apache.maven.wagon.authorization.AuthorizationException;
   import org.apache.maven.wagon.proxy.ProxyInfo;
  @@ -52,6 +53,8 @@
   
       private Map proxies = new HashMap();
   
  +    private TransferListener downloadMonitor;
  +
       public Artifact createArtifact( String groupId, String artifactId, String version,
String type )
       {
           Artifact artifact = new DefaultArtifact( groupId, artifactId, version, type );
  @@ -132,6 +135,7 @@
   
           try
           {
  +            // TODO [BP]: do this handling in Wagon itself
               temp = new File( destination + ".tmp" );
   
               temp.deleteOnExit();
  @@ -158,10 +162,16 @@
   
                   //wagon.addTransferListener( md5SumObserver );
   
  +                if ( downloadMonitor != null )
  +                {
  +                    wagon.addTransferListener( downloadMonitor );
  +                }
  +
                   wagon.connect( repository, getProxy( repository.getProtocol() ) );
   
                   wagon.get( path( artifact ), temp );
   
  +                // TODO [BP]: put all disconnects in finally
                   wagon.disconnect();
   
                   releaseWagon( wagon );
  @@ -271,4 +281,11 @@
       {
           container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
       }
  +
  +    /** @todo I'd rather not be setting this explicitly. */
  +    public void setDownloadMonitor( TransferListener downloadMonitor )
  +    {
  +        this.downloadMonitor = downloadMonitor;
  +    }
  +
   }
  
  
  
  1.4       +5 -2      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
  
  Index: WagonManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/manager/WagonManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WagonManager.java	8 Feb 2005 07:48:08 -0000	1.3
  +++ WagonManager.java	10 Feb 2005 07:09:57 -0000	1.4
  @@ -22,6 +22,7 @@
   import org.apache.maven.wagon.TransferFailedException;
   import org.apache.maven.wagon.UnsupportedProtocolException;
   import org.apache.maven.wagon.Wagon;
  +import org.apache.maven.wagon.events.TransferListener;
   
   import java.io.File;
   import java.util.Set;
  @@ -46,8 +47,10 @@
   
       void put( File source, Artifact artifact, ArtifactRepository deploymentRepository )
           throws Exception;
  -
  +    
       void setProxy( String protocol, String host, int port, String username, String password,
String nonProxyHosts );
   
  +    void setDownloadMonitor( TransferListener downloadMonitor );
  +
       Artifact createArtifact( String groupId, String artifactId, String version, String
type );
   }
  \ No newline at end of file
  
  
  

Mime
View raw message