You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/08/15 04:59:06 UTC

svn commit: r431499 - in /maven/repository-manager/trunk: maven-repository-core/src/main/java/org/apache/maven/repository/ maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ maven-repository-core/src/main/java/org/apache/mav...

Author: brett
Date: Mon Aug 14 19:59:06 2006
New Revision: 431499

URL: http://svn.apache.org/viewvc?rev=431499&view=rev
Log:
[MRM-138] add proxy to the webapp

Added:
    maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java   (with props)
Modified:
    maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java
    maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java
    maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java
    maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
    maven/repository-manager/trunk/maven-repository-webapp/pom.xml
    maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java
    maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml

Modified: maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java (original)
+++ maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java Mon Aug 14 19:59:06 2006
@@ -21,32 +21,32 @@
     implements RepositoryManager
 {
     /**
-     * @plexus.requirement role="org.apache.maven.artifact.repository.discovery.ArtifactDiscoverer" role-hint="legacy"
+     * @plexus.requirement role-hint="legacy"
      */
     private ArtifactDiscoverer artifactDiscoverer;
 
     /**
-     * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" role-hint="legacy"
+     * @plexus.requirement role-hint="legacy"
      */
     private ArtifactRepositoryLayout legacyLayout;
 
     /**
-     * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" role-hint="default"
+     * @plexus.requirement role-hint="default"
      */
     private ArtifactRepositoryLayout defaultLayout;
 
     /**
-     * @plexus.requirement role="org.apache.maven.artifact.repository.ArtifactRepositoryFactory"
+     * @plexus.requirement
      */
     private ArtifactRepositoryFactory artifactRepositoryFactory;
 
     /**
-     * @plexus.requirement role="org.apache.maven.repository.converter.ArtifactRepositoryFactory"
+     * @plexus.requirement
      */
     private RepositoryConverter repositoryConverter;
 
     /**
-     * @plexus.requirement role="org.apache.maven.artifact.repository.reporter.ArtifactReporter" role-hint="default"
+     * @plexus.requirement role-hint="default"
      */
     private ArtifactReporter reporter;
 

Modified: maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java (original)
+++ maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java Mon Aug 14 19:59:06 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.proxy.ProxiedArtifactRepository;
 
 import java.util.List;
 
@@ -59,7 +60,7 @@
      * @param configuration the configuration
      * @return the artifact repository
      */
-    ArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration );
+    ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration );
 
     /**
      * Create artifact repositories from the given proxy repository configurations.

Modified: maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java (original)
+++ maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java Mon Aug 14 19:59:06 2006
@@ -20,6 +20,7 @@
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.repository.proxy.ProxiedArtifactRepository;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -55,7 +56,7 @@
         return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null );
     }
 
-    public ArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
+    public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration )
     {
         boolean enabled = isEnabled( configuration.getSnapshotsPolicy() );
         String updatePolicy =
@@ -69,8 +70,15 @@
             new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
 
         ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() );
-        return repoFactory.createArtifactRepository( configuration.getId(), configuration.getUrl(), layout,
-                                                     snapshotsPolicy, releasesPolicy );
+        ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(),
+                                                                                      configuration.getUrl(), layout,
+                                                                                      snapshotsPolicy, releasesPolicy );
+        ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository );
+        repository.setCacheFailures( configuration.isCacheFailures() );
+        repository.setHardFail( configuration.isHardFail() );
+        repository.setName( configuration.getName() );
+        repository.setUseNetworkProxy( configuration.isUseNetworkProxy() );
+        return repository;
     }
 
     public List createRepositories( Configuration configuration )

Modified: maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java (original)
+++ maven/repository-manager/trunk/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java Mon Aug 14 19:59:06 2006
@@ -51,7 +51,8 @@
     private ConfigurationStore configurationStore;
 
     /**
-     * @plexus.requirement
+     * @plexus.requirement role="org.apache.maven.repository.proxy.ProxyRequestHandler"
+     * @todo seems to be a bug in qdox that the role above is required
      */
     private ProxyRequestHandler requestHandler;
 
@@ -61,22 +62,40 @@
     private ConfiguredRepositoryFactory repositoryFactory;
 
     /**
-     * The proxy handlers for each managed repository.
+     * The proxy groups for each managed repository.
      */
     private Map/*<String,ProxiedRepositoryGroup>*/ proxyGroups;
 
+    /**
+     * The default proxy group/managed repository.
+     */
+    private ProxiedRepositoryGroup defaultProxyGroup;
+
     public File get( String path )
         throws ProxyException, ResourceDoesNotExistException
     {
         assert path.startsWith( "/" );
 
-        Map groups = getProxyRepositoryHandlers();
+        Map groups = getProxyGroups();
 
-        String id = parseRepositoryId( path, groups );
+        ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups );
 
-        String repositoryPath = path.substring( id.length() + 2 );
-
-        ProxiedRepositoryGroup proxyGroup = (ProxiedRepositoryGroup) groups.get( id );
+        String repositoryPath = path;
+        if ( proxyGroup == null )
+        {
+            if ( defaultProxyGroup != null )
+            {
+                proxyGroup = defaultProxyGroup;
+            }
+            else
+            {
+                throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+            }
+        }
+        else
+        {
+            repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 );
+        }
 
         return requestHandler.get( repositoryPath, proxyGroup.getProxiedRepositories(),
                                    proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() );
@@ -87,13 +106,26 @@
     {
         assert path.startsWith( "/" );
 
-        Map groups = getProxyRepositoryHandlers();
-
-        String id = parseRepositoryId( path, groups );
+        Map groups = getProxyGroups();
 
-        String repositoryPath = path.substring( id.length() + 2 );
+        ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups );
 
-        ProxiedRepositoryGroup proxyGroup = (ProxiedRepositoryGroup) groups.get( id );
+        String repositoryPath = path;
+        if ( proxyGroup == null )
+        {
+            if ( defaultProxyGroup != null )
+            {
+                proxyGroup = defaultProxyGroup;
+            }
+            else
+            {
+                throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+            }
+        }
+        else
+        {
+            repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 );
+        }
 
         return requestHandler.getAlways( repositoryPath, proxyGroup.getProxiedRepositories(),
                                          proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() );
@@ -115,7 +147,7 @@
         return configuration;
     }
 
-    private Map getProxyRepositoryHandlers()
+    private Map getProxyGroups()
         throws ProxyException
     {
         if ( proxyGroups == null )
@@ -137,6 +169,13 @@
                             new ProxiedRepositoryGroup( proxiedRepositories, managedRepository, wagonProxy ) );
             }
 
+            // TODO: ability to configure default proxy separately
+
+            if ( groups.size() == 1 )
+            {
+                defaultProxyGroup = (ProxiedRepositoryGroup) groups.values().iterator().next();
+            }
+
             proxyGroups = groups;
         }
         return proxyGroups;
@@ -157,19 +196,22 @@
         return repositories;
     }
 
-    private static String parseRepositoryId( String path, Map handlers )
+    private static ProxiedRepositoryGroup parseRepositoryId( String path, Map groups )
         throws ProxyException, ResourceDoesNotExistException
     {
-        for ( Iterator i = handlers.keySet().iterator(); i.hasNext(); )
+        ProxiedRepositoryGroup group = null;
+
+        for ( Iterator i = groups.entrySet().iterator(); i.hasNext() && group == null; )
         {
-            String id = (String) i.next();
+            Map.Entry entry = (Map.Entry) i.next();
 
-            if ( path.startsWith( "/" + id + "/" ) )
+            if ( path.startsWith( "/" + entry.getKey() + "/" ) )
             {
-                return id;
+                group = (ProxiedRepositoryGroup) entry.getValue();
             }
         }
-        throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path );
+
+        return group;
     }
 
     private static ProxyInfo createWagonProxy( Proxy proxy )

Modified: maven/repository-manager/trunk/maven-repository-webapp/pom.xml
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/pom.xml?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/pom.xml Mon Aug 14 19:59:06 2006
@@ -59,6 +59,12 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http-lightweight</artifactId>
+      <version>1.0-beta-1</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-file</artifactId>
       <version>1.0-beta-1</version>
       <scope>runtime</scope>

Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java?rev=431499&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java (added)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java Mon Aug 14 19:59:06 2006
@@ -0,0 +1,104 @@
+package org.apache.maven.repository.manager.web.action;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.opensymphony.xwork.ActionSupport;
+import org.apache.maven.repository.proxy.ProxyException;
+import org.apache.maven.repository.proxy.ProxyManager;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * Proxy functionality.
+ *
+ * @plexus.component role="com.opensymphony.xwork.Action" role-hint="proxyAction"
+ */
+public class ProxyAction
+    extends ActionSupport
+{
+    /**
+     * @plexus.requirement
+     */
+    private ProxyManager proxyManager;
+
+    private String path;
+
+    private String filename;
+
+    private String contentType;
+
+    private static final String NOT_FOUND = "notFound";
+
+    private InputStream artifactStream;
+
+    public String execute()
+        throws ProxyException
+    {
+        try
+        {
+            File file = proxyManager.get( path );
+
+            artifactStream = new FileInputStream( file );
+
+            // TODO: could be better
+            contentType = "application/octet-stream";
+
+            filename = file.getName();
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            // TODO: set message?
+            return NOT_FOUND;
+        }
+        catch ( FileNotFoundException e )
+        {
+            // TODO: set message?
+            return NOT_FOUND;
+        }
+
+        return SUCCESS;
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath( String path )
+    {
+        this.path = path;
+    }
+
+    public String getFilename()
+    {
+        return filename;
+    }
+
+    public String getContentType()
+    {
+        return contentType;
+    }
+
+    public InputStream getArtifactStream()
+    {
+        return artifactStream;
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java Mon Aug 14 19:59:06 2006
@@ -33,6 +33,8 @@
 {
     private static final String BROWSE_PREFIX = "/browse/";
 
+    private static final String PROXY_PREFIX = "/proxy/";
+
     public String getUriFromActionMapping( ActionMapping actionMapping )
     {
         Map params = actionMapping.getParams();
@@ -49,6 +51,10 @@
             return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
                 params.remove( "version" );
         }
+        else if ( "proxy".equals( actionMapping.getName() ) )
+        {
+            return PROXY_PREFIX + params.remove( "path" );
+        }
 
         return super.getUriFromActionMapping( actionMapping );
     }
@@ -88,6 +94,15 @@
                     return new ActionMapping( "showArtifact", "/", "", params );
                 }
             }
+        }
+        else if ( path.startsWith( PROXY_PREFIX ) )
+        {
+            // retain the leading /
+            path = path.substring( PROXY_PREFIX.length() - 1 );
+
+            Map params = new HashMap();
+            params.put( "path", path );
+            return new ActionMapping( "proxy", "/", "", params );
         }
 
         return super.getMapping( httpServletRequest );

Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml?rev=431499&r1=431498&r2=431499&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml (original)
+++ maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/xwork.xml Mon Aug 14 19:59:06 2006
@@ -111,17 +111,15 @@
       <result>/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
 
-    <!-- TODO! old actions
-    <action name="proxy" class="org.apache.maven.repository.proxy.web.action.RepositoryProxyAction">
-      <result name="success" type="stream">
-        <param name="contentType">application/octet-stream</param>
+    <action name="proxy" class="proxyAction">
+      <result type="stream">
+        <param name="contentType">${contentType}</param>
+        <param name="contentDisposition">filename="${filename}"</param>
         <param name="inputName">artifactStream</param>
         <param name="bufferSize">1024</param>
       </result>
-      <result name="notFound" type="dispatcher">notFoundError</result>
-      <result name="proxyError" type="dispatcher">proxyError</result>
+      <result name="notFound" type="httpheader">404</result>
     </action>
-    -->
   </package>
 
   <!-- Configuration for the admin package. -->