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
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.repository.Repository;
36 import java.io.IOException;
37 import java.util.List;
40 * A dummy wagon implementation
42 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44 public class WagonDelegate
47 private Wagon delegate;
49 private String contentToGet;
51 public void get( String resourceName, File destination )
52 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
54 delegate.get( resourceName, destination );
55 create( destination );
58 public boolean getIfNewer( String resourceName, File destination, long timestamp )
59 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
61 boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
62 createIfMissing( destination );
66 public void put( File source, String destination )
67 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
69 delegate.put( source, destination );
72 public void putDirectory( File sourceDirectory, String destinationDirectory )
73 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
75 delegate.putDirectory( sourceDirectory, destinationDirectory );
78 public boolean resourceExists( String resourceName )
79 throws TransferFailedException, AuthorizationException
81 return delegate.resourceExists( resourceName );
84 public List getFileList( String destinationDirectory )
85 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
87 return delegate.getFileList( destinationDirectory );
90 public boolean supportsDirectoryCopy()
92 return delegate.supportsDirectoryCopy();
95 public Repository getRepository()
97 return delegate.getRepository();
100 public void connect( Repository source )
101 throws ConnectionException, AuthenticationException
103 delegate.connect( source );
106 public void connect( Repository source, ProxyInfo proxyInfo )
107 throws ConnectionException, AuthenticationException
109 delegate.connect( source, proxyInfo );
112 public void connect( Repository source, AuthenticationInfo authenticationInfo )
113 throws ConnectionException, AuthenticationException
115 delegate.connect( source, authenticationInfo );
118 public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo )
119 throws ConnectionException, AuthenticationException
121 delegate.connect( source, authenticationInfo, proxyInfo );
124 public void openConnection()
125 throws ConnectionException, AuthenticationException
127 delegate.openConnection();
130 public void disconnect()
131 throws ConnectionException
133 delegate.disconnect();
136 public void addSessionListener( SessionListener listener )
138 delegate.addSessionListener( listener );
141 public void removeSessionListener( SessionListener listener )
143 delegate.removeSessionListener( listener );
146 public boolean hasSessionListener( SessionListener listener )
148 return delegate.hasSessionListener( listener );
151 public void addTransferListener( TransferListener listener )
153 delegate.addTransferListener( listener );
156 public void removeTransferListener( TransferListener listener )
158 delegate.removeTransferListener( listener );
161 public boolean hasTransferListener( TransferListener listener )
163 return delegate.hasTransferListener( listener );
166 public boolean isInteractive()
168 return delegate.isInteractive();
171 public void setInteractive( boolean interactive )
173 delegate.setInteractive( interactive );
176 public void setDelegate( Wagon delegate )
178 this.delegate = delegate;
181 void setContentToGet( String content )
183 contentToGet = content;
186 private void createIfMissing( File destination )
188 // since the mock won't actually copy a file, create an empty one to simulate file existence
189 if ( !destination.exists() )
191 create( destination );
195 private void create( File destination )
199 destination.getParentFile().mkdirs();
200 if ( contentToGet == null )
202 destination.createNewFile();
206 FileUtils.writeStringToFile( new File( destination.getAbsolutePath() ), contentToGet, null );
209 catch ( IOException e )
211 throw new RuntimeException( e.getMessage(), e );