1   package org.apache.maven.artifact.resolver;
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.InputStream;
24  
25  import org.apache.maven.wagon.ResourceDoesNotExistException;
26  import org.apache.maven.wagon.TransferFailedException;
27  import org.apache.maven.wagon.authorization.AuthorizationException;
28  import org.apache.maven.wagon.events.TransferListener;
29  import org.apache.maven.wagon.providers.file.FileWagon;
30  import org.apache.maven.wagon.resource.Resource;
31  
32  /**
33   * Wagon used for test cases that annotates some methods. Note that this is not a thread-safe implementation. 
34   */
35  public class TestFileWagon
36      extends FileWagon
37  {
38      private TestTransferListener testTransferListener;
39      private boolean insideGet;
40  
41      protected void getTransfer( Resource resource, 
42                                  File destination, 
43                                  InputStream input, 
44                                  boolean closeInput, 
45                                  int maxSize )
46          throws TransferFailedException
47      {
48          addTransfer( "getTransfer " + resource.getName() );
49          super.getTransfer( resource, destination, input, closeInput, maxSize );
50      }
51  
52      public void get( String resourceName, File destination )
53          throws TransferFailedException, 
54                 ResourceDoesNotExistException, 
55                 AuthorizationException
56      {
57          addTransfer( "get " + resourceName );
58          
59          insideGet = true;
60          
61          super.get( resourceName, destination );
62          
63          insideGet = false;
64      }
65  
66      private void addTransfer( String resourceName )
67      {
68          if ( testTransferListener != null )
69          {
70              testTransferListener.addTransfer( resourceName );
71          }
72      }
73  
74      public boolean getIfNewer( String resourceName, File destination, long timestamp )
75          throws TransferFailedException, 
76                 ResourceDoesNotExistException, 
77                 AuthorizationException
78      {
79          if ( !insideGet )
80          {
81              addTransfer( "getIfNewer " + resourceName );
82          }
83          return super.getIfNewer( resourceName, destination, timestamp );
84      }
85  
86      public void addTransferListener( TransferListener listener )
87      {
88          if ( listener instanceof TestTransferListener )
89          {
90              testTransferListener = (TestTransferListener) listener;
91          }
92          super.addTransferListener( listener );
93      }
94  }