Return-Path: Delivered-To: apmail-avalon-cvs-archive@www.apache.org Received: (qmail 25907 invoked from network); 20 Nov 2003 04:25:32 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 20 Nov 2003 04:25:32 -0000 Received: (qmail 45200 invoked by uid 500); 20 Nov 2003 04:25:12 -0000 Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 45150 invoked by uid 500); 20 Nov 2003 04:25:12 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 45137 invoked by uid 500); 20 Nov 2003 04:25:12 -0000 Received: (qmail 45133 invoked from network); 20 Nov 2003 04:25:12 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 20 Nov 2003 04:25:12 -0000 Received: (qmail 25833 invoked by uid 1438); 20 Nov 2003 04:25:31 -0000 Date: 20 Nov 2003 04:25:31 -0000 Message-ID: <20031120042531.25832.qmail@minotaur.apache.org> From: mcconnell@apache.org To: avalon-sandbox-cvs@apache.org Subject: cvs commit: avalon-sandbox/repository/util/src/test/org/apache/avalon/repository/util ArtifactFactoryTest.java MavenArtifactFactoryTest.java RepositoryUtilsTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N mcconnell 2003/11/19 20:25:31 Modified: repository .cvsignore Added: repository/util .cvsignore project.xml repository/util/src/java/org/apache/avalon/repository/util ArtifactFactory.java DefaultRepositoryContext.java LOADER.java MavenArtifactFactory.java RepositoryUtils.java package.html repository/util/src/test/org/apache/avalon/repository/util ArtifactFactoryTest.java MavenArtifactFactoryTest.java RepositoryUtilsTest.java Log: More seperatation and enhancements on replication. Revision Changes Path 1.3 +1 -2 avalon-sandbox/repository/.cvsignore Index: .cvsignore =================================================================== RCS file: /home/cvs/avalon-sandbox/repository/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- .cvsignore 19 Nov 2003 17:28:37 -0000 1.2 +++ .cvsignore 20 Nov 2003 04:25:30 -0000 1.3 @@ -2,6 +2,5 @@ velocity.log build.properties target -.classpath -.project +.* event.zip 1.1 avalon-sandbox/repository/util/.cvsignore Index: .cvsignore =================================================================== maven.log velocity.log build.properties target .classpath .project 1.1 avalon-sandbox/repository/util/project.xml Index: project.xml =================================================================== ${basedir}/../project.xml avalon-repository avalon-repository-util Avalon Repository Utilities 1.2-dev org.apache.avalon.repository 2002 Avalon Repository Utilities avalon-repository avalon-repository-api 1.2-dev avalon-repository avalon-repository-spi 1.2-dev 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/ArtifactFactory.java Index: ArtifactFactory.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util ; import java.util.Properties; import org.apache.avalon.repository.Artifact; /** * The ArtifactFactory is a factory for domain independent artifacts. The * factory makes no assumptions about a repository layout beyond the notions * a directory and filename. * * @author Stephen McConnell * @author Alex Karasulu * @version $Revision: 1.1 $ */ public class ArtifactFactory { // ------------------------------------------------------------------------ // static // ------------------------------------------------------------------------ /** * Creation of a new Artifact relative to a supplied base directory * and filename. The argument supplied to the path is a nominal relative * reference anchored relative to a repository root. The filename * when appended to the base path forms a logical relative root path. * * @param base the base directory path * @param filename the artifact filename * @return the artifact reference */ public static Artifact createArtifact( String base, String filename ) { return createArtifact( base, filename, null ); } /** * Creation of a new Artifact relative to a supplied base directory * and filename. The argument supplied to the path is a nominal relative * reference anchored relative to a repository root. The filename * when appended to the base path forms a logical relative root path. * The supplied properties argument may be used to attribute domain * specific information to the artifact. * * @param base the base directory path * @param filename the artifact filename * @param properties a properties set to attribute to the artifact * @return the artifact reference */ public static Artifact createArtifact( String base, String filename, Properties properties ) { if( base == null ) throw new NullPointerException( base ); if( filename == null ) throw new NullPointerException( filename ); return new Artifact( base, filename, properties ); } } 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/DefaultRepositoryContext.java Index: DefaultRepositoryContext.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util ; import java.io.File; import java.net.URL ; import java.net.MalformedURLException ; import org.apache.avalon.repository.ProxyContext; import org.apache.avalon.repository.RepositoryContext; import org.apache.avalon.repository.util.DefaultRepositoryContext ; /** * Default implementation for a repository configuration parameters bean. * * @author Alex Karasulu * @author $Author: mcconnell $ * @version $Revision: 1.1 $ */ public class DefaultRepositoryContext implements RepositoryContext { /** * The set of remote repositories fro which resource retrival * will be attempted. */ private URL [] m_remoteRepositories = new URL[0] ; /** * The path to the local repository that caches remote artifacts */ private String m_cacheDir = System.getProperty( "user.home" ) + File.separator + ".avalon" + File.separator + "repository"; /** * Descriptor for proxy used to access remote repositories */ private ProxyContext m_proxyCtx = null ; /** * Creation of a new default context. */ public DefaultRepositoryContext() { } /** * Creation of a new context using a suppplied context as * the defaults reference. */ public DefaultRepositoryContext( RepositoryContext context ) { m_remoteRepositories = context.getRemoteRepositories(); m_cacheDir = context.getCacheDir(); m_proxyCtx = context.getProxyContext(); } /** * Gets the ProxyContext used by the Kernel to access remote repositories. * * @return the proxy context used by the Kernel */ public ProxyContext getProxyContext() { return m_proxyCtx ; } /** * Sets the ProxyContext for this KernelConfig. * * @param a_proxyCtx sets the proxy context */ public void setProxyContext( ProxyContext a_proxyCtx ) { m_proxyCtx = a_proxyCtx ; } /** * Gets the set of remote repositories used to download artifacts. * * @return the remote repositories to use */ public URL[] getRemoteRepositories() { return m_remoteRepositories ; } /** * Gets the remote repository urls for downloading artifacts. * * @param a_remoteRepositories the remote Repositories to use. */ public void setRemoteRepositoryUrls( URL[] a_remoteRepositories ) { m_remoteRepositories = a_remoteRepositories ; } /** * Sets the remote repository urls for downloading artifacts. * * @param urls the remote Repositories to use. */ public void setRemoteRepositoryUrls( String[] urls ) throws MalformedURLException { URL [] a_urls = new URL [urls.length] ; for ( int ii = 0; ii < a_urls.length; ii++ ) { a_urls[ii] = new URL( urls[ii] ) ; } m_remoteRepositories = a_urls ; } /** * Gets the directory where repository artifacts are stored after being * downloaded from the Repository. * * @return the place to cache repository artifacts */ public String getCacheDir() { return m_cacheDir ; } /** * Sets the directory where we store downloaded artifacts. * * @param a_cacheDir the place to cache repository artifacts */ public void setCacheDir( String a_cacheDir ) { m_cacheDir = a_cacheDir ; } } 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/LOADER.java Index: LOADER.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util; import java.io.File ; import java.io.IOException ; import java.io.InputStream ; import java.io.FileOutputStream ; import java.util.ArrayList ; import java.util.Properties ; import java.text.ParseException ; import java.net.URL ; import java.net.URLConnection ; import java.net.URLClassLoader ; import java.net.HttpURLConnection ; import java.net.MalformedURLException ; import javax.naming.NamingException ; import javax.naming.NamingEnumeration ; import javax.naming.directory.Attributes ; import org.apache.avalon.repository.Artifact; import org.apache.avalon.repository.RepositoryException; /** * Utility class supporting downloading of resources based on * artifact references. * * @author Alex Karasulu * @author Stephen McConnell * @version $Revision: 1.1 $ */ public class LOADER { /** * Attempts to download and cache a remote artifact trying a set of remote * repositories. The operation is not fail fast and so it keeps trying if * the first repository does not have the artifact in question. * * @param artifact the artifact to retrieve and cache * @param repositories the remote repositories to try to download from * @param destination where to store it locally in the cache * @param timestamping whether to check the modified timestamp on the * destinationFile against the remote source * @return URL a url referencing the local resource */ public static URL getResource( Artifact artifact, String [] repositories, File root, boolean timestamping ) throws RepositoryException { Exception cause = null; File destination = new File( root, artifact.getPath() ); /* * Don't fail fast - keep trying until we get something. */ for ( int i = 0; i < repositories.length; i++ ) { try { String url = artifact.getURL( repositories[i] ) ; return getResource( url, destination, timestamping ) ; } catch ( Exception e ) { cause = e ; } } StringBuffer buffer = new StringBuffer(); buffer.append( "Failed to download artifact to local cache file " + destination.getAbsolutePath() + " from hosts: " ); for( int i=0; idestinationFile against the remote source * @return URL a url referencing the local resource */ public static URL getResource( String url, File destination, boolean timestamping ) throws Exception { // // if timestamp is enabled and the destination file exists and // the source is a file - then do a quick check using native File // last modification dates to see if anything needs to be done // if( timestamping && destination.exists() && url.startsWith( "file:" ) ) { try { URL sourceFileUrl = new URL( url ); String sourcePath = sourceFileUrl.getPath(); File sourceFile = new File( sourcePath ); if( destination.lastModified() >= sourceFile.lastModified() ) { return destination.toURL(); } } catch( Throwable e ) { e.printStackTrace(); } } // // otherwise continue with classic processing // URL source = null ; String username = null ; String password = null ; // We want to be able to deal with Basic Auth where the username // and password are part of the URL. An example of the URL string // we would like to be able to parse is like the following: // // http://username:password@repository.mycompany.com int atIdx = url.indexOf( "@" ) ; if ( atIdx > 0 ) { String s = url.substring( 7, atIdx ) ; int colon = s.indexOf( ":" ) ; username = s.substring( 0, colon ) ; password = s.substring( colon + 1 ) ; source = new URL( "http://" + url.substring( atIdx + 1 ) ) ; } else { source = new URL( url ) ; } //set the timestamp to the file date. long timestamp = 0 ; boolean hasTimestamp = false ; if ( timestamping && destination.exists() ) { timestamp = destination.lastModified() ; hasTimestamp = true ; } //set up the URL connection URLConnection connection = source.openConnection() ; //modify the headers //NB: things like user authentication could go in here too. if ( timestamping && hasTimestamp ) { connection.setIfModifiedSince( timestamp ) ; } //connect to the remote site (may take some time) connection.connect() ; //next test for a 304 result (HTTP only) if ( connection instanceof HttpURLConnection ) { HttpURLConnection httpConnection = ( HttpURLConnection ) connection ; if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED ) { return destination.toURL() ; } // test for 401 result (HTTP only) if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED ) { throw new Exception( "Not authorized." ) ; } } // REVISIT: at this point even non HTTP connections may support the // if-modified-since behaviour - we just check the date of the // content and skip the write if it is not newer. // Some protocols (FTP) dont include dates, of course. InputStream in = null ; for ( int ii = 0; ii < 3; ii++ ) { try { in = connection.getInputStream() ; break ; } catch ( IOException ex ) { // do nothing } } if ( in == null ) { final String error = "Connection returned a null input stream: " + url ; throw new IOException( error ) ; } File parent = destination.getParentFile() ; parent.mkdirs() ; FileOutputStream out = new FileOutputStream( destination ) ; byte[] buffer = new byte[100 * 1024] ; int length ; System.out.print( "Source: " + source + "\n") ; while ( ( length = in.read( buffer ) ) >= 0 ) { out.write( buffer, 0, length ) ; System.out.print( "." ) ; } System.out.println( "" ) ; out.close() ; in.close() ; // if (and only if) the use file time option is set, then the // saved file now has its timestamp set to that of the downloaded // file if ( timestamping ) { long remoteTimestamp = connection.getLastModified() ; if ( remoteTimestamp != 0 ) { long modifiedTime ; if ( remoteTimestamp < 0 ) { modifiedTime = System.currentTimeMillis() ; } else { modifiedTime = remoteTimestamp ; } destination.setLastModified( modifiedTime ) ; } } return destination.toURL(); } } 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/MavenArtifactFactory.java Index: MavenArtifactFactory.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util ; import java.util.Properties ; import org.apache.avalon.repository.Artifact; /** * A factory suppporting the creation of artifacts based on structural * assumptions associated with the Maven repository layout. This includes * the notion of a path derived from of a /[s"] association * and a filename derived from [-][.]. * * @author Stephen McConnell * @author Alex Karasulu * @version $Revision: 1.1 $ */ public class MavenArtifactFactory extends ArtifactFactory { // ------------------------------------------------------------------------ // static // ------------------------------------------------------------------------ public static final String GROUP_KEY = "avalon.artifact.group"; public static final String NAME_KEY = "avalon.artifact.name"; public static final String VERSION_KEY = "avalon.artifact.version"; public static final String TYPE_KEY = "avalon.artifact.type"; /** * Creation of an untyped versionless artifact relative to a supplied * group identifier and artifact name. * * @param group the artifact group id * @param name the artifact name * @return the artifact reference */ public static Artifact createMavenArtifact( String group, String name ) { return createMavenArtifact( group, name, null, null ); } public static Artifact createMavenArtifact( String group, String name, String version ) { return createMavenArtifact( group, name, version, null ); } public static Artifact createMavenArtifact( String group, String name, String version, String type ) { if( group == null ) throw new NullPointerException( "group" ); if( name == null ) throw new NullPointerException( "name" ); Properties properties = new Properties(); properties.setProperty( GROUP_KEY, group ); properties.setProperty( NAME_KEY, name ); if( version != null ) properties.setProperty( VERSION_KEY, version ); if( type != null ) properties.setProperty( TYPE_KEY, type ); String base = createBase( group, type ); String filename = createFilename( name, version, type ); return createArtifact( base, filename, properties ); } public static Artifact createJarArtifact( String spec ) { if ( null == spec ) throw new NullPointerException( "spec" ); String version = getVersion( spec ); String group = getGroup( spec ); String name = getName( spec ); return createJarArtifact( group, name, version ); } public static Artifact createJarArtifact( String group, String name, String version ) { return createMavenArtifact( group, name, version, "jar" ); } //---------------------------------------------------------------------- // internal utilities //---------------------------------------------------------------------- private static String createBase( String group, String type ) { if( type == null ) return group; return group + Artifact.SEP + type + "s"; } private static String createFilename( String name, String version, String type ) { if( name == null ) throw new NullPointerException( "name" ); StringBuffer buffer = new StringBuffer( name ); if( version != null ) { buffer.append( "-" ); buffer.append( version ); } if( type != null ) { buffer.append( "." ); buffer.append( type ); } return buffer.toString(); } private static String getGroup( String spec ) { int semiColon = spec.indexOf( ';' ) ; if ( -1 == semiColon ) { int colon = spec.indexOf( ':' ) ; if( -1 == colon ) return spec; return spec.substring( 0, colon ); } else { return getGroup( spec.substring( 0, semiColon-1 ) ); } } private static String getName( String spec ) { int semiColon = spec.indexOf( ';' ) ; if ( -1 == semiColon ) { int colon = spec.indexOf( ':' ) ; if( -1 == colon ) return spec; return spec.substring( colon+1, spec.length() ); } else { return getName( spec.substring( 0, semiColon ) ); } } private static String getVersion( String spec ) { int semiColon = spec.indexOf( ';' ) ; if ( -1 == semiColon ) { return null; } else { return spec.substring( semiColon+1, spec.length() ); } } // ------------------------------------------------------------------------ // utilities // ------------------------------------------------------------------------ /** * Return the group identifier for an artifact. This function * is a convinience operation equivalent to * artifact.getProperty( GROUP_KEY );. The value returned * will be null if the group key is not defined. * * @return group id of the supplied artifact or null if not declared */ public static String getGroup( Artifact artifact ) { return artifact.getProperty( GROUP_KEY ); } /** * Return the name identifier for an artifact. This function * is a convinience operation equivalent to * artifact.getProperty( NAME_KEY );. The value returned * will be null if the name key is not defined. * * @return group id of the supplied artifact or null if not declared */ public static String getName( Artifact artifact ) { return artifact.getProperty( NAME_KEY ); } /** * Return the type identifier for an artifact. This function * is a convinience operation equivalent to * artifact.getProperty( TYPE_KEY );. The value returned * will be null if the type key is not defined. * * @return group id of the supplied artifact or null if not declared */ public static String getType( Artifact artifact ) { return artifact.getProperty( TYPE_KEY ); } /** * Return the version identifier for an artifact. This function * is a convinience operation equivalent to * artifact.getProperty( VERSION_KEY );. The value returned * will be null if the version key is not defined. * * @return group id of the supplied artifact or null if not declared */ public static String getVersion( Artifact artifact ) { return artifact.getProperty( VERSION_KEY ); } /** * Gets the artifact specification for this ArtifactDescriptor * in the form [:][;]. * * @return the artifact specification */ public static String getSpecification( Artifact artifact ) { final String group = getGroup( artifact ); final String name = getName( artifact ); if( group == null ) { final String error = "Undefined group property in artifact: " + artifact; throw new IllegalArgumentException( error ); } if( name == null ) { final String error = "Undefined name property in artifact: " + artifact; throw new IllegalArgumentException( error ); } StringBuffer buffer = new StringBuffer() ; buffer.append( getGroup( artifact ) ) ; if( !name.equals( group ) ) { buffer.append( ':' ) ; buffer.append( getName( artifact ) ) ; } String version = getVersion( artifact ); if( version != null ) { buffer.append( ';' ) ; buffer.append( version ) ; } return buffer.toString() ; } } 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/RepositoryUtils.java Index: RepositoryUtils.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util ; import java.net.URL ; import java.io.IOException ; import java.io.InputStream ; import java.util.ArrayList; import java.util.Properties ; import java.util.Enumeration ; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes ; import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes ; import org.apache.avalon.repository.Artifact; import org.apache.avalon.repository.RepositoryException; /** * Various static utility methods used throughout repository related programing * interfaces. * * @author Alex Karasulu * @author Stephen McConnell * @version $Revision: 1.1 $ */ public class RepositoryUtils { /** meta extension tag for meta-data containing artifacts */ public static final String META = "meta" ; /** * Transforms a Properties into a Attributes using a simple enumeration * convention for property names which appends a numeric enumeration name * component to the dotted property key. Note that changes to the * Attributes object do not have any effect on the Properties object and * vice versa. All values are copied. * * @param a_props the properties to be transformed * @return the Attributes representing the properties */ public static Attributes getAsAttributes( Properties a_props ) { Attributes l_attrs = new BasicAttributes( false ) ; Enumeration l_list = a_props.propertyNames() ; while ( l_list.hasMoreElements() ) { String l_key = ( String ) l_list.nextElement() ; if ( isEnumerated( l_key ) ) { String l_keyBase = getEnumeratedBase( l_key ) ; Attribute l_attr = l_attrs.get( l_keyBase ) ; if ( null == l_attr ) { l_attr = new BasicAttribute( l_keyBase, false ) ; } l_attr.add( a_props.getProperty( l_key ) ) ; l_attrs.put( l_attr ) ; } else { l_attrs.put( l_key, a_props.getProperty( l_key ) ) ; } } return l_attrs ; } /** * Gets the Properties in a remote properties file. * * @param a_url the url to the properties file * @return the loaded properties for the file * @throws IOException if there is any problem loading the properties */ public static Properties getProperties( String [] repos, Artifact a_artifact ) throws RepositoryException { String[] a_repos = new String[]{}; if( repos != null ) a_repos = repos; Throwable l_throwable = null ; Properties l_props = null ; for( int ii = 0; ii < a_repos.length; ii++ ) { StringBuffer l_buf = new StringBuffer() ; l_buf.append( a_artifact.getURL( a_repos[ii] ) ) ; l_buf.append( "." ) ; l_buf.append( META ) ; try { URL l_url = new URL( l_buf.toString() ) ; l_props = getProperties( l_url ) ; return l_props ; } catch ( Throwable e ) { l_throwable = e ; } } StringBuffer l_repos = new StringBuffer() ; for ( int ii = 0; ii < a_repos.length; ii++ ) { l_repos.append( a_repos[ii] ).append( ',' ) ; } throw new RepositoryException( "None of the repositories " + l_repos.toString() + " contained the metadata properties for " + a_artifact, l_throwable ) ; } /** * Gets the Properties in a remote properties file. * * @param a_url the url to the properties file * @return the loaded properties for the file * @throws IOException if there is any problem loading the properties */ public static Properties getProperties( URL a_url ) throws IOException { // // TODO: // this method is not using the local cache // // // TODO2: // This request is not checking the date of the remote resources // relative to a cached value. If the remote resource is cached // remotely we may not be picking up the good values. I.e. out // local resouce in the context classloader may be more up-to-date. // InputStream l_in = null ; Properties l_props = new Properties() ; l_in = a_url.openStream() ; l_props.load( l_in ) ; if ( l_in != null ) { l_in.close() ; } return l_props ; } /** * Detects whether or not a property key is of the multivalued enumeration * kind. A multivalued key simply enumerates values by appending a '.' and * a number after the dot: i.e. artifact.dependency.2 and artifact.alias.23 * et. cetera. * * @param a_key the property name or key * @return true if the property conforms to the enumerated property * convention, false otherwise */ public static boolean isEnumerated( String a_key ) { int l_lastDot = a_key.lastIndexOf( '.' ) ; String l_lastComponent = null ; if ( -1 == l_lastDot ) { return false ; } l_lastComponent = a_key.substring( l_lastDot + 1 ) ; // names like .123 are not really considered enumerated without a base if ( a_key.equals( a_key.substring( l_lastDot ) ) ) { return false ; } try { Integer.parseInt( l_lastComponent ) ; } catch ( NumberFormatException e ) { return false ; } return true ; } /** * Gets the key base of an enumerated property using the multivalued * property key naming convention. * * @param a_key the enumerated key whose last name component is a number * @return the base name of the enumerated property */ public static String getEnumeratedBase( String a_key ) { if ( null == a_key ) { return null ; } if ( ! isEnumerated( a_key ) ) { return a_key ; } int l_lastDot = a_key.lastIndexOf( '.' ) ; String l_base = null ; if ( -1 == l_lastDot ) { return a_key ; } return a_key.substring( 0, l_lastDot ) ; } /** * * @param a_delimiter * @param a_substrate * @return */ public static String [] getDelimited( char a_delim, String a_substrate ) { int l_start = 0, l_end = 0 ; ArrayList l_list = new ArrayList() ; if ( null == a_substrate || a_substrate.equals( "" ) ) { return null ; } while( l_end < a_substrate.length() ) { l_end = a_substrate.indexOf( ',', l_start ) ; if ( -1 == l_end ) { l_end = a_substrate.length() ; l_list.add( a_substrate.substring( l_start, l_end ) ) ; break ; } l_list.add( a_substrate.substring( l_start, l_end ) ) ; l_start = l_end + 1 ; } return ( String [] ) l_list.toArray( new String[0] ) ; } } 1.1 avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/package.html Index: package.html ===================================================================

The repository package contains an contract for abstract repository services.

1.1 avalon-sandbox/repository/util/src/test/org/apache/avalon/repository/util/ArtifactFactoryTest.java Index: ArtifactFactoryTest.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util; import java.util.Properties; import java.util.Enumeration; import junit.framework.TestCase; import org.apache.avalon.repository.Artifact; /** * @todo * @author Alex Karasulu * @author $Author: mcconnell $ * @version $Revision: 1.1 $ */ public class ArtifactFactoryTest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run( ArtifactFactoryTest.class ); } /** * Constructor for ArtifactFactoryTest. * @param arg0 */ public ArtifactFactoryTest(String arg0) { super(arg0); } public void testConstructorOne() throws Exception { try { ArtifactFactory.createArtifact( null, null ); fail( "No null pointer exception (case 1)" ); } catch( Throwable e ) { assertTrue( true ); } } public void testConstructorTwo() throws Exception { try { ArtifactFactory.createArtifact( null, "xxx" ); fail( "No null pointer exception (case 2)" ); } catch( Throwable e ) { assertTrue( true ); } } public void testConstructorThree() throws Exception { try { ArtifactFactory.createArtifact( "xxx", null ); fail( "No null pointer exception (case 3)" ); } catch( Throwable e ) { assertTrue( true ); } } public void testURLGeneralIntegrity() throws Exception { Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy" ); assertNotNull( artifact ); assertTrue( artifact.getURL( "http://dpml.net" ).equals( "http://dpml.net/xxx/yyy" ) ); } public void testURLFromEmptyRepository() throws Exception { Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy" ); assertNotNull( artifact ); assertTrue( artifact.getURL( "" ).equals( "/xxx/yyy" ) ); } public void testURLFromNullRepository() throws Exception { Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy" ); assertTrue( artifact.getURL( null ).equals( "/xxx/yyy" ) ); } public void testArtifactProperties() throws Exception { Properties p = new Properties(); p.setProperty( "aaa", "Aaa" ); p.setProperty( "bbb", "Bbb" ); Artifact artifact = ArtifactFactory.createArtifact( "xxx", "yyy", p ); assertTrue( artifact.getProperty( "aaa" ).equals( "Aaa" ) ); assertTrue( artifact.getProperty( "bbb" ).equals( "Bbb" ) ); Enumeration e = artifact.getPropertyNames(); int n = 0; while( e.hasMoreElements() ) { final String name = (String) e.nextElement(); n++; } assertTrue( n == 2 ); } } 1.1 avalon-sandbox/repository/util/src/test/org/apache/avalon/repository/util/MavenArtifactFactoryTest.java Index: MavenArtifactFactoryTest.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util; import java.util.Properties; import java.util.Enumeration; import junit.framework.TestCase; import org.apache.avalon.repository.Artifact; /** * @todo * @author Alex Karasulu * @author $Author: mcconnell $ * @version $Revision: 1.1 $ */ public class MavenArtifactFactoryTest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run( MavenArtifactFactoryTest.class ); } /** * Constructor for ArtifactFactoryTest. * @param arg0 */ public MavenArtifactFactoryTest(String arg0) { super(arg0); } public void testCreateMavenArtifactNullArguments() throws Exception { try { ArtifactFactory.createArtifact( null, null ); fail( "No null pointer exception (case 1)" ); } catch( Throwable e ) { assertTrue( true ); } try { ArtifactFactory.createArtifact( null, "xxx" ); fail( "No null pointer exception (case 2)" ); } catch( Throwable e ) { assertTrue( true ); } try { ArtifactFactory.createArtifact( "xxx", null ); fail( "No null pointer exception (case 3)" ); } catch( Throwable e ) { assertTrue( true ); } } public void testCreateSimpleMavenArtifact() throws Exception { Artifact artifact = MavenArtifactFactory.createMavenArtifact( "xxx", "yyy" ); assertNotNull( artifact ); assertTrue( artifact.getURL( null ).equals( "/xxx/yyy" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.GROUP_KEY ).equals( "xxx" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.NAME_KEY ).equals( "yyy" ) ); } public void testCreateVersionedMavenArtifact() throws Exception { Artifact artifact = MavenArtifactFactory.createMavenArtifact( "xxx", "yyy", "1.0-dev" ); assertNotNull( artifact ); assertTrue( artifact.getURL( null ).equals( "/xxx/yyy-1.0-dev" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.GROUP_KEY ).equals( "xxx" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.NAME_KEY ).equals( "yyy" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.VERSION_KEY ).equals( "1.0-dev" ) ); } public void testCreateTypedMavenArtifact() throws Exception { Artifact artifact = MavenArtifactFactory.createMavenArtifact( "xxx", "yyy", "1.0-dev", "foo" ); assertNotNull( artifact ); assertTrue( artifact.getURL( null ).equals( "/xxx/foos/yyy-1.0-dev.foo" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.GROUP_KEY ).equals( "xxx" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.NAME_KEY ).equals( "yyy" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.VERSION_KEY ).equals( "1.0-dev" ) ); assertTrue( artifact.getProperty( MavenArtifactFactory.TYPE_KEY ).equals( "foo" ) ); } public void testUtilityFunctions() throws Exception { Artifact artifact = MavenArtifactFactory.createMavenArtifact( "xxx", "yyy", "vvv", "zzz" ); assertNotNull( artifact ); assertTrue( MavenArtifactFactory.getGroup( artifact ).equals( "xxx" ) ); assertTrue( MavenArtifactFactory.getName( artifact ).equals( "yyy" ) ); assertTrue( MavenArtifactFactory.getVersion( artifact ).equals( "vvv" ) ); assertTrue( MavenArtifactFactory.getType( artifact ).equals( "zzz" ) ); } public void testJarArtifactCreation() throws Exception { Artifact artifact = MavenArtifactFactory.createJarArtifact( "xxx", "yyy", "vvv" ); assertNotNull( artifact ); assertTrue( MavenArtifactFactory.getGroup( artifact ).equals( "xxx" ) ); assertTrue( MavenArtifactFactory.getName( artifact ).equals( "yyy" ) ); assertTrue( MavenArtifactFactory.getVersion( artifact ).equals( "vvv" ) ); assertTrue( MavenArtifactFactory.getType( artifact ).equals( "jar" ) ); assertTrue( artifact.getURL( null ).equals( "/xxx/jars/yyy-vvv.jar" ) ); } public void testJarArtifactCreationBySimpleSpec() throws Exception { final String spec = "xxx"; Artifact artifact = MavenArtifactFactory.createJarArtifact( spec ); assertNotNull( artifact ); assertTrue( MavenArtifactFactory.getGroup( artifact ).equals( "xxx" ) ); assertTrue( MavenArtifactFactory.getName( artifact ).equals( "xxx" ) ); assertTrue( MavenArtifactFactory.getType( artifact ).equals( "jar" ) ); assertTrue( artifact.getURL( null ).equals( "/xxx/jars/xxx.jar" ) ); } public void testJarArtifactCreationByCompoundSpec() throws Exception { final String spec = "xxx:yyy"; Artifact artifact = MavenArtifactFactory.createJarArtifact( spec ); assertNotNull( artifact ); assertTrue( "group", MavenArtifactFactory.getGroup( artifact ).equals( "xxx" ) ); assertTrue( "name", MavenArtifactFactory.getName( artifact ).equals( "yyy" ) ); assertTrue( "type", MavenArtifactFactory.getType( artifact ).equals( "jar" ) ); assertTrue( "url", artifact.getURL( null ).equals( "/xxx/jars/yyy.jar" ) ); } public void testJarArtifactCreationBySpec() throws Exception { final String spec = "xxx:yyy;zzz"; Artifact artifact = MavenArtifactFactory.createJarArtifact( spec ); assertNotNull( artifact ); assertTrue( "group", MavenArtifactFactory.getGroup( artifact ).equals( "xxx" ) ); assertTrue( "name", MavenArtifactFactory.getName( artifact ).equals( "yyy" ) ); assertTrue( "version", MavenArtifactFactory.getVersion( artifact ).equals( "zzz" ) ); assertTrue( "type", MavenArtifactFactory.getType( artifact ).equals( "jar" ) ); assertTrue( "url", artifact.getURL( null ).equals( "/xxx/jars/yyy-zzz.jar" ) ); } } 1.1 avalon-sandbox/repository/util/src/test/org/apache/avalon/repository/util/RepositoryUtilsTest.java Index: RepositoryUtilsTest.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.repository.util ; import java.net.URL; import java.util.Properties; import javax.naming.directory.Attributes; import junit.framework.TestCase; import org.apache.avalon.repository.Artifact; /** * @todo * @author Alex Karasulu * @author $Author: mcconnell $ * @version $Revision: 1.1 $ */ public class RepositoryUtilsTest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run(RepositoryUtilsTest.class); } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } /** * Constructor for RepositoryUtilsTest. * @param arg0 */ public RepositoryUtilsTest(String arg0) { super(arg0); } final public void testGetAsAttributes() throws Exception { Properties l_props = RepositoryUtils.getProperties( new URL( "http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) ) ; Attributes l_attrs = RepositoryUtils.getAsAttributes( l_props ) ; assertEquals( ".repository", l_attrs.get( "cache.dir" ).get( 0 ) ) ; assertEquals( "org.apache.avalon.repository.impl.DefaultFactory", l_attrs.get( "factory" ).get( 0 ) ) ; assertEquals( "http://ibiblio.org/maven", l_attrs.get( "remote.repository.url" ).get( 0 ) ) ; assertNotNull( l_attrs.get( "url" ).get( 0 ) ) ; assertNotNull( l_attrs.get( "url" ).get( 1 ) ) ; assertNotNull( l_attrs.get( "url" ).get( 2 ) ) ; } final public void testGetProperties() throws Exception { /* Test for these properties * cache.dir=.repository * factory=org.apache.avalon.repository.impl.DefaultFactory * remote.repository.url.0=http://ibiblio.org/maven */ Properties l_props = RepositoryUtils.getProperties( new URL( "http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) ) ; assertEquals( ".repository", l_props.getProperty( "cache.dir" ) ) ; assertEquals( "org.apache.avalon.repository.impl.DefaultFactory", l_props.getProperty( "factory" ) ) ; assertEquals( "http://ibiblio.org/maven", l_props.getProperty( "remote.repository.url.0" ) ) ; } final public void testIsEnumerated() { assertFalse( "false for empty string \"\"", RepositoryUtils.isEnumerated( "" ) ) ; assertFalse( "false for \".\"", RepositoryUtils.isEnumerated( "." ) ) ; assertFalse( "false for \"nodot\"", RepositoryUtils.isEnumerated( "nodot" ) ) ; assertFalse( "false for \"before.\"", RepositoryUtils.isEnumerated( "before." ) ) ; assertFalse( "false for \".after\"", RepositoryUtils.isEnumerated( ".after" ) ) ; assertFalse( "false for \"123.\"", RepositoryUtils.isEnumerated( "123." ) ) ; assertFalse( "false for \".123\"", RepositoryUtils.isEnumerated( ".123" ) ) ; assertFalse( "false for \"123.asdf\"", RepositoryUtils.isEnumerated( "123.asdf" ) ) ; assertTrue( "true for \"asdf.123\"", RepositoryUtils.isEnumerated( "asdf.123" ) ) ; assertTrue( "true for \"asdf.1\"", RepositoryUtils.isEnumerated( "asdf.1" ) ) ; } final public void testGetEnumeratedBase() { assertEquals( "", RepositoryUtils.getEnumeratedBase( "" ) ) ; assertEquals( ".", RepositoryUtils.getEnumeratedBase( "." ) ) ; assertEquals( "nodot", RepositoryUtils.getEnumeratedBase( "nodot" ) ) ; assertEquals( "before.", RepositoryUtils.getEnumeratedBase( "before." ) ) ; assertEquals( ".after", RepositoryUtils.getEnumeratedBase( ".after" ) ) ; assertEquals( "123.", RepositoryUtils.getEnumeratedBase( "123." ) ) ; assertEquals( ".123", RepositoryUtils.getEnumeratedBase( ".123" ) ) ; assertEquals( "123.asdf", RepositoryUtils.getEnumeratedBase( "123.asdf" ) ) ; assertEquals( "asdf", RepositoryUtils.getEnumeratedBase( "asdf.123" ) ) ; assertEquals( "asdf", RepositoryUtils.getEnumeratedBase( "asdf.1" ) ) ; } public void testGetDelimited() throws Exception { String [] l_processed = null ; assertNull( RepositoryUtils.getDelimited( ',', null) ) ; assertNull( RepositoryUtils.getDelimited( ',', "") ) ; l_processed = RepositoryUtils.getDelimited( ',', "asdf" ) ; assertEquals( "asdf", l_processed[0] ) ; l_processed = RepositoryUtils.getDelimited( ',', "asdf,1234" ) ; assertEquals( "asdf", l_processed[0] ) ; assertEquals( "1234", l_processed[1] ) ; l_processed = RepositoryUtils.getDelimited( ',', "asdf,1234,abcd" ) ; assertEquals( "asdf", l_processed[0] ) ; assertEquals( "1234", l_processed[1] ) ; assertEquals( "abcd", l_processed[2] ) ; } } --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org