mirror of https://github.com/apache/maven.git
PR: MNG-418
use a silent transfer monitor in batch mode git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
22f6d7e1a7
commit
ae93f02c8d
|
@ -0,0 +1,79 @@
|
||||||
|
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.WagonConstants;
|
||||||
|
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 169548 2005-05-11 01:04:50Z brett $
|
||||||
|
*/
|
||||||
|
public class BatchModeDownloadMonitor
|
||||||
|
extends AbstractLogEnabled
|
||||||
|
implements TransferListener
|
||||||
|
{
|
||||||
|
public void transferInitiated( TransferEvent transferEvent )
|
||||||
|
{
|
||||||
|
String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
|
||||||
|
|
||||||
|
String url = transferEvent.getWagon().getRepository().getUrl();
|
||||||
|
|
||||||
|
// TODO: can't use getLogger() because this isn't currently instantiated as a component
|
||||||
|
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transferStarted( TransferEvent transferEvent )
|
||||||
|
{
|
||||||
|
// This space left intentionally blank
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
|
||||||
|
{
|
||||||
|
// This space left intentionally blank
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transferCompleted( TransferEvent transferEvent )
|
||||||
|
{
|
||||||
|
long contentLength = transferEvent.getResource().getContentLength();
|
||||||
|
if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
|
||||||
|
{
|
||||||
|
String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
|
||||||
|
String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
|
||||||
|
System.out.println( l + " " + type );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transferError( TransferEvent transferEvent )
|
||||||
|
{
|
||||||
|
// TODO: can't use getLogger() because this isn't currently instantiated as a component
|
||||||
|
transferEvent.getException().printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug( String message )
|
||||||
|
{
|
||||||
|
// TODO: can't use getLogger() because this isn't currently instantiated as a component
|
||||||
|
// getLogger().debug( message );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,15 +55,27 @@ public class ConsoleDownloadMonitor
|
||||||
long total = transferEvent.getResource().getContentLength();
|
long total = transferEvent.getResource().getContentLength();
|
||||||
complete += length;
|
complete += length;
|
||||||
// TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()?
|
// TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()?
|
||||||
System.out.print( ( complete / 1024 ) + "/" +
|
if ( total >= 1024 )
|
||||||
( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) + "\r" );
|
{
|
||||||
|
System.out.print(
|
||||||
|
( complete / 1024 ) + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) +
|
||||||
|
"\r" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.print( complete + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : total + "b" ) + "\r" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferCompleted( TransferEvent transferEvent )
|
public void transferCompleted( TransferEvent transferEvent )
|
||||||
{
|
{
|
||||||
System.out.println(
|
long contentLength = transferEvent.getResource().getContentLength();
|
||||||
( complete / 1024 ) + "K " +
|
if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
|
||||||
( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" ) );
|
{
|
||||||
|
String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
|
||||||
|
String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
|
||||||
|
System.out.println( l + " " + type );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferError( TransferEvent transferEvent )
|
public void transferError( TransferEvent transferEvent )
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class MavenCli
|
||||||
|
|
||||||
request = createRequest( projectFiles, embedder, commandLine, settings, eventDispatcher, manager );
|
request = createRequest( projectFiles, embedder, commandLine, settings, eventDispatcher, manager );
|
||||||
|
|
||||||
maven = createMavenInstance( embedder );
|
maven = createMavenInstance( embedder, settings.isInteractiveMode() );
|
||||||
}
|
}
|
||||||
catch ( ComponentLookupException e )
|
catch ( ComponentLookupException e )
|
||||||
{
|
{
|
||||||
|
@ -346,12 +346,19 @@ public class MavenCli
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Maven createMavenInstance( Embedder embedder )
|
private static Maven createMavenInstance( Embedder embedder, boolean interactive )
|
||||||
throws ComponentLookupException
|
throws ComponentLookupException
|
||||||
{
|
{
|
||||||
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger).
|
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger).
|
||||||
WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
||||||
|
if ( interactive )
|
||||||
|
{
|
||||||
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
|
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wagonManager.setDownloadMonitor( new BatchModeDownloadMonitor() );
|
||||||
|
}
|
||||||
|
|
||||||
return (Maven) embedder.lookup( Maven.ROLE );
|
return (Maven) embedder.lookup( Maven.ROLE );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue