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:
Brett Leslie Porter 2005-06-20 15:21:50 +00:00
parent 22f6d7e1a7
commit ae93f02c8d
3 changed files with 106 additions and 8 deletions

View File

@ -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 );
}
}

View File

@ -55,15 +55,27 @@ public void transferProgress( TransferEvent transferEvent, byte[] buffer, int le
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 == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) + "\r" );
if ( total >= 1024 )
{
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 )
{
System.out.println(
( complete / 1024 ) + "K " +
( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" ) );
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 )

View File

@ -224,7 +224,7 @@ public static int main( String[] args, ClassWorld classWorld )
request = createRequest( projectFiles, embedder, commandLine, settings, eventDispatcher, manager );
maven = createMavenInstance( embedder );
maven = createMavenInstance( embedder, settings.isInteractiveMode() );
}
catch ( ComponentLookupException e )
{
@ -346,12 +346,19 @@ private static List getProjectFiles( CommandLine commandLine )
return files;
}
private static Maven createMavenInstance( Embedder embedder )
private static Maven createMavenInstance( Embedder embedder, boolean interactive )
throws ComponentLookupException
{
// 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.setDownloadMonitor( new ConsoleDownloadMonitor() );
if ( interactive )
{
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
}
else
{
wagonManager.setDownloadMonitor( new BatchModeDownloadMonitor() );
}
return (Maven) embedder.lookup( Maven.ROLE );
}