formatting
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/6e87a7ec Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/6e87a7ec Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/6e87a7ec Branch: refs/heads/master Commit: 6e87a7ecc06f6d544ffe809e370c329da7610575 Parents: de4f3c7 Author: Olivier Lamy <[email protected]> Authored: Thu Sep 4 12:09:34 2014 +1000 Committer: Olivier Lamy <[email protected]> Committed: Thu Sep 4 12:09:39 2014 +1000 ---------------------------------------------------------------------- .../providers/http/LightweightHttpWagon.java | 43 +++--- .../maven/wagon/shared/http/EncodingUtil.java | 131 +++++++++---------- .../wagon/shared/http/EncodingUtilTest.java | 50 +++---- .../webdav/AbstractHttpClientWagon.java | 36 +++-- 4 files changed, 129 insertions(+), 131 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/6e87a7ec/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java ---------------------------------------------------------------------- diff --git a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java index 76c46a4..758d618 100644 --- a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java +++ b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java @@ -19,6 +19,22 @@ package org.apache.maven.wagon.providers.http; * under the License. */ +import org.apache.commons.io.IOUtils; +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.InputData; +import org.apache.maven.wagon.OutputData; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.StreamWagon; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.events.TransferEvent; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.resource.Resource; +import org.apache.maven.wagon.shared.http.EncodingUtil; +import org.apache.maven.wagon.shared.http.HtmlFileListParser; +import org.codehaus.plexus.util.Base64; + import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -36,27 +52,10 @@ import java.util.List; import java.util.Properties; import java.util.zip.GZIPInputStream; -import org.apache.commons.io.IOUtils; -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.InputData; -import org.apache.maven.wagon.OutputData; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.StreamWagon; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.authentication.AuthenticationException; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.apache.maven.wagon.events.TransferEvent; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.resource.Resource; -import org.apache.maven.wagon.shared.http.EncodingUtil; -import org.apache.maven.wagon.shared.http.HtmlFileListParser; -import org.codehaus.plexus.util.Base64; - /** * LightweightHttpWagon, using JDK's HttpURLConnection. * * @author <a href="[email protected]">Michal Maczka</a> - * * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="http" instantiation-strategy="per-lookup" * @see HttpURLConnection */ @@ -96,7 +95,7 @@ public class LightweightHttpWagon */ private String buildUrl( Resource resource ) { - return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() ); + return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() ); } public void fillInputData( InputData inputData ) @@ -239,14 +238,12 @@ public class LightweightHttpWagon throw new AuthorizationException( "Access denied to: " + buildUrl( resource ) ); case HttpURLConnection.HTTP_NOT_FOUND: - throw new ResourceDoesNotExistException( - "File: " + buildUrl( resource ) + " does not exist" ); + throw new ResourceDoesNotExistException( "File: " + buildUrl( resource ) + " does not exist" ); // add more entries here default: throw new TransferFailedException( - "Failed to transfer file: " + buildUrl( resource ) + ". Return code is: " - + statusCode ); + "Failed to transfer file: " + buildUrl( resource ) + ". Return code is: " + statusCode ); } } catch ( IOException e ) @@ -382,7 +379,7 @@ public class LightweightHttpWagon try { Resource resource = new Resource( resourceName ); - URL url = new URL( buildUrl( resource ) ); + URL url = new URL( buildUrl( resource ) ); headConnection = (HttpURLConnection) url.openConnection( this.proxy ); addHeaders( headConnection ); http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/6e87a7ec/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java ---------------------------------------------------------------------- diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java index 951df99..e98b9a9 100644 --- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java +++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java @@ -1,12 +1,12 @@ package org.apache.maven.wagon.shared.http; +import org.apache.commons.lang.StringUtils; + import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import org.apache.commons.lang.StringUtils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -28,81 +28,80 @@ import org.apache.commons.lang.StringUtils; /** * Encoding utility. + * + * @since 2.7 */ public class EncodingUtil -{ - /** - * Parses and returns an encoded version of the given URL string. - * - * @param url Raw/decoded string form of a URL to parse/encode. - * @return Parsed/encoded {@link URI} that represents the string form URL passed in. - * @throws MalformedURLException - * @throws URISyntaxException - */ - public static URI encodeURL( String url ) throws MalformedURLException, URISyntaxException - { - URL urlObject = new URL(url); - - URI uriEncoded = new URI( - urlObject.getProtocol(), - urlObject.getAuthority(), - urlObject.getPath(), - urlObject.getQuery(), - urlObject.getRef() - ); +{ + /** + * Parses and returns an encoded version of the given URL string. + * + * @param url Raw/decoded string form of a URL to parse/encode. + * @return Parsed/encoded {@link URI} that represents the string form URL passed in. + * @throws MalformedURLException + * @throws URISyntaxException + */ + public static URI encodeURL( String url ) + throws MalformedURLException, URISyntaxException + { + URL urlObject = new URL( url ); + + URI uriEncoded = + new URI( urlObject.getProtocol(), // + urlObject.getAuthority(), // + urlObject.getPath(), // + urlObject.getQuery(), // + urlObject.getRef() ); + + return uriEncoded; + } + + /** + * Parses and returns an encoded version of the given URL string. + * Wraps the {@link MalformedURLException} and {@link URISyntaxException} in case the passed URL is invalid. + * + * @param url Raw/decoded string form of a URL to parse/encode. + * @return Parsed/encoded URI (as string) that represents the + * @throws IllegalArgumentException in case the URL string is invalid. + */ + public static String encodeURLToString( String url ) + { + try + { + return encodeURL( url ).toString(); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( String.format( "Error parsing url: %s", url ), e ); + } + } - return uriEncoded; - } - - /** - * Parses and returns an encoded version of the given URL string. - * Wraps the {@link MalformedURLException} and {@link URISyntaxException} in case the passed URL is invalid. - * - * @param url Raw/decoded string form of a URL to parse/encode. - * @return Parsed/encoded URI (as string) that represents the - * @throws IllegalArgumentException in case the URL string is invalid. - */ - public static String encodeURLToString( String url ) - { - try - { - return encodeURL( url ).toString(); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( String.format( "Error parsing url: %s", url ), e ); - } - } - - /** - * Parses and returns an encoded version of the given URL string alongside the given paths. - * - * @param baseUrl Base URL to use when constructing the final URL, ie: scheme://authority/initial.path. - * @param paths Additional path(s) to append at the end of the base path. - * @return Composed URL (base + paths) already encoded, separating the individual path components by "/". - * @since TODO - */ - public static String encodeURLToString( String baseUrl, String... paths ) - { + /** + * Parses and returns an encoded version of the given URL string alongside the given paths. + * + * @param baseUrl Base URL to use when constructing the final URL, ie: scheme://authority/initial.path. + * @param paths Additional path(s) to append at the end of the base path. + * @return Composed URL (base + paths) already encoded, separating the individual path components by "/". + * @since TODO + */ + public static String encodeURLToString( String baseUrl, String... paths ) + { StringBuilder url = new StringBuilder( baseUrl ); - - String[] parts = - paths == null ? - new String[0] : - paths.length == 1 ? - StringUtils.split( paths[0], "/" ) : - paths; - + + String[] parts = paths == null ? // + new String[0] : // + paths.length == 1 ? StringUtils.split( paths[0], "/" ) : paths; + for ( String part : parts ) { if ( !url.toString().endsWith( "/" ) ) { url.append( '/' ); } - + url.append( part ); } - + return encodeURLToString( url.toString() ); - } + } } http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/6e87a7ec/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java ---------------------------------------------------------------------- diff --git a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java index e14133e..f20f35f 100644 --- a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java +++ b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java @@ -19,31 +19,35 @@ package org.apache.maven.wagon.shared.http; * under the License. */ +import junit.framework.TestCase; + import java.net.MalformedURLException; import java.net.URISyntaxException; -import junit.framework.TestCase; +public class EncodingUtilTest + extends TestCase +{ + public void testEncodeURLWithSpaces() + throws URISyntaxException, MalformedURLException + { + String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/path with spaces" ); + + assertEquals( "file://host:1/path%20with%20spaces", encodedURL ); + } + + public void testEncodeURLWithSpacesInPath() + throws URISyntaxException, MalformedURLException + { + String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", "path with spaces" ); + + assertEquals( "file://host:1/path%20with%20spaces", encodedURL ); + } + + public void testEncodeURLWithSpacesInBothBaseAndPath() + throws URISyntaxException, MalformedURLException + { + String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/with a", "path with spaces" ); -public class EncodingUtilTest extends TestCase -{ - public void testEncodeURLWithSpaces() throws URISyntaxException, MalformedURLException - { - String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/path with spaces" ); - - assertEquals( "file://host:1/path%20with%20spaces", encodedURL ); - } - - public void testEncodeURLWithSpacesInPath() throws URISyntaxException, MalformedURLException - { - String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", "path with spaces" ); - - assertEquals( "file://host:1/path%20with%20spaces", encodedURL ); - } - - public void testEncodeURLWithSpacesInBothBaseAndPath() throws URISyntaxException, MalformedURLException - { - String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/with a", "path with spaces" ); - - assertEquals( "file://host:1/with%20a/path%20with%20spaces", encodedURL ); - } + assertEquals( "file://host:1/with%20a/path%20with%20spaces", encodedURL ); + } } http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/6e87a7ec/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java ---------------------------------------------------------------------- diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java index 85b3b76..35d1258 100644 --- a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java +++ b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagon.java @@ -19,20 +19,6 @@ package org.apache.maven.wagon.providers.webdav; * under the License. */ -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.Properties; -import java.util.TimeZone; -import java.util.zip.GZIPInputStream; - import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HostConfiguration; @@ -69,6 +55,20 @@ import org.apache.maven.wagon.repository.Repository; import org.apache.maven.wagon.resource.Resource; import org.apache.maven.wagon.shared.http.EncodingUtil; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.Properties; +import java.util.TimeZone; +import java.util.zip.GZIPInputStream; + /** * @author <a href="[email protected]">Michal Maczka</a> * @author <a href="mailto:[email protected]">James William Dumay</a> @@ -197,8 +197,6 @@ public abstract class AbstractHttpClientWagon // WAGON-273: default the cookie-policy to browser compatible client.getParams().setCookiePolicy( CookiePolicy.BROWSER_COMPATIBILITY ); - - String username = null; String password = null; String domain = null; @@ -321,8 +319,8 @@ public abstract class AbstractHttpClientWagon { RequestEntityImplementation requestEntityImplementation = new RequestEntityImplementation( stream, resource, this, source ); - - put( resource, source, requestEntityImplementation, buildUrl( resource ) ); + + put( resource, source, requestEntityImplementation, buildUrl( resource ) ); } @@ -334,7 +332,7 @@ public abstract class AbstractHttpClientWagon */ private String buildUrl( Resource resource ) { - return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() ); + return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() ); } private void put( Resource resource, File source, RequestEntityImplementation requestEntityImplementation,
