Coverage Report - org.apache.maven.wagon.AbstractWagon
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractWagon
81 %
228/279
65 %
29/44
1,725
AbstractWagon$1
100 %
4/4
100 %
6/6
1,725
 
 1  
 package org.apache.maven.wagon;
 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 java.io.File;
 23  
 import java.io.FileInputStream;
 24  
 import java.io.FileNotFoundException;
 25  
 import java.io.IOException;
 26  
 import java.io.InputStream;
 27  
 import java.io.OutputStream;
 28  
 import java.util.List;
 29  
 
 30  
 import org.apache.maven.wagon.authentication.AuthenticationException;
 31  
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 32  
 import org.apache.maven.wagon.authorization.AuthorizationException;
 33  
 import org.apache.maven.wagon.events.SessionEvent;
 34  
 import org.apache.maven.wagon.events.SessionEventSupport;
 35  
 import org.apache.maven.wagon.events.SessionListener;
 36  
 import org.apache.maven.wagon.events.TransferEvent;
 37  
 import org.apache.maven.wagon.events.TransferEventSupport;
 38  
 import org.apache.maven.wagon.events.TransferListener;
 39  
 import org.apache.maven.wagon.proxy.ProxyInfo;
 40  
 import org.apache.maven.wagon.proxy.ProxyInfoProvider;
 41  
 import org.apache.maven.wagon.proxy.ProxyUtils;
 42  
 import org.apache.maven.wagon.repository.Repository;
 43  
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 44  
 import org.apache.maven.wagon.resource.Resource;
 45  
 import org.codehaus.plexus.util.IOUtil;
 46  
 
 47  
 /**
 48  
  * Implementation of common facilities for Wagon providers.
 49  
  *
 50  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 51  
  * @version $Id: AbstractWagon.java 1174134 2011-09-22 13:47:58Z olamy $
 52  
  */
 53  44
 public abstract class AbstractWagon
 54  
     implements Wagon
 55  
 {
 56  
     protected static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
 57  
 
 58  
     protected Repository repository;
 59  
 
 60  44
     protected SessionEventSupport sessionEventSupport = new SessionEventSupport();
 61  
 
 62  44
     protected TransferEventSupport transferEventSupport = new TransferEventSupport();
 63  
 
 64  
     protected AuthenticationInfo authenticationInfo;
 65  
 
 66  44
     protected boolean interactive = true;
 67  
     
 68  44
     private int connectionTimeout = 60000;
 69  
     
 70  
     private ProxyInfoProvider proxyInfoProvider;
 71  
     
 72  
     /** @deprecated */
 73  
     protected ProxyInfo proxyInfo;
 74  
     
 75  
     private RepositoryPermissions permissionsOverride;
 76  
 
 77  
     // ----------------------------------------------------------------------
 78  
     // Accessors
 79  
     // ----------------------------------------------------------------------
 80  
 
 81  
     public Repository getRepository()
 82  
     {
 83  6
         return repository;
 84  
     }
 85  
 
 86  
     public ProxyInfo getProxyInfo()
 87  
     {
 88  6
         return proxyInfoProvider != null ? proxyInfoProvider.getProxyInfo( null ) : null;
 89  
     }
 90  
 
 91  
     public AuthenticationInfo getAuthenticationInfo()
 92  
     {
 93  2
         return authenticationInfo;
 94  
     }
 95  
 
 96  
     // ----------------------------------------------------------------------
 97  
     // Connection
 98  
     // ----------------------------------------------------------------------
 99  
 
 100  
     public void openConnection()
 101  
         throws ConnectionException, AuthenticationException
 102  
     {
 103  
         try
 104  
         {
 105  35
             openConnectionInternal();
 106  
         }
 107  1
         catch ( ConnectionException e )
 108  
         {
 109  1
             fireSessionConnectionRefused();
 110  
             
 111  1
             throw e;
 112  
         }
 113  1
         catch ( AuthenticationException e )
 114  
         {
 115  1
             fireSessionConnectionRefused();
 116  
             
 117  1
             throw e;
 118  33
         }
 119  33
     }
 120  
 
 121  
     public void connect( Repository repository )
 122  
         throws ConnectionException, AuthenticationException
 123  
     {
 124  30
         connect( repository, null, (ProxyInfoProvider) null );
 125  27
     }
 126  
 
 127  
     public void connect( Repository repository, ProxyInfo proxyInfo )
 128  
         throws ConnectionException, AuthenticationException
 129  
     {
 130  2
         connect( repository, null, proxyInfo );
 131  2
     }
 132  
 
 133  
     public void connect( Repository repository, ProxyInfoProvider proxyInfoProvider )
 134  
         throws ConnectionException, AuthenticationException
 135  
     {
 136  1
         connect( repository, null, proxyInfoProvider );
 137  1
     }
 138  
 
 139  
     public void connect( Repository repository, AuthenticationInfo authenticationInfo )
 140  
         throws ConnectionException, AuthenticationException
 141  
     {
 142  3
         connect( repository, authenticationInfo, (ProxyInfoProvider) null );
 143  3
     }
 144  
 
 145  
     public void connect( Repository repository, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
 146  
         throws ConnectionException, AuthenticationException
 147  
     {
 148  2
         final ProxyInfo proxy = proxyInfo;
 149  2
         connect( repository, authenticationInfo, new ProxyInfoProvider()
 150  2
         {
 151  
             public ProxyInfo getProxyInfo( String protocol )
 152  
             {
 153  11
                 if ( protocol == null || proxy == null || protocol.equalsIgnoreCase( proxy.getType() ) )
 154  
                 {
 155  8
                     return proxy;
 156  
                 }
 157  
                 else
 158  
                 {
 159  3
                     return null;
 160  
                 }
 161  
             }
 162  
         } );
 163  2
         this.proxyInfo = proxyInfo;
 164  2
     }
 165  
     
 166  
     public void connect( Repository repository, AuthenticationInfo authenticationInfo,
 167  
                          ProxyInfoProvider proxyInfoProvider )
 168  
         throws ConnectionException, AuthenticationException
 169  
     {
 170  36
         if ( repository == null )
 171  
         {
 172  1
             throw new IllegalStateException( "The repository specified cannot be null." );
 173  
         }
 174  
 
 175  35
         if ( permissionsOverride != null )
 176  
         {
 177  1
             repository.setPermissions( permissionsOverride );
 178  
         }
 179  
         
 180  35
         this.repository = repository;
 181  
 
 182  35
         if ( authenticationInfo == null )
 183  
         {
 184  32
             authenticationInfo = new AuthenticationInfo();
 185  
         }
 186  
 
 187  35
         if ( authenticationInfo.getUserName() == null )
 188  
         {
 189  
             // Get user/pass that were encoded in the URL.
 190  34
             if ( repository.getUsername() != null )
 191  
             {
 192  1
                 authenticationInfo.setUserName( repository.getUsername() );
 193  1
                 if ( repository.getPassword() != null && authenticationInfo.getPassword() == null )
 194  
                 {
 195  1
                     authenticationInfo.setPassword( repository.getPassword() );
 196  
                 }
 197  
             }
 198  
         }
 199  
 
 200  
         // TODO: Do these needs to be fields, or are they only used in openConnection()?
 201  35
         this.authenticationInfo = authenticationInfo;
 202  
         
 203  35
         this.proxyInfoProvider = proxyInfoProvider;
 204  
         
 205  35
         fireSessionOpening();
 206  
 
 207  35
         openConnection();
 208  
 
 209  33
         fireSessionOpened();
 210  33
     }
 211  
 
 212  
     protected abstract void openConnectionInternal()
 213  
         throws ConnectionException, AuthenticationException;
 214  
 
 215  
     public void disconnect()
 216  
         throws ConnectionException
 217  
     {
 218  22
         fireSessionDisconnecting();
 219  
 
 220  
         try
 221  
         {
 222  22
             closeConnection();
 223  
         }
 224  1
         catch ( ConnectionException e )
 225  
         {
 226  1
             fireSessionError( e );
 227  1
             throw e;
 228  21
         }
 229  
 
 230  21
         fireSessionDisconnected();
 231  21
     }
 232  
 
 233  
     protected abstract void closeConnection()
 234  
         throws ConnectionException;
 235  
 
 236  
     protected void createParentDirectories( File destination )
 237  
         throws TransferFailedException
 238  
     {
 239  6
         File destinationDirectory = destination.getParentFile();
 240  
         try
 241  
         {
 242  6
             destinationDirectory = destinationDirectory.getCanonicalFile();
 243  
         }
 244  0
         catch ( IOException e )
 245  
         {
 246  
             // not essential to have a canonical file
 247  6
         }
 248  6
         if ( destinationDirectory != null && !destinationDirectory.exists() )
 249  
         {
 250  0
             destinationDirectory.mkdirs();
 251  0
             if ( !destinationDirectory.exists() )
 252  
             {
 253  0
                 throw new TransferFailedException(
 254  
                     "Specified destination directory cannot be created: " + destinationDirectory );
 255  
             }
 256  
         }
 257  6
     }
 258  
     
 259  
     public void setTimeout( int timeoutValue )
 260  
     {
 261  0
         connectionTimeout = timeoutValue;
 262  0
     }
 263  
     
 264  
     public int getTimeout()
 265  
     {
 266  0
         return connectionTimeout;
 267  
     }
 268  
 
 269  
     // ----------------------------------------------------------------------
 270  
     // Stream i/o
 271  
     // ----------------------------------------------------------------------
 272  
 
 273  
     protected void getTransfer( Resource resource, File destination, InputStream input )
 274  
         throws TransferFailedException
 275  
     {
 276  6
         getTransfer( resource, destination, input, true, Integer.MAX_VALUE );
 277  3
     }
 278  
 
 279  
     protected void getTransfer( Resource resource, OutputStream output, InputStream input )
 280  
         throws TransferFailedException
 281  
     {
 282  0
         getTransfer( resource, output, input, true, Integer.MAX_VALUE );
 283  0
     }
 284  
 
 285  
     protected void getTransfer( Resource resource, File destination, InputStream input, boolean closeInput,
 286  
                                 int maxSize )
 287  
         throws TransferFailedException
 288  
     {
 289  
         // ensure that the destination is created only when we are ready to transfer
 290  6
         fireTransferDebug( "attempting to create parent directories for destination: " + destination.getName() );
 291  6
         createParentDirectories( destination );
 292  
 
 293  6
         OutputStream output = new LazyFileOutputStream( destination );
 294  
 
 295  6
         fireGetStarted( resource, destination );
 296  
 
 297  
         try
 298  
         {
 299  6
             getTransfer( resource, output, input, closeInput, maxSize );
 300  
         }
 301  3
         catch ( TransferFailedException e )
 302  
         {
 303  3
             if ( destination.exists() )
 304  
             {
 305  2
                 boolean deleted = destination.delete();
 306  
 
 307  2
                 if ( !deleted )
 308  
                 {
 309  0
                     destination.deleteOnExit();
 310  
                 }
 311  
             }
 312  3
             throw e;
 313  
         }
 314  
         finally
 315  
         {
 316  6
             IOUtil.close( output );
 317  3
         }
 318  
 
 319  3
         fireGetCompleted( resource, destination );
 320  3
     }
 321  
 
 322  
     protected void getTransfer( Resource resource, OutputStream output, InputStream input, boolean closeInput,
 323  
                                 int maxSize )
 324  
         throws TransferFailedException
 325  
     {
 326  
         try
 327  
         {
 328  8
             transfer( resource, input, output, TransferEvent.REQUEST_GET, maxSize );
 329  
             
 330  5
             finishGetTransfer( resource, input, output );
 331  
         }
 332  3
         catch ( IOException e )
 333  
         {
 334  3
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 335  
 
 336  3
             String msg = "GET request of: " + resource.getName() + " from " + repository.getName() + " failed";
 337  
 
 338  3
             throw new TransferFailedException( msg, e );
 339  
         }
 340  
         finally
 341  
         {
 342  8
             if ( closeInput )
 343  
             {
 344  8
                 IOUtil.close( input );
 345  
             }
 346  
 
 347  8
             cleanupGetTransfer( resource );
 348  5
         }
 349  5
     }
 350  
 
 351  
     protected void finishGetTransfer( Resource resource, InputStream input, OutputStream output )
 352  
         throws TransferFailedException
 353  
     {
 354  5
     }
 355  
 
 356  
     protected void cleanupGetTransfer( Resource resource )
 357  
     {
 358  15
     }
 359  
 
 360  
     protected void putTransfer( Resource resource, File source, OutputStream output, boolean closeOutput )
 361  
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
 362  
     {
 363  2
         firePutStarted( resource, source );
 364  
 
 365  2
         transfer( resource, source, output, closeOutput );
 366  
 
 367  2
         firePutCompleted( resource, source );
 368  2
     }
 369  
 
 370  
     /**
 371  
      * Write from {@link File} to {@link OutputStream}
 372  
      * 
 373  
      * @since 1.0-beta-1
 374  
      * 
 375  
      * @param resource resource to transfer
 376  
      * @param source file to read from
 377  
      * @param output output stream
 378  
      * @param closeOutput whether the output stream should be closed or not
 379  
      * @throws TransferFailedException
 380  
      * @throws ResourceDoesNotExistException 
 381  
      * @throws AuthorizationException 
 382  
      */
 383  
     protected void transfer( Resource resource, File source, OutputStream output, boolean closeOutput )
 384  
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
 385  
     {
 386  2
         InputStream input = null;
 387  
 
 388  
         try
 389  
         {
 390  2
             input = new FileInputStream( source );
 391  
 
 392  2
             putTransfer( resource, input, output, closeOutput );
 393  
         }
 394  0
         catch ( FileNotFoundException e )
 395  
         {
 396  0
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
 397  
 
 398  0
             throw new TransferFailedException( "Specified source file does not exist: " + source, e );
 399  
         }
 400  
         finally
 401  
         {
 402  2
             IOUtil.close( input );
 403  2
         }
 404  2
     }
 405  
 
 406  
     protected void putTransfer( Resource resource, InputStream input, OutputStream output, boolean closeOutput )
 407  
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
 408  
     {
 409  
         try
 410  
         {
 411  4
             transfer( resource, input, output, TransferEvent.REQUEST_PUT );
 412  
             
 413  4
             finishPutTransfer( resource, input, output );
 414  
         }
 415  0
         catch ( IOException e )
 416  
         {
 417  0
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
 418  
 
 419  0
             String msg = "PUT request to: " + resource.getName() + " in " + repository.getName() + " failed";
 420  
 
 421  0
             throw new TransferFailedException( msg, e );
 422  
         }
 423  
         finally
 424  
         {
 425  4
             if ( closeOutput )
 426  
             {
 427  4
                 IOUtil.close( output );
 428  
             }
 429  
             
 430  4
             cleanupPutTransfer( resource );
 431  4
         }
 432  4
     }
 433  
 
 434  
     protected void cleanupPutTransfer( Resource resource )
 435  
     {
 436  7
     }
 437  
 
 438  
     protected void finishPutTransfer( Resource resource, InputStream input, OutputStream output )
 439  
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
 440  
     {
 441  4
     }
 442  
 
 443  
     /**
 444  
      * Write from {@link InputStream} to {@link OutputStream}.
 445  
      * Equivalent to {@link #transfer(Resource, InputStream, OutputStream, int, int)} with a maxSize equals to
 446  
      * {@link Integer#MAX_VALUE}
 447  
      * 
 448  
      * @param resource resource to transfer
 449  
      * @param input input stream
 450  
      * @param output output stream
 451  
      * @param requestType one of {@link TransferEvent#REQUEST_GET} or {@link TransferEvent#REQUEST_PUT}
 452  
      * @throws IOException
 453  
      */
 454  
     protected void transfer( Resource resource, InputStream input, OutputStream output, int requestType )
 455  
         throws IOException
 456  
     {
 457  4
         transfer( resource, input, output, requestType, Integer.MAX_VALUE );
 458  4
     }
 459  
 
 460  
     /**
 461  
      * Write from {@link InputStream} to {@link OutputStream}.
 462  
      * Equivalent to {@link #transfer(Resource, InputStream, OutputStream, int, int)} with a maxSize equals to
 463  
      * {@link Integer#MAX_VALUE}
 464  
      * 
 465  
      * @param resource resource to transfer
 466  
      * @param input input stream
 467  
      * @param output output stream
 468  
      * @param requestType one of {@link TransferEvent#REQUEST_GET} or {@link TransferEvent#REQUEST_PUT}
 469  
      * @param maxSize size of the buffer
 470  
      * @throws IOException
 471  
      */
 472  
     protected void transfer( Resource resource, InputStream input, OutputStream output, int requestType, int maxSize )
 473  
         throws IOException
 474  
     {
 475  12
         byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
 476  
 
 477  12
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS, requestType );
 478  12
         transferEvent.setTimestamp( System.currentTimeMillis() );
 479  
 
 480  12
         int remaining = maxSize;
 481  23
         while ( remaining > 0 )
 482  
         {
 483  23
             int n = input.read( buffer, 0, Math.min( buffer.length, remaining ) );
 484  
 
 485  20
             if ( n == -1 )
 486  
             {
 487  9
                 break;
 488  
             }
 489  
 
 490  11
             fireTransferProgress( transferEvent, buffer, n );
 491  
 
 492  11
             output.write( buffer, 0, n );
 493  
 
 494  11
             remaining -= n;
 495  11
         }
 496  9
         output.flush();
 497  9
     }
 498  
 
 499  
     // ----------------------------------------------------------------------
 500  
     //
 501  
     // ----------------------------------------------------------------------
 502  
 
 503  
     protected void fireTransferProgress( TransferEvent transferEvent, byte[] buffer, int n )
 504  
     {
 505  12
         transferEventSupport.fireTransferProgress( transferEvent, buffer, n );
 506  12
     }
 507  
 
 508  
     protected void fireGetCompleted( Resource resource, File localFile )
 509  
     {
 510  5
         long timestamp = System.currentTimeMillis();
 511  
 
 512  5
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_COMPLETED,
 513  
                                                          TransferEvent.REQUEST_GET );
 514  
 
 515  5
         transferEvent.setTimestamp( timestamp );
 516  
 
 517  5
         transferEvent.setLocalFile( localFile );
 518  
 
 519  5
         transferEventSupport.fireTransferCompleted( transferEvent );
 520  5
     }
 521  
 
 522  
     protected void fireGetStarted( Resource resource, File localFile )
 523  
     {
 524  8
         long timestamp = System.currentTimeMillis();
 525  
 
 526  8
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_STARTED,
 527  
                                                          TransferEvent.REQUEST_GET );
 528  
 
 529  8
         transferEvent.setTimestamp( timestamp );
 530  
 
 531  8
         transferEvent.setLocalFile( localFile );
 532  
 
 533  8
         transferEventSupport.fireTransferStarted( transferEvent );
 534  8
     }
 535  
 
 536  
     protected void fireGetInitiated( Resource resource, File localFile )
 537  
     {
 538  16
         long timestamp = System.currentTimeMillis();
 539  
 
 540  16
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_INITIATED,
 541  
                                                          TransferEvent.REQUEST_GET );
 542  
 
 543  16
         transferEvent.setTimestamp( timestamp );
 544  
 
 545  16
         transferEvent.setLocalFile( localFile );
 546  
 
 547  16
         transferEventSupport.fireTransferInitiated( transferEvent );
 548  16
     }
 549  
 
 550  
     protected void firePutInitiated( Resource resource, File localFile )
 551  
     {
 552  7
         long timestamp = System.currentTimeMillis();
 553  
 
 554  7
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_INITIATED,
 555  
                                                          TransferEvent.REQUEST_PUT );
 556  
 
 557  7
         transferEvent.setTimestamp( timestamp );
 558  
 
 559  7
         transferEvent.setLocalFile( localFile );
 560  
 
 561  7
         transferEventSupport.fireTransferInitiated( transferEvent );
 562  7
     }
 563  
 
 564  
     protected void firePutCompleted( Resource resource, File localFile )
 565  
     {
 566  4
         long timestamp = System.currentTimeMillis();
 567  
 
 568  4
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_COMPLETED,
 569  
                                                          TransferEvent.REQUEST_PUT );
 570  
 
 571  4
         transferEvent.setTimestamp( timestamp );
 572  
 
 573  4
         transferEvent.setLocalFile( localFile );
 574  
 
 575  4
         transferEventSupport.fireTransferCompleted( transferEvent );
 576  4
     }
 577  
 
 578  
     protected void firePutStarted( Resource resource, File localFile )
 579  
     {
 580  4
         long timestamp = System.currentTimeMillis();
 581  
 
 582  4
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_STARTED,
 583  
                                                          TransferEvent.REQUEST_PUT );
 584  
 
 585  4
         transferEvent.setTimestamp( timestamp );
 586  
 
 587  4
         transferEvent.setLocalFile( localFile );
 588  
 
 589  4
         transferEventSupport.fireTransferStarted( transferEvent );
 590  4
     }
 591  
 
 592  
     protected void fireSessionDisconnected()
 593  
     {
 594  21
         long timestamp = System.currentTimeMillis();
 595  
 
 596  21
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_DISCONNECTED );
 597  
 
 598  21
         sessionEvent.setTimestamp( timestamp );
 599  
 
 600  21
         sessionEventSupport.fireSessionDisconnected( sessionEvent );
 601  21
     }
 602  
 
 603  
     protected void fireSessionDisconnecting()
 604  
     {
 605  22
         long timestamp = System.currentTimeMillis();
 606  
 
 607  22
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_DISCONNECTING );
 608  
 
 609  22
         sessionEvent.setTimestamp( timestamp );
 610  
 
 611  22
         sessionEventSupport.fireSessionDisconnecting( sessionEvent );
 612  22
     }
 613  
 
 614  
     protected void fireSessionLoggedIn()
 615  
     {
 616  0
         long timestamp = System.currentTimeMillis();
 617  
 
 618  0
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_LOGGED_IN );
 619  
 
 620  0
         sessionEvent.setTimestamp( timestamp );
 621  
 
 622  0
         sessionEventSupport.fireSessionLoggedIn( sessionEvent );
 623  0
     }
 624  
 
 625  
     protected void fireSessionLoggedOff()
 626  
     {
 627  0
         long timestamp = System.currentTimeMillis();
 628  
 
 629  0
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_LOGGED_OFF );
 630  
 
 631  0
         sessionEvent.setTimestamp( timestamp );
 632  
 
 633  0
         sessionEventSupport.fireSessionLoggedOff( sessionEvent );
 634  0
     }
 635  
 
 636  
     protected void fireSessionOpened()
 637  
     {
 638  33
         long timestamp = System.currentTimeMillis();
 639  
 
 640  33
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_OPENED );
 641  
 
 642  33
         sessionEvent.setTimestamp( timestamp );
 643  
 
 644  33
         sessionEventSupport.fireSessionOpened( sessionEvent );
 645  33
     }
 646  
 
 647  
     protected void fireSessionOpening()
 648  
     {
 649  35
         long timestamp = System.currentTimeMillis();
 650  
 
 651  35
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_OPENING );
 652  
 
 653  35
         sessionEvent.setTimestamp( timestamp );
 654  
 
 655  35
         sessionEventSupport.fireSessionOpening( sessionEvent );
 656  35
     }
 657  
 
 658  
     protected void fireSessionConnectionRefused()
 659  
     {
 660  2
         long timestamp = System.currentTimeMillis();
 661  
 
 662  2
         SessionEvent sessionEvent = new SessionEvent( this, SessionEvent.SESSION_CONNECTION_REFUSED );
 663  
 
 664  2
         sessionEvent.setTimestamp( timestamp );
 665  
 
 666  2
         sessionEventSupport.fireSessionConnectionRefused( sessionEvent );
 667  2
     }
 668  
 
 669  
     protected void fireSessionError( Exception exception )
 670  
     {
 671  1
         long timestamp = System.currentTimeMillis();
 672  
 
 673  1
         SessionEvent sessionEvent = new SessionEvent( this, exception );
 674  
 
 675  1
         sessionEvent.setTimestamp( timestamp );
 676  
 
 677  1
         sessionEventSupport.fireSessionError( sessionEvent );
 678  
 
 679  1
     }
 680  
 
 681  
     protected void fireTransferDebug( String message )
 682  
     {
 683  8
         transferEventSupport.fireDebug( message );
 684  8
     }
 685  
 
 686  
     protected void fireSessionDebug( String message )
 687  
     {
 688  0
         sessionEventSupport.fireDebug( message );
 689  0
     }
 690  
 
 691  
     public boolean hasTransferListener( TransferListener listener )
 692  
     {
 693  2
         return transferEventSupport.hasTransferListener( listener );
 694  
     }
 695  
 
 696  
     public void addTransferListener( TransferListener listener )
 697  
     {
 698  28
         transferEventSupport.addTransferListener( listener );
 699  28
     }
 700  
 
 701  
     public void removeTransferListener( TransferListener listener )
 702  
     {
 703  1
         transferEventSupport.removeTransferListener( listener );
 704  1
     }
 705  
 
 706  
     public void addSessionListener( SessionListener listener )
 707  
     {
 708  23
         sessionEventSupport.addSessionListener( listener );
 709  23
     }
 710  
 
 711  
     public boolean hasSessionListener( SessionListener listener )
 712  
     {
 713  2
         return sessionEventSupport.hasSessionListener( listener );
 714  
     }
 715  
 
 716  
     public void removeSessionListener( SessionListener listener )
 717  
     {
 718  1
         sessionEventSupport.removeSessionListener( listener );
 719  1
     }
 720  
 
 721  
     protected void fireTransferError( Resource resource, Exception e, int requestType )
 722  
     {
 723  10
         TransferEvent transferEvent = new TransferEvent( this, resource, e, requestType );
 724  10
         transferEventSupport.fireTransferError( transferEvent );
 725  10
     }
 726  
 
 727  
 
 728  
     public SessionEventSupport getSessionEventSupport()
 729  
     {
 730  0
         return sessionEventSupport;
 731  
     }
 732  
 
 733  
     public void setSessionEventSupport( SessionEventSupport sessionEventSupport )
 734  
     {
 735  0
         this.sessionEventSupport = sessionEventSupport;
 736  0
     }
 737  
 
 738  
     public TransferEventSupport getTransferEventSupport()
 739  
     {
 740  0
         return transferEventSupport;
 741  
     }
 742  
 
 743  
     public void setTransferEventSupport( TransferEventSupport transferEventSupport )
 744  
     {
 745  0
         this.transferEventSupport = transferEventSupport;
 746  0
     }
 747  
 
 748  
     /**
 749  
      * This method is used if you are not streaming the transfer, to make sure any listeners dependent on state
 750  
      * (eg checksum observers) succeed.
 751  
      */
 752  
     protected void postProcessListeners( Resource resource, File source, int requestType )
 753  
         throws TransferFailedException
 754  
     {
 755  1
         byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
 756  
 
 757  1
         TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS, requestType );
 758  1
         transferEvent.setTimestamp( System.currentTimeMillis() );
 759  1
         transferEvent.setLocalFile( source );
 760  
 
 761  1
         InputStream input = null;
 762  
         try
 763  
         {
 764  1
             input = new FileInputStream( source );
 765  
 
 766  
             while ( true )
 767  
             {
 768  2
                 int n = input.read( buffer );
 769  
 
 770  2
                 if ( n == -1 )
 771  
                 {
 772  1
                     break;
 773  
                 }
 774  
 
 775  1
                 fireTransferProgress( transferEvent, buffer, n );
 776  1
             }
 777  
         }
 778  0
         catch ( IOException e )
 779  
         {
 780  0
             fireTransferError( resource, e, requestType );
 781  
             
 782  0
             throw new TransferFailedException( "Failed to post-process the source file", e );
 783  
         }
 784  
         finally
 785  
         {
 786  1
             IOUtil.close( input );
 787  1
         }
 788  1
     }
 789  
 
 790  
     public void putDirectory( File sourceDirectory, String destinationDirectory )
 791  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 792  
     {
 793  0
         throw new UnsupportedOperationException( "The wagon you are using has not implemented putDirectory()" );
 794  
     }
 795  
 
 796  
     public boolean supportsDirectoryCopy()
 797  
     {
 798  0
         return false;
 799  
     }
 800  
 
 801  
     protected static String getPath( String basedir, String dir )
 802  
     {
 803  
         String path;
 804  0
         path = basedir;
 805  0
         if ( !basedir.endsWith( "/" ) && !dir.startsWith( "/" ) )
 806  
         {
 807  0
             path += "/";
 808  
         }
 809  0
         path += dir;
 810  0
         return path;
 811  
     }
 812  
 
 813  
     public boolean isInteractive()
 814  
     {
 815  0
         return interactive;
 816  
     }
 817  
 
 818  
     public void setInteractive( boolean interactive )
 819  
     {
 820  0
         this.interactive = interactive;
 821  0
     }
 822  
 
 823  
     public List getFileList( String destinationDirectory )
 824  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 825  
     {
 826  0
         throw new UnsupportedOperationException( "The wagon you are using has not implemented getFileList()" );
 827  
     }
 828  
 
 829  
     public boolean resourceExists( String resourceName )
 830  
         throws TransferFailedException, AuthorizationException
 831  
     {
 832  0
         throw new UnsupportedOperationException( "The wagon you are using has not implemented resourceExists()" );
 833  
     }
 834  
 
 835  
     protected ProxyInfo getProxyInfo( String protocol, String host )
 836  
     {
 837  28
         if ( proxyInfoProvider != null )
 838  
         {
 839  13
             ProxyInfo proxyInfo = proxyInfoProvider.getProxyInfo( protocol );
 840  13
             if ( !ProxyUtils.validateNonProxyHosts( proxyInfo, host ) )
 841  
             {
 842  13
                 return proxyInfo;
 843  
             }
 844  
         }
 845  15
         return null;
 846  
     }
 847  
 
 848  
     public RepositoryPermissions getPermissionsOverride()
 849  
     {
 850  0
         return permissionsOverride;
 851  
     }
 852  
 
 853  
     public void setPermissionsOverride( RepositoryPermissions permissionsOverride )
 854  
     {
 855  1
         this.permissionsOverride = permissionsOverride;
 856  1
     }
 857  
 }