From 41a3a997dc97d72356129d3b7227ad7a5cea3776 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 11 Dec 2006 06:43:39 +0000 Subject: [PATCH] [MRM-242] Replace the proxy url of the Download link into the absolute url 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 --- .../web/action/ShowArtifactAction.java | 65 +++++++++++++++---- .../main/webapp/WEB-INF/jsp/showArtifact.jsp | 11 +--- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index 42adbb776..70b413100 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -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; + } } diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp index 7c1993d7f..b2abc19b6 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -70,15 +70,8 @@
- - - <%-- 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. --%> - - - + <%-- TODO! create a tag for this, include classifier for javadoc, sources below --%> + Download
-- 2.39.5