archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r530916 - in /maven/archiva/branches/archiva-jpox-database-refactor: archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/ archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/
Date Fri, 20 Apr 2007 20:55:15 GMT
Author: joakime
Date: Fri Apr 20 13:55:14 2007
New Revision: 530916

URL: http://svn.apache.org/viewvc?view=rev&rev=530916
Log:
Adding VersionedReference metadata to .fetchFromProxies()


Modified:
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java?view=diff&rev=530916&r1=530915&r2=530916
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
(original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
Fri Apr 20 13:55:14 2007
@@ -27,6 +27,7 @@
 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.layout.BidirectionalRepositoryLayout;
@@ -70,8 +71,6 @@
     extends AbstractLogEnabled
     implements RepositoryProxyConnectors, RegistryListener, Initializable
 {
-    private static final String FILENAME_MAVEN_METADATA = "maven-metadata.xml";
-
     /**
      * @plexus.requirement
      */
@@ -166,6 +165,59 @@
 
         return null;
     }
+    
+    public File fetchFromProxies( ArchivaRepository repository, VersionedReference 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,
+                                                    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
@@ -179,7 +231,7 @@
         try
         {
             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 );
         }
         catch ( LayoutException e )
@@ -199,7 +251,7 @@
             try
             {
                 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 );

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java?view=diff&rev=530916&r1=530915&r2=530916
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
(original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
Fri Apr 20 13:55:14 2007
@@ -22,6 +22,7 @@
 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 java.io.File;
 import java.util.List;
@@ -47,6 +48,21 @@
      * @throws ProxyException if there was a problem fetching the content from the target
repositories.
      */
     public File fetchFromProxies( ArchivaRepository repository, ArtifactReference artifact
)
+        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;
     
     /**

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java?view=diff&rev=530916&r1=530915&r2=530916
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
(original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ProxiedDavServer.java
Fri Apr 20 13:55:14 2007
@@ -19,25 +19,19 @@
  * under the License.
  */
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 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.ArchivaRepositoryMetadata;
 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.proxy.ProxyConnector;
 import org.apache.maven.archiva.proxy.ProxyException;
 import org.apache.maven.archiva.proxy.RepositoryProxyConnectors;
 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;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.codehaus.plexus.webdav.AbstractDavServerComponent;
 import org.codehaus.plexus.webdav.DavServerComponent;
 import org.codehaus.plexus.webdav.DavServerException;
@@ -46,10 +40,6 @@
 
 import java.io.File;
 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.ServletException;
@@ -61,8 +51,8 @@
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @version $Id$
  * @plexus.component role="org.codehaus.plexus.webdav.DavServerComponent"
- * role-hint="proxied"
- * instantiation-strategy="per-lookup"
+ *                   role-hint="proxied"
+ *                   instantiation-strategy="per-lookup"
  */
 public class ProxiedDavServer
     extends AbstractDavServerComponent
@@ -93,8 +83,6 @@
 
     private ArchivaRepository managedRepository;
 
-    private List/*<ArtifactRepository>*/proxiedRepositories;
-
     public String getPrefix()
     {
         return davServer.getPrefix();
@@ -120,8 +108,6 @@
     {
         davServer.init( servletConfig );
 
-        proxiedRepositories = new ArrayList();
-
         Configuration config = archivaConfiguration.getConfiguration();
 
         repositoryConfiguration = config.findRepositoryById( getPrefix() );
@@ -156,45 +142,60 @@
         throws ServletException
     {
         String resource = request.getLogicalResource();
-        
-        if( resource.endsWith( ".sha1" ) ||
-            resource.endsWith( ".md5") )
+
+        if ( resource.endsWith( ".sha1" ) || resource.endsWith( ".md5" ) )
         {
             // Checksums are fetched with artifact / metadata.
             return;
         }
-        
+
         try
         {
             ProjectReference project;
             VersionedReference versioned;
             ArtifactReference artifact;
-            
-            artifact = layout.toArtifactReference( resource );
-            if( artifact != null )
-            {
-                connectors.fetchFromProxies( managedRepository, artifact );
-                return;
-            }
-            
-            versioned = layout.toVersionedReference( resource );
-            if( versioned != null )
-            {
-                connectors.fetchFromProxies( managedRepository, versioned );
-                return;
-            }
-            
-            project = layout.toProjectReference( resource );
-            if( project != null )
+
+            try
             {
-                connectors.fetchFromProxies( managedRepository, project );
-                return;
+                artifact = layout.toArtifactReference( resource );
+                if ( artifact != null )
+                {
+                    connectors.fetchFromProxies( managedRepository, artifact );
+                    return;
+                }
+            }
+            catch ( LayoutException e )
+            {
+                /* eat it */
+            }
+
+            try
+            {
+                versioned = layout.toVersionedReference( resource );
+                if ( versioned != null )
+                {
+                    connectors.fetchFromProxies( managedRepository, versioned );
+                    return;
+                }
+            }
+            catch ( LayoutException e )
+            {
+                /* eat it */
+            }
+
+            try
+            {
+                project = layout.toProjectReference( resource );
+                if ( project != null )
+                {
+                    connectors.fetchFromProxies( managedRepository, project );
+                    return;
+                }
+            }
+            catch ( LayoutException e )
+            {
+                /* eat it */
             }
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            // return an HTTP 404 instead of HTTP 500 error.
-            return;
         }
         catch ( ProxyException e )
         {



Mime
View raw message