1 package org.apache.maven.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
23 import java.io.IOException;
24 import java.util.List;
26 import org.apache.commons.io.FileUtils;
27 import org.apache.maven.wagon.ConnectionException;
28 import org.apache.maven.wagon.ResourceDoesNotExistException;
29 import org.apache.maven.wagon.TransferFailedException;
30 import org.apache.maven.wagon.Wagon;
31 import org.apache.maven.wagon.authentication.AuthenticationException;
32 import org.apache.maven.wagon.authentication.AuthenticationInfo;
33 import org.apache.maven.wagon.authorization.AuthorizationException;
34 import org.apache.maven.wagon.events.SessionListener;
35 import org.apache.maven.wagon.events.TransferListener;
36 import org.apache.maven.wagon.proxy.ProxyInfo;
37 import org.apache.maven.wagon.proxy.ProxyInfoProvider;
38 import org.apache.maven.wagon.repository.Repository;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * A dummy wagon implementation
46 public class WagonDelegate
49 private Logger log = LoggerFactory.getLogger( WagonDelegate.class );
51 private Wagon delegate;
53 private String contentToGet;
55 public void get( String resourceName, File destination )
56 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
58 log.debug( ".get(" + resourceName + ", " + destination + ")" );
59 delegate.get( resourceName, destination );
60 create( destination );
63 public boolean getIfNewer( String resourceName, File destination, long timestamp )
64 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
66 log.info( ".getIfNewer(" + resourceName + ", " + destination + ", " + timestamp + ")" );
68 boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
69 createIfMissing( destination );
73 public void put( File source, String destination )
74 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
76 delegate.put( source, destination );
79 public void putDirectory( File sourceDirectory, String destinationDirectory )
80 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
82 delegate.putDirectory( sourceDirectory, destinationDirectory );
85 public boolean resourceExists( String resourceName )
86 throws TransferFailedException, AuthorizationException
88 return delegate.resourceExists( resourceName );
91 public List<String> getFileList( String destinationDirectory )
92 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
94 return delegate.getFileList( destinationDirectory );
97 public boolean supportsDirectoryCopy()
99 return delegate.supportsDirectoryCopy();
102 public void setTimeout(int val)
107 public int getTimeout()
112 public Repository getRepository()
114 return delegate.getRepository();
117 public void connect( Repository source )
118 throws ConnectionException, AuthenticationException
120 delegate.connect( source );
123 public void connect( Repository source, ProxyInfo proxyInfo )
124 throws ConnectionException, AuthenticationException
126 delegate.connect( source, proxyInfo );
129 public void connect( Repository source, ProxyInfoProvider proxyInfoProvider )
130 throws ConnectionException, AuthenticationException
132 delegate.connect( source, proxyInfoProvider );
135 public void connect( Repository source, AuthenticationInfo authenticationInfo )
136 throws ConnectionException, AuthenticationException
138 delegate.connect( source, authenticationInfo );
141 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
142 throws ConnectionException, AuthenticationException
144 delegate.connect( source, authenticationInfo, proxyInfo );
147 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider )
148 throws ConnectionException, AuthenticationException
150 delegate.connect( source, authenticationInfo, proxyInfoProvider );
153 public void openConnection()
154 throws ConnectionException, AuthenticationException
156 delegate.openConnection();
159 public void disconnect()
160 throws ConnectionException
162 delegate.disconnect();
165 public void addSessionListener( SessionListener listener )
167 delegate.addSessionListener( listener );
170 public void removeSessionListener( SessionListener listener )
172 delegate.removeSessionListener( listener );
175 public boolean hasSessionListener( SessionListener listener )
177 return delegate.hasSessionListener( listener );
180 public void addTransferListener( TransferListener listener )
182 delegate.addTransferListener( listener );
185 public void removeTransferListener( TransferListener listener )
187 delegate.removeTransferListener( listener );
190 public boolean hasTransferListener( TransferListener listener )
192 return delegate.hasTransferListener( listener );
195 public boolean isInteractive()
197 return delegate.isInteractive();
200 public void setInteractive( boolean interactive )
202 delegate.setInteractive( interactive );
205 public void setDelegate( Wagon delegate )
207 this.delegate = delegate;
210 void setContentToGet( String content )
212 contentToGet = content;
215 private void createIfMissing( File destination )
217 // since the mock won't actually copy a file, create an empty one to simulate file existence
218 if ( !destination.exists() )
220 create( destination );
224 private void create( File destination )
228 destination.getParentFile().mkdirs();
229 if ( contentToGet == null )
231 destination.createNewFile();
235 FileUtils.writeStringToFile( new File( destination.getAbsolutePath() ), contentToGet, null );
238 catch ( IOException e )
240 throw new RuntimeException( e.getMessage(), e );