Adding VersionedReference metadata to .fetchFromProxies()

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@530916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-04-20 20:55:14 +00:00
parent 32f1b4afd2
commit d9e4b87d60
3 changed files with 115 additions and 46 deletions

View File

@ -27,6 +27,7 @@ import org.apache.maven.archiva.configuration.RepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference; 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.DownloadPolicy;
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
@ -70,8 +71,6 @@ public class DefaultRepositoryProxyConnectors
extends AbstractLogEnabled extends AbstractLogEnabled
implements RepositoryProxyConnectors, RegistryListener, Initializable implements RepositoryProxyConnectors, RegistryListener, Initializable
{ {
private static final String FILENAME_MAVEN_METADATA = "maven-metadata.xml";
/** /**
* @plexus.requirement * @plexus.requirement
*/ */
@ -167,7 +166,7 @@ public class DefaultRepositoryProxyConnectors
return null; return null;
} }
public File fetchFromProxies( ArchivaRepository repository, ProjectReference metadata ) public File fetchFromProxies( ArchivaRepository repository, VersionedReference metadata )
throws ProxyException throws ProxyException
{ {
if ( !repository.isManaged() ) if ( !repository.isManaged() )
@ -179,7 +178,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
BidirectionalRepositoryLayout sourceLayout = layoutFactory.getLayout( repository.getLayoutType() ); BidirectionalRepositoryLayout sourceLayout = layoutFactory.getLayout( repository.getLayoutType() );
String sourcePath = sourceLayout.toPath( metadata ) + FILENAME_MAVEN_METADATA; String sourcePath = sourceLayout.toPath( metadata );
localFile = new File( repository.getUrl().getPath(), sourcePath ); localFile = new File( repository.getUrl().getPath(), sourcePath );
} }
catch ( LayoutException e ) catch ( LayoutException e )
@ -199,7 +198,60 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
BidirectionalRepositoryLayout targetLayout = layoutFactory.getLayout( targetRepository.getLayoutType() ); BidirectionalRepositoryLayout targetLayout = layoutFactory.getLayout( targetRepository.getLayoutType() );
String targetPath = targetLayout.toPath( metadata ) + FILENAME_MAVEN_METADATA; String targetPath = targetLayout.toPath( metadata );
File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile,
requestProperties );
if ( fileExists( downloadedFile ) )
{
getLogger().info( "Successfully transfered: " + downloadedFile.getAbsolutePath() );
return downloadedFile;
}
}
catch ( LayoutException e )
{
getLogger().error( "Unable to proxy due to bad layout definition: " + e.getMessage(), e );
return null;
}
}
return null;
}
public File fetchFromProxies( ArchivaRepository repository, ProjectReference metadata )
throws ProxyException
{
if ( !repository.isManaged() )
{
throw new ProxyException( "Can only proxy managed repositories." );
}
File localFile;
try
{
BidirectionalRepositoryLayout sourceLayout = layoutFactory.getLayout( repository.getLayoutType() );
String sourcePath = sourceLayout.toPath( metadata );
localFile = new File( repository.getUrl().getPath(), sourcePath );
}
catch ( LayoutException e )
{
throw new ProxyException( "Unable to proxy due to bad source repository layout definition: "
+ e.getMessage(), e );
}
Properties requestProperties = new Properties();
List connectors = getProxyConnectors( repository );
Iterator it = connectors.iterator();
while ( it.hasNext() )
{
ProxyConnector connector = (ProxyConnector) it.next();
ArchivaRepository targetRepository = connector.getTargetRepository();
try
{
BidirectionalRepositoryLayout targetLayout = layoutFactory.getLayout( targetRepository.getLayoutType() );
String targetPath = targetLayout.toPath( metadata );
File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile, File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile,
requestProperties ); requestProperties );

View File

@ -22,6 +22,7 @@ package org.apache.maven.archiva.proxy;
import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -49,6 +50,21 @@ public interface RepositoryProxyConnectors
public File fetchFromProxies( ArchivaRepository repository, ArtifactReference artifact ) public File fetchFromProxies( ArchivaRepository repository, ArtifactReference artifact )
throws ProxyException; throws ProxyException;
/**
* Performs the metadata fetch operation against the target repositories
* of the provided source repository.
*
* If the metadata is found, it is downloaded and placed into the source repository
* filesystem.
*
* @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.
* @throws ProxyException if there was a problem fetching the content from the target repositories.
*/
public File fetchFromProxies( ArchivaRepository repository, VersionedReference metadata )
throws ProxyException;
/** /**
* Performs the metadata fetch operation against the target repositories * Performs the metadata fetch operation against the target repositories
* of the provided source repository. * of the provided source repository.

View File

@ -19,25 +19,19 @@ package org.apache.maven.archiva.web.repository;
* under the License. * under the License.
*/ */
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.proxy.ProxyConnector;
import org.apache.maven.archiva.proxy.ProxyException; import org.apache.maven.archiva.proxy.ProxyException;
import org.apache.maven.archiva.proxy.RepositoryProxyConnectors; import org.apache.maven.archiva.proxy.RepositoryProxyConnectors;
import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.codehaus.plexus.webdav.AbstractDavServerComponent; import org.codehaus.plexus.webdav.AbstractDavServerComponent;
import org.codehaus.plexus.webdav.DavServerComponent; import org.codehaus.plexus.webdav.DavServerComponent;
import org.codehaus.plexus.webdav.DavServerException; import org.codehaus.plexus.webdav.DavServerException;
@ -46,10 +40,6 @@ import org.codehaus.plexus.webdav.util.WebdavMethodUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -93,8 +83,6 @@ public class ProxiedDavServer
private ArchivaRepository managedRepository; private ArchivaRepository managedRepository;
private List/*<ArtifactRepository>*/proxiedRepositories;
public String getPrefix() public String getPrefix()
{ {
return davServer.getPrefix(); return davServer.getPrefix();
@ -120,8 +108,6 @@ public class ProxiedDavServer
{ {
davServer.init( servletConfig ); davServer.init( servletConfig );
proxiedRepositories = new ArrayList();
Configuration config = archivaConfiguration.getConfiguration(); Configuration config = archivaConfiguration.getConfiguration();
repositoryConfiguration = config.findRepositoryById( getPrefix() ); repositoryConfiguration = config.findRepositoryById( getPrefix() );
@ -157,8 +143,7 @@ public class ProxiedDavServer
{ {
String resource = request.getLogicalResource(); String resource = request.getLogicalResource();
if( resource.endsWith( ".sha1" ) || if ( resource.endsWith( ".sha1" ) || resource.endsWith( ".md5" ) )
resource.endsWith( ".md5") )
{ {
// Checksums are fetched with artifact / metadata. // Checksums are fetched with artifact / metadata.
return; return;
@ -170,20 +155,36 @@ public class ProxiedDavServer
VersionedReference versioned; VersionedReference versioned;
ArtifactReference artifact; ArtifactReference artifact;
try
{
artifact = layout.toArtifactReference( resource ); artifact = layout.toArtifactReference( resource );
if ( artifact != null ) if ( artifact != null )
{ {
connectors.fetchFromProxies( managedRepository, artifact ); connectors.fetchFromProxies( managedRepository, artifact );
return; return;
} }
}
catch ( LayoutException e )
{
/* eat it */
}
try
{
versioned = layout.toVersionedReference( resource ); versioned = layout.toVersionedReference( resource );
if ( versioned != null ) if ( versioned != null )
{ {
connectors.fetchFromProxies( managedRepository, versioned ); connectors.fetchFromProxies( managedRepository, versioned );
return; return;
} }
}
catch ( LayoutException e )
{
/* eat it */
}
try
{
project = layout.toProjectReference( resource ); project = layout.toProjectReference( resource );
if ( project != null ) if ( project != null )
{ {
@ -191,10 +192,10 @@ public class ProxiedDavServer
return; return;
} }
} }
catch ( ResourceDoesNotExistException e ) catch ( LayoutException e )
{ {
// return an HTTP 404 instead of HTTP 500 error. /* eat it */
return; }
} }
catch ( ProxyException e ) catch ( ProxyException e )
{ {