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.repository.Repository;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * A dummy wagon implementation
44 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
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, AuthenticationInfo authenticationInfo )
130 throws ConnectionException, AuthenticationException
132 delegate.connect( source, authenticationInfo );
135 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
136 throws ConnectionException, AuthenticationException
138 delegate.connect( source, authenticationInfo, proxyInfo );
141 public void openConnection()
142 throws ConnectionException, AuthenticationException
144 delegate.openConnection();
147 public void disconnect()
148 throws ConnectionException
150 delegate.disconnect();
153 public void addSessionListener( SessionListener listener )
155 delegate.addSessionListener( listener );
158 public void removeSessionListener( SessionListener listener )
160 delegate.removeSessionListener( listener );
163 public boolean hasSessionListener( SessionListener listener )
165 return delegate.hasSessionListener( listener );
168 public void addTransferListener( TransferListener listener )
170 delegate.addTransferListener( listener );
173 public void removeTransferListener( TransferListener listener )
175 delegate.removeTransferListener( listener );
178 public boolean hasTransferListener( TransferListener listener )
180 return delegate.hasTransferListener( listener );
183 public boolean isInteractive()
185 return delegate.isInteractive();
188 public void setInteractive( boolean interactive )
190 delegate.setInteractive( interactive );
193 public void setDelegate( Wagon delegate )
195 this.delegate = delegate;
198 void setContentToGet( String content )
200 contentToGet = content;
203 private void createIfMissing( File destination )
205 // since the mock won't actually copy a file, create an empty one to simulate file existence
206 if ( !destination.exists() )
208 create( destination );
212 private void create( File destination )
216 destination.getParentFile().mkdirs();
217 if ( contentToGet == null )
219 destination.createNewFile();
223 FileUtils.writeStringToFile( new File( destination.getAbsolutePath() ), contentToGet, null );
226 catch ( IOException e )
228 throw new RuntimeException( e.getMessage(), e );