mcconnell 2003/02/27 15:08:57 Modified: assembly/src/java/org/apache/avalon/assembly/engine EngineClassLoader.java Log: Improving the assesment of jar files relative to the supplied URL approach (jar: or file:). Revision Changes Path 1.37 +130 -27 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java Index: EngineClassLoader.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- EngineClassLoader.java 23 Feb 2003 14:08:43 -0000 1.36 +++ EngineClassLoader.java 27 Feb 2003 23:08:57 -0000 1.37 @@ -208,6 +208,11 @@ */ private File m_home; + /** + * The system root directory. + */ + private File m_root; + /** * Description of the extension directories. */ @@ -343,11 +348,17 @@ if( context.hasEntry( "urn:assembly:engine.extensions" ) ) { + String scope = "home"; m_descriptor = (LibraryDescriptor)context.get( "urn:assembly:engine.extensions" ); - } - else - { - m_descriptor = new LibraryDescriptor(); + if( m_descriptor.isSystem() ) + { + scope = "system"; + } + final String message = + "registering " + scope + " extension descriptor (" + + m_descriptor.getIncludeDescriptors().length + + ")"; + getLogger().debug( message ); } if( context.hasEntry( "urn:assembly:engine.classpath" ) ) @@ -368,6 +379,11 @@ m_home = new File( System.getProperty( "user.dir" ) ); } + if( context.hasEntry( "urn:assembly:system" ) ) + { + m_root = (File)context.get( "urn:assembly:system" ); + } + if( context.hasEntry( "urn:assembly:engine.bootstrap" ) ) { m_bootstrap = "true".equals( context.get( "urn:assembly:engine.bootstrap" ) ); @@ -444,28 +460,58 @@ // ArrayList list = new ArrayList(); - File anchor = new File( m_home, m_descriptor.getBaseDirectory() ).getCanonicalFile(); - IncludeDescriptor[] includes = m_descriptor.getIncludeDescriptors(); - for( int j = 0; j < includes.length; j++ ) + File anchor = null; + + if( m_descriptor != null ) { - File include = new File( anchor, includes[ j ].getFile() ).getCanonicalFile(); - if( include.isDirectory() ) + if( m_descriptor.isSystem() ) { - list.add( include ); - getLogger().debug( REZ.getString( "kernel.extension", include ) ); + if( m_root != null ) + { + anchor = new File( m_root, m_descriptor.getBaseDirectory() ).getCanonicalFile(); + } + else + { + final String warning = + "Cannot process system extension descriptor in " + + this + " due to undeclared system path."; + getLogger().warn( warning ); + } } else { - final String error = REZ.getString( "error.include", include ); - throw new IllegalArgumentException( error ); + if( m_home != null ) + { + anchor = new File( m_home, m_descriptor.getBaseDirectory() ).getCanonicalFile(); + } + else + { + final String warning = + "Cannot process home extension descriptor in " + + this + " due to undeclared home path."; + getLogger().warn( warning ); + } + } + if( anchor != null ) + { + IncludeDescriptor[] includes = m_descriptor.getIncludeDescriptors(); + for( int j = 0; j < includes.length; j++ ) + { + File include = new File( anchor, includes[ j ].getFile() ).getCanonicalFile(); + if( include.isDirectory() ) + { + list.add( include ); + getLogger().debug( REZ.getString( "kernel.extension", include ) ); + } + else + { + final String error = REZ.getString( "error.include", include ); + throw new IllegalArgumentException( error ); + } + } } } - for( int k=0; k<m_parsable.length; k++ ) - { - m_repository.install( m_parsable[k] ); - } - if( m_bootstrap ) { String sep = System.getProperty( "path.separator" ); @@ -535,7 +581,7 @@ } // - // handle the classpath + // handle the jre classpath // String sep = System.getProperty( "path.separator" ); @@ -554,7 +600,16 @@ } // - // load the classpath + // auto scan jars from parent classloaders + // + + for( int k=0; k<m_parsable.length; k++ ) + { + m_repository.install( m_parsable[k] ); + } + + // + // load the classpath descriptor // try @@ -567,6 +622,7 @@ throw new EngineException( error, e ); } + // // load the explicit URLs // @@ -691,9 +747,13 @@ engine.enableLogging( getLogger() ); DefaultLocator context = new DefaultLocator(); context.put( "urn:assembly:home", m_home ); + context.put( "urn:assembly:system", m_root ); context.put( "urn:assembly:engine.base", base ); context.put( "urn:assembly:engine.bootstrap", "false" ); - context.put( "urn:assembly:engine.extensions", extensions ); + if( extensions != null ) + { + context.put( "urn:assembly:engine.extensions", extensions ); + } context.put( "urn:assembly:engine.classpath", classpath ); context.put( "urn:assembly:logging.manager", m_logging ); context.put( "urn:assembly:threads.manager", m_pool ); @@ -751,6 +811,36 @@ getLogger().debug( REZ.getString( "add.classpath" ) ); } + // + // expand the classpath relative to the home directory + // + + try + { + URL[] urls = ClasspathDescriptor.expand( m_home, classpath ); + for( int j = 0; j < urls.length; j++ ) + { + URL inc = urls[ j ]; + try + { + addURL( inc ); + } + catch( Throwable e ) + { + throw new EngineRuntimeException( + REZ.getString( "classpath.include.error", inc ) , e ); + } + } + return; + } + catch( Throwable e ) + { + final String error = + "Unexpected exception while attampting to expand the supplied classpath."; + throw new EngineRuntimeException( error, e ); + } + + /* if( m_base != null ) { URL[] urls = ClasspathDescriptor.expand( m_base, classpath ); @@ -773,6 +863,7 @@ { getLogger().debug( "expanding a classpath without a base" ); } + */ // // ######################################################### @@ -780,6 +871,7 @@ // context value - or we construct a rationale default // ########################################################## + /* List list = new ArrayList(); FilesetDescriptor[] dirs = classpath.getFilesetDescriptors(); if( getLogger().isDebugEnabled() ) @@ -829,6 +921,7 @@ { getLogger().debug( REZ.getString( "classpath.ok" ) ); } + */ } /** @@ -904,7 +997,9 @@ } catch( Throwable e ) { - // type already registered + final String error = + "Unexpected error during type registration."; + throw new EngineRuntimeException( error, e ); } } @@ -1160,11 +1255,11 @@ if(( parent != null ) && ( parent instanceof EngineClassLoader )) { manager = new DefaultRepositoryManager( - this, ((EngineClassLoader)parent).getRepository() ); + this, ((EngineClassLoader)parent).getRepository(), m_home ); } else { - manager = new DefaultRepositoryManager( this ); + manager = new DefaultRepositoryManager( this, m_home ); } manager.enableLogging( getLogger() ); manager.initialize(); @@ -1297,11 +1392,19 @@ { final String element = classPath[ i ]; - if( element.endsWith( ".jar" ) ) + if( element.endsWith( ".jar" ) || element.startsWith( "jar:" ) ) { try { - final URL url = new URL( "jar:" + element + "!/" ); + URL url = null; + if( element.startsWith("jar:") ) + { + url = new URL( element ); + } + else + { + url = new URL( "jar:" + element + "!/" ); + } final JarURLConnection connection = (JarURLConnection)url.openConnection(); final Manifest manifest = connection.getManifest();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]