diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-09-08 21:05:34 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-09-22 00:09:54 +0200 |
commit | b072f6921df0b59843f9c411b292b467dbe0f01a (patch) | |
tree | c3274836bbff9a419d930aa0a470e0d4b0027d3d /archiva-modules/archiva-maven/archiva-maven-proxy/src | |
parent | 0fef7e9c5ff5ceed2f8cb4414295009a5816fc46 (diff) | |
download | archiva-b072f6921df0b59843f9c411b292b467dbe0f01a.tar.gz archiva-b072f6921df0b59843f9c411b292b467dbe0f01a.zip |
Proxy changes
Diffstat (limited to 'archiva-modules/archiva-maven/archiva-maven-proxy/src')
12 files changed, 151 insertions, 105 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java index 25dfcb6a0..b8006d328 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java @@ -27,6 +27,7 @@ import org.apache.archiva.proxy.NotModifiedException; import org.apache.archiva.proxy.ProxyException; import org.apache.archiva.proxy.model.NetworkProxy; import org.apache.archiva.proxy.model.ProxyConnector; +import org.apache.archiva.proxy.model.RepositoryProxyHandler; import org.apache.archiva.repository.*; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.commons.lang3.StringUtils; @@ -55,7 +56,7 @@ import java.util.concurrent.ConcurrentMap; * TODO exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than * your average brown onion */ -@Service("repositoryProxyConnectors#maven") +@Service( "repositoryProxyHandler#maven" ) public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { private static final List<RepositoryType> REPOSITORY_TYPES = new ArrayList<>(); @@ -76,7 +77,6 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { private void updateWagonProxyInfo(Map<String, NetworkProxy> proxyList) { this.networkProxyMap.clear(); - List<NetworkProxyConfiguration> networkProxies = getArchivaConfiguration().getConfiguration().getNetworkProxies(); for (Map.Entry<String, NetworkProxy> proxyEntry : proxyList.entrySet()) { String key = proxyEntry.getKey(); NetworkProxy networkProxyDef = proxyEntry.getValue(); @@ -94,9 +94,9 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } @Override - public void setNetworkProxies(Map<String, NetworkProxy> proxies) { - super.setNetworkProxies(proxies); - updateWagonProxyInfo(proxies); + public void setNetworkProxies(Map<String, NetworkProxy> networkProxies ) { + super.setNetworkProxies( networkProxies ); + updateWagonProxyInfo( networkProxies ); } /** @@ -112,13 +112,13 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @throws ProxyException * @throws NotModifiedException */ - protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, + protected void transferResources( ProxyConnector connector, RemoteRepository remoteRepository, StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource, - Path workingDirectory, ManagedRepositoryContent repository ) + Path workingDirectory, ManagedRepository repository ) throws ProxyException, NotModifiedException { Wagon wagon = null; try { - RepositoryURL repoUrl = remoteRepository.getURL(); + RepositoryURL repoUrl = remoteRepository.getContent().getURL(); String protocol = repoUrl.getProtocol(); NetworkProxy networkProxy = null; String proxyId = connector.getProxyId(); @@ -127,7 +127,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { networkProxy = getNetworkProxy(proxyId); } WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol, - remoteRepository.getRepository().getExtraHeaders()); + remoteRepository.getExtraHeaders()); if (networkProxy == null) { log.warn("No network proxy with id {} found for connector {}->{}", proxyId, @@ -180,8 +180,8 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } } - protected void transferArtifact(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, Path resource, Path tmpDirectory, + protected void transferArtifact(Wagon wagon, RemoteRepository remoteRepository, String remotePath, + ManagedRepository repository, Path resource, Path tmpDirectory, StorageAsset destFile) throws ProxyException { transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile.getFilePath()); @@ -200,11 +200,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @param ext the type of checksum to transfer (example: ".md5" or ".sha1") * @throws ProxyException if copying the downloaded file into place did not succeed. */ - protected void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, Path resource, String ext, + protected void transferChecksum( Wagon wagon, RemoteRepository remoteRepository, String remotePath, + ManagedRepository repository, Path resource, String ext, Path destFile ) throws ProxyException { - String url = remoteRepository.getURL().getUrl() + remotePath + ext; + String url = remoteRepository.getLocation().toString() + remotePath + ext; // Transfer checksum does not use the policy. if (urlFailureCache.hasFailedBefore(url)) { @@ -239,8 +239,8 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @param origFile the local file to save to * @throws ProxyException if there was a problem moving the downloaded file into place. */ - protected void transferSimpleFile(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, Path origFile, Path destFile) + protected void transferSimpleFile(Wagon wagon, RemoteRepository remoteRepository, String remotePath, + ManagedRepository repository, Path origFile, Path destFile) throws ProxyException { assert (remotePath != null); @@ -249,16 +249,16 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { boolean success = false; if (!Files.exists(origFile)) { - log.debug("Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName()); - wagon.get(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile()); + log.debug("Retrieving {} from {}", remotePath, remoteRepository.getId()); + wagon.get(addParameters(remotePath, remoteRepository), destFile.toFile()); success = true; // You wouldn't get here on failure, a WagonException would have been thrown. log.debug("Downloaded successfully."); } else { - log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName()); + log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getId()); try { - success = wagon.getIfNewer(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile(), + success = wagon.getIfNewer(addParameters(remotePath, remoteRepository), destFile.toFile(), Files.getLastModifiedTime(origFile).toMillis()); } catch (IOException e) { throw new ProxyException("Failed to the modification time of " + origFile.toAbsolutePath()); @@ -274,13 +274,13 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } } catch (ResourceDoesNotExistException e) { throw new NotFoundException( - "Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(), + "Resource [" + remoteRepository.getLocation() + "/" + remotePath + "] does not exist: " + e.getMessage(), e); } catch (WagonException e) { // TODO: shouldn't have to drill into the cause, but TransferFailedException is often not descriptive enough String msg = - "Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:" + e.getMessage(); + "Download failure on resource [" + remoteRepository.getLocation() + "/" + remotePath + "]:" + e.getMessage(); if (e.getCause() != null) { msg += " (cause: " + e.getCause() + ")"; } @@ -297,7 +297,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @return true if the connection was successful. false if not connected. */ protected boolean connectToRepository(ProxyConnector connector, Wagon wagon, - RemoteRepositoryContent remoteRepository) { + RemoteRepository remoteRepository) { boolean connected = false; final ProxyInfo networkProxy = @@ -307,7 +307,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { if (networkProxy != null) { // TODO: move to proxyInfo.toString() String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort() - + " to connect to remote repository " + remoteRepository.getURL(); + + " to connect to remote repository " + remoteRepository.getLocation(); if (networkProxy.getNonProxyHosts() != null) { msg += "; excluding hosts: " + networkProxy.getNonProxyHosts(); } @@ -321,7 +321,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { AuthenticationInfo authInfo = null; String username = ""; String password = ""; - RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials(); + RepositoryCredentials repCred = remoteRepository.getLoginCredentials(); if (repCred != null && repCred instanceof PasswordCredentials) { PasswordCredentials pwdCred = (PasswordCredentials) repCred; username = pwdCred.getUsername(); @@ -329,7 +329,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { - log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getURL()); + log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getLocation()); authInfo = new AuthenticationInfo(); authInfo.setUserName(username); authInfo.setPassword(password); @@ -337,7 +337,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { // Convert seconds to milliseconds - long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis(); + long timeoutInMilliseconds = remoteRepository.getTimeout().toMillis(); // Set timeout read and connect // FIXME olamy having 2 config values @@ -346,11 +346,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { try { Repository wagonRepository = - new Repository(remoteRepository.getId(), remoteRepository.getURL().toString()); + new Repository(remoteRepository.getId(), remoteRepository.getLocation().toString()); wagon.connect(wagonRepository, authInfo, networkProxy); connected = true; } catch (ConnectionException | AuthenticationException e) { - log.warn("Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage()); + log.warn("Could not connect to {}: {}", remoteRepository.getId(), e.getMessage()); connected = false; } @@ -370,4 +370,20 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { public List<RepositoryType> supports() { return REPOSITORY_TYPES; } + + @Override + public void addNetworkproxy( String id, NetworkProxy networkProxy ) + { + + } + + @Override + public <T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException + { + if (clazz.isAssignableFrom( this.getClass() )) { + return (T)this; + } else { + throw new IllegalArgumentException( "This Proxy Handler is no subclass of " + clazz ); + } + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index 3331525ad..765905259 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -64,6 +64,9 @@ public abstract class AbstractProxyTestCase protected ApplicationContext applicationContext; @Inject + private ProxyRegistry proxyRegistry; + + @Inject RepositoryRegistry repositoryRegistry; protected static final String ID_PROXIED1 = "proxied1"; @@ -152,14 +155,16 @@ public abstract class AbstractProxyTestCase // Setup the proxy handler. //proxyHandler = applicationContext.getBean (RepositoryProxyHandler) lookup( RepositoryProxyHandler.class.getName() ); - proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyHandler.class ); + proxyHandler = applicationContext.getBean( "repositoryProxyHandler#test", RepositoryProxyHandler.class ); + assertNotNull( proxyRegistry ); + assertTrue(proxyRegistry.getAllHandler( ).get( RepositoryType.MAVEN).contains( proxyHandler )); // Setup the wagon mock. wagonMockControl = EasyMock.createNiceControl(); wagonMock = wagonMockControl.createMock( Wagon.class ); - delegate = (WagonDelegate) applicationContext.getBean( "wagon#test", Wagon.class ); + delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class ); delegate.setDelegate( wagonMock ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java index 5a9032f30..de9b78c50 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java @@ -67,8 +67,8 @@ public class CacheFailuresTransferTest ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Configure Repository (usually done within archiva.xml configuration) - saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, @@ -84,14 +84,14 @@ public class CacheFailuresTransferTest wagonMockControl.replay(); //noinspection UnusedAssignment - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); // Second attempt to download same artifact use cache wagonMockControl.reset(); wagonMockControl.replay(); - downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); assertNotDownloaded( downloadedFile); @@ -111,8 +111,8 @@ public class CacheFailuresTransferTest ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Configure Repository (usually done within archiva.xml configuration) - saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) @@ -126,7 +126,7 @@ public class CacheFailuresTransferTest wagonMockControl.replay(); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); @@ -138,7 +138,7 @@ public class CacheFailuresTransferTest wagonMockControl.replay(); - downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); @@ -170,7 +170,7 @@ public class CacheFailuresTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); // Validate that file actually came from proxied2 (as intended). Path proxied2File = Paths.get( REPOPATH_PROXIED2, path ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java index f0066c390..d249885b5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java @@ -64,7 +64,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNull( downloadedFile ); } @@ -86,7 +86,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -112,7 +112,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -138,7 +138,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -163,7 +163,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -188,7 +188,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -213,7 +213,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertChecksums( expectedFile, null, null ); @@ -236,7 +236,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -262,7 +262,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertChecksums( expectedFile, null, null ); @@ -285,7 +285,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); // This is a success situation. No SHA1 with a Good MD5. Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); @@ -311,7 +311,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertChecksums( expectedFile, null, null ); @@ -334,7 +334,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -361,7 +361,7 @@ public class ChecksumTransferTest SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -387,7 +387,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -413,7 +413,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -436,7 +436,7 @@ public class ChecksumTransferTest assertFalse( Files.exists(expectedFile.getParent()) ); assertFalse( Files.exists(expectedFile) ); - saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "http://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, @@ -453,7 +453,7 @@ public class ChecksumTransferTest wagonMockControl.replay(); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); @@ -490,7 +490,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); @@ -517,7 +517,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertNoTempFiles( expectedFile ); @@ -545,7 +545,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java index 8bafb426d..2f7d2dca7 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java @@ -526,14 +526,14 @@ public class ErrorHandlingTest private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy ) { - saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" ); saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, errorPolicy, false ); } private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy ) { - saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" ); saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false ); } @@ -596,7 +596,7 @@ public class ErrorHandlingTest StorageAsset downloadedFile = null; try { - downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, + downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toArtifactReference( path ) ); fail( "Proxy should not have succeeded" ); } @@ -637,7 +637,7 @@ public class ErrorHandlingTest wagonMockControl.replay(); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toArtifactReference( path ) ); wagonMockControl.verify(); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index 90cb2174c..b35967f3e 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -30,11 +30,16 @@ import org.apache.archiva.policies.PropagateErrorsDownloadPolicy; import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; +import org.apache.archiva.proxy.maven.DefaultWagonFactory; +import org.apache.archiva.proxy.maven.WagonFactory; +import org.apache.archiva.proxy.maven.WagonFactoryRequest; import org.apache.archiva.proxy.model.RepositoryProxyHandler; import org.apache.archiva.repository.*; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.providers.http.HttpWagon; import org.assertj.core.api.Assertions; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -80,8 +85,6 @@ public class HttpProxyTransferTest private RepositoryProxyHandler proxyHandler; - private ArchivaConfiguration config; - private ManagedRepositoryContent managedDefaultRepository; @Inject @@ -90,6 +93,12 @@ public class HttpProxyTransferTest @Inject private RepositoryRegistry repositoryRegistry; + @Inject + private ArchivaConfiguration config; + + @Inject + private ProxyRegistry proxyRegistry; + private Server server; protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) @@ -104,9 +113,7 @@ public class HttpProxyTransferTest public void setUp() throws Exception { - proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyHandler.class ); - - config = applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class ); + proxyHandler = applicationContext.getBean( "repositoryProxyHandler#test", RepositoryProxyHandler.class ); // clear from previous tests - TODO the spring context should be initialised per test instead, or the config // made a complete mock @@ -180,6 +187,11 @@ public class HttpProxyTransferTest config.getConfiguration().addRemoteRepository( repoConfig ); + Wagon wagon = new HttpWagon( ); + WagonDelegate delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class ); + delegate.setDelegate( wagon ); + + proxyRegistry.reload(); repositoryRegistry.reload(); managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default"); @@ -208,10 +220,11 @@ public class HttpProxyTransferTest addConnector(); Path expectedFile = Paths.get( managedDefaultRepository.getRepoRoot() ).resolve( path ); + Files.deleteIfExists( expectedFile ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path sourceFile = Paths.get( PROXIED_BASEDIR, path ); assertNotNull( "Expected File should not be null.", expectedFile ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java index aad62e8e0..f1491f8e9 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java @@ -65,7 +65,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, true ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNull( "File should not have been downloaded", downloadedFile ); } @@ -87,7 +87,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path sourceFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), sourceFile ); @@ -111,7 +111,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), path ); Path sourceFile = Paths.get(REPOPATH_PROXIED1, path); assertNotNull(downloadedFile); @@ -147,7 +147,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), expectedFile ); assertNoTempFiles( expectedFile ); @@ -181,7 +181,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), path ); assertNotDownloaded( downloadedFile ); assertNotModified( expectedFile, originalModificationTime ); @@ -227,7 +227,7 @@ public class ManagedDefaultTransferTest SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertNotModified( expectedFile, originalModificationTime ); @@ -272,7 +272,7 @@ public class ManagedDefaultTransferTest SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -304,7 +304,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -328,7 +328,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); Path proxied2File = Paths.get(REPOPATH_PROXIED2, path); @@ -359,7 +359,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxied2File = Paths.get(REPOPATH_PROXIED2, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File ); @@ -383,7 +383,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", downloadedFile ); @@ -403,7 +403,8 @@ public class ManagedDefaultTransferTest assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Repository (usually done within archiva.xml configuration) - saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "" + + "http://bad.machine.com/repo/", "default" ); wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) ); EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" ) ); @@ -414,7 +415,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); wagonMockControl.verify(); @@ -436,8 +437,8 @@ public class ManagedDefaultTransferTest assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Repository (usually done within archiva.xml configuration) - saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://dead.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", false ); @@ -453,7 +454,7 @@ public class ManagedDefaultTransferTest wagonMockControl.replay(); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java index 323f6668b..289a82cc8 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java @@ -128,7 +128,7 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -145,7 +145,7 @@ public class MetadataTransferTest String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); - saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, @@ -991,7 +991,7 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1017,7 +1017,7 @@ public class MetadataTransferTest Path expectedFile = managedDefaultDir.resolve(requestedResource); ProjectReference metadata = createProjectReference( requestedResource ); - StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1038,7 +1038,7 @@ public class MetadataTransferTest VersionedReference metadata = createVersionedReference( requestedResource ); - StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1064,7 +1064,7 @@ public class MetadataTransferTest Path expectedFile = managedDefaultDir.resolve(requestedResource); VersionedReference metadata = createVersionedReference( requestedResource ); - StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(), managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index c686e8df9..1579ce7bb 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -91,6 +91,7 @@ public class MockConfiguration registryListeners.add( listener ); } + @Override public void removeChangeListener( RegistryListener listener ) { @@ -123,6 +124,10 @@ public class MockConfiguration e.printStackTrace(); } } + + for (ConfigurationListener listener : configListeners) { + listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) ); + } } @Override diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java index 98055b5dc..01d59c2df 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java @@ -60,7 +60,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertNoTempFiles( expectedFile ); } @@ -81,7 +81,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -104,7 +104,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -129,7 +129,7 @@ public class SnapshotTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); // Attempt to download. - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); // Should not have downloaded as managed is newer than remote. assertNotDownloaded( downloadedFile ); @@ -221,7 +221,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); assertNoTempFiles( expectedFile ); @@ -245,7 +245,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); assertNotDownloaded( downloadedFile ); assertNotModified( expectedFile, expectedTimestamp ); @@ -271,7 +271,7 @@ public class SnapshotTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -294,7 +294,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); @@ -321,7 +321,7 @@ public class SnapshotTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile ); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java index 702fe99c7..6c733a2b0 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java @@ -269,11 +269,11 @@ public class WagonDelegate try { Files.createDirectories(destination.getParent()); - if ( contentToGet == null ) + if ( contentToGet == null && !Files.exists(destination)) { Files.createFile(destination); } - else + else if (contentToGet != null) { org.apache.archiva.common.utils.FileUtils.writeStringToFile(destination, Charset.defaultCharset(), contentToGet); } @@ -283,4 +283,8 @@ public class WagonDelegate throw new RuntimeException( e.getMessage(), e ); } } + + public void cleanup() { + + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/resources/spring-context.xml b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/resources/spring-context.xml index d79ce1afe..488c1e695 100755 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/resources/spring-context.xml @@ -50,11 +50,13 @@ <bean name="repositoryContentProvider#mocked" class="org.apache.archiva.repository.mock.RepositoryContentProviderMock" /> - <bean name="repositoryProxyConnectors#test" class="org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler"> + <bean name="repositoryProxyHandler#test" class="org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler"> <property name="archivaConfiguration" ref="archivaConfiguration#mock"/> <property name="metadataTools" ref="metadataTools#mocked"/> </bean> + <alias name="repositoryProxyHandler#test" alias="repositoryProxyHandler#maven"/> + <bean name="metadataTools#default" class="org.apache.archiva.repository.metadata.MetadataTools"> <property name="configuration" ref="archivaConfiguration#mock"/> </bean> @@ -79,7 +81,7 @@ <property name="timeToLiveSeconds" value="1800"/> </bean> - <bean name="wagon#test" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/> + <bean name="wagon#http" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/> <bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/> <alias name="userConfiguration#redback" alias="userConfiguration#default"/> |