View Javadoc

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 649861 2008-04-19 23:03:55Z hboutemy $
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 + event.getWagon().getRepository().getId() );
64      }
65  
66      public void transferProgress( TransferEvent event, byte[] bytes, int i )
67      {
68      }
69  
70      public void transferStarted( TransferEvent event )
71      {
72          long contentLength = event.getResource().getContentLength();
73          if ( contentLength > 0 )
74          {
75              log( "Transferring " + ( ( contentLength + KILO / 2 ) / KILO ) + "K from "
76                              + event.getWagon().getRepository().getId() );
77          }
78      }
79  }