1 package org.apache.archiva.proxy;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.wagon.ConnectionException;
23 import org.apache.maven.wagon.ResourceDoesNotExistException;
24 import org.apache.maven.wagon.TransferFailedException;
25 import org.apache.maven.wagon.Wagon;
26 import org.apache.maven.wagon.authentication.AuthenticationException;
27 import org.apache.maven.wagon.authentication.AuthenticationInfo;
28 import org.apache.maven.wagon.authorization.AuthorizationException;
29 import org.apache.maven.wagon.events.SessionListener;
30 import org.apache.maven.wagon.events.TransferListener;
31 import org.apache.maven.wagon.proxy.ProxyInfo;
32 import org.apache.maven.wagon.proxy.ProxyInfoProvider;
33 import org.apache.maven.wagon.repository.Repository;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.stereotype.Service;
39 import java.io.IOException;
40 import java.nio.charset.Charset;
41 import java.nio.file.Files;
42 import java.nio.file.Path;
43 import java.util.List;
46 * A dummy wagon implementation
48 @Service ("wagon#test")
49 public class WagonDelegate
52 private Logger log = LoggerFactory.getLogger( WagonDelegate.class );
54 private Wagon delegate;
56 private String contentToGet;
59 public void get( String resourceName, File destination )
60 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
62 log.debug( ".get({}, {})", resourceName, destination );
63 delegate.get( resourceName, destination );
64 create( destination.toPath() );
68 public boolean getIfNewer( String resourceName, File destination, long timestamp )
69 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
71 log.info( ".getIfNewer({}, {}, {})", resourceName, destination, timestamp );
73 boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
74 createIfMissing( destination.toPath() );
79 public void put( File source, String destination )
80 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
82 delegate.put( source, destination );
86 public void putDirectory( File sourceDirectory, String destinationDirectory )
87 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
89 delegate.putDirectory( sourceDirectory, destinationDirectory );
93 public boolean resourceExists( String resourceName )
94 throws TransferFailedException, AuthorizationException
96 return delegate.resourceExists( resourceName );
99 @SuppressWarnings ("unchecked")
101 public List<String> getFileList( String destinationDirectory )
102 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
104 return delegate.getFileList( destinationDirectory );
108 public boolean supportsDirectoryCopy()
110 return delegate.supportsDirectoryCopy();
114 public void setTimeout( int val )
120 public int getTimeout()
126 public void setReadTimeout( int timeoutValue )
132 public int getReadTimeout()
138 public Repository getRepository()
140 return delegate.getRepository();
144 public void connect( Repository source )
145 throws ConnectionException, AuthenticationException
147 delegate.connect( source );
151 public void connect( Repository source, ProxyInfo proxyInfo )
152 throws ConnectionException, AuthenticationException
154 delegate.connect( source, proxyInfo );
158 public void connect( Repository source, ProxyInfoProvider proxyInfoProvider )
159 throws ConnectionException, AuthenticationException
161 delegate.connect( source, proxyInfoProvider );
165 public void connect( Repository source, AuthenticationInfo authenticationInfo )
166 throws ConnectionException, AuthenticationException
168 delegate.connect( source, authenticationInfo );
172 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
173 throws ConnectionException, AuthenticationException
175 delegate.connect( source, authenticationInfo, proxyInfo );
179 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider )
180 throws ConnectionException, AuthenticationException
182 delegate.connect( source, authenticationInfo, proxyInfoProvider );
185 @SuppressWarnings ("deprecation")
187 public void openConnection()
188 throws ConnectionException, AuthenticationException
190 delegate.openConnection();
194 public void disconnect()
195 throws ConnectionException
197 delegate.disconnect();
201 public void addSessionListener( SessionListener listener )
203 delegate.addSessionListener( listener );
207 public void removeSessionListener( SessionListener listener )
209 delegate.removeSessionListener( listener );
213 public boolean hasSessionListener( SessionListener listener )
215 return delegate.hasSessionListener( listener );
219 public void addTransferListener( TransferListener listener )
221 delegate.addTransferListener( listener );
225 public void removeTransferListener( TransferListener listener )
227 delegate.removeTransferListener( listener );
231 public boolean hasTransferListener( TransferListener listener )
233 return delegate.hasTransferListener( listener );
237 public boolean isInteractive()
239 return delegate.isInteractive();
243 public void setInteractive( boolean interactive )
245 delegate.setInteractive( interactive );
248 public void setDelegate( Wagon delegate )
250 this.delegate = delegate;
253 void setContentToGet( String content )
255 contentToGet = content;
258 private void createIfMissing( Path destination )
260 // since the mock won't actually copy a file, create an empty one to simulate file existence
261 if ( !Files.exists(destination) )
263 create( destination );
267 private void create( Path destination )
271 Files.createDirectories(destination.getParent());
272 if ( contentToGet == null && !Files.exists(destination))
274 Files.createFile(destination);
276 else if (contentToGet != null)
278 org.apache.archiva.common.utils.FileUtils.writeStringToFile(destination, Charset.defaultCharset(), contentToGet);
281 catch ( IOException e )
283 throw new RuntimeException( e.getMessage(), e );
287 public void cleanup() {