Coverage Report - org.apache.maven.wagon.events.TransferEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
TransferEvent
49%
44/89
46%
22/48
3,571
 
 1  
 package org.apache.maven.wagon.events;
 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.Wagon;
 23  
 import org.apache.maven.wagon.resource.Resource;
 24  
 
 25  
 import java.io.File;
 26  
 
 27  
 /**
 28  
  * TransferEvent is used to notify TransferListeners about progress
 29  
  * in transfer of resources form/to the repository
 30  
  *
 31  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 32  
  * @version $Id: TransferEvent.java 682051 2008-08-02 21:29:38Z hboutemy $
 33  
  */
 34  
 public class TransferEvent
 35  
     extends WagonEvent
 36  
 {
 37  
 
 38  
     /**
 39  
      * A transfer was attempted, but has not yet commenced.
 40  
      */
 41  
     public static final int TRANSFER_INITIATED = 0;
 42  
 
 43  
     /**
 44  
      * A transfer was started.
 45  
      */
 46  
     public static final int TRANSFER_STARTED = 1;
 47  
 
 48  
     /**
 49  
      * A transfer is completed.
 50  
      */
 51  
     public static final int TRANSFER_COMPLETED = 2;
 52  
 
 53  
     /**
 54  
      * A transfer is in progress.
 55  
      */
 56  
     public static final int TRANSFER_PROGRESS = 3;
 57  
 
 58  
     /**
 59  
      * An error occurred during transfer
 60  
      */
 61  
     public static final int TRANSFER_ERROR = 4;
 62  
 
 63  
     /**
 64  
      * Indicates GET transfer  (from the repository)
 65  
      */
 66  
     public static final int REQUEST_GET = 5;
 67  
 
 68  
     /**
 69  
      * Indicates PUT transfer (to the repository)
 70  
      */
 71  
     public static final int REQUEST_PUT = 6;
 72  
 
 73  
     private Resource resource;
 74  
 
 75  
     private int eventType;
 76  
 
 77  
     private int requestType;
 78  
 
 79  
     private Exception exception;
 80  
 
 81  
     private File localFile;
 82  
 
 83  
     public TransferEvent( final Wagon wagon, final Resource resource, final int eventType, final int requestType )
 84  
     {
 85  84
         super( wagon );
 86  
 
 87  84
         this.resource = resource;
 88  
 
 89  84
         setEventType( eventType );
 90  
 
 91  84
         setRequestType( requestType );
 92  
 
 93  84
     }
 94  
 
 95  
     public TransferEvent( final Wagon wagon, final Resource resource, final Exception exception, final int requestType )
 96  
     {
 97  17
         this( wagon, resource, TRANSFER_ERROR, requestType );
 98  
 
 99  17
         this.exception = exception;
 100  17
     }
 101  
 
 102  
     /**
 103  
      * @return Returns the resource.
 104  
      */
 105  
     public Resource getResource()
 106  
     {
 107  4
         return resource;
 108  
     }
 109  
 
 110  
     /**
 111  
      * @return Returns the exception.
 112  
      */
 113  
     public Exception getException()
 114  
     {
 115  1
         return exception;
 116  
     }
 117  
 
 118  
     /**
 119  
      * Returns the request type.
 120  
      *
 121  
      * @return Returns the request type. The Request type is one of
 122  
      *         <code>TransferEvent.REQUEST_GET<code> or <code>TransferEvent.REQUEST_PUT<code>
 123  
      */
 124  
     public int getRequestType()
 125  
     {
 126  4
         return requestType;
 127  
     }
 128  
 
 129  
     /**
 130  
      * Sets the request type
 131  
      *
 132  
      * @param requestType The requestType to set.
 133  
      *                    The Request type value should be either
 134  
      *                    <code>TransferEvent.REQUEST_GET<code> or <code>TransferEvent.REQUEST_PUT<code>.
 135  
      * @throws IllegalArgumentException when
 136  
      */
 137  
     public void setRequestType( final int requestType )
 138  
     {
 139  87
         switch ( requestType )
 140  
         {
 141  
 
 142  
             case REQUEST_PUT:
 143  27
                 break;
 144  
             case REQUEST_GET:
 145  59
                 break;
 146  
 
 147  
             default :
 148  1
                 throw new IllegalArgumentException( "Illegal request type: " + requestType );
 149  
         }
 150  
 
 151  86
         this.requestType = requestType;
 152  86
     }
 153  
 
 154  
     /**
 155  
      * @return Returns the eventType.
 156  
      */
 157  
     public int getEventType()
 158  
     {
 159  6
         return eventType;
 160  
     }
 161  
 
 162  
     /**
 163  
      * @param eventType The eventType to set.
 164  
      */
 165  
     public void setEventType( final int eventType )
 166  
     {
 167  89
         switch ( eventType )
 168  
         {
 169  
 
 170  
             case TRANSFER_INITIATED:
 171  24
                 break;
 172  
             case TRANSFER_STARTED:
 173  14
                 break;
 174  
             case TRANSFER_COMPLETED:
 175  16
                 break;
 176  
             case TRANSFER_PROGRESS:
 177  16
                 break;
 178  
             case TRANSFER_ERROR:
 179  18
                 break;
 180  
             default :
 181  1
                 throw new IllegalArgumentException( "Illegal event type: " + eventType );
 182  
         }
 183  
 
 184  88
         this.eventType = eventType;
 185  88
     }
 186  
 
 187  
     /**
 188  
      * @param resource The resource to set.
 189  
      */
 190  
     public void setResource( final Resource resource )
 191  
     {
 192  2
         this.resource = resource;
 193  2
     }
 194  
 
 195  
     /**
 196  
      * @return Returns the local file.
 197  
      */
 198  
     public File getLocalFile()
 199  
     {
 200  0
         return localFile;
 201  
     }
 202  
 
 203  
     /**
 204  
      * @param localFile The local file to set.
 205  
      */
 206  
     public void setLocalFile( File localFile )
 207  
     {
 208  46
         this.localFile = localFile;
 209  46
     }
 210  
 
 211  
     public String toString()
 212  
     {
 213  0
         StringBuffer sb = new StringBuffer();
 214  
 
 215  0
         sb.append( "TransferEvent[" );
 216  
 
 217  0
         switch ( this.getRequestType() )
 218  
         {
 219  
             case REQUEST_GET:
 220  0
                 sb.append( "GET" );
 221  0
                 break;
 222  
             case REQUEST_PUT:
 223  0
                 sb.append( "PUT" );
 224  0
                 break;
 225  
             default:
 226  0
                 sb.append( this.getRequestType() );
 227  
                 break;
 228  
         }
 229  
 
 230  0
         sb.append( "|" );
 231  0
         switch ( this.getEventType() )
 232  
         {
 233  
             case TRANSFER_COMPLETED:
 234  0
                 sb.append( "COMPLETED" );
 235  0
                 break;
 236  
             case TRANSFER_ERROR:
 237  0
                 sb.append( "ERROR" );
 238  0
                 break;
 239  
             case TRANSFER_INITIATED:
 240  0
                 sb.append( "INITIATED" );
 241  0
                 break;
 242  
             case TRANSFER_PROGRESS:
 243  0
                 sb.append( "PROGRESS" );
 244  0
                 break;
 245  
             case TRANSFER_STARTED:
 246  0
                 sb.append( "STARTED" );
 247  0
                 break;
 248  
             default:
 249  0
                 sb.append( this.getEventType() );
 250  
                 break;
 251  
         }
 252  
 
 253  0
         sb.append( "|" );
 254  
 
 255  0
         sb.append( this.getWagon().getRepository() ).append( "|" );
 256  0
         sb.append( this.getLocalFile() ).append( "|" );
 257  0
         sb.append( this.getResource().inspect() );
 258  0
         sb.append( "]" );
 259  
 
 260  0
         return sb.toString();
 261  
     }
 262  
 
 263  
     public int hashCode()
 264  
     {
 265  0
         final int prime = 31;
 266  0
         int result = 1;
 267  0
         result = prime * result + eventType;
 268  0
         result = prime * result + ( ( exception == null ) ? 0 : exception.hashCode() );
 269  0
         result = prime * result + ( ( localFile == null ) ? 0 : localFile.hashCode() );
 270  0
         result = prime * result + requestType;
 271  0
         result = prime * result + ( ( resource == null ) ? 0 : resource.hashCode() );
 272  0
         return result;
 273  
     }
 274  
 
 275  
     public boolean equals( Object obj )
 276  
     {
 277  15
         if ( this == obj )
 278  
         {
 279  8
             return true;
 280  
         }
 281  7
         if ( ( obj == null ) || ( getClass() != obj.getClass() ) )
 282  
         {
 283  0
             return false;
 284  
         }
 285  7
         final TransferEvent other = (TransferEvent) obj;
 286  7
         if ( eventType != other.eventType )
 287  
         {
 288  0
             return false;
 289  
         }
 290  7
         if ( exception == null )
 291  
         {
 292  1
             if ( other.exception != null )
 293  
             {
 294  0
                 return false;
 295  
             }
 296  
         }
 297  6
         else if ( !exception.getClass().equals( other.exception.getClass() ) )
 298  
         {
 299  0
             return false;
 300  
         }
 301  7
         if ( requestType != other.requestType )
 302  
         {
 303  0
             return false;
 304  
         }
 305  7
         if ( resource == null )
 306  
         {
 307  0
             if ( other.resource != null )
 308  
             {
 309  0
                 return false;
 310  
             }
 311  
         }
 312  7
         else if ( !resource.equals( other.resource ) )
 313  
         {
 314  0
             return false;
 315  
         }
 316  7
         else if ( !source.equals( other.source ) )
 317  
         {
 318  0
             return false;
 319  
         }
 320  7
         return true;
 321  
     }
 322  
     
 323  
 }