RepositoryURL updates.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@528631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-04-13 19:50:44 +00:00
parent 46c9341c34
commit e0fc78b02c
3 changed files with 127 additions and 4 deletions

View File

@ -112,4 +112,16 @@ public class ArchivaRepository
{
return this.model.getName();
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append( "ArchivaRepository[" );
sb.append( this.model.getId() ).append( "," );
sb.append( this.model.getUrl() );
sb.append( "]" );
return sb.toString();
}
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.archiva.model;
* under the License.
*/
/**
* RepositoryURL - Mutable (and protocol forgiving) URL object.
*
@ -50,7 +49,7 @@ public class RepositoryURL
int pos;
pos = url.indexOf( "://" );
pos = url.indexOf( ":/" );
if ( pos == ( -1 ) )
{
throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
@ -58,8 +57,23 @@ public class RepositoryURL
protocol = url.substring( 0, pos );
// Determine the post protocol position.
int postProtocolPos = protocol.length() + 1;
while ( url.charAt( postProtocolPos ) == '/' )
{
postProtocolPos++;
}
// Handle special case with file protocol (which has no host, port, username, or password)
if ( "file".equals( protocol ) )
{
path = "/" + url.substring( postProtocolPos );
return;
}
// attempt to find the start of the 'path'
pos = url.indexOf( "/", protocol.length() + 3 );
pos = url.indexOf( "/", postProtocolPos );
// no path specified - ex "http://localhost"
if ( pos == ( -1 ) )
@ -76,7 +90,7 @@ public class RepositoryURL
}
// get the middle section ( username : password @ hostname : port )
String middle = url.substring( protocol.length() + 3, pos );
String middle = url.substring( postProtocolPos, pos );
pos = middle.indexOf( '@' );

View File

@ -0,0 +1,97 @@
package org.apache.maven.archiva.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import junit.framework.TestCase;
/**
* RepositoryURLTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class RepositoryURLTest
extends TestCase
{
private static final String NO_HOST = null;
private static final String NO_PORT = null;
private static final String NO_USER = null;
private static final String NO_PASS = null;
private void assertURL( String url, String expectedProtocol, String expectedHost, String expectedPort,
String expectedPath, String expectedUsername, String expectedPassword )
{
RepositoryURL rurl = new RepositoryURL( url );
assertEquals( "Protocol", expectedProtocol, rurl.getProtocol() );
assertEquals( "Host", expectedHost, rurl.getHost() );
assertEquals( "Port", expectedPort, rurl.getPort() );
assertEquals( "Path", expectedPath, rurl.getPath() );
assertEquals( "Username", expectedUsername, rurl.getUsername() );
assertEquals( "Password", expectedPassword, rurl.getPassword() );
}
public void testFileUrlNormal()
{
assertURL( "file:///home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
NO_USER, NO_PASS );
}
public void testFileUrlShort()
{
assertURL( "file:/home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
NO_USER, NO_PASS );
}
public void testHttpUrlPathless()
{
assertURL( "http://machine", "http", "machine", NO_PORT, "/", NO_USER, NO_PASS );
}
public void testHttpUrlWithPort()
{
assertURL( "http://machine:8080/", "http", "machine", "8080", "/", NO_USER, NO_PASS );
}
public void testHttpUrlWithUsernamePassword()
{
assertURL( "http://user:pass@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", "pass" );
}
public void testHttpUrlWithUsernameNoPassword()
{
assertURL( "http://user@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", NO_PASS );
}
public void testHttpUrlWithUsernamePasswordAndPort()
{
assertURL( "http://user:pass@machine:9090/secured/", "http", "machine", "9090", "/secured/", "user", "pass" );
}
public void testBogusWithPath()
{
// This should not fail. The intent of RepositoryURL is to have it support oddball protocols that
// are used by maven-scm and maven-wagon (unlike java.net.URL)
assertURL( "bogus://a.machine.name.com/path/to/resource/file.txt", "bogus", "a.machine.name.com", NO_PORT,
"/path/to/resource/file.txt", NO_USER, NO_PASS );
}
}