summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2008-07-18 05:47:04 +0000
committerBrett Porter <brett@apache.org>2008-07-18 05:47:04 +0000
commit28e545b65a3079ca6b09d691c2ebb0d64d23254f (patch)
treeb8b9dffe4529abeb35818d27e3a15dd8dfddaf2a /archiva-modules/archiva-base
parent0d580b48c1ed3cda6ca5681e20a7bcce72991504 (diff)
downloadarchiva-28e545b65a3079ca6b09d691c2ebb0d64d23254f.tar.gz
archiva-28e545b65a3079ca6b09d691c2ebb0d64d23254f.zip
[MRM-876] let Archiva proxy arbitrary paths, particularly allowing it for pre-emptive proxying of support files when requested before the artifact
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@677828 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java83
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java16
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java23
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc7
4 files changed, 95 insertions, 34 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
index c2937fe3e..7f5a1e1d2 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
@@ -138,15 +138,6 @@ public class DefaultRepositoryProxyConnectors
*/
private RepositoryContentConsumers consumers;
- /**
- * 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.
- * @throws PolicyViolationException if there was a problem fetching the artifact.
- */
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException
{
@@ -205,11 +196,56 @@ public class DefaultRepositoryProxyConnectors
return null;
}
- /**
- * 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( ManagedRepositoryContent repository, String path )
+ {
+ File localFile = new File( repository.getRepoRoot(), path );
+
+ Properties requestProperties = new Properties();
+ requestProperties.setProperty( "filetype", "resource" );
+ requestProperties.setProperty( "managedRepositoryId", repository.getId() );
+
+ List<ProxyConnector> connectors = getProxyConnectors( repository );
+ for ( ProxyConnector connector : connectors )
+ {
+ RemoteRepositoryContent targetRepository = connector.getTargetRepository();
+ requestProperties.setProperty( "remoteRepositoryId", targetRepository.getId() );
+
+ String targetPath = path;
+
+ try
+ {
+ File downloadedFile =
+ transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties );
+
+ if ( fileExists( downloadedFile ) )
+ {
+ log.debug( "Successfully transferred: " + downloadedFile.getAbsolutePath() );
+ return downloadedFile;
+ }
+ }
+ catch ( NotFoundException e )
+ {
+ log.debug( "Resource " + path + " not found on repository \""
+ + targetRepository.getRepository().getId() + "\"." );
+ }
+ catch ( NotModifiedException e )
+ {
+ log.debug( "Resource " + path + " not updated on repository \""
+ + targetRepository.getRepository().getId() + "\"." );
+ }
+ catch ( ProxyException e )
+ {
+ log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId()
+ + "\" for resource " + path + ", continuing to next repository. Error message: " + e.getMessage() );
+ log.debug( "Full stack trace", e );
+ }
+ }
+
+ log.debug( "Exhausted all target repositories, resource " + path + " not found." );
+
+ return null;
+ }
+
public File fetchFromProxies( ManagedRepositoryContent repository, VersionedReference metadata )
{
File localFile = toLocalFile( repository, metadata );
@@ -323,12 +359,6 @@ public class DefaultRepositoryProxyConnectors
return ( currentLastModified > originalLastModified );
}
- /**
- * 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.
- * @throws ProxyException if there was a problem fetching the metadata file.
- */
public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata )
{
File localFile = toLocalFile( repository, metadata );
@@ -984,7 +1014,7 @@ public class DefaultRepositoryProxyConnectors
List<ProxyConnector> ret = (List<ProxyConnector>) this.proxyConnectorMap.get( repository.getId() );
if ( ret == null )
{
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
Collections.sort( ret, ProxyConnectorOrderComparator.getInstance() );
@@ -1008,16 +1038,7 @@ public class DefaultRepositoryProxyConnectors
/* do nothing */
}
- private void logProcess( String managedRepoId, String resource, String event )
- {
-
- }
-
- private void logRejection( String managedRepoId, String remoteRepoId, String resource, String reason )
- {
-
- }
-
+ @SuppressWarnings("unchecked")
private void initConnectorsAndNetworkProxies()
{
synchronized ( this.proxyConnectorMap )
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
index c27c5b8ab..cf68c9509 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
@@ -45,7 +45,7 @@ public interface RepositoryProxyConnectors
*
* @param repository the source repository to use. (must be a managed repository)
* @param artifact the artifact to fetch.
- * @return true if the fetch operation succeeded in obtaining content, false if no content was obtained.
+ * @return the file that was obtained, or null if no content was obtained
* @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
*/
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
@@ -60,7 +60,7 @@ public interface RepositoryProxyConnectors
*
* @param repository the source repository to use. (must be a managed repository)
* @param metadata the metadata to fetch.
- * @return true if the fetch operation succeeded in obtaining content, false if no content was obtained.
+ * @return the file that was obtained, or null if no content was obtained
*/
public File fetchFromProxies( ManagedRepositoryContent repository, VersionedReference metadata );
@@ -73,11 +73,21 @@ public interface RepositoryProxyConnectors
*
* @param repository the source repository to use. (must be a managed repository)
* @param metadata the metadata to fetch.
- * @return true if the fetch operation succeeded in obtaining content, false if no content was obtained.
+ * @return the file that was obtained, or null if no content was obtained
*/
public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata );
/**
+ * Performs the fetch operation against the target repositories
+ * of the provided source repository.
+ *
+ * @param repository the source repository to use. (must be a managed repository)
+ * @param path the path of the resource to fetch
+ * @return the file that was obtained, or null if no content was obtained
+ */
+ public File fetchFromProxies( ManagedRepositoryContent managedRepository, String path );
+
+ /**
* Get the List of {@link ProxyConnector} objects of the source repository.
*
* @param repository the source repository to look for.
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
index 9819f7cc0..32f6db1a5 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
@@ -64,6 +64,29 @@ public class ManagedDefaultTransferTest
assertNoTempFiles( expectedFile );
}
+ public void testGetDefaultLayoutNotPresentPassthrough()
+ throws Exception
+ {
+ String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc";
+ setupTestableManagedRepository( path );
+
+ File expectedFile = new File( managedDefaultDir, path );
+
+ // Ensure file isn't present first.
+ assertNotExistsInManagedDefaultRepo( expectedFile );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
+ CachedFailuresPolicy.NO );
+
+ // Attempt the proxy fetch.
+ File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
+
+ File sourceFile = new File( REPOPATH_PROXIED1, path );
+ assertFileEquals( expectedFile, downloadedFile, sourceFile );
+ assertNoTempFiles( expectedFile );
+ }
+
/**
* The attempt here should result in no file being transferred.
* <p/>
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc
new file mode 100644
index 000000000..bf07c716d
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc
@@ -0,0 +1,7 @@
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.8 (Darwin)
+
+iEUEABECAAYFAkiAKPMACgkQTusOMqfRa9RpcQCfUsvdYGZ7P97TYXzQ0MclsV2r
+ASkAmJNCpmKjersaTXmsCupNGAJu38c=
+=/yRo
+-----END PGP SIGNATURE-----