From 86536e319fbc2415567452ea19a1c8093234165c Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 13 Apr 2005 12:32:26 +0000 Subject: [PATCH] turn off caching in mboot for snapshot version files git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163940 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/download/ArtifactDownloader.java | 2 +- .../src/main/java/download/HttpUtils.java | 72 +++++-------------- 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/maven-mboot2/src/main/java/download/ArtifactDownloader.java b/maven-mboot2/src/main/java/download/ArtifactDownloader.java index 5a565cc421..bafd04e429 100644 --- a/maven-mboot2/src/main/java/download/ArtifactDownloader.java +++ b/maven-mboot2/src/main/java/download/ArtifactDownloader.java @@ -173,7 +173,7 @@ public class ArtifactDownloader try { HttpUtils.getFile( metaUrl, new File( filename ), ignoreErrors, useTimestamp, proxyHost, - proxyPort, proxyUserName, proxyPassword, true ); + proxyPort, proxyUserName, proxyPassword, false ); String version = FileUtils.fileRead( filename ); log( "Resolved version: " + version ); version = version.substring( version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 ); diff --git a/maven-mboot2/src/main/java/download/HttpUtils.java b/maven-mboot2/src/main/java/download/HttpUtils.java index 906d6a592b..aa474ed0e2 100644 --- a/maven-mboot2/src/main/java/download/HttpUtils.java +++ b/maven-mboot2/src/main/java/download/HttpUtils.java @@ -52,9 +52,7 @@ public class HttpUtils * @throws SecurityException if an operation is not authorized by the * SecurityManager */ - public static void useProxyUser( final String proxyHost, - final String proxyPort, - final String proxyUserName, + public static void useProxyUser( final String proxyHost, final String proxyPort, final String proxyUserName, final String proxyPassword ) { if ( proxyHost != null && proxyPort != null ) @@ -70,7 +68,8 @@ public class HttpUtils protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( proxyUserName, - proxyPassword == null ? new char[0] : proxyPassword.toCharArray() ); + proxyPassword == null + ? new char[0] : proxyPassword.toCharArray() ); } } ); } @@ -97,26 +96,13 @@ public class HttpUtils * artifact if it is available. * @throws IOException If an I/O exception occurs. */ - public static void getFile( String url, - File destinationFile, - boolean ignoreErrors, - boolean useTimestamp, - String proxyHost, - String proxyPort, - String proxyUserName, - String proxyPassword, + public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp, + String proxyHost, String proxyPort, String proxyUserName, String proxyPassword, boolean useChecksum ) throws IOException { // Get the requested file. - getFile( url, - destinationFile, - ignoreErrors, - useTimestamp, - proxyHost, - proxyPort, - proxyUserName, - proxyPassword ); + getFile( url, destinationFile, ignoreErrors, useTimestamp, proxyHost, proxyPort, proxyUserName, proxyPassword ); // Get the checksum if requested. if ( useChecksum ) @@ -125,13 +111,7 @@ public class HttpUtils try { - getFile( url + ".md5", - checksumFile, - ignoreErrors, - useTimestamp, - proxyHost, - proxyPort, - proxyUserName, + getFile( url + ".md5", checksumFile, ignoreErrors, useTimestamp, proxyHost, proxyPort, proxyUserName, proxyPassword ); } catch ( Exception e ) @@ -160,14 +140,8 @@ public class HttpUtils * or null * @throws IOException If an I/O exception occurs. */ - public static void getFile( String url, - File destinationFile, - boolean ignoreErrors, - boolean useTimestamp, - String proxyHost, - String proxyPort, - String proxyUserName, - String proxyPassword ) + public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp, + String proxyHost, String proxyPort, String proxyUserName, String proxyPassword ) throws IOException { //set the timestamp to the file date. @@ -179,13 +153,7 @@ public class HttpUtils try { - getFile( url, - destinationFile, - timestamp, - proxyHost, - proxyPort, - proxyUserName, - proxyPassword ); + getFile( url, destinationFile, timestamp, proxyHost, proxyPort, proxyUserName, proxyPassword ); } catch ( IOException ex ) { @@ -212,13 +180,8 @@ public class HttpUtils * or null * @throws IOException If an I/O exception occurs. */ - public static void getFile( String url, - File destinationFile, - long timestamp, - String proxyHost, - String proxyPort, - String proxyUserName, - String proxyPassword ) + public static void getFile( String url, File destinationFile, long timestamp, String proxyHost, String proxyPort, + String proxyUserName, String proxyPassword ) throws IOException { String[] s = parseUrl( url ); @@ -247,6 +210,8 @@ public class HttpUtils connection.setRequestProperty( "Authorization", "Basic " + encoding ); } + connection.setUseCaches( timestamp >= 0 ); + //connect to the remote site (may take some time) connection.connect(); //next test for a 304 result (HTTP only) @@ -258,8 +223,10 @@ public class HttpUtils // test for 404 ourselves, and throw FileNotFoundException as needed if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND ) { - throw new FileNotFoundException( url.toString() + " (HTTP Error: " - + httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage() + ")" ); + throw new FileNotFoundException( + url.toString() + " (HTTP Error: " + httpConnection.getResponseCode() + " " + + httpConnection.getResponseMessage() + + ")" ); } if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED ) { @@ -301,8 +268,7 @@ public class HttpUtils throw isException; } - if ( connection.getLastModified() <= timestamp && - connection.getLastModified() != 0 ) + if ( connection.getLastModified() <= timestamp && connection.getLastModified() != 0 ) { return; }