diff options
author | Olivier Lamy <olamy@apache.org> | 2013-12-09 02:46:56 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2013-12-09 02:46:56 +0000 |
commit | b256625132fefd7893b6149d1af6b6e4c77a0dd0 (patch) | |
tree | f8223392c381aff850081156d15d25dc8b0de85e /archiva-modules/plugins/maven2-repository/src | |
parent | 978ab1446b07ede86c1f4e5dbc277e9b476a4c3e (diff) | |
download | archiva-b256625132fefd7893b6149d1af6b6e4c77a0dd0.tar.gz archiva-b256625132fefd7893b6149d1af6b6e4c77a0dd0.zip |
[MRM-1761] Returned URL in search result does not work for SNAPSHOTS
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549368 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/maven2-repository/src')
-rw-r--r-- | archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java index 699f41bfc..30cc56958 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java @@ -35,6 +35,7 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.filter.Filter; import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; @@ -50,6 +51,8 @@ import org.apache.archiva.proxy.common.WagonFactory; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.content.PathParser; +import org.apache.archiva.repository.layout.LayoutException; import org.apache.archiva.xml.XMLException; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; @@ -131,6 +134,10 @@ public class Maven2RepositoryStorage @Inject private ApplicationContext applicationContext; + @Inject + @Named ( value = "pathParser#default") + private PathParser pathParser; + private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class ); private static final String METADATA_FILENAME_START = "maven-metadata"; @@ -757,6 +764,34 @@ public class Maven2RepositoryStorage } + public String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent ) + throws LayoutException, XMLException + { + String requestPathNoRepository = removePrefix( requestPath ); + ArtifactReference artifactReference = pathParser.toArtifactReference( requestPathNoRepository ); + + String filePath = getFilePath( requestPath, managedRepositoryContent.getRepository() ); + + if (StringUtils.endsWith( artifactReference.getVersion(), "SNAPSHOT" )) + { + // read maven metadata to get last timestamp + File metadataDir = new File( managedRepositoryContent.getRepoRoot(), filePath).getParentFile(); + ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( new File(metadataDir, METADATA_FILENAME ) ); + int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); + String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); + + // org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar + // -> archiva-checksum-1.4-M4-20130425.081822-1.jar + + filePath = StringUtils.replace( filePath, artifactReference.getArtifactId() + "-" + artifactReference.getVersion(), + artifactReference.getArtifactId() + "-" + StringUtils.remove( artifactReference.getVersion(), "-SNAPSHOT") + + "-" + timestamp + "-" + buildNumber ); + + } + + return filePath; + } + //----------------------------- @@ -1002,4 +1037,13 @@ public class Maven2RepositoryStorage } + public PathParser getPathParser() + { + return pathParser; + } + + public void setPathParser( PathParser pathParser ) + { + this.pathParser = pathParser; + } } |