donaldp 2002/09/16 01:15:17
Modified: loader/src/test/org/apache/excalibur/loader/test
AbstractLoaderTestCase.java LoaderTestSuite.java
loader/src/test/org/apache/excalibur/loader/verifier/test
VerifierTestCase.java
Added: loader/src/java/org/apache/excalibur/loader/reader
ClassLoaderSetBuilder.java classloader.dtd
loader/src/test/org/apache/excalibur/loader/reader/test
ReaderTestCase.java config1.xml config2.xml
config3.xml config4.xml
Removed: loader/src/java/org/apache/excalibur/loader/builder
ClassLoaderSetBuilder.java classloader.dtd
loader/src/test/org/apache/excalibur/loader/builder/test
ReaderTestCase.java config1.xml config2.xml
config3.xml config4.xml
Log:
Rename the "builder" package to "reader"
Revision Changes Path
1.1
jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/loader/reader/ClassLoaderSetBuilder.java
Index: ClassLoaderSetBuilder.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.loader.reader;
import java.util.ArrayList;
import org.apache.avalon.excalibur.extension.Extension;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.excalibur.loader.metadata.ClassLoaderMetaData;
import org.apache.excalibur.loader.metadata.ClassLoaderSetMetaData;
import org.apache.excalibur.loader.metadata.FileSetMetaData;
import org.apache.excalibur.loader.metadata.JoinMetaData;
/**
* This class builds a [EMAIL PROTECTED] ClassLoaderSetMetaData} object from
* specified configuration.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/09/16 08:15:16 $
*/
public class ClassLoaderSetBuilder
{
public ClassLoaderSetMetaData build( final Configuration config )
throws Exception
{
final String defaultClassLoader =
config.getAttribute( "default" );
final String version =
config.getAttribute( "version" );
if( !"1.0".equals( version ) )
{
final String message = "Bad version:" + version;
throw new Exception( message );
}
final Configuration[] joinConfigs =
config.getChildren( "join" );
final JoinMetaData[] joins = buildJoins( joinConfigs );
final Configuration[] clConfigs =
config.getChildren( "classloader" );
final ClassLoaderMetaData[] classloaders =
buildClassLoaders( clConfigs );
final Configuration[] predefinedConfigs =
config.getChildren( "predefined" );
final String[] predefined =
buildPredefined( predefinedConfigs );
return new ClassLoaderSetMetaData( defaultClassLoader,
predefined,
classloaders,
joins );
}
private String[] buildPredefined( final Configuration[] configs )
throws Exception
{
final ArrayList predefines = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final String predefined = configs[ i ].getAttribute( "name" );
predefines.add( predefined );
}
return (String[])predefines.toArray( new String[ predefines.size() ]
);
}
private ClassLoaderMetaData[] buildClassLoaders( Configuration[] configs )
throws Exception
{
final ArrayList loaders = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final ClassLoaderMetaData loader = buildLoader( configs[ i ] );
loaders.add( loader );
}
return (ClassLoaderMetaData[])loaders.toArray( new
ClassLoaderMetaData[ loaders.size() ] );
}
private ClassLoaderMetaData buildLoader( final Configuration config )
throws Exception
{
final String name = config.getAttribute( "name" );
final String parent = config.getAttribute( "parent" );
final String[] entrys =
buildEntrys( config.getChildren( "entry" ) );
final Extension[] extensions =
buildExtensions( config.getChildren( "extension" ) );
final FileSetMetaData[] fileSets =
buildFileSets( config.getChildren( "fileset" ) );
return new ClassLoaderMetaData( name, parent, entrys,
extensions, fileSets );
}
private Extension[] buildExtensions( final Configuration[] configs )
throws Exception
{
final ArrayList extensions = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final Extension extension =
buildExtension( configs[ i ] );
extensions.add( extension );
}
return (Extension[])extensions.toArray( new Extension[
extensions.size() ] );
}
private Extension buildExtension( final Configuration config )
throws Exception
{
final String name =
config.getAttribute( "name" );
final String specVersion =
config.getAttribute( "specification-version", null );
final String specVendor =
config.getAttribute( "specification-vendor", null );
final String implVersion =
config.getAttribute( "implementation-version", null );
final String implVendor =
config.getAttribute( "implementation-vendor", null );
final String implVendorID =
config.getAttribute( "implementation-vendor-id", null );
final String implURL =
config.getAttribute( "implementation-url", null );
return new Extension( name, specVersion, specVendor,
implVersion, implVendor, implVendorID,
implURL );
}
private FileSetMetaData[] buildFileSets( final Configuration[] configs )
throws Exception
{
final ArrayList fileSets = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final FileSetMetaData fileSet =
buildFileSet( configs[ i ] );
fileSets.add( fileSet );
}
return (FileSetMetaData[])fileSets.toArray( new FileSetMetaData[
fileSets.size() ] );
}
private FileSetMetaData buildFileSet( Configuration config )
throws Exception
{
final String dir = config.getAttribute( "dir" );
final String[] includes =
buildSelectors( config.getChildren( "include" ) );
final String[] excludes =
buildSelectors( config.getChildren( "exclude" ) );
return new FileSetMetaData( dir, includes, excludes );
}
private String[] buildSelectors( Configuration[] configs )
throws Exception
{
final ArrayList selectors = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final String name =
configs[ i ].getAttribute( "name" );
selectors.add( name );
}
return (String[])selectors.toArray( new String[ selectors.size() ] );
}
private String[] buildEntrys( final Configuration[] configs )
throws Exception
{
final ArrayList entrys = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final Configuration config = configs[ i ];
final String entry = config.getAttribute( "location" );
entrys.add( entry );
}
return (String[])entrys.toArray( new String[ entrys.size() ] );
}
private JoinMetaData[] buildJoins( final Configuration[] configs )
throws Exception
{
final ArrayList joins = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final JoinMetaData join = buildJoin( configs[ i ] );
joins.add( join );
}
return (JoinMetaData[])joins.toArray( new JoinMetaData[ joins.size()
] );
}
private JoinMetaData buildJoin( final Configuration config )
throws Exception
{
final String name = config.getAttribute( "name" );
final Configuration[] children =
config.getChildren( "classloader-ref" );
final String[] classloaders =
buildClassLoaderRefs( children );
return new JoinMetaData( name, classloaders );
}
private String[] buildClassLoaderRefs( final Configuration[] configs )
throws Exception
{
final ArrayList refs = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
final String ref = configs[ i ].getAttribute( "name" );
refs.add( ref );
}
return (String[])refs.toArray( new String[ refs.size() ] );
}
}
1.1
jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/loader/reader/classloader.dtd
Index: classloader.dtd
===================================================================
<!--
This is the DTD defining the ClassLoader 1.0
descriptor (XML) file format/syntax.
Author: Peter Donald <peter at apache.org>
This descriptor is used to describe a mechanism of defining
a set of ClassLoaders and the arrangment of specified ClassLoaders.
Copyright (C) The Apache Software Foundation. All rights reserved.
This software is published under the terms of the Apache Software License
version 1.1, a copy of which has been included with this distribution in
the LICENSE.txt file.
-->
<!--
The classloaders is the document root, it defines:
join the join classloaders
classloader the regular classloaders
-->
<!ELEMENT classloaders (predefined*,classloader*,join*)>
<!ATTLIST classloaders id ID #IMPLIED
xmlns CDATA #FIXED
"http://jakarta.apache.org/avalon/dtds/phoenix/classloaders_1_0.dtd" >
<!ATTLIST classloaders
default CDATA #REQUIRED
version CDATA #REQUIRED >
<!--
The classloader element describes a regular classloader It defines:
Attributes:
name the name of classloader type. Must be a string
containing alphanumeric characters, '.', '-', '_' and
starting with a letter or a '_'.
parent the name of the parent classloader
Elements:
entry an entry in classloader
fileset an fileset in classloader
extension an extension in classloader
-->
<!ELEMENT classloader (entry*,fileset*,extension*)>
<!ATTLIST classloader
name CDATA #REQUIRED
parent CDATA #REQUIRED >
<!--
The predefined element defines a predefined classloader. It defines:
Attributes:
name the name of classloader.
-->
<!ELEMENT predefined EMPTY>
<!ATTLIST predefined name CDATA #REQUIRED >
<!--
The classloader element describes a regular classloader It defines:
Attributes:
name the name of classloader type. Must be a string
containing alphanumeric characters, '.', '-', '_' and
starting with a letter or a '_'.
Elements:
classloader-ref a reference to all classloaders that are joined
-->
<!ELEMENT join (classloader-ref*)>
<!ATTLIST join name CDATA #REQUIRED >
<!--
The classloader-ref defines a ClassLoader that are part of join.
It defines:
Attributes:
name the name of other classloader that will join with
-->
<!ELEMENT classloader-ref EMPTY>
<!ATTLIST classloader-ref name CDATA #REQUIRED>
<!--
The entry describes a entry in ClassLoader. It defines:
Attributes:
location the location (URL) to add to classloader
-->
<!ELEMENT entry EMPTY>
<!ATTLIST entry location CDATA #REQUIRED>
<!--
The classloader element describes a regular classloader It defines:
Attributes:
name the name of classloader type. Must be a string
containing alphanumeric characters, '.', '-', '_' and
starting with a letter or a '_'.
Elements:
classloader-ref a reference to all classloaders that are joined
-->
<!ELEMENT fileset ((include|exclude)*)>
<!ATTLIST fileset dir CDATA #REQUIRED >
<!--
The entry describes a include for fileset. It defines:
Attributes:
name the pattern to include
-->
<!ELEMENT include EMPTY>
<!ATTLIST include name CDATA #REQUIRED>
<!--
The entry describes a exclude for fileset. It defines:
Attributes:
name the pattern to exclude
-->
<!ELEMENT exclude EMPTY>
<!ATTLIST exclude name CDATA #REQUIRED>
<!--
The extension describes a extension for ClassLoader.
-->
<!ELEMENT extension EMPTY>
<!ATTLIST extension
name CDATA #REQUIRED
specification-version CDATA #IMPLIED
specification-vendor CDATA #IMPLIED
implementation-version CDATA #IMPLIED
implementation-vendor CDATA #IMPLIED
implementation-vendor-id CDATA #IMPLIED
implementation-url CDATA #IMPLIED
>
1.1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/reader/test/ReaderTestCase.java
Index: ReaderTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.loader.reader.test;
import org.apache.excalibur.loader.reader.ClassLoaderSetBuilder;
import org.apache.excalibur.loader.metadata.ClassLoaderSetMetaData;
import org.apache.excalibur.loader.test.AbstractLoaderTestCase;
/**
* TestCase for [EMAIL PROTECTED] ClassLoaderSetBuilder}.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
*/
public class ReaderTestCase
extends AbstractLoaderTestCase
{
public ReaderTestCase( final String name )
{
super( name );
}
public void testConfig1()
throws Exception
{
final ClassLoaderSetMetaData defs =
buildFromResource( "config1.xml" );
assertEquals( "ClassLoader Predefined Count",
1,
defs.getPredefined().length );
assertEquals( "ClassLoader Predefined",
"*system*",
defs.getPredefined()[ 0 ] );
assertEquals( "ClassLoader Default",
"join2",
defs.getDefault() );
assertEquals( "ClassLoader Count",
2,
defs.getClassLoaders().length );
assertEquals( "Join Count",
2,
defs.getJoins().length );
assertNotNull( "ClassLoader cl1",
defs.getClassLoader( "cl1" ) );
assertNotNull( "ClassLoader cl2",
defs.getClassLoader( "cl2" ) );
assertNotNull( "Join join1",
defs.getJoin( "join1" ) );
assertNotNull( "Join join2",
defs.getJoin( "join2" ) );
assertEquals( "ClassLoader cl1.entrys Name",
defs.getClassLoader( "cl1" ).getName(),
"cl1" );
assertEquals( "ClassLoader cl1.entrys Count",
defs.getClassLoader( "cl1" ).getEntrys().length,
2 );
assertEquals( "ClassLoader cl1.filesets Count",
defs.getClassLoader( "cl1" ).getFilesets().length,
1 );
assertEquals( "ClassLoader cl1.extensions Count",
defs.getClassLoader( "cl1" ).getExtensions().length,
1 );
assertEquals( "ClassLoader cl1.fileset[0] Dir",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getBaseDirectory(),
"someDir" );
assertEquals( "ClassLoader cl1.fileset[0] Include count",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getIncludes().length,
2 );
assertEquals( "ClassLoader cl1.fileset[0] Exclude count",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getExcludes().length,
1 );
assertEquals( "ClassLoader cl1.fileset[0].include[0] name",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getIncludes()[ 0 ],
"**/*.jar" );
assertEquals( "ClassLoader cl1.fileset[0].include[1] name",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getIncludes()[ 1 ],
"**/*.bar" );
assertEquals( "ClassLoader cl1.fileset[0].exclude[0] name",
defs.getClassLoader( "cl1" ).getFilesets()[ 0
].getExcludes()[ 0 ],
"**/unwanted/*" );
assertEquals( "ClassLoader cl1.entrys[0] Location",
defs.getClassLoader( "cl1" ).getEntrys()[ 0 ],
"someFile.jar" );
assertEquals( "ClassLoader cl1.entrys[1] Location",
defs.getClassLoader( "cl1" ).getEntrys()[ 1 ],
"someOtherFile.jar" );
assertEquals( "ClassLoader cl2.entrys Name",
defs.getClassLoader( "cl2" ).getName(),
"cl2" );
assertEquals( "ClassLoader cl2.entrys Count",
defs.getClassLoader( "cl2" ).getEntrys().length,
1 );
assertEquals( "ClassLoader cl2.filesets Count",
defs.getClassLoader( "cl2" ).getFilesets().length,
0 );
assertEquals( "ClassLoader cl2.extensions Count",
defs.getClassLoader( "cl2" ).getExtensions().length,
0 );
assertEquals( "ClassLoader cl2.entrys[0] Location",
defs.getClassLoader( "cl2" ).getEntrys()[ 0 ],
"aFile.jar" );
assertEquals( "Join join1.refs Name",
defs.getJoin( "join1" ).getName(),
"join1" );
assertEquals( "Join join1.refs Count",
defs.getJoin( "join1" ).getClassloaders().length,
1 );
assertEquals( "Join join1.refs[0] Name",
defs.getJoin( "join1" ).getClassloaders()[ 0 ],
"cl1" );
assertEquals( "Join join2.refs Name",
defs.getJoin( "join2" ).getName(),
"join2" );
assertEquals( "Join join2.refs Count",
defs.getJoin( "join2" ).getClassloaders().length,
2 );
assertEquals( "Join join2.refs[0] Name",
defs.getJoin( "join2" ).getClassloaders()[ 0 ],
"cl1" );
assertEquals( "Join join2.refs[1] Name",
defs.getJoin( "join2" ).getClassloaders()[ 1 ],
"cl2" );
}
public void testConfig2()
throws Exception
{
try
{
buildFromResource( "config2.xml" );
}
catch( final Throwable t )
{
return;
}
fail( "Should have failed as loaded a " +
"configuration with no default set" );
}
public void testConfig3()
throws Exception
{
try
{
buildFromResource( "config3.xml" );
}
catch( final Throwable t )
{
return;
}
fail( "Should have failed as loaded a " +
"configuration with no version set" );
}
public void testConfig4()
throws Exception
{
try
{
buildFromResource( "config4.xml" );
}
catch( final Throwable t )
{
return;
}
fail( "Should have failed as loaded a " +
"configuration with bad version" );
}
}
1.1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/reader/test/config1.xml
Index: config1.xml
===================================================================
<classloaders default="join2" version="1.0">
<predefined name="*system*"/>
<classloader name="cl1" parent="*system*">
<entry location="someFile.jar"/>
<entry location="someOtherFile.jar"/>
<fileset dir="someDir">
<include name="**/*.jar"/>
<include name="**/*.bar"/>
<exclude name="**/unwanted/*"/>
</fileset>
<extension
name="Avalon.Framework"
specification-version="4.1"
specification-vendor="Apache"
implementation-version="4.1"
implementation-vendor="Apache"
implementation-vendor-id="Apache"
implementation-url="http://jakarta..." />
</classloader>
<classloader name="cl2" parent="*system*">
<entry location="aFile.jar"/>
</classloader>
<join name="join1">
<classloader-ref name="cl1"/>
</join>
<join name="join2">
<classloader-ref name="cl1"/>
<classloader-ref name="cl2"/>
</join>
</classloaders>
1.1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/reader/test/config2.xml
Index: config2.xml
===================================================================
<classloaders version="1.0">
<predefined name="*system*"/>
</classloaders>
1.1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/reader/test/config3.xml
Index: config3.xml
===================================================================
<classloaders default="*system*">
<predefined name="*system*"/>
</classloaders>
1.1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/reader/test/config4.xml
Index: config4.xml
===================================================================
<classloaders default="*system*" version="1.2">
<predefined name="*system*"/>
</classloaders>
1.4 +2 -2
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/AbstractLoaderTestCase.java
Index: AbstractLoaderTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/AbstractLoaderTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractLoaderTestCase.java 16 Sep 2002 08:12:17 -0000 1.3
+++ AbstractLoaderTestCase.java 16 Sep 2002 08:15:17 -0000 1.4
@@ -11,7 +11,7 @@
import junit.framework.TestCase;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.excalibur.loader.builder.ClassLoaderSetBuilder;
+import org.apache.excalibur.loader.reader.ClassLoaderSetBuilder;
import org.apache.excalibur.loader.metadata.ClassLoaderSetMetaData;
/**
1.4 +1 -1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/LoaderTestSuite.java
Index: LoaderTestSuite.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/LoaderTestSuite.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LoaderTestSuite.java 7 Sep 2002 05:48:01 -0000 1.3
+++ LoaderTestSuite.java 16 Sep 2002 08:15:17 -0000 1.4
@@ -9,7 +9,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.excalibur.loader.builder.test.ReaderTestCase;
+import org.apache.excalibur.loader.reader.test.ReaderTestCase;
import org.apache.excalibur.loader.verifier.test.VerifierTestCase;
/**
1.4 +1 -1
jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/VerifierTestCase.java
Index: VerifierTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/VerifierTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- VerifierTestCase.java 16 Sep 2002 08:12:17 -0000 1.3
+++ VerifierTestCase.java 16 Sep 2002 08:15:17 -0000 1.4
@@ -8,7 +8,7 @@
package org.apache.excalibur.loader.verifier.test;
import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.excalibur.loader.builder.ClassLoaderSetBuilder;
+import org.apache.excalibur.loader.reader.ClassLoaderSetBuilder;
import org.apache.excalibur.loader.metadata.ClassLoaderSetMetaData;
import org.apache.excalibur.loader.test.AbstractLoaderTestCase;
import org.apache.excalibur.loader.verifier.ClassLoaderVerifier;
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>