]> source.dussan.org Git - archiva.git/commitdiff
[MRM-242] Replace the proxy url of the Download link into the absolute url
authorBrett Porter <brett@apache.org>
Mon, 11 Dec 2006 06:43:39 +0000 (06:43 +0000)
committerBrett Porter <brett@apache.org>
Mon, 11 Dec 2006 06:43:39 +0000 (06:43 +0000)
Submitted by: Nap Ramirez (applied with modifications)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@485529 13f79535-47bb-0310-9956-ffa450edef68

archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp

index 42adbb776b1ec4e690a005f2242a40e37bd4a335..70b413100f7f3bc22956af83e30608d788a346b1 100644 (file)
@@ -16,6 +16,7 @@ package org.apache.maven.archiva.web.action;
  * limitations under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.TermQuery;
 import org.apache.maven.archiva.configuration.Configuration;
@@ -28,6 +29,7 @@ import org.apache.maven.archiva.indexer.RepositoryIndexException;
 import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
 import org.apache.maven.archiva.indexer.lucene.LuceneQuery;
 import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
+import org.apache.maven.archiva.proxy.ProxyException;
 import org.apache.maven.archiva.web.util.VersionMerger;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -35,6 +37,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactCollector;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
@@ -46,7 +49,7 @@ import org.apache.maven.shared.dependency.tree.DependencyNode;
 import org.apache.maven.shared.dependency.tree.DependencyTree;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
 import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.apache.commons.lang.StringUtils;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
@@ -102,12 +105,17 @@ public class ShowArtifactAction
      * @plexus.requirement
      */
     private ArtifactCollector collector;
-    
+
     /**
      * @plexus.requirement
      */
     private DependencyTreeBuilder dependencyTreeBuilder;
 
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactResolver artifactResolver;
+
     private String groupId;
 
     private String artifactId;
@@ -117,11 +125,16 @@ public class ShowArtifactAction
     private Model model;
 
     private Collection dependencies;
-    
+
     private List dependencyTree;
 
+    private String repositoryId;
+
+    private String artifactPath;
+
     public String artifact()
-        throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
+        throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException,
+        ResourceDoesNotExistException, ProxyException, ArtifactResolutionException
     {
         if ( !checkParameters() )
         {
@@ -132,6 +145,26 @@ public class ShowArtifactAction
 
         model = project.getModel();
 
+        Configuration configuration = configurationStore.getConfigurationFromStore();
+        List repositories = repositoryFactory.createRepositories( configuration );
+
+        Artifact artifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
+                                                                 project.getVersion(), project.getPackaging() );
+
+        for ( Iterator i = repositories.iterator(); i.hasNext(); )
+        {
+            ArtifactRepository repository = (ArtifactRepository) i.next();
+
+            String path = repository.pathOf( artifact );
+            File f = new File( repository.getBasedir(), path );
+            if ( f.exists() )
+            {
+                repositoryId = repository.getId();
+
+                artifactPath = path;
+            }
+        }
+
         return SUCCESS;
     }
 
@@ -148,7 +181,7 @@ public class ShowArtifactAction
         model = project.getModel();
 
         // TODO: should this be the whole set of artifacts, and be more like the maven dependencies report?
-        this.dependencies = VersionMerger.wrap(project.getModel().getDependencies());
+        this.dependencies = VersionMerger.wrap( project.getModel().getDependencies() );
 
         return SUCCESS;
     }
@@ -171,7 +204,7 @@ public class ShowArtifactAction
         String id = createId( groupId, artifactId, version );
         List records = index.search( new LuceneQuery( new TermQuery( new Term( "dependencies", id ) ) ) );
 
-        dependencies = VersionMerger.merge(records);
+        dependencies = VersionMerger.merge( records );
 
         return SUCCESS;
     }
@@ -197,11 +230,10 @@ public class ShowArtifactAction
 
         getLogger().debug( " processing : " + groupId + ":" + artifactId + ":" + version );
 
-        DependencyTree dependencies =
-            collectDependencies( project, artifact, localRepository, repositories );
-        
+        DependencyTree dependencies = collectDependencies( project, artifact, localRepository, repositories );
+
         this.dependencyTree = new ArrayList();
-        
+
         populateFlatTreeList( dependencies.getRootNode(), dependencyTree );
 
         return SUCCESS;
@@ -220,7 +252,7 @@ public class ShowArtifactAction
     }
 
     private DependencyTree collectDependencies( MavenProject project, Artifact artifact,
-                                              ArtifactRepository localRepository, List repositories )
+                                                ArtifactRepository localRepository, List repositories )
         throws ArtifactResolutionException, ProjectBuildingException, InvalidDependencyVersionException,
         ConfigurationStoreException
     {
@@ -323,7 +355,7 @@ public class ShowArtifactAction
     {
         return dependencyTree;
     }
-    
+
     public String getVersion()
     {
         return version;
@@ -334,6 +366,11 @@ public class ShowArtifactAction
         this.version = version;
     }
 
+    public String getArtifactPath()
+    {
+        return artifactPath;
+    }
+
     public static class DependencyWrapper
     {
         private final String groupId;
@@ -473,4 +510,8 @@ public class ShowArtifactAction
         }
     }
 
+    public String getRepositoryId()
+    {
+        return repositoryId;
+    }
 }
index 7c1993d7f9b36815110e061c628b0969a2ec14e3..b2abc19b6d798b47898b495628a46f160c99906a 100644 (file)
 
 <div class="sidebar3">
   <div id="download">
-    <c:set var="url">
-      <ww:url action="proxy">
-        <%-- TODO! create a tag for this, include classifier for javadoc, sources below --%>
-        <%-- TODO: what about other repositories? --%>
-        <%-- TODO! extension probably doesn't match type. Use artifact handler instead. --%>
-        <ww:param name="path"
-                  value="%{'${model.groupId}/${model.artifactId}/${model.version}/${model.artifactId}-${model.version}.${model.packaging}'}"/>
-      </ww:url>
-    </c:set>
+    <%-- TODO! create a tag for this, include classifier for javadoc, sources below --%>
+    <c:url var="url" value="/repository/${repositoryId}/${artifactPath}"/>
     <a href="${url}">Download</a>
   </div>
 </div>