mcconnell 2002/12/09 04:09:40 Modified: assembly/src/java/org/apache/avalon/assembly/engine/model ClasspathDescriptor.java Log: Added classpath static expansion operation. Revision Changes Path 1.2 +62 -1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/model/ClasspathDescriptor.java Index: ClasspathDescriptor.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/model/ClasspathDescriptor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ClasspathDescriptor.java 7 Dec 2002 09:34:28 -0000 1.1 +++ ClasspathDescriptor.java 9 Dec 2002 12:09:40 -0000 1.2 @@ -55,7 +55,11 @@ package org.apache.avalon.assembly.engine.model; +import java.io.File; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.net.URL; /** * <p>A classpath descriptor that describes a scoped set of jar files. @@ -124,4 +128,61 @@ { return m_filesets; } + + /** + * Expand a classpath to an array of URLS. + * @param home the base directory from which relative classpath entries + * will be resolved. + */ + public static URL[] expand( File home, ClasspathDescriptor classpath ) + { + if( home == null ) + { + throw new NullPointerException( "home" ); + } + + if( classpath == null ) + { + throw new NullPointerException( "classpath" ); + } + + List list = new ArrayList(); + FilesetDescriptor[] dirs = classpath.getFilesetDescriptors(); + for( int i = 0; i < dirs.length; i++ ) + { + FilesetDescriptor descriptor = dirs[ i ]; + File anchor = new File( home, descriptor.getBaseDirectory() ); + if( !anchor.exists() ) + { + final String error = + "Classpath base directory does not exist: " + + anchor; + throw new ClasspathRuntimeException( error ); + } + + IncludeDescriptor[] includes = descriptor.getIncludeDescriptors(); + for( int j = 0; j < includes.length; j++ ) + { + String inc = includes[ j ].getFile(); + try + { + URL url = new File( anchor, inc ).toURL(); + if( inc.endsWith( ".jar" ) ) + { + url = new URL( "jar:" + url.toString() + "!/" ); + } + list.add( url ); + } + catch( Throwable e ) + { + final String error = + "Error processing a classpath include: " + + inc; + throw new ClasspathRuntimeException( error, e ); + } + } + } + return (URL[]) list.toArray( new URL[0] ); + } + }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>