View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.artifact.resolver;
20  
21  import java.io.File;
22  import java.io.InputStream;
23  
24  import org.apache.maven.wagon.ResourceDoesNotExistException;
25  import org.apache.maven.wagon.TransferFailedException;
26  import org.apache.maven.wagon.authorization.AuthorizationException;
27  import org.apache.maven.wagon.events.TransferListener;
28  import org.apache.maven.wagon.providers.file.FileWagon;
29  import org.apache.maven.wagon.resource.Resource;
30  
31  /**
32   * Wagon used for test cases that annotate some methods. Note that this is not a thread-safe implementation.
33   */
34  public class TestFileWagon extends FileWagon {
35      private TestTransferListener testTransferListener;
36      private boolean insideGet;
37  
38      @Deprecated
39      protected void getTransfer(Resource resource, File destination, InputStream input, boolean closeInput, int maxSize)
40              throws TransferFailedException {
41          addTransfer("getTransfer " + resource.getName());
42          super.getTransfer(resource, destination, input, closeInput, maxSize);
43      }
44  
45      public void get(String resourceName, File destination)
46              throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
47          addTransfer("get " + resourceName);
48  
49          insideGet = true;
50  
51          super.get(resourceName, destination);
52  
53          insideGet = false;
54      }
55  
56      private void addTransfer(String resourceName) {
57          if (testTransferListener != null) {
58              testTransferListener.addTransfer(resourceName);
59          }
60      }
61  
62      public boolean getIfNewer(String resourceName, File destination, long timestamp)
63              throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
64          if (!insideGet) {
65              addTransfer("getIfNewer " + resourceName);
66          }
67          return super.getIfNewer(resourceName, destination, timestamp);
68      }
69  
70      public void addTransferListener(TransferListener listener) {
71          if (listener instanceof TestTransferListener) {
72              testTransferListener = (TestTransferListener) listener;
73          }
74          super.addTransferListener(listener);
75      }
76  }