From c237a7e1746894d49fd8e251d6252e1b761d3bac Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 25 Apr 2013 11:30:11 +0000 Subject: [PATCH] try to use timestamped version if exist locally git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1475709 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/services/DefaultBrowseService.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index dba71ab8e..a9e6e042c 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder; +import org.apache.archiva.maven2.metadata.MavenMetadataReader; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.maven2.model.TreeEntry; import org.apache.archiva.metadata.generic.GenericMetadataFacet; @@ -38,11 +39,13 @@ import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMetadataVersionComparator; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.model.ArchivaArtifact; +import org.apache.archiva.model.ArchivaRepositoryMetadata; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.rest.api.model.ArtifactContent; import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; @@ -54,6 +57,7 @@ import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.BrowseService; import org.apache.archiva.rest.services.utils.ArtifactContentEntryComparator; import org.apache.archiva.security.ArchivaSecurityException; +import org.apache.archiva.xml.XMLException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -805,6 +809,37 @@ public class DefaultBrowseService return true; } + // in case of SNAPSHOT we can have timestamped version locally ! + if ( StringUtils.endsWith( version, VersionUtil.SNAPSHOT ) ) + { + File metadataFile = new File( file.getParent(), MetadataTools.MAVEN_METADATA ); + if ( metadataFile.exists() ) + { + try + { + ArchivaRepositoryMetadata archivaRepositoryMetadata = + MavenMetadataReader.read( metadataFile ); + int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); + String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); + // rebuild file name with timestamped version and build number + File timeStampFile = new File( file.getParent(), artifactId + "-" + StringUtils.remove( version, + "-" + + VersionUtil.SNAPSHOT ) + + "-" + timeStamp + "-" + Integer.toString( buildNumber ) + ( StringUtils.isEmpty( + classifier ) ? "" : "-" + classifier ) + ".jar" ); + + if ( timeStampFile.exists() ) + { + return true; + } + } + catch ( XMLException e ) + { + log.warn( "skip fail to find timestamped snapshot file: {}", e.getMessage() ); + } + } + } + String path = managedRepositoryContent.toPath( archivaArtifact ); file = connectors.fetchFromProxies( managedRepositoryContent, path ); -- 2.39.5