mirror of https://github.com/apache/maven.git
*very* quick download monitor. Instantiation and output to be reviewed later
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163348 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5d0ae1c56e
commit
8ad0f8f745
|
@ -26,6 +26,7 @@ import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
import org.apache.maven.wagon.TransferFailedException;
|
||||||
import org.apache.maven.wagon.UnsupportedProtocolException;
|
import org.apache.maven.wagon.UnsupportedProtocolException;
|
||||||
import org.apache.maven.wagon.Wagon;
|
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.authentication.AuthenticationException;
|
||||||
import org.apache.maven.wagon.authorization.AuthorizationException;
|
import org.apache.maven.wagon.authorization.AuthorizationException;
|
||||||
import org.apache.maven.wagon.proxy.ProxyInfo;
|
import org.apache.maven.wagon.proxy.ProxyInfo;
|
||||||
|
@ -52,6 +53,8 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
private Map proxies = new HashMap();
|
private Map proxies = new HashMap();
|
||||||
|
|
||||||
|
private TransferListener downloadMonitor;
|
||||||
|
|
||||||
public Artifact createArtifact( String groupId, String artifactId, String version, String type )
|
public Artifact createArtifact( String groupId, String artifactId, String version, String type )
|
||||||
{
|
{
|
||||||
Artifact artifact = new DefaultArtifact( groupId, artifactId, version, type );
|
Artifact artifact = new DefaultArtifact( groupId, artifactId, version, type );
|
||||||
|
@ -132,6 +135,7 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// TODO [BP]: do this handling in Wagon itself
|
||||||
temp = new File( destination + ".tmp" );
|
temp = new File( destination + ".tmp" );
|
||||||
|
|
||||||
temp.deleteOnExit();
|
temp.deleteOnExit();
|
||||||
|
@ -158,10 +162,16 @@ public class DefaultWagonManager
|
||||||
|
|
||||||
//wagon.addTransferListener( md5SumObserver );
|
//wagon.addTransferListener( md5SumObserver );
|
||||||
|
|
||||||
|
if ( downloadMonitor != null )
|
||||||
|
{
|
||||||
|
wagon.addTransferListener( downloadMonitor );
|
||||||
|
}
|
||||||
|
|
||||||
wagon.connect( repository, getProxy( repository.getProtocol() ) );
|
wagon.connect( repository, getProxy( repository.getProtocol() ) );
|
||||||
|
|
||||||
wagon.get( path( artifact ), temp );
|
wagon.get( path( artifact ), temp );
|
||||||
|
|
||||||
|
// TODO [BP]: put all disconnects in finally
|
||||||
wagon.disconnect();
|
wagon.disconnect();
|
||||||
|
|
||||||
releaseWagon( wagon );
|
releaseWagon( wagon );
|
||||||
|
@ -271,4 +281,11 @@ public class DefaultWagonManager
|
||||||
{
|
{
|
||||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @todo I'd rather not be setting this explicitly. */
|
||||||
|
public void setDownloadMonitor( TransferListener downloadMonitor )
|
||||||
|
{
|
||||||
|
this.downloadMonitor = downloadMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
import org.apache.maven.wagon.TransferFailedException;
|
||||||
import org.apache.maven.wagon.UnsupportedProtocolException;
|
import org.apache.maven.wagon.UnsupportedProtocolException;
|
||||||
import org.apache.maven.wagon.Wagon;
|
import org.apache.maven.wagon.Wagon;
|
||||||
|
import org.apache.maven.wagon.events.TransferListener;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -46,8 +47,10 @@ public interface WagonManager
|
||||||
|
|
||||||
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository )
|
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository )
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
|
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 );
|
Artifact createArtifact( String groupId, String artifactId, String version, String type );
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
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$
|
||||||
|
*/
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.commons.cli.PosixParser;
|
||||||
import org.apache.maven.Maven;
|
import org.apache.maven.Maven;
|
||||||
import org.apache.maven.MavenConstants;
|
import org.apache.maven.MavenConstants;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.MavenExecutionRequest;
|
||||||
import org.apache.maven.execution.MavenExecutionResponse;
|
import org.apache.maven.execution.MavenExecutionResponse;
|
||||||
import org.apache.maven.execution.initialize.MavenInitializingExecutionRequest;
|
import org.apache.maven.execution.initialize.MavenInitializingExecutionRequest;
|
||||||
|
@ -129,6 +130,12 @@ public class MavenCli
|
||||||
|
|
||||||
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
|
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
|
||||||
embedder.start( classWorld );
|
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 );
|
Maven maven = (Maven) embedder.lookup( Maven.ROLE );
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue