Save This Page
Home » maven-ant-tasks-2.1.0-src » org.apache » maven » artifact » ant » [javadoc | source]
    1   package org.apache.maven.artifact.ant;
    2   
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   import org.apache.maven.wagon.events.TransferEvent;
   23   import org.apache.maven.wagon.events.TransferListener;
   24   import org.apache.tools.ant.Project;
   25   import org.apache.tools.ant.ProjectComponent;
   26   
   27   /**
   28    * Log wagon events in the ant tasks
   29    *
   30    * @author <a href="mailto:brett@apache.org">Brett Porter</a>
   31    * @version $Id: AntDownloadMonitor.java 814436 2009-09-13 23:29:03Z bentmann $
   32    */
   33   public class AntDownloadMonitor
   34       extends ProjectComponent
   35       implements TransferListener
   36   {
   37       private static final int KILO = 1024;
   38   
   39       public void debug( String s )
   40       {
   41           log( s, Project.MSG_DEBUG );
   42       }
   43   
   44       public void transferCompleted( TransferEvent event )
   45       {
   46           long contentLength = event.getResource().getContentLength();
   47           if ( ( contentLength > 0 ) && ( event.getRequestType() == TransferEvent.REQUEST_PUT ) )
   48           {
   49               log( "Uploaded " + ( ( contentLength + KILO / 2 ) / KILO ) + "K" );
   50           }
   51       }
   52   
   53       public void transferError( TransferEvent event )
   54       {
   55           log( event.getException().getMessage(), Project.MSG_ERR );
   56       }
   57   
   58       public void transferInitiated( TransferEvent event )
   59       {
   60           String message = event.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
   61           String dest = event.getRequestType() == TransferEvent.REQUEST_PUT ? " to " : " from ";
   62   
   63           log( message + ": " + event.getResource().getName() + dest + "repository "
   64               + event.getWagon().getRepository().getId() + " at " + event.getWagon().getRepository().getUrl() );
   65       }
   66   
   67       public void transferProgress( TransferEvent event, byte[] bytes, int i )
   68       {
   69       }
   70   
   71       public void transferStarted( TransferEvent event )
   72       {
   73           long contentLength = event.getResource().getContentLength();
   74           if ( contentLength > 0 )
   75           {
   76               log( "Transferring " + ( ( contentLength + KILO / 2 ) / KILO ) + "K from "
   77                               + event.getWagon().getRepository().getId() );
   78           }
   79       }
   80   }

Save This Page
Home » maven-ant-tasks-2.1.0-src » org.apache » maven » artifact » ant » [javadoc | source]