diff options
author | Brett Porter <brett@apache.org> | 2007-09-12 09:33:41 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2007-09-12 09:33:41 +0000 |
commit | 17f229020f24ab34c553ef619f11834ae6882b21 (patch) | |
tree | 1867c4e8f537fe2f7cb05c129aa75b728ae035e5 /archiva-base/archiva-proxy/src | |
parent | b8cca284caff8744badd9db482f6db163b6e0a18 (diff) | |
download | archiva-17f229020f24ab34c553ef619f11834ae6882b21.tar.gz archiva-17f229020f24ab34c553ef619f11834ae6882b21.zip |
[MRM-462] separate configuration of managed and remote repositories
Merged from branches/MRM-462
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@574859 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-proxy/src')
7 files changed, 183 insertions, 201 deletions
diff --git a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 005d229e8..12c08be58 100644 --- a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -23,15 +23,17 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.NetworkProxyConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.policies.DownloadPolicy; import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; +import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; import org.apache.maven.archiva.repository.layout.LayoutException; @@ -60,15 +62,14 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Map.Entry; +import java.util.Properties; /** - * DefaultRepositoryProxyConnectors + * DefaultRepositoryProxyConnectors * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ - * * @plexus.component role-hint="default" */ public class DefaultRepositoryProxyConnectors @@ -116,18 +117,16 @@ public class DefaultRepositoryProxyConnectors /** * Fetch an artifact from a remote repository. - * + * * @param repository the managed repository to utilize for the request. - * @param artifact the artifact reference to fetch. - * @return the local file in the managed repository that was fetched, or null if the artifact was not (or - * could not be) fetched. + * @param artifact the artifact reference to fetch. + * @return the local file in the managed repository that was fetched, or null if the artifact was not (or + * could not be) fetched. * @throws ProxyException if there was a problem fetching the artifact. */ public File fetchFromProxies( ArchivaRepository repository, ArtifactReference artifact ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, artifact ); Properties requestProperties = new Properties(); @@ -155,14 +154,12 @@ public class DefaultRepositoryProxyConnectors /** * Fetch, from the proxies, a metadata.xml file for the groupId:artifactId:version metadata contents. - * + * * @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists. */ public File fetchFromProxies( ArchivaRepository repository, VersionedReference metadata ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); @@ -175,9 +172,10 @@ public class DefaultRepositoryProxyConnectors ProxyConnector connector = (ProxyConnector) it.next(); ArchivaRepository targetRepository = connector.getTargetRepository(); String targetPath = metadataTools.toPath( metadata ); - + File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); + File downloadedFile = + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); if ( fileExists( downloadedFile ) ) { @@ -221,14 +219,12 @@ public class DefaultRepositoryProxyConnectors /** * Fetch from the proxies a metadata.xml file for the groupId:artifactId metadata contents. - * + * * @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists. */ public File fetchFromProxies( ArchivaRepository repository, ProjectReference metadata ) throws ProxyException { - assertProxyCapable( repository ); - File localFile = toLocalFile( repository, metadata ); Properties requestProperties = new Properties(); @@ -243,7 +239,8 @@ public class DefaultRepositoryProxyConnectors String targetPath = metadataTools.toPath( metadata ); File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - File downloadedFile = transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); + File downloadedFile = + transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties ); if ( fileExists( downloadedFile ) ) { @@ -302,21 +299,6 @@ public class DefaultRepositoryProxyConnectors } } - /** - * Test the repository to see if it is proxy capable. - * - * @param repository the repository to test. - * @throws ProxyException if the repository is not proxy capable. - */ - private void assertProxyCapable( ArchivaRepository repository ) - throws ProxyException - { - if ( !repository.isManaged() ) - { - throw new ProxyException( "Can only proxy managed repositories." ); - } - } - private File toLocalFile( ArchivaRepository repository, ArtifactReference artifact ) throws ProxyException { @@ -341,7 +323,7 @@ public class DefaultRepositoryProxyConnectors /** * Get the layout for the repository. - * + * * @param repository the repository to get the layout from. * @return the layout * @throws ProxyException if there was a problem obtaining the layout from the repository (usually due to a bad @@ -356,14 +338,14 @@ public class DefaultRepositoryProxyConnectors } catch ( LayoutException e ) { - throw new ProxyException( "Unable to proxy due to bad repository layout definition [" + repository.getId() - + "] had a layout defined as [" + repository.getLayoutType() + "] : " + e.getMessage(), e ); + throw new ProxyException( "Unable to proxy due to bad repository layout definition [" + repository.getId() + + "] had a layout defined as [" + repository.getLayoutType() + "] : " + e.getMessage(), e ); } } /** * Simple method to test if the file exists on the local disk. - * + * * @param file the file to test. (may be null) * @return true if file exists. false if the file param is null, doesn't exist, or is not of type File. */ @@ -389,11 +371,11 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the file. - * - * @param connector the connector configuration to use. - * @param remoteRepository the remote repository get the resource from. - * @param remotePath the path in the remote repository to the resource to get. - * @param localFile the local file to place the downloaded resource into + * + * @param connector the connector configuration to use. + * @param remoteRepository the remote repository get the resource from. + * @param remotePath the path in the remote repository to the resource to get. + * @param localFile the local file to place the downloaded resource into * @param requestProperties the request properties to utilize for policy handling. * @return the local file that was downloaded, or null if not downloaded. * @throws ProxyException if transfer was unsuccessful. @@ -499,14 +481,14 @@ public class DefaultRepositoryProxyConnectors /** * Quietly transfer the checksum file from the remote repository to the local file. - * + * <p/> * NOTE: This will not throw a WagonException if the checksum is unable to be downloaded. - * - * @param wagon the wagon instance (should already be connected) to use. + * + * @param wagon the wagon instance (should already be connected) to use. * @param remoteRepository the remote repository to transfer from. - * @param remotePath the remote path to the resource to get. - * @param localFile the local file that should contain the downloaded contents - * @param type the type of checksum to transfer (example: ".md5" or ".sha1") + * @param remotePath the remote path to the resource to get. + * @param localFile the local file that should contain the downloaded contents + * @param type the type of checksum to transfer (example: ".md5" or ".sha1") * @throws ProxyException if copying the downloaded file into place did not succeed. */ private void transferChecksum( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, File localFile, @@ -540,16 +522,17 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the remote file to the local file specified. - * - * @param wagon the wagon instance to use. + * + * @param wagon the wagon instance to use. * @param remoteRepository the remote repository to use - * @param remotePath the remote path to attempt to get - * @param localFile the local file to save to + * @param remotePath the remote path to attempt to get + * @param localFile the local file to save to * @return The local file that was transfered. * @throws ProxyException if there was a problem moving the downloaded file into place. * @throws WagonException if there was a problem tranfering the file. */ - private File transferSimpleFile( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, File localFile ) + private File transferSimpleFile( Wagon wagon, ArchivaRepository remoteRepository, String remotePath, + File localFile ) throws ProxyException, WagonException { assert ( remotePath != null ); @@ -584,8 +567,7 @@ public class DefaultRepositoryProxyConnectors if ( !success ) { getLogger().info( - "Not downloaded, as local file is newer than remote side: " - + localFile.getAbsolutePath() ); + "Not downloaded, as local file is newer than remote side: " + localFile.getAbsolutePath() ); } else if ( temp.exists() ) { @@ -617,11 +599,11 @@ public class DefaultRepositoryProxyConnectors /** * Apply the policies. - * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) - * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy setting) - * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) - * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) - * + * + * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) + * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy setting) + * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) + * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) * @return true if all of the policies passed, false if a policy failed. */ private boolean applyPolicies( Map policies, Map settings, Properties request, File localFile ) @@ -682,9 +664,9 @@ public class DefaultRepositoryProxyConnectors /** * Using wagon, connect to the remote repository. - * - * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) - * @param wagon the wagon instance to establish the connection on. + * + * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) + * @param wagon the wagon instance to establish the connection on. * @param remoteRepository the remote repository to connect to. * @return true if the connection was successful. false if not connected. */ @@ -700,7 +682,8 @@ public class DefaultRepositoryProxyConnectors try { - Repository wagonRepository = new Repository( remoteRepository.getId(), remoteRepository.getUrl().toString() ); + Repository wagonRepository = + new Repository( remoteRepository.getId(), remoteRepository.getUrl().toString() ); if ( networkProxy != null ) { wagon.connect( wagonRepository, networkProxy ); @@ -727,8 +710,8 @@ public class DefaultRepositoryProxyConnectors /** * Tests whitelist and blacklist patterns against path. - * - * @param path the path to test. + * + * @param path the path to test. * @param patterns the list of patterns to check. * @return true if the path matches at least 1 pattern in the provided patterns list. */ @@ -770,8 +753,10 @@ public class DefaultRepositoryProxyConnectors public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { - if ( ConfigurationNames.isNetworkProxy( propertyName ) || ConfigurationNames.isRepositories( propertyName ) - || ConfigurationNames.isProxyConnector( propertyName ) ) + if ( ConfigurationNames.isNetworkProxy( propertyName ) || + ConfigurationNames.isManagedRepositories( propertyName ) || + ConfigurationNames.isRemoteRepositories( propertyName ) || + ConfigurationNames.isProxyConnector( propertyName ) ) { initConnectorsAndNetworkProxies(); } @@ -799,8 +784,8 @@ public class DefaultRepositoryProxyConnectors // Create connector object. ProxyConnector connector = new ProxyConnector(); - connector.setSourceRepository( getRepository( proxyConfig.getSourceRepoId() ) ); - connector.setTargetRepository( getRepository( proxyConfig.getTargetRepoId() ) ); + connector.setSourceRepository( getManagedRepository( proxyConfig.getSourceRepoId() ) ); + connector.setTargetRepository( getRemoteRepository( proxyConfig.getTargetRepoId() ) ); connector.setProxyId( proxyConfig.getProxyId() ); connector.setPolicies( proxyConfig.getPolicies() ); @@ -870,19 +855,24 @@ public class DefaultRepositoryProxyConnectors return collection.size() == 0; } - private ArchivaRepository getRepository( String repoId ) + private ArchivaRepository getRemoteRepository( String repoId ) { - RepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration().findRepositoryById( repoId ); - if ( repoConfig == null ) - { - return null; - } + RemoteRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId ); ArchivaRepository repo = new ArchivaRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl() ); repo.getModel().setLayoutName( repoConfig.getLayout() ); return repo; } + private ArchivaRepository getManagedRepository( String repoId ) + { + ManagedRepositoryConfiguration repoConfig = + archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); + + return ArchivaConfigurationAdaptor.toArchivaRepository( repoConfig ); + } + public void initialize() throws InitializationException { diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java index 7c498a1dd..6c6113506 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java @@ -22,8 +22,9 @@ package org.apache.maven.archiva.proxy; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArtifactReference; @@ -47,12 +48,12 @@ import java.util.Iterator; import java.util.Locale; /** - * AbstractProxyTestCase + * AbstractProxyTestCase * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ -public class AbstractProxyTestCase +public abstract class AbstractProxyTestCase extends PlexusTestCase { protected static final String ID_LEGACY_PROXIED = "legacy-proxied"; @@ -161,7 +162,7 @@ public class AbstractProxyTestCase return; } - Collection tmpFiles = FileUtils.listFiles( workingDir, new String[] { "tmp" }, false ); + Collection tmpFiles = FileUtils.listFiles( workingDir, new String[]{"tmp"}, false ); if ( !tmpFiles.isEmpty() ) { StringBuffer emsg = new StringBuffer(); @@ -220,8 +221,8 @@ public class AbstractProxyTestCase { if ( !destination.exists() && !destination.mkdirs() ) { - throw new IOException( "Could not create destination directory '" - + destination.getAbsolutePath() + "'." ); + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } copyDirectoryStructure( file, destination ); @@ -260,19 +261,19 @@ public class AbstractProxyTestCase "Test Proxied (Legacy) Repository", "legacy" ); } - protected RepositoryConfiguration createRepoConfig( ArchivaRepository repo ) + protected ManagedRepositoryConfiguration createRepoConfig( ArchivaRepository repo ) { return createRepoConfig( repo.getId(), repo.getName(), repo.getUrl().toString(), repo.getLayoutType() ); } - protected RepositoryConfiguration createRepoConfig( String id, String name, String path, String layout ) + protected ManagedRepositoryConfiguration createRepoConfig( String id, String name, String path, String layout ) { - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( id ); repoConfig.setName( name ); - repoConfig.setUrl( PathUtil.toUrl( path ) ); + repoConfig.setLocation( path ); repoConfig.setLayout( layout ); return repoConfig; @@ -323,8 +324,8 @@ public class AbstractProxyTestCase } } - protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, - String releasePolicy, String snapshotPolicy, String cacheFailuresPolicy ) + protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy, String releasePolicy, + String snapshotPolicy, String cacheFailuresPolicy ) { ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration(); connectorConfig.setSourceRepoId( sourceRepoId ); @@ -348,24 +349,33 @@ public class AbstractProxyTestCase config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) ); } - protected void saveRepositoryConfig( String id, String name, String path, String layout ) + protected void saveManagedRepositoryConfig( String id, String name, String path, String layout ) { - RepositoryConfiguration repoConfig = new RepositoryConfiguration(); + ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( id ); repoConfig.setName( name ); + repoConfig.setLayout( layout ); - if ( path.startsWith( "test://" ) ) - { - repoConfig.setUrl( path ); - } - else - { - repoConfig.setUrl( PathUtil.toUrl( path ) ); - } + repoConfig.setLocation( path ); + + config.getConfiguration().addManagedRepository( repoConfig ); + + config.triggerChange( "repository", "" ); + } + + protected void saveRemoteRepositoryConfig( String id, String name, String path, String layout ) + { + RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration(); + + repoConfig.setId( id ); + repoConfig.setName( name ); repoConfig.setLayout( layout ); - config.getConfiguration().addRepository( repoConfig ); + repoConfig.setUrl( path ); + + config.getConfiguration().addRemoteRepository( repoConfig ); + config.triggerChange( "repository", "" ); } @@ -376,7 +386,7 @@ public class AbstractProxyTestCase FileUtils.deleteDirectory( repoLocation ); copyDirectoryStructure( getTestFile( originalPath ), repoLocation ); - saveRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); + saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); return repoLocation; } @@ -390,20 +400,19 @@ public class AbstractProxyTestCase .getName() ); config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - RepositoryConfiguration repoConfig; // Setup source repository (using default layout) String repoPath = "target/test-repository/managed/" + getName(); File repoLocation = getTestFile( repoPath ); - managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, - "default" ); + managedDefaultRepository = + createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" ); managedDefaultDir = new File( managedDefaultRepository.getUrl().getPath() ); - repoConfig = createRepoConfig( managedDefaultRepository ); + ManagedRepositoryConfiguration repoConfig = createRepoConfig( managedDefaultRepository ); - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); // Setup source repository (using legacy layout) repoLocation = getTestFile( REPOPATH_LEGACY_MANAGED_TARGET ); @@ -417,16 +426,19 @@ public class AbstractProxyTestCase repoConfig = createRepoConfig( managedLegacyRepository ); - config.getConfiguration().addRepository( repoConfig ); + config.getConfiguration().addManagedRepository( repoConfig ); // Setup target (proxied to) repository. - saveRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", REPOPATH_PROXIED1, "default" ); + saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", + new File( REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository. - saveRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", REPOPATH_PROXIED2, "default" ); + saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", + new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository using legacy layout. - saveRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", REPOPATH_PROXIED_LEGACY, "legacy" ); + saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", + new File( REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" ); // Setup the proxy handler. proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); @@ -443,21 +455,21 @@ public class AbstractProxyTestCase /** * Copy the specified resource directory from the src/test/repository/managed/ to * the testable directory under target/test-repository/managed/${testName}/ - * + * * @param resourceDir - * @throws IOException + * @throws IOException */ protected void setupTestableManagedRepository( String resourcePath ) throws IOException { String resourceDir = resourcePath; - - if( !resourcePath.endsWith( "/" ) ) + + if ( !resourcePath.endsWith( "/" ) ) { int idx = resourcePath.lastIndexOf( '/' ); resourceDir = resourcePath.substring( 0, idx ); } - + File sourceRepoDir = new File( REPOPATH_DEFAULT_MANAGED ); File sourceDir = new File( sourceRepoDir, resourceDir ); @@ -474,8 +486,8 @@ public class AbstractProxyTestCase if ( !sourceDir.exists() ) { // This is just a warning. - System.err.println( "Skipping setup of testable managed repsoitory, source dir does not exist: " - + sourceDir ); + System.err.println( + "Skipping setup of testable managed repsoitory, source dir does not exist: " + sourceDir ); return; } diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java index 552762313..548c6d860 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java @@ -23,7 +23,7 @@ import junit.framework.Test; import junit.framework.TestSuite; /** - * IDE Provided Utility Class for all tests. + * IDE Provided Utility Class for all tests. * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java index 86bfa5f2f..622c7bc04 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java @@ -31,7 +31,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * CacheFailuresTransferTest + * CacheFailuresTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -51,8 +51,8 @@ public class CacheFailuresTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, @@ -85,8 +85,8 @@ public class CacheFailuresTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java index 62e3f0e30..f23b2d6f3 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java @@ -30,7 +30,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * ChecksumTransferTest + * ChecksumTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -44,7 +44,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -69,7 +69,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -85,7 +85,8 @@ public class ChecksumTransferTest File proxied1File = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); - assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null ); + assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + null ); } public void testGetChecksumNoSha1CorrectMd5() @@ -93,7 +94,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -117,7 +118,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -141,7 +142,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -165,7 +166,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -187,7 +188,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -212,7 +213,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -234,7 +235,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -259,7 +260,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -281,7 +282,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -306,7 +307,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -331,7 +332,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -356,7 +357,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -381,7 +382,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -389,7 +390,7 @@ public class ChecksumTransferTest assertFalse( expectedFile.getParentFile().exists() ); assertFalse( expectedFile.exists() ); - saveRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, @@ -417,7 +418,8 @@ public class ChecksumTransferTest File proxied1File = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); - assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null ); + assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + null ); } public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting() @@ -425,7 +427,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -449,7 +451,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -473,7 +475,7 @@ public class ChecksumTransferTest { String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java index 1807d0f77..605eb9d61 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java @@ -31,7 +31,7 @@ import org.apache.maven.wagon.TransferFailedException; import java.io.File; /** - * ManagedDefaultTransferTest + * ManagedDefaultTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> @@ -45,7 +45,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -67,9 +67,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in no file being transferred. - * + * <p/> * The file exists locally, and the policy is ONCE. - * + * * @throws Exception */ public void testGetDefaultLayoutAlreadyPresentPolicyOnce() @@ -77,7 +77,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -97,9 +97,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in file being transferred. - * + * <p/> * The file exists locally, and the policy is IGNORE. - * + * * @throws Exception */ public void testGetDefaultLayoutAlreadyPresentPolicyIgnored() @@ -107,7 +107,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); long originalModificationTime = expectedFile.lastModified(); @@ -135,15 +135,15 @@ public class ManagedDefaultTransferTest * This delta is the amount of milliseconds of 'fudge factor' we allow for * the unit test to still be considered 'passed'. */ - int delta = 1100; + int delta = 20000; long hirange = originalModificationTime + ( delta / 2 ); long lorange = originalModificationTime - ( delta / 2 ); if ( ( downloadedLastModified < lorange ) || ( downloadedLastModified > hirange ) ) { - fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange - + "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" ); + fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange + + "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" ); } } assertNoTempFiles( expectedFile ); @@ -151,9 +151,9 @@ public class ManagedDefaultTransferTest /** * The attempt here should result in file being transferred. - * + * <p/> * The file exists locally, is over 6 years old, and the policy is DAILY. - * + * * @throws Exception */ public void testGetDefaultLayoutRemoteUpdate() @@ -161,7 +161,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -169,8 +169,8 @@ public class ManagedDefaultTransferTest expectedFile.setLastModified( getPastDate().getTime() ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, - SnapshotsPolicy.DAILY, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY, + CachedFailuresPolicy.IGNORED ); // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -185,7 +185,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -209,8 +209,8 @@ public class ManagedDefaultTransferTest // TODO: is this check even needed if it passes above? String actualContents = FileUtils.readFileToString( downloadedFile, null ); String badContents = FileUtils.readFileToString( proxied2File, null ); - assertFalse( "Downloaded file contents should not be that of proxy 2", StringUtils.equals( actualContents, - badContents ) ); + assertFalse( "Downloaded file contents should not be that of proxy 2", + StringUtils.equals( actualContents, badContents ) ); } public void testGetInSecondProxiedRepo() @@ -218,7 +218,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -244,7 +244,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -261,7 +261,8 @@ public class ManagedDefaultTransferTest // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", downloadedFile ); + assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", + downloadedFile ); assertNoTempFiles( expectedFile ); } @@ -270,7 +271,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -278,7 +279,7 @@ public class ManagedDefaultTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); wagonMock.getIfNewer( path, new File( expectedFile.getAbsolutePath() + ".tmp" ), 0 ); wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); @@ -305,7 +306,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -313,8 +314,8 @@ public class ManagedDefaultTransferTest assertFalse( expectedFile.exists() ); // Configure Repository (usually done within archiva.xml configuration) - saveRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); - saveRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); + saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, @@ -346,7 +347,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -358,8 +359,8 @@ public class ManagedDefaultTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, - "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); + File proxiedFile = + new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertNoTempFiles( expectedFile ); } @@ -373,7 +374,7 @@ public class ManagedDefaultTransferTest String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); @@ -396,7 +397,7 @@ public class ManagedDefaultTransferTest { String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - + File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = createArtifactReference( "default", path ); diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java index 5e3399195..a23ace51d 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java @@ -19,31 +19,8 @@ package org.apache.maven.archiva.proxy; * under the License. */ -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.common.utils.PathUtil; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.RepositoryConfiguration; -import org.apache.maven.archiva.model.ArchivaRepository; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.ProjectReference; -import org.apache.maven.archiva.policies.CachedFailuresPolicy; -import org.apache.maven.archiva.policies.ChecksumPolicy; -import org.apache.maven.archiva.policies.ReleasesPolicy; -import org.apache.maven.archiva.policies.SnapshotsPolicy; -import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.easymock.MockControl; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; - /** - * RelocateTransferTest + * RelocateTransferTest * * @author Brett Porter * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> |