From d5be37cf00e5b056005aab6f5fb064d37d946086 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 13 Apr 2005 07:03:18 +0000 Subject: [PATCH] PR: MNG-232 resolve snapshots in bootstrap git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163931 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/download/ArtifactDownloader.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/maven-mboot2/src/main/java/download/ArtifactDownloader.java b/maven-mboot2/src/main/java/download/ArtifactDownloader.java index b616a4b429..5a565cc421 100644 --- a/maven-mboot2/src/main/java/download/ArtifactDownloader.java +++ b/maven-mboot2/src/main/java/download/ArtifactDownloader.java @@ -2,9 +2,11 @@ package download; import model.Dependency; import model.Repository; +import util.FileUtils; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -82,7 +84,7 @@ public class ArtifactDownloader directory.mkdirs(); } - boolean snapshot = dep.getVersion().indexOf( SNAPSHOT_SIGNATURE ) >= 0; + boolean snapshot = isSnapshot( dep ); if ( dep.getGroupId().equals( "org.apache.maven" ) && snapshot ) { @@ -107,6 +109,11 @@ public class ArtifactDownloader } } + private static boolean isSnapshot( Dependency dep ) + { + return dep.getVersion().indexOf( SNAPSHOT_SIGNATURE ) >= 0; + } + private void setRemoteRepos( List repositories ) { remoteRepos = new ArrayList(); @@ -158,6 +165,27 @@ public class ArtifactDownloader // of the checksum file was successful. try { + if ( isSnapshot( dep ) ) + { + String filename = getSnapshotMetadataFile( destinationFile.getPath(), "SNAPSHOT.version.txt" ); + String metaUrl = getSnapshotMetadataFile( url, "SNAPSHOT.version.txt" ); + log( "Downloading " + metaUrl ); + try + { + HttpUtils.getFile( metaUrl, new File( filename ), ignoreErrors, useTimestamp, proxyHost, + proxyPort, proxyUserName, proxyPassword, true ); + String version = FileUtils.fileRead( filename ); + log( "Resolved version: " + version ); + version = version.substring( version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); + String extension = url.substring( url.length() - 4 ); + url = getSnapshotMetadataFile( url, version + extension ); + } + catch ( IOException e ) + { + log( "WARNING: SNAPSHOT version not found, using default" ); + } + } + log( "Downloading " + url ); HttpUtils.getFile( url, destinationFile, ignoreErrors, useTimestamp, proxyHost, proxyPort, proxyUserName, proxyPassword, true ); @@ -197,6 +225,12 @@ public class ArtifactDownloader return fileFound; } + private static String getSnapshotMetadataFile( String filename, String s ) + { + int index = filename.lastIndexOf( "SNAPSHOT" ); + return filename.substring( 0, index ) + s; + } + private String replace( String text, String repl, String with ) { StringBuffer buf = new StringBuffer( text.length() );