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.commons.io.FileUtils;
23 import org.apache.maven.wagon.ConnectionException;
24 import org.apache.maven.wagon.ResourceDoesNotExistException;
25 import org.apache.maven.wagon.TransferFailedException;
26 import org.apache.maven.wagon.Wagon;
27 import org.apache.maven.wagon.authentication.AuthenticationException;
28 import org.apache.maven.wagon.authentication.AuthenticationInfo;
29 import org.apache.maven.wagon.authorization.AuthorizationException;
30 import org.apache.maven.wagon.events.SessionListener;
31 import org.apache.maven.wagon.events.TransferListener;
32 import org.apache.maven.wagon.proxy.ProxyInfo;
33 import org.apache.maven.wagon.proxy.ProxyInfoProvider;
34 import org.apache.maven.wagon.repository.Repository;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.stereotype.Service;
40 import java.io.IOException;
41 import java.nio.charset.Charset;
42 import java.util.List;
45 * A dummy wagon implementation
47 @Service ("wagon#test")
48 public class WagonDelegate
51 private Logger log = LoggerFactory.getLogger( WagonDelegate.class );
53 private Wagon delegate;
55 private String contentToGet;
57 public void get( String resourceName, File destination )
58 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
60 log.debug( ".get({}, {})", resourceName, destination );
61 delegate.get( resourceName, destination );
62 create( destination );
65 public boolean getIfNewer( String resourceName, File destination, long timestamp )
66 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
68 log.info( ".getIfNewer({}, {}, {})", resourceName, destination, timestamp );
70 boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
71 createIfMissing( destination );
75 public void put( File source, String destination )
76 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
78 delegate.put( source, destination );
81 public void putDirectory( File sourceDirectory, String destinationDirectory )
82 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
84 delegate.putDirectory( sourceDirectory, destinationDirectory );
87 public boolean resourceExists( String resourceName )
88 throws TransferFailedException, AuthorizationException
90 return delegate.resourceExists( resourceName );
93 @SuppressWarnings ("unchecked")
94 public List<String> getFileList( String destinationDirectory )
95 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
97 return delegate.getFileList( destinationDirectory );
100 public boolean supportsDirectoryCopy()
102 return delegate.supportsDirectoryCopy();
105 public void setTimeout( int val )
110 public int getTimeout()
115 public void setReadTimeout( int timeoutValue )
120 public int getReadTimeout()
125 public Repository getRepository()
127 return delegate.getRepository();
130 public void connect( Repository source )
131 throws ConnectionException, AuthenticationException
133 delegate.connect( source );
136 public void connect( Repository source, ProxyInfo proxyInfo )
137 throws ConnectionException, AuthenticationException
139 delegate.connect( source, proxyInfo );
142 public void connect( Repository source, ProxyInfoProvider proxyInfoProvider )
143 throws ConnectionException, AuthenticationException
145 delegate.connect( source, proxyInfoProvider );
148 public void connect( Repository source, AuthenticationInfo authenticationInfo )
149 throws ConnectionException, AuthenticationException
151 delegate.connect( source, authenticationInfo );
154 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
155 throws ConnectionException, AuthenticationException
157 delegate.connect( source, authenticationInfo, proxyInfo );
160 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider )
161 throws ConnectionException, AuthenticationException
163 delegate.connect( source, authenticationInfo, proxyInfoProvider );
166 @SuppressWarnings ("deprecation")
167 public void openConnection()
168 throws ConnectionException, AuthenticationException
170 delegate.openConnection();
173 public void disconnect()
174 throws ConnectionException
176 delegate.disconnect();
179 public void addSessionListener( SessionListener listener )
181 delegate.addSessionListener( listener );
184 public void removeSessionListener( SessionListener listener )
186 delegate.removeSessionListener( listener );
189 public boolean hasSessionListener( SessionListener listener )
191 return delegate.hasSessionListener( listener );
194 public void addTransferListener( TransferListener listener )
196 delegate.addTransferListener( listener );
199 public void removeTransferListener( TransferListener listener )
201 delegate.removeTransferListener( listener );
204 public boolean hasTransferListener( TransferListener listener )
206 return delegate.hasTransferListener( listener );
209 public boolean isInteractive()
211 return delegate.isInteractive();
214 public void setInteractive( boolean interactive )
216 delegate.setInteractive( interactive );
219 public void setDelegate( Wagon delegate )
221 this.delegate = delegate;
224 void setContentToGet( String content )
226 contentToGet = content;
229 private void createIfMissing( File destination )
231 // since the mock won't actually copy a file, create an empty one to simulate file existence
232 if ( !destination.exists() )
234 create( destination );
238 private void create( File destination )
242 destination.getParentFile().mkdirs();
243 if ( contentToGet == null )
245 destination.createNewFile();
249 FileUtils.writeStringToFile( new File( destination.getAbsolutePath() ), contentToGet,
250 Charset.defaultCharset() );
253 catch ( IOException e )
255 throw new RuntimeException( e.getMessage(), e );