summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2013-04-25 11:30:11 +0000
committerOlivier Lamy <olamy@apache.org>2013-04-25 11:30:11 +0000
commitc237a7e1746894d49fd8e251d6252e1b761d3bac (patch)
tree8cdbffca559f31ed77eee36e6f69afe37f8318bf /archiva-modules/archiva-web/archiva-rest
parentde94fa3631b7a4862ae0397b4e13c62853f919a2 (diff)
downloadarchiva-c237a7e1746894d49fd8e251d6252e1b761d3bac.tar.gz
archiva-c237a7e1746894d49fd8e251d6252e1b761d3bac.zip
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
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java35
1 files changed, 35 insertions, 0 deletions
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 );