From 997774aa7bb0cf4828bc7148ddf39bc88636345f Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 12 Sep 2005 16:21:52 +0000 Subject: [PATCH] make sure local snapshot is used in mboot git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280362 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/download/ArtifactDownloader.java | 101 +++++++++--------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/maven-mboot2/src/main/java/download/ArtifactDownloader.java b/maven-mboot2/src/main/java/download/ArtifactDownloader.java index eb98fc16ea..e79959d72e 100644 --- a/maven-mboot2/src/main/java/download/ArtifactDownloader.java +++ b/maven-mboot2/src/main/java/download/ArtifactDownloader.java @@ -155,8 +155,10 @@ public class ArtifactDownloader catch ( IOException e ) { log( "WARNING: remote metadata version not found, using local: " + e.getMessage() ); + remoteFile.delete(); } + boolean legacy = false; File file = localFile; if ( remoteFile.exists() ) { @@ -165,78 +167,48 @@ public class ArtifactDownloader file = remoteFile; } } - - boolean found = false; - if ( file.exists() ) - { - log( "Using metadata: " + file ); - - RepositoryMetadata metadata; - metadata = RepositoryMetadata.read( file ); - - if ( version.equals( metadata.getVersion() ) ) - { - found = true; - version = metadata.constructVersion( version ); - log( "Resolved version: " + version ); - dep.setResolvedVersion( version ); - if ( !version.endsWith( "SNAPSHOT" ) ) - { - String ver = version.substring( - version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); - String extension = url.substring( url.length() - 4 ); - url = getSnapshotMetadataFile( url, ver + extension ); - } - else if ( destinationFile.exists() ) - { - // It's already there - return true; - } - } - else - { - log( "WARNING: versions did not match, not using metadata (" + version + " vs " + - metadata.getVersion() + ")" ); - } - } - - if ( !found ) + else { log( "WARNING: attempting to use legacy metadata" ); filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" ); - file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), - dep.getType(), filename ); + File f = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(), + dep.getVersion(), dep.getType(), filename ); metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getType(), filename ); metaUrl = remoteRepo.getBasedir() + "/" + metadataPath; log( "Downloading " + metaUrl ); try { - HttpUtils.getFile( metaUrl, file, ignoreErrors, true, proxyHost, proxyPort, proxyUserName, + HttpUtils.getFile( metaUrl, f, ignoreErrors, true, proxyHost, proxyPort, proxyUserName, proxyPassword, false ); } catch ( IOException e ) { log( "WARNING: remote SNAPSHOT version not found, using local: " + e.getMessage() ); + f.delete(); } - if ( file.exists() ) + if ( f.exists() ) { - version = FileUtils.fileRead( file ); - log( "Resolved version: " + version ); - dep.setResolvedVersion( version ); - if ( !version.endsWith( "SNAPSHOT" ) ) + if ( !localFile.exists() || localFile.lastModified() < f.lastModified() ) { - String ver = version.substring( - version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); - String extension = url.substring( url.length() - 4 ); - url = getSnapshotMetadataFile( url, ver + extension ); - } - else if ( destinationFile.exists() ) - { - // It's already there - return true; + version = FileUtils.fileRead( f ); + log( "Resolved version: " + version ); + dep.setResolvedVersion( version ); + if ( !version.endsWith( "SNAPSHOT" ) ) + { + String ver = version.substring( + version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); + String extension = url.substring( url.length() - 4 ); + url = getSnapshotMetadataFile( url, ver + extension ); + } + else if ( destinationFile.exists() ) + { + // It's already there + return true; + } + legacy = true; } } else @@ -244,6 +216,29 @@ public class ArtifactDownloader log( "WARNING: local SNAPSHOT version not found, using default" ); } } + + if ( !legacy && file.exists() ) + { + log( "Using metadata: " + file ); + + RepositoryMetadata metadata = RepositoryMetadata.read( file ); + + version = metadata.constructVersion( version ); + log( "Resolved version: " + version ); + dep.setResolvedVersion( version ); + if ( !version.endsWith( "SNAPSHOT" ) ) + { + String ver = version.substring( + version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); + String extension = url.substring( url.length() - 4 ); + url = getSnapshotMetadataFile( url, ver + extension ); + } + else if ( destinationFile.exists() ) + { + // It's already there + return true; + } + } } if ( !"pom".equals( dep.getType() ) ) {