From f2b75376d9d282f21208c1b1247f8c2da5ee8920 Mon Sep 17 00:00:00 2001
From: jvanzyl q~m3z;@D5-y;9Q&6s1Koee7fZT135*gC65#2vKX;%Ad5s#PCbQ
zN|-?CDUSk1>4YWi&eiLOw31W$5XzyitOQ~|S7YEG&49=SOR=%l!KIZWYeHgufh0^N
z-q=;E>hk7;ZC*y7HScbJ;~EKR!kR9)r#Ajxtkf$^y!0O1Q${RAvEeRzfp9b~M7KUH
zChpVw-n&J8f@oC82WD}FHCx#gsXKDV971dn3@Iqhv&fkck1cY35#)O&FAE})c1?jg
z4ELCXK|io8@W>2_-7X_7`%s0^gV`G(w38CIxyw^F;S5wCZ
ClassWorld.
- *
- *
- * This class most closed maps to the ClassLoader
- * role from Java and in facts can provide a ClassLoader
- * view of itself using {@link #getClassLoader}.
- *
ClassWorld errors.
- *
- * @author bob mcwhirter
- * @version $Id$
- */
-public class ClassWorldException extends Exception
-{
- // ------------------------------------------------------------
- // Instance members
- // ------------------------------------------------------------
-
- /**
- * The world.
- */
- private ClassWorld world;
-
- // ------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------
-
- /**
- * Construct.
- *
- * @param world The world.
- */
- public ClassWorldException( final ClassWorld world )
- {
- this.world = world;
- }
-
- /**
- * Construct.
- *
- * @param world The world.
- * @param msg The detail message.
- */
- public ClassWorldException( final ClassWorld world, final String msg )
- {
- super( msg );
- this.world = world;
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
-
- /**
- * Retrieve the world.
- *
- * @return The world.
- */
- public ClassWorld getWorld()
- {
- return this.world;
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java b/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java
deleted file mode 100644
index 3f182ef..0000000
--- a/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.codehaus.classworlds;
-
-import java.util.HashMap;
-import java.util.Collection;
-import java.util.Vector;
-import java.util.Iterator;
-
-/**
- * A reverse adapter for ClassWorlds
- *
- * @author Andrew Williams
- * @version $Id$
- */
-public class ClassWorldReverseAdapter
- extends org.codehaus.plexus.classworlds.ClassWorld
-{
- private static HashMap instances = new HashMap();
-
- public static ClassWorldReverseAdapter getInstance( ClassWorld oldWorld )
- {
- if ( instances.containsKey( oldWorld ) )
- return (ClassWorldReverseAdapter) instances.get( oldWorld );
-
- ClassWorldReverseAdapter adapter = new ClassWorldReverseAdapter( oldWorld );
- instances.put( oldWorld, adapter );
-
- return adapter;
- }
-
- private ClassWorld world;
-
- private ClassWorldReverseAdapter( ClassWorld newWorld )
- {
- super();
- this.world = newWorld;
- }
-
- public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id )
- throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
- {
- try
- {
- return ClassRealmReverseAdapter.getInstance( world.newRealm( id ) );
- }
- catch ( DuplicateRealmException e )
- {
- throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() );
- }
- }
-
- public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id,
- ClassLoader classLoader )
- throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
- {
- try
- {
- return ClassRealmReverseAdapter.getInstance( world.newRealm( id,
- classLoader ) );
- }
- catch ( DuplicateRealmException e )
- {
- throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() );
- }
- }
-
- public void disposeRealm( String id )
- throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
- {
- try
- {
- world.disposeRealm( id );
- }
- catch ( NoSuchRealmException e )
- {
- throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() );
- }
- }
-
- public org.codehaus.plexus.classworlds.realm.ClassRealm getRealm( String id )
- throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
- {
- try
- {
- return ClassRealmReverseAdapter.getInstance( world.getRealm( id ) );
- }
- catch ( NoSuchRealmException e )
- {
- throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() );
- }
- }
-
- public Collection getRealms()
- {
- Collection realms = world.getRealms();
- Vector ret = new Vector();
-
- Iterator it = realms.iterator();
- while ( it.hasNext() )
- {
- ClassRealm realm = (ClassRealm) it.next();
- ret.add( ClassRealmReverseAdapter.getInstance( realm ) );
- }
-
- return ret;
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/ConfigurationException.java b/src/main/java/org/codehaus/classworlds/ConfigurationException.java
deleted file mode 100644
index 2faaa0d..0000000
--- a/src/main/java/org/codehaus/classworlds/ConfigurationException.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-/**
- * Indicates an error during Launcher configuration.
- *
- * @author bob mcwhirter
- * @version $Id$
- */
-public class ConfigurationException extends Exception
-{
- /**
- * Construct.
- *
- * @param msg The message.
- */
- public ConfigurationException( String msg )
- {
- super( msg );
- }
-
- /**
- * Construct.
- *
- * @param msg The message.
- * @param lineNo The number of configuraton line where the problem occured.
- * @param line The configuration line where the problem occured.
- */
- public ConfigurationException( String msg, int lineNo, String line )
- {
- super( msg + " (" + lineNo + "): " + line );
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/Configurator.java b/src/main/java/org/codehaus/classworlds/Configurator.java
deleted file mode 100644
index c630158..0000000
--- a/src/main/java/org/codehaus/classworlds/Configurator.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package org.codehaus.classworlds;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-
-/**
- * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Configurator
- * provided for legacy code
- *
- * @author Andrew Williams
- * @version $Id$
- */
-public class Configurator
-{
- private ConfiguratorAdapter config;
-
- /** Construct.
- *
- * @param launcher The launcher to configure.
- */
- public Configurator( Launcher launcher )
- {
- config = ConfiguratorAdapter.getInstance(
- new org.codehaus.plexus.classworlds.launcher.Configurator( launcher ), launcher );
- }
-
- /** Construct.
- *
- * @param world The classWorld to configure.
- */
- public Configurator( ClassWorld world )
- {
- config = ConfiguratorAdapter.getInstance(
- new org.codehaus.plexus.classworlds.launcher.Configurator(
- ClassWorldReverseAdapter.getInstance( world ) ), world );
- }
-
- /** set world.
- * this setter is provided so you can use the same configurator to configure several "worlds"
- *
- * @param world The classWorld to configure.
- */
- public void setClassWorld( ClassWorld world )
- {
- config.setClassWorld( world );
- }
-
- /**
- * Configure from a file.
- *
- * @param is The config input stream
- * @throws IOException If an error occurs reading the config file.
- * @throws MalformedURLException If the config file contains invalid URLs.
- * @throws ConfigurationException If the config file is corrupt.
- * @throws DuplicateRealmException If the config file defines two realms with the same id.
- * @throws NoSuchRealmException If the config file defines a main entry point in
- * a non-existent realm.
- */
- public void configure( InputStream is )
- throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
- {
- config.configureAdapter( is );
- }
-
- /**
- * Associate parent realms with their children.
- */
- protected void associateRealms()
- {
- config.associateRealms();
- }
-
- /**
- * Load a glob into the specified classloader.
- *
- * @param line The path configuration line.
- * @param realm The realm to populate
- * @throws MalformedURLException If the line does not represent
- * a valid path element.
- * @throws FileNotFoundException If the line does not represent
- * a valid path element in the filesystem.
- */
- protected void loadGlob( String line, ClassRealm realm )
- throws MalformedURLException, FileNotFoundException
- {
- loadGlob( line, realm, false );
- }
-
- /**
- * Load a glob into the specified classloader.
- *
- * @param line The path configuration line.
- * @param realm The realm to populate
- * @param optionally Whether the path is optional or required
- * @throws MalformedURLException If the line does not represent
- * a valid path element.
- * @throws FileNotFoundException If the line does not represent
- * a valid path element in the filesystem.
- */
- protected void loadGlob( String line, ClassRealm realm, boolean optionally )
- throws MalformedURLException, FileNotFoundException
- {
- config.loadGlob( line, realm, optionally );
- }
-
- /**
- * Filter a string for system properties.
- *
- * @param text The text to filter.
- * @return The filtered text.
- * @throws ConfigurationException If the property does not
- * exist or if there is a syntax error.
- */
- protected String filter( String text )
- throws ConfigurationException
- {
- return config.filter( text );
- }
-
-}
-
diff --git a/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java b/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java
deleted file mode 100644
index 84023f5..0000000
--- a/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.codehaus.classworlds;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.HashMap;
-
-/**
- * Created by IntelliJ IDEA.
- *
- * @uthor: Andrew Williams
- * @since: Nov 25, 2006
- * @version: $Id$
- */
-public class ConfiguratorAdapter
- extends Configurator
-{
- private static HashMap instances = new HashMap();
-
- public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig,
- Launcher launcher )
- {
- if ( instances.containsKey( newConfig ) )
- return (ConfiguratorAdapter) instances.get( newConfig );
-
- ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, launcher );
- instances.put( newConfig, adapter );
-
- return adapter;
- }
-
- public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig,
- ClassWorld world )
- {
- if ( instances.containsKey( newConfig ) )
- return (ConfiguratorAdapter) instances.get( newConfig );
-
- ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, world );
- instances.put( newConfig, adapter );
-
- return adapter;
- }
-
- private org.codehaus.plexus.classworlds.launcher.Configurator config;
-
- private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, Launcher launcher )
- {
- super( launcher );
- this.config = config;
- }
-
- private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, ClassWorld world )
- {
- super( world );
- this.config = config;
- }
-
- public void associateRealms()
- {
- config.associateRealms();
- }
-
- public void configureAdapter( InputStream is )
- throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
- {
- try
- {
- config.configure( is );
- }
- catch ( org.codehaus.plexus.classworlds.launcher.ConfigurationException e )
- {
- throw new ConfigurationException( e.getMessage() );
- }
- catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
- {
- throw new DuplicateRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() );
- }
- catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
- {
- throw new NoSuchRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() );
- }
- }
-
-}
diff --git a/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java b/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java
deleted file mode 100644
index ee818b4..0000000
--- a/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package org.codehaus.classworlds;
-
-/**
- * A compatibility wrapper for org.codehaus.plexus.classworlds.realm.ClassRealm
- * provided for legacy code
- *
- * @author Andrew Williams
- * @version $Id$
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
-
-public class DefaultClassRealm
- implements ClassRealm
-{
- private ClassRealmAdapter adapter;
-
- public DefaultClassRealm( ClassWorld world, String id )
- {
- this( world, id, null );
- }
-
- public DefaultClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader )
- {
- this.adapter = ClassRealmAdapter.getInstance(
- new org.codehaus.plexus.classworlds.realm.ClassRealm(
- ClassWorldReverseAdapter.getInstance( world ), id, foreignClassLoader ) );
- }
-
- public URL[] getConstituents()
- {
- return adapter.getConstituents();
- }
-
- public ClassRealm getParent()
- {
- return adapter.getParentRealm();
- }
-
- public void setParent( ClassRealm parent )
- {
- adapter.setParent( parent );
- }
-
- public String getId()
- {
- return adapter.getId();
- }
-
- public ClassWorld getWorld()
- {
- return adapter.getWorld();
- }
-
- public void importFrom( String realmId, String packageName )
- throws NoSuchRealmException
- {
- adapter.importFrom( realmId, packageName );
- }
-
- public void addConstituent( URL constituent )
- {
- adapter.addConstituent( constituent );
- }
-
- /**
- * Adds a byte[] class definition as a constituent for locating classes.
- * Currently uses BytesURLStreamHandler to hold a reference of the byte[] in memory.
- * This ensures we have a unifed URL resource model for all constituents.
- * The code to cache to disk is commented out - maybe a property to choose which method?
- *
- * @param constituent class name
- * @param b the class definition as a byte[]
- */
- public void addConstituent(String constituent,
- byte[] b) throws ClassNotFoundException
- {
- try
- {
- File path, file;
- if (constituent.lastIndexOf('.') != -1)
- {
- path = new File("byteclass/" + constituent.substring(0, constituent.lastIndexOf('.') + 1).replace('.', File.separatorChar));
-
- file = new File(path, constituent.substring(constituent.lastIndexOf('.') + 1) + ".class");
- }
- else
- {
- path = new File("byteclass/");
-
- file = new File(path, constituent + ".class");
- }
-
- addConstituent( new URL( null,
- file.toURI().toURL().toExternalForm(),
- new BytesURLStreamHandler(b) ) );
- }
- catch (java.io.IOException e)
- {
- throw new ClassNotFoundException( "Couldn't load byte stream.", e );
- }
- }
-
- public ClassRealm locateSourceRealm( String classname )
- {
- return adapter.locateSourceRealm( classname );
- }
-
- public ClassLoader getClassLoader()
- {
- return adapter.getClassLoader();
- }
-
- public ClassRealm createChildRealm( String id )
- throws DuplicateRealmException
- {
- return adapter.createChildRealm( id );
- }
-
- // ----------------------------------------------------------------------
- // ClassLoader API
- // ----------------------------------------------------------------------
-
- public Class loadClass( String name )
- throws ClassNotFoundException
- {
- return adapter.loadClass( name );
- }
-
- public URL getResource( String name )
- {
- return adapter.getResource( name );
- }
-
- public InputStream getResourceAsStream( String name )
- {
- return adapter.getResourceAsStream( name );
- }
-
- public Enumeration findResources(String name)
- throws IOException
- {
- return adapter.findResources( name );
- }
-
- public void display()
- {
- adapter.display();
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java b/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java
deleted file mode 100644
index 8808ade..0000000
--- a/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-/**
- * Indicates an attempt to add a ClassRealm to a
- * ClassWorld with a duplicate id.
- *
- * @author bob mcwhirter
- * @version $Id$
- */
-public class DuplicateRealmException extends ClassWorldException
-{
- // ------------------------------------------------------------
- // Instance members
- // ------------------------------------------------------------
-
- /**
- * The realm id.
- */
- private String id;
-
- // ------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------
-
- /**
- * Construct.
- *
- * @param world The world.
- * @param id The realm id.
- */
- public DuplicateRealmException( ClassWorld world,
- String id )
- {
- super( world, id );
- this.id = id;
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
-
- /**
- * Retrieve the duplicate realm id.
- *
- * @return The id.
- */
- public String getId()
- {
- return this.id;
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/Launcher.java b/src/main/java/org/codehaus/classworlds/Launcher.java
deleted file mode 100644
index de4ae59..0000000
--- a/src/main/java/org/codehaus/classworlds/Launcher.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.codehaus.classworlds;
-
-/**
- * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Launcher
- * provided for legacy code
- *
- * @author Andrew Williams
- * @version $Id$
- */
-public class Launcher
- extends org.codehaus.plexus.classworlds.launcher.Launcher
-{
- public Launcher()
- {
- }
-
-
- // ------------------------------------------------------------
- // Class methods
- // ------------------------------------------------------------
-
- /**
- * Launch the launcher from the command line.
- * Will exit using System.exit with an exit code of 0 for success, 100 if there was an unknown exception,
- * or some other code for an application error.
- *
- * @param args The application command-line arguments.
- */
- public static void main( String[] args )
- {
- org.codehaus.plexus.classworlds.launcher.Launcher.main( args );
- }
-
- /**
- * Launch the launcher.
- *
- * @param args The application command-line arguments.
- * @return an integer exit code
- * @throws Exception If an error occurs.
- */
- public static int mainWithExitCode( String[] args )
- throws Exception
- {
- return org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode( args );
- }
-}
diff --git a/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java b/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java
deleted file mode 100644
index a05401b..0000000
--- a/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-/**
- * Indicates an attempt to retrieve a ClassRealm from a
- * ClassWorld with an invalid id.
- *
- * @author bob mcwhirter
- * @version $Id$
- */
-public class NoSuchRealmException extends ClassWorldException
-{
- // ------------------------------------------------------------
- // Instance members
- // ------------------------------------------------------------
-
- /**
- * The realm id.
- */
- private String id;
-
- // ------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------
-
- /**
- * Construct.
- *
- * @param world The world.
- * @param id The realm id.
- */
- public NoSuchRealmException( ClassWorld world,
- String id )
- {
- super( world, id );
- this.id = id;
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
-
- /**
- * Retrieve the invalid realm id.
- *
- * @return The id.
- */
- public String getId()
- {
- return this.id;
- }
-}
diff --git a/src/test/java/org/codehaus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/classworlds/ClassWorldTest.java
deleted file mode 100644
index 93f6f35..0000000
--- a/src/test/java/org/codehaus/classworlds/ClassWorldTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-import junit.framework.TestCase;
-
-public class ClassWorldTest extends TestCase
-{
- private ClassWorld world;
-
- public ClassWorldTest( String name )
- {
- super( name );
- }
-
- public void setUp()
- {
- this.world = new ClassWorld();
- }
-
- public void tearDown()
- {
- this.world = null;
- }
-
- public void testEmpty()
- {
- assertTrue( this.world.getRealms().isEmpty() );
- }
-
- public void testNewRealm() throws Exception
- {
- ClassRealm realm = this.world.newRealm( "foo" );
-
- assertNotNull( realm );
- }
-
- public void testGetRealm() throws Exception
- {
- ClassRealm realm = this.world.newRealm( "foo" );
-
- assertSame( realm,
- this.world.getRealm( "foo" ) );
- }
-
- public void testNewRealm_Duplicate() throws Exception
- {
- try
- {
- this.world.newRealm( "foo" );
- this.world.newRealm( "foo" );
-
- fail( "throw DuplicateRealmException" );
- }
- catch ( DuplicateRealmException e )
- {
- // expected and correct
-
-// TODO decide if these tests should be re-enabled, usign the wrappers they simply don't make sense
-// assertSame( this.world,
-// e.getWorld() );
-
- assertEquals( "foo",
- e.getId() );
- }
- }
-
- public void testGetRealm_NoSuch() throws Exception
- {
- try
- {
- this.world.getRealm( "foo" );
- fail( "throw NoSuchRealmException" );
- }
- catch ( NoSuchRealmException e )
- {
- // expected and correct
-
-// TODO decide if these tests should be re-enabled, usign the wrappers they simply don't make sense
-// assertSame( this.world,
-// e.getWorld() );
-
- assertEquals( "foo",
- e.getId() );
- }
- }
-
- public void testGetRealms() throws Exception
- {
- assertTrue( this.world.getRealms().isEmpty() );
-
- ClassRealm foo = this.world.newRealm( "foo" );
-
- assertEquals( 1,
- this.world.getRealms().size() );
-
- assertTrue( this.world.getRealms().contains( foo ) );
-
- ClassRealm bar = this.world.newRealm( "bar" );
-
- assertEquals( 2,
- this.world.getRealms().size() );
-
- assertTrue( this.world.getRealms().contains( bar ) );
- }
-}
diff --git a/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java b/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java
deleted file mode 100644
index c41f48e..0000000
--- a/src/test/java/org/codehaus/classworlds/DefaultClassRealmTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.net.URL;
-
-public class DefaultClassRealmTest
- extends TestCase
-{
- public DefaultClassRealmTest( String name )
- {
- super( name );
- }
-
- // ----------------------------------------------------------------------
- // Class testing
- // ----------------------------------------------------------------------
-
- public void testLoadClassFromRealm()
- throws Exception
- {
- DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" );
-
- mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- mainRealm.loadClass( "org.codehaus.plexus.Component0" );
- }
-
- public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm()
- throws Exception
- {
- DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" );
-
- mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- ClassRealm childRealm = mainRealm.createChildRealm( "child" );
-
- childRealm.loadClass( "org.codehaus.plexus.Component0" );
- }
-
- public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm()
- throws Exception
- {
- DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" );
-
- mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- ClassRealm childRealm = mainRealm.createChildRealm( "child" );
-
- ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" );
-
- grandchildRealm.loadClass( "org.codehaus.plexus.Component0" );
- }
-
- public void testLoadNonExistentClass()
- throws Exception
- {
- DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" );
-
- mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- try
- {
- mainRealm.loadClass( "org.foo.bar.NonExistentClass" );
-
- fail( "A ClassNotFoundException should have been thrown!" );
- }
- catch ( ClassNotFoundException e )
- {
- }
- }
-
- public void testImport()
- throws Exception
- {
- ClassWorld world = new ClassWorld();
-
- ClassRealm r0 = world.newRealm( "r0" );
-
- ClassRealm r1 = world.newRealm( "r1" );
-
- r0.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- r1.importFrom( "r0", "org.codehaus.plexus" );
-
- r1.loadClass( "org.codehaus.plexus.Component0" );
- }
-
- // ----------------------------------------------------------------------
- // Resource testing
- // ----------------------------------------------------------------------
-
- public void testResource()
- throws Exception
- {
- DefaultClassRealm mainRealm = new DefaultClassRealm( new ClassWorld(), "main" );
-
- mainRealm.addConstituent( getJarUrl( "component0-1.0.jar" ) );
-
- URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" );
-
- assertNotNull( resource );
- }
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- protected URL getJarUrl( String jarName )
- throws Exception
- {
- File jarFile = new File( System.getProperty( "basedir" ), "src/test-jars/" + jarName );
-
- return jarFile.toURI().toURL();
- }
-}
-
diff --git a/src/test/java/org/codehaus/classworlds/LauncherTest.java b/src/test/java/org/codehaus/classworlds/LauncherTest.java
deleted file mode 100644
index 3bf222a..0000000
--- a/src/test/java/org/codehaus/classworlds/LauncherTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package org.codehaus.classworlds;
-
-/*
- $Id$
-
- Copyright 2002 (C) The Werken Company. All Rights Reserved.
-
- Redistribution and use of this software and associated documentation
- ("Software"), with or without modification, are permitted provided
- that the following conditions are met:
-
- 1. Redistributions of source code must retain copyright
- statements and notices. Redistributions must also contain a
- copy of this document.
-
- 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 name "classworlds" must not be used to endorse or promote
- products derived from this Software without prior written
- permission of The Werken Company. For written permission,
- please contact bob@werken.com.
-
- 4. Products derived from this Software may not be called "classworlds"
- nor may "classworlds" appear in their names without prior written
- permission of The Werken Company. "classworlds" is a registered
- trademark of The Werken Company.
-
- 5. Due credit should be given to The Werken Company.
- (http://classworlds.werken.com/).
-
- THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
- ``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 WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, 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.
-
- */
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.FileInputStream;
-
-public class LauncherTest
- extends TestCase
-{
- private Launcher launcher;
-
- public LauncherTest( String name )
- {
- super( name );
- }
-
- public void setUp()
- {
- System.setProperty( "java.protocol.handler.pkgs", "org.codehaus.classworlds.protocol" );
-
- this.launcher = new Launcher();
- }
-
- public void tearDown()
- {
- this.launcher = null;
- }
-
- public void testConfigure_Valid() throws Exception
- {
- launcher.configure( getConfigPath( "valid-launch.conf" ) );
-
- Class mainClass = launcher.getMainClass();
-
- assertNotNull( mainClass );
-
- assertEquals( "a.A", mainClass.getName() );
-
- assertEquals( "app", launcher.getMainRealm().getId() );
- }
-
- public void testLaunch_ValidStandard() throws Exception
- {
- launcher.configure( getConfigPath( "valid-launch.conf" ) );
-
- launcher.launch( new String[]{} );
- }
-
- public void testLaunch_ValidStandardExitCode() throws Exception
- {
- launcher.configure( getConfigPath( "valid-launch-exitCode.conf" ) );
-
- launcher.launch( new String[]{} );
-
- assertEquals( "check exit code", 15, launcher.getExitCode() );
- }
-
- public void testLaunch_ValidEnhanced() throws Exception
- {
- launcher.configure( getConfigPath( "valid-enh-launch.conf" ) );
-
- launcher.launch( new String[]{} );
- }
-
- public void testLaunch_ValidEnhancedExitCode() throws Exception
- {
- launcher.configure( getConfigPath( "valid-enh-launch-exitCode.conf" ) );
-
- launcher.launch( new String[]{} );
-
- assertEquals( "check exit code", 45, launcher.getExitCode() );
- }
-
- public void testLaunch_NoSuchMethod() throws Exception
- {
- launcher.configure( getConfigPath( "launch-nomethod.conf" ) );
-
- try
- {
- launcher.launch( new String[]{} );
- fail( "should have thrown NoSuchMethodException" );
- }
- catch ( NoSuchMethodException e )
- {
- // expected and correct
- }
- }
-
- public void testLaunch_ClassNotFound() throws Exception
- {
- launcher.configure( getConfigPath( "launch-noclass.conf" ) );
-
- try
- {
- launcher.launch( new String[]{} );
- fail( "throw ClassNotFoundException" );
- }
- catch ( ClassNotFoundException e )
- {
- // expected and correct
- }
- }
-
- private FileInputStream getConfigPath( String name )
- throws Exception
- {
- return new FileInputStream( new File( new File( System.getProperty( "basedir" ), "src/test/test-data" ), name ) );
- }
-}
From ce5ced670bd90428b4b3f5851ecf7746e7557e59 Mon Sep 17 00:00:00 2001
From: jvanzyl ClassRealms, indexed by id.
- *
+ *
* @author bob mcwhirter
* @version $Id$
*/
@@ -36,8 +34,7 @@ public class ClassWorld
{
private Map realms;
- public ClassWorld( String realmId,
- ClassLoader classLoader )
+ public ClassWorld( String realmId, ClassLoader classLoader )
{
this();
@@ -62,8 +59,7 @@ public ClassRealm newRealm( String id )
return newRealm( id, null );
}
- public synchronized ClassRealm newRealm( String id,
- ClassLoader classLoader )
+ public synchronized ClassRealm newRealm( String id, ClassLoader classLoader )
throws DuplicateRealmException
{
if ( realms.containsKey( id ) )
@@ -108,6 +104,6 @@ public synchronized ClassRealm getRealm( String id )
public synchronized Collection getRealms()
{
- return Collections.unmodifiableList( new ArrayList(realms.values()) );
+ return Collections.unmodifiableList( new ArrayList( realms.values() ) );
}
}
diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java
index af0ce3f..76e3cba 100644
--- a/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java
+++ b/src/main/java/org/codehaus/plexus/classworlds/realm/ClassRealm.java
@@ -2,22 +2,22 @@
/*
* Copyright 2001-2006 Codehaus Foundation.
- *
- * Licensed 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.
+ *
+ * Licensed 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 org.codehaus.plexus.classworlds.strategy.DefaultStrategy;
+import org.codehaus.plexus.classworlds.strategy.ForeignStrategy;
import org.codehaus.plexus.classworlds.strategy.Strategy;
-import org.codehaus.plexus.classworlds.strategy.StrategyFactory;
+import org.codehaus.plexus.classworlds.strategy.UrlUtils;
import org.codehaus.plexus.classworlds.ClassWorld;
import java.io.IOException;
@@ -29,19 +29,7 @@
import java.util.Iterator;
import java.util.TreeSet;
-
/**
- * Implementation of ClassRealm. The realm is the class loading gateway.
- * The search is proceded as follows:
- * true if this entry matches the
- * classname, otherwise false.
+ * @return true if this entry matches the classname, otherwise false.
*/
boolean matches( String classname )
{
@@ -78,17 +73,12 @@ boolean matches( String classname )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
- * Compare this entry to another for relative ordering.
- *
- *
- * The natural ordering of Entry objects is reverse-alphabetical
- * based upon package name.
- *
- *
+ * Compare this entry to another for relative ordering. The natural ordering of Entry
+ * objects is reverse-alphabetical based upon package name.
+ *
* @param thatObj The object to compare.
- * @return -1 if this object sorts before that object, 0
- * if they are equal, or 1 if this object sorts
- * after that object.
+ * @return -1 if this object sorts before that object, 0 if they are equal, or 1 if this object
+ * sorts after that object.
*/
public int compareTo( Object thatObj )
{
@@ -109,16 +99,12 @@ public int compareTo( Object thatObj )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
- * Test this entry for equality to another.
- *
- *
- * Consistent with {@link #compareTo}, this method tests
- * for equality purely on the package name.
- *
- *
+ * Test this entry for equality to another. Consistent with {@link #compareTo}, this
+ * method tests for equality purely on the package name.
+ *
* @param thatObj The object to compare
- * @return true if the two objects are
- * semantically equivalent, otherwise false.
+ * @return true if the two objects are semantically equivalent, otherwise
+ * false.
*/
public boolean equals( Object thatObj )
{
@@ -128,10 +114,8 @@ public boolean equals( Object thatObj )
}
/**
- *
- * Consistent with {@link #equals}, this method creates a hashCode
- * based on the packagename.
- *
+ * Consistent with {@link #equals}, this method creates a hashCode based on the
+ * packagename.
*/
public int hashCode()
{
@@ -140,6 +124,6 @@ public int hashCode()
public String toString()
{
- return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]";
+ return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]";
}
}
diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java
index 4843f96..1fae429 100644
--- a/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java
+++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java
@@ -1,7 +1,6 @@
package org.codehaus.plexus.classworlds.strategy;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
-import org.codehaus.plexus.classworlds.UrlUtils;
/*
* Copyright 2001-2006 Codehaus Foundation.
@@ -25,7 +24,7 @@
public abstract class AbstractStrategy
implements Strategy
{
- private ClassRealm realm;
+ protected ClassRealm realm;
public AbstractStrategy( ClassRealm realm )
{
diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java
index 6e20c0d..6d9831d 100644
--- a/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java
+++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/DefaultStrategy.java
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-import org.codehaus.plexus.classworlds.UrlUtils;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import java.io.IOException;
@@ -43,11 +42,6 @@ public DefaultStrategy( ClassRealm realm )
public Class loadClass( String name )
throws ClassNotFoundException
{
- if ( name.startsWith( "org.codehaus.plexus.classworlds." ) || name.startsWith( "org.codehaus.classworlds." ) )
- {
- return getRealm().getWorld().getClass().getClassLoader().loadClass( name );
- }
-
try
{
ClassRealm sourceRealm = getRealm().locateSourceRealm( name );
@@ -79,8 +73,6 @@ public Class loadClass( String name )
public URL getResource( String name )
{
- name = getNormalizedResource( name );
-
URL resource = null;
ClassRealm sourceRealm = getRealm().locateSourceRealm( name );
@@ -126,8 +118,6 @@ public InputStream getResourceAsStream( String name )
public Enumeration findResources( String name )
throws IOException
{
- name = UrlUtils.normalizeUrlPath( name );
-
Vector resources = new Vector();
// Load imports
diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java
index e8e3c79..2ee2839 100644
--- a/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java
+++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/ForeignStrategy.java
@@ -8,19 +8,15 @@
import java.util.Vector;
/**
- * Created by IntelliJ IDEA.
- *
- * @uthor: Andrew Williams
- * @since: Nov 22, 2006
- * @version: $Id$
+ * @author Jason van Zyl
+ * @author: Andrew Williams
*/
public class ForeignStrategy
extends DefaultStrategy
{
private ClassLoader foreign;
- public ForeignStrategy( ClassRealm realm,
- ClassLoader foreign )
+ public ForeignStrategy( ClassRealm realm, ClassLoader foreign )
{
super( realm );
@@ -42,8 +38,6 @@ public Class loadClass( String name )
public URL getResource( String name )
{
- name = getNormalizedResource( name );
-
URL resource;
resource = foreign.getResource( name );
@@ -59,8 +53,6 @@ public URL getResource( String name )
public Enumeration findResources( String name )
throws IOException
{
- name = getNormalizedResource( name );
-
Vector resources = new Vector();
// Load from DefaultStrategy
diff --git a/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java
deleted file mode 100644
index aefadb6..0000000
--- a/src/main/java/org/codehaus/plexus/classworlds/strategy/StrategyFactory.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.codehaus.plexus.classworlds.strategy;
-
-/*
- * Copyright 2001-2006 Codehaus Foundation.
- *
- * Licensed 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 org.codehaus.plexus.classworlds.realm.ClassRealm;
-
-/**
- * StrategyFactory loads a strategy, either default or from a given hint.
- *
- * @uthor: Andrew Williams
- * @since: Nov 19, 2006
- * @version: $Id$
- */
-public class StrategyFactory
-{
-
- public static Strategy getStrategy( ClassRealm realm )
- {
- return getStrategy( realm, "default", null );
- }
-
- public static Strategy getStrategy( ClassRealm realm,
- ClassLoader foreign )
- {
- return getStrategy( realm, "default", foreign );
- }
-
- public static Strategy getStrategy( ClassRealm realm,
- String hint )
- {
- return getStrategy( realm, hint, null );
- }
-
- public static Strategy getStrategy( ClassRealm realm,
- String hint,
- ClassLoader foreign )
- {
- if ( foreign != null )
- {
- return new ForeignStrategy( realm, foreign );
- }
-
- // Here we shall check hint to load non-default strategies
-
- Strategy ret = new DefaultStrategy( realm );
-
- return ret;
- }
-}
diff --git a/src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java b/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java
similarity index 94%
rename from src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java
rename to src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java
index 07a866b..3049aad 100644
--- a/src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java
+++ b/src/main/java/org/codehaus/plexus/classworlds/strategy/UrlUtils.java
@@ -1,4 +1,4 @@
-package org.codehaus.plexus.classworlds;
+package org.codehaus.plexus.classworlds.strategy;
/*
* Copyright 2001-2006 Codehaus Foundation.
@@ -21,7 +21,7 @@
import java.net.URLClassLoader;
/**
- * @author Jason van Zyl
+ * @author Jason van Zyl
* @version $Id$
*/
public class UrlUtils
From 922870df2a29fbf365ad6e141c8c952d519dc266 Mon Sep 17 00:00:00 2001
From: jvanzyl Launcher configurator.
@@ -50,63 +51,28 @@
public class Configurator
{
public static final String MAIN_PREFIX = "main is";
-
public static final String SET_PREFIX = "set";
-
public static final String IMPORT_PREFIX = "import";
-
public static final String LOAD_PREFIX = "load";
- /**
- * Optionally spec prefix.
- */
- public static final String OPTIONALLY_PREFIX = "optionally";
-
- /**
- * The launcher to configure.
- */
+ /** The launcher to configure. */
private Launcher launcher;
+ /** The ClassWorld to create */
private ClassWorld world;
- /**
- * Processed Realms.
- */
+ /** Processed Realms. */
private Map configuredRealms;
- /**
- * Construct.
- *
- * @param launcher The launcher to configure.
- */
public Configurator( Launcher launcher )
{
this.launcher = launcher;
-
- configuredRealms = new HashMap();
+ this.configuredRealms = new HashMap();
}
- /**
- * Construct.
- *
- * @param world The classWorld to configure.
- */
public Configurator( ClassWorld world )
- {
- setClassWorld( world );
- }
-
- /**
- * set world.
- * this setter is provided so you can use the same configurator to configure several "worlds"
- *
- * @param world The classWorld to configure.
- */
- public void setClassWorld( ClassWorld world )
{
this.world = world;
-
- configuredRealms = new HashMap();
}
/**
@@ -279,7 +245,8 @@ else if ( line.startsWith( "[" ) )
curRealm = world.newRealm( realmName, foreignClassLoader );
// Stash the configured realm for subsequent association processing.
- configuredRealms.put( realmName, curRealm );
+ //configuredRealms.put( realmName, curRealm );
+ configuredRealms.put( realmName, new RealmConfiguration( realmName ) );
}
else if ( line.startsWith( IMPORT_PREFIX ) )
{
@@ -335,37 +302,6 @@ else if ( line.startsWith( LOAD_PREFIX ) )
}
}
}
- else if ( line.startsWith( OPTIONALLY_PREFIX ) )
- {
- String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim();
-
- constituent = filter( constituent );
-
- if ( constituent.indexOf( "*" ) >= 0 )
- {
- loadGlob( constituent, curRealm, true );
- }
- else
- {
- File file = new File( constituent );
-
- if ( file.exists() )
- {
- curRealm.addURL( file.toURI().toURL() );
- }
- else
- {
- try
- {
- curRealm.addURL( new URL( constituent ) );
- }
- catch ( MalformedURLException e )
- {
- // swallow
- }
- }
- }
- }
else
{
throw new ConfigurationException( "Unhandled configuration", lineNo, line );
@@ -386,8 +322,10 @@ else if ( line.startsWith( OPTIONALLY_PREFIX ) )
// TODO return this to protected when the legacy wrappers can be removed.
/**
* Associate parent realms with their children.
+ * @throws DuplicateRealmException
+ * @throws NoSuchRealmException
*/
- public void associateRealms()
+ public void associateRealms() throws DuplicateRealmException, NoSuchRealmException
{
List sortRealmNames = new ArrayList( configuredRealms.keySet() );
@@ -425,15 +363,19 @@ public int compare( Object o1,
{
String parentRealmName = realmName.substring( 0, j );
- ClassRealm parentRealm = (ClassRealm) configuredRealms.get( parentRealmName );
+ RealmConfiguration parentRealm = (RealmConfiguration) configuredRealms.get( parentRealmName );
if ( parentRealm != null )
{
- ClassRealm realm = (ClassRealm) configuredRealms.get( realmName );
+ RealmConfiguration realm = (RealmConfiguration) configuredRealms.get( realmName );
- realm.setParentRealm( parentRealm );
+ world.newRealm( realm.id, world.getRealm( parentRealm.id ) );
}
}
+ else
+ {
+ world.newRealm( realmName );
+ }
}
}
@@ -566,7 +508,6 @@ protected String filter( String text )
if ( propName.equals( "basedir" ) && ( propValue == null || propValue.equals( "" ) ) )
{
propValue = ( new File( "" ) ).getAbsolutePath();
-
}
if ( propValue == null )
@@ -595,4 +536,32 @@ private boolean canIgnore( String line )
{
return ( line.length() == 0 || line.startsWith( "#" ) );
}
+
+ class RealmConfiguration
+ {
+ String id;
+ TreeSet imports;
+ TreeSet exports;
+ TreeSet loads;
+
+ public RealmConfiguration( String id )
+ {
+ this.id = id;
+ }
+
+ public void addImport( String importStatement )
+ {
+ imports.add( importStatement );
+ }
+
+ public void addExport( String exportStatement )
+ {
+ exports.add( exportStatement );
+ }
+
+ public void addLoad( String loadStatement )
+ {
+ loads.add( loadStatement );
+ }
+ }
}
From d8e79cde8a260effaa96e7efbb3b6dd9dffb5eb3 Mon Sep 17 00:00:00 2001
From: jvanzyl Launcher configurator.
- *
+ *
* @author bob mcwhirter
* @author Jason van Zyl
* @version $Id$
@@ -77,14 +75,15 @@ public Configurator( ClassWorld world )
/**
* Configure from a file.
- *
+ *
* @param is The config input stream
- * @throws IOException If an error occurs reading the config file.
- * @throws MalformedURLException If the config file contains invalid URLs.
- * @throws ConfigurationException If the config file is corrupt.
- * @throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException If the config file defines two realms with the same id.
- * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException If the config file defines a main entry point in
- * a non-existent realm.
+ * @throws IOException If an error occurs reading the config file.
+ * @throws MalformedURLException If the config file contains invalid URLs.
+ * @throws ConfigurationException If the config file is corrupt.
+ * @throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException If the config file
+ * defines two realms with the same id.
+ * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException If the config file defines
+ * a main entry point in a non-existent realm.
*/
public void configure( InputStream is )
throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
@@ -103,7 +102,7 @@ public void configure( InputStream is )
foreignClassLoader = this.launcher.getSystemClassLoader();
}
- ClassRealm curRealm = null;
+ RealmConfiguration currentRealm = null;
String line = null;
@@ -242,15 +241,15 @@ else if ( line.startsWith( "[" ) )
String realmName = line.substring( 1, rbrack );
- curRealm = world.newRealm( realmName, foreignClassLoader );
+ currentRealm = new RealmConfiguration( realmName );
// Stash the configured realm for subsequent association processing.
//configuredRealms.put( realmName, curRealm );
- configuredRealms.put( realmName, new RealmConfiguration( realmName ) );
+ configuredRealms.put( realmName, currentRealm );
}
else if ( line.startsWith( IMPORT_PREFIX ) )
{
- if ( curRealm == null )
+ if ( currentRealm == null )
{
throw new ConfigurationException( "Unhandled import", lineNo, line );
}
@@ -268,18 +267,20 @@ else if ( line.startsWith( IMPORT_PREFIX ) )
String relamName = conf.substring( fromLoc + 4 ).trim();
- curRealm.importFrom( relamName, importSpec );
+ currentRealm.addImport( new ImportStatement( relamName, importSpec ) );
}
else if ( line.startsWith( LOAD_PREFIX ) )
{
String constituent = line.substring( LOAD_PREFIX.length() ).trim();
+ currentRealm.addLoad( constituent );
+
constituent = filter( constituent );
if ( constituent.indexOf( "*" ) >= 0 )
{
- loadGlob( constituent, curRealm );
+ loadGlob( constituent, currentRealm );
}
else
{
@@ -287,13 +288,13 @@ else if ( line.startsWith( LOAD_PREFIX ) )
if ( file.exists() )
{
- curRealm.addURL( file.toURI().toURL() );
+ currentRealm.addLoad( file.toURI().toURL().toExternalForm() );
}
else
{
try
{
- curRealm.addURL( new URL( constituent ) );
+ currentRealm.addLoad( new URL( constituent ).toExternalForm() );
}
catch ( MalformedURLException e )
{
@@ -309,7 +310,7 @@ else if ( line.startsWith( LOAD_PREFIX ) )
}
// Associate child realms to their parents.
- associateRealms();
+ createRealms();
if ( this.launcher != null )
{
@@ -322,18 +323,19 @@ else if ( line.startsWith( LOAD_PREFIX ) )
// TODO return this to protected when the legacy wrappers can be removed.
/**
* Associate parent realms with their children.
- * @throws DuplicateRealmException
- * @throws NoSuchRealmException
+ *
+ * @throws DuplicateRealmException
+ * @throws NoSuchRealmException
*/
- public void associateRealms() throws DuplicateRealmException, NoSuchRealmException
+ public void createRealms()
+ throws DuplicateRealmException, NoSuchRealmException
{
List sortRealmNames = new ArrayList( configuredRealms.keySet() );
// sort by name
Comparator comparator = new Comparator()
{
- public int compare( Object o1,
- Object o2 )
+ public int compare( Object o1, Object o2 )
{
String g1 = (String) o1;
String g2 = (String) o2;
@@ -381,35 +383,15 @@ public int compare( Object o1,
/**
* Load a glob into the specified classloader.
- *
- * @param line The path configuration line.
+ *
+ * @param line The path configuration line.
* @param realm The realm to populate
- * @throws MalformedURLException If the line does not represent
- * a valid path element.
- * @throws FileNotFoundException If the line does not represent
- * a valid path element in the filesystem.
- */
- protected void loadGlob( String line,
- ClassRealm realm )
- throws MalformedURLException, FileNotFoundException
- {
- loadGlob( line, realm, false );
- }
-
- /**
- * Load a glob into the specified classloader.
- *
- * @param line The path configuration line.
- * @param realm The realm to populate
* @param optionally Whether the path is optional or required
- * @throws MalformedURLException If the line does not represent
- * a valid path element.
- * @throws FileNotFoundException If the line does not represent
- * a valid path element in the filesystem.
+ * @throws MalformedURLException If the line does not represent a valid path element.
+ * @throws FileNotFoundException If the line does not represent a valid path element in the
+ * filesystem.
*/
- protected void loadGlob( String line,
- ClassRealm realm,
- boolean optionally )
+ protected void loadGlob( String line, RealmConfiguration realm )
throws MalformedURLException, FileNotFoundException
{
File globFile = new File( line );
@@ -417,14 +399,7 @@ protected void loadGlob( String line,
File dir = globFile.getParentFile();
if ( !dir.exists() )
{
- if ( optionally )
- {
- return;
- }
- else
- {
- throw new FileNotFoundException( dir.toString() );
- }
+ throw new FileNotFoundException( dir.toString() );
}
String localName = globFile.getName();
@@ -437,8 +412,7 @@ protected void loadGlob( String line,
File[] matches = dir.listFiles( new FilenameFilter()
{
- public boolean accept( File dir,
- String name )
+ public boolean accept( File dir, String name )
{
if ( !name.startsWith( prefix ) )
{
@@ -456,17 +430,16 @@ public boolean accept( File dir,
for ( int i = 0; i < matches.length; ++i )
{
- realm.addURL( matches[i].toURI().toURL() );
+ realm.addLoad( matches[i].toURI().toURL().toExternalForm() );
}
}
/**
* Filter a string for system properties.
- *
+ *
* @param text The text to filter.
* @return The filtered text.
- * @throws ConfigurationException If the property does not
- * exist or if there is a syntax error.
+ * @throws ConfigurationException If the property does not exist or if there is a syntax error.
*/
protected String filter( String text )
throws ConfigurationException
@@ -525,43 +498,52 @@ protected String filter( String text )
}
/**
- * Determine if a line can be ignored because it is
- * a comment or simply blank.
- *
+ * Determine if a line can be ignored because it is a comment or simply blank.
+ *
* @param line The line to test.
- * @return true if the line is ignorable,
- * otherwise false.
+ * @return true if the line is ignorable, otherwise false.
*/
private boolean canIgnore( String line )
{
return ( line.length() == 0 || line.startsWith( "#" ) );
}
-
+
class RealmConfiguration
- {
+ {
String id;
TreeSet imports;
TreeSet exports;
TreeSet loads;
-
+
public RealmConfiguration( String id )
{
this.id = id;
}
-
- public void addImport( String importStatement )
- {
- imports.add( importStatement );
+
+ public void addImport( ImportStatement importStatement )
+ {
+ imports.add( importStatement );
}
public void addExport( String exportStatement )
{
- exports.add( exportStatement );
+ exports.add( exportStatement );
}
-
+
public void addLoad( String loadStatement )
{
loads.add( loadStatement );
}
}
+
+ class ImportStatement
+ {
+ public ImportStatement( String relamName, String importSpec )
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ String importRealm;
+ String importSpecification;
+ }
}
From 9badbc806083b6430e14f5ed226152b4dea62cf8 Mon Sep 17 00:00:00 2001
From: jvanzyl
+ * ClassLoaderRegistry.register (this);
+ *
+ * to the end of both java.lang.ClassLoader constructors (you have to do this
+ * independently for every JDK version, the same hacked version cannot be used
+ * across all of them). This class needs to be in the bootstrap classpath to
+ * work as intended.
+ *
+ * @author (C) Vlad Roubtsov, 2003
+ */
+public
+abstract class ClassLoaderRegistry // this class is not instantiable
+{
+ // public: ................................................................
+
+ /**
+ * Adds 'loader' to the weak set maintained by this registry.
+ */
+ public static void register (final ClassLoader loader)
+ {
+ if (loader != null)
+ {
+ synchronized (CLASSLOADER_SET)
+ {
+ CLASSLOADER_SET.put (loader, null);
+ }
+ }
+ }
+
+ /**
+ * Returns an enumeration of all class loaders currently registered
+ * in the JVM. Note that this may not include all class loaders ever'
+ * created because this registry uses weak keys as class loader references.
+ *
+ * @param ClassLoader array [never null].
+ */
+ public static ClassLoader [] getClassLoaders ()
+ {
+ final List /* ClassLoader */ resultList = new LinkedList ();
+
+ synchronized (CLASSLOADER_SET)
+ {
+ // we are using a weak map: be careful when traversing the key set
+ // [it's unsafe to use resultList.addAll(CLASSLOADER_SET.keySet())]
+
+ for (Iterator keys = CLASSLOADER_SET.keySet ().iterator (); keys.hasNext (); )
+ {
+ // note that WeakHashMap guarantees that the weak key will not be
+ // cleared between hasNext() and next():
+ resultList.add (keys.next ());
+ }
+ }
+
+ final ClassLoader [] result = new ClassLoader [resultList.size ()];
+ resultList.toArray (result);
+
+ return result;
+ }
+
+ // protected: .............................................................
+
+ // package: ...............................................................
+
+ // private: ...............................................................
+
+
+ private ClassLoaderRegistry () {} // this class is not extendible
+
+ // this field is used as a 'weak set' to avoid interfering with class and
+ // class loader unloading and garbage collection:
+ private static final WeakHashMap /* ClassLoader->null */ CLASSLOADER_SET =
+ new WeakHashMap ();
+
+} // end of class
+// ----------------------------------------------------------------------------
\ No newline at end of file
diff --git a/ClassScope.java b/ClassScope.java
new file mode 100644
index 0000000..1e6b0b1
--- /dev/null
+++ b/ClassScope.java
@@ -0,0 +1,276 @@
+package com.vladium.utils;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.security.ProtectionDomain;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+// ----------------------------------------------------------------------------
+/**
+ * A simple static API for listing classes loaded in a JVM. {@link #getClassLocation(Class)} from
+ * http://www.javaworld.com/javaworld/javaqa/2003-07/01-qa-0711-classsrc.html also thrown in for a
+ * good measure. See individual methods for further details.
+ *
+ *
+ * NOTE: use for testing/debugging only.
+ *
+ * @author (C) Vlad Roubtsov, 2003
+ */
+public abstract class ClassScope // this class is not instantiable
+{
+ // public: ................................................................
+
+ /**
+ * Given a class loader instance, returns all classes currently loaded by that class loader.
+ *
+ * @param defining class loader to inspect [may not be null]
+ * @return Class array such that every Class has 'loader' as its defining class loader [never
+ * null, may be empty]
+ *
+ * @throws RuntimeException if the "classes" field hack is not possible in this JRE
+ */
+ public static Class[] getLoadedClasses( final ClassLoader loader )
+ {
+ if ( loader == null )
+ throw new IllegalArgumentException( "null input: loader" );
+ if ( CLASSES_VECTOR_FIELD == null )
+ throw new RuntimeException( "ClassScope::getLoadedClasses() cannot be used in this JRE", CVF_FAILURE );
+
+ try
+ {
+ final Vector classes = (Vector) CLASSES_VECTOR_FIELD.get( loader );
+ if ( classes == null )
+ return EMPTY_CLASS_ARRAY;
+
+ final Class[] result;
+
+ // note: Vector is synchronized in Java 2, which helps us make
+ // the following into a safe critical section:
+
+ synchronized ( classes )
+ {
+ result = new Class[classes.size()];
+ classes.toArray( result );
+ }
+
+ return result;
+ }
+ // this should not happen if true if this entry matches the classname, otherwise
+ * false.
+ */
+ boolean matches( String classname )
+ {
+ return classname.startsWith( getPackageName() );
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ // java.lang.Comparable
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ /**
+ * Compare this entry to another for relative ordering. The natural ordering of
+ * Entry objects is reverse-alphabetical based upon package name.
true if the two objects are semantically equivalent, otherwise
+ * false.
+ */
+ public boolean equals( Object thatObj )
+ {
+ Entry that = (Entry) thatObj;
+
+ return getPackageName().equals( that.getPackageName() );
+ }
+
+ /**
+ * Consistent with {@link #equals}, this method creates a hashCode based on the
+ * packagename.
+ */
+ public int hashCode()
+ {
+ return getPackageName().hashCode();
+ }
+ }
}
diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java b/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java
deleted file mode 100644
index 2b21ac0..0000000
--- a/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.codehaus.plexus.classworlds.realm;
-
-/*
- * Copyright 2001-2006 Codehaus Foundation.
- *
- * Licensed 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 description entry.
- *
- * @author bob mcwhirter
- */
-public class Entry
- implements Comparable
-{
- private final ClassRealm realm;
-
- private final String pkgName;
-
- Entry( ClassRealm realm, String pkgName )
- {
- this.realm = realm;
-
- this.pkgName = pkgName;
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
-
- /**
- * Retrieve the realm.
- *
- * @return The realm.
- */
- ClassRealm getRealm()
- {
- return this.realm;
- }
-
- /**
- * Retrieve the package name.
- *
- * @return The package name.
- */
- String getPackageName()
- {
- return this.pkgName;
- }
-
- /**
- * Determine if the classname matches the package described by this entry.
- *
- * @param classname The class name to test.
- * @return true if this entry matches the classname, otherwise false.
- */
- boolean matches( String classname )
- {
- return classname.startsWith( getPackageName() );
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // java.lang.Comparable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- /**
- * Compare this entry to another for relative ordering. The natural ordering of Entry
- * objects is reverse-alphabetical based upon package name.
- *
- * @param thatObj The object to compare.
- * @return -1 if this object sorts before that object, 0 if they are equal, or 1 if this object
- * sorts after that object.
- */
- public int compareTo( Object thatObj )
- {
- Entry that = (Entry) thatObj;
-
- // We are reverse sorting this list, so that
- // we get longer matches first:
- //
- // com.werken.foo.bar
- // com.werken.foo
- // com.werken
-
- return ( getPackageName().compareTo( that.getPackageName() ) ) * -1;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // java.lang.Object
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- /**
- * Test this entry for equality to another. Consistent with {@link #compareTo}, this
- * method tests for equality purely on the package name.
- *
- * @param thatObj The object to compare
- * @return true if the two objects are semantically equivalent, otherwise
- * false.
- */
- public boolean equals( Object thatObj )
- {
- Entry that = (Entry) thatObj;
-
- return getPackageName().equals( that.getPackageName() );
- }
-
- /**
- * Consistent with {@link #equals}, this method creates a hashCode based on the
- * packagename.
- */
- public int hashCode()
- {
- return getPackageName().hashCode();
- }
-
- public String toString()
- {
- return "Entry[import " + getPackageName() + " from realm " + getRealm() + "]";
- }
-}
diff --git a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java
index 643b767..e35a26e 100644
--- a/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java
+++ b/src/test/java/org/codehaus/plexus/classworlds/ClassWorldTest.java
@@ -107,17 +107,11 @@ public void testGetRealms()
throws Exception
{
assertTrue( this.world.getRealms().isEmpty() );
-
ClassRealm foo = this.world.newRealm( "foo" );
-
assertEquals( 1, this.world.getRealms().size() );
-
assertTrue( this.world.getRealms().contains( foo ) );
-
ClassRealm bar = this.world.newRealm( "bar" );
-
assertEquals( 2, this.world.getRealms().size() );
-
assertTrue( this.world.getRealms().contains( bar ) );
}
diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java
index 8284011..59f22fe 100644
--- a/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java
+++ b/src/test/java/org/codehaus/plexus/classworlds/realm/EntryTest.java
@@ -19,15 +19,11 @@
import junit.framework.TestCase;
import org.codehaus.plexus.classworlds.ClassWorld;
+import org.codehaus.plexus.classworlds.realm.ClassRealm.Entry;
-/**
- * @author Ben Walding
- * @version $Id$
- */
public class EntryTest
extends TestCase
{
-
/**
* Constructor for EntryTest.
*
@@ -42,10 +38,10 @@ public void testCompareTo()
throws Exception
{
ClassWorld cw = new ClassWorld();
- ClassRealm r = (ClassRealm) cw.newRealm( "test1" );
+ ClassRealm r = cw.newRealm( "test1" );
- Entry entry1 = new Entry( r, "org.test" );
- Entry entry2 = new Entry( r, "org.test.impl" );
+ Entry entry1 = new Entry( "org.test" );
+ Entry entry2 = new Entry( "org.test.impl" );
assertTrue( "org.test > org.test.impl", entry1.compareTo( entry2 ) > 0 );
}
@@ -59,11 +55,11 @@ public void testEquals()
throws Exception
{
ClassWorld cw = new ClassWorld();
- ClassRealm r1 = (ClassRealm) cw.newRealm( "test1" );
- ClassRealm r2 = (ClassRealm) cw.newRealm( "test2" );
+ ClassRealm r1 = cw.newRealm( "test1" );
+ ClassRealm r2 = cw.newRealm( "test2" );
- Entry entry1 = new Entry( r1, "org.test" );
- Entry entry2 = new Entry( r2, "org.test" );
+ Entry entry1 = new Entry( "org.test" );
+ Entry entry2 = new Entry( "org.test" );
assertTrue( "entry1 == entry2", entry1.equals( entry2 ) );
assertTrue( "entry1.hashCode() == entry2.hashCode()", entry1.hashCode() == entry2.hashCode() );
From f1c08865829716b6ab274de1aedc6850470a41fe Mon Sep 17 00:00:00 2001
From: jvanzyl Launcher configurator.
@@ -102,7 +103,7 @@ public void configure( InputStream is )
foreignClassLoader = this.launcher.getSystemClassLoader();
}
- RealmConfiguration currentRealm = null;
+ ClassRealmConfiguration currentRealm = null;
String line = null;
@@ -246,7 +247,7 @@ else if ( line.startsWith( "[" ) )
throw new DuplicateRealmException(world, realmName );
}
- currentRealm = new RealmConfiguration( realmName );
+ currentRealm = new ClassRealmConfiguration( realmName );
// Stash the configured realm for subsequent association processing.
//configuredRealms.put( realmName, curRealm );
@@ -268,11 +269,11 @@ else if ( line.startsWith( IMPORT_PREFIX ) )
throw new ConfigurationException( "Missing from clause", lineNo, line );
}
- String importSpec = conf.substring( 0, fromLoc ).trim();
-
- String relamName = conf.substring( fromLoc + 4 ).trim();
-
- currentRealm.addImport( new ImportStatement( relamName, importSpec ) );
+ String importSpecification = conf.substring( 0, fromLoc ).trim();
+
+ String realmName = conf.substring( fromLoc + 4 ).trim();
+
+ currentRealm.addImport( realmName, importSpecification );
}
else if ( line.startsWith( LOAD_PREFIX ) )
@@ -323,7 +324,6 @@ else if ( line.startsWith( LOAD_PREFIX ) )
reader.close();
}
- // TODO return this to protected when the legacy wrappers can be removed.
/**
* Associate parent realms with their children.
*
@@ -331,7 +331,7 @@ else if ( line.startsWith( LOAD_PREFIX ) )
* @throws NoSuchRealmException
* @throws MalformedURLException
*/
- public void createRealms()
+ protected void createRealms()
throws DuplicateRealmException, NoSuchRealmException, MalformedURLException
{
List sortRealmNames = new ArrayList( configuredRealms.keySet() );
@@ -369,12 +369,12 @@ public int compare( Object o1, Object o2 )
{
String parentRealmName = realmName.substring( 0, j );
- RealmConfiguration parentRealmConfiguration = (RealmConfiguration) configuredRealms.get( parentRealmName );
+ ClassRealmConfiguration parentRealmConfiguration = (ClassRealmConfiguration) configuredRealms.get( parentRealmName );
if ( parentRealmConfiguration != null )
{
- RealmConfiguration realmConfiguration = (RealmConfiguration) configuredRealms.get( realmName );
- world.newRealm( realmConfiguration.id, world.getRealm( parentRealmConfiguration.id ) );
+ ClassRealmConfiguration realmConfiguration = (ClassRealmConfiguration) configuredRealms.get( realmName );
+ world.newRealm( realmConfiguration.getId(), world.getRealm( parentRealmConfiguration.getId() ) );
}
}
else
@@ -385,29 +385,28 @@ public int compare( Object o1, Object o2 )
for ( Iterator i = configuredRealms.values().iterator(); i.hasNext(); )
{
- RealmConfiguration rc = (RealmConfiguration) i.next();
+ ClassRealmConfiguration rc = (ClassRealmConfiguration) i.next();
- configureRealm( world.getRealm( rc.id ), rc );
+ configureRealm( world.getRealm( rc.getId() ), rc );
}
}
- private void configureRealm( ClassRealm realm, RealmConfiguration realmConfiguration )
+ private void configureRealm( ClassRealm realm, ClassRealmConfiguration realmConfiguration )
throws NoSuchRealmException, MalformedURLException
{
- for ( Iterator i = realmConfiguration.imports.iterator(); i.hasNext(); )
+ for ( Iterator i = realmConfiguration.getImports().iterator(); i.hasNext(); )
{
- ImportStatement is = (ImportStatement) i.next();
+ ClassRealmImport is = (ClassRealmImport) i.next();
- realm.importFrom( is.importRealm, is.importSpecification );
+ realm.importFrom( is.getImportRealm(), is.getImportSpecification() );
}
- for ( Iterator i = realmConfiguration.loads.iterator(); i.hasNext(); )
+ for ( Iterator i = realmConfiguration.getLoads().iterator(); i.hasNext(); )
{
String load = (String) i.next();
realm.addURL( new URL( load ) );
}
-
}
/**
@@ -420,7 +419,7 @@ private void configureRealm( ClassRealm realm, RealmConfiguration realmConfigura
* @throws FileNotFoundException If the line does not represent a valid path element in the
* filesystem.
*/
- protected void loadGlob( String line, RealmConfiguration realm )
+ protected void loadGlob( String line, ClassRealmConfiguration realm )
throws MalformedURLException, FileNotFoundException
{
File globFile = new File( line );
@@ -536,44 +535,4 @@ private boolean canIgnore( String line )
{
return ( line.length() == 0 || line.startsWith( "#" ) );
}
-
- class RealmConfiguration
- {
- String id;
- TreeSet imports = new TreeSet();
- TreeSet exports = new TreeSet();
- TreeSet loads = new TreeSet();
-
- public RealmConfiguration( String id )
- {
- this.id = id;
- }
-
- public void addImport( ImportStatement importStatement )
- {
- imports.add( importStatement );
- }
-
- public void addExport( String exportStatement )
- {
- exports.add( exportStatement );
- }
-
- public void addLoad( String loadStatement )
- {
- loads.add( loadStatement );
- }
- }
-
- class ImportStatement
- {
- public ImportStatement( String importRealm, String importSpecification )
- {
- this.importRealm = importRealm;
- this.importSpecification = importSpecification;
- }
-
- String importRealm;
- String importSpecification;
- }
}
diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java
new file mode 100644
index 0000000..8e6ec3c
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmConfiguration.java
@@ -0,0 +1,51 @@
+package org.codehaus.plexus.classworlds.realm.configuration;
+
+import java.util.TreeSet;
+
+public class ClassRealmConfiguration
+{
+ String id;
+ TreeSet imports = new TreeSet();
+ TreeSet exports = new TreeSet();
+ TreeSet loads = new TreeSet();
+
+ public ClassRealmConfiguration( String id )
+ {
+ this.id = id;
+ }
+
+ public void addImport( String importRealm, String importSpecification )
+ {
+ imports.add( new ClassRealmImport( importRealm, importSpecification ) );
+ }
+
+ public void addExport( String exportStatement )
+ {
+ exports.add( exportStatement );
+ }
+
+ public void addLoad( String loadStatement )
+ {
+ loads.add( loadStatement );
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public TreeSet getImports()
+ {
+ return imports;
+ }
+
+ public TreeSet getExports()
+ {
+ return exports;
+ }
+
+ public TreeSet getLoads()
+ {
+ return loads;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java
new file mode 100644
index 0000000..03315b3
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/classworlds/realm/configuration/ClassRealmImport.java
@@ -0,0 +1,23 @@
+package org.codehaus.plexus.classworlds.realm.configuration;
+
+public class ClassRealmImport
+{
+ String importRealm;
+ String importSpecification;
+
+ public ClassRealmImport( String importRealm, String importSpecification )
+ {
+ this.importRealm = importRealm;
+ this.importSpecification = importSpecification;
+ }
+
+ public String getImportRealm()
+ {
+ return importRealm;
+ }
+
+ public String getImportSpecification()
+ {
+ return importSpecification;
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java
index 8e05af4..97d3024 100644
--- a/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java
+++ b/src/test/java/org/codehaus/plexus/classworlds/realm/ClassRealmTest.java
@@ -435,4 +435,9 @@ public void testResource()
URL resource = mainRealm.getResource( "META-INF/plexus/components.xml" );
assertNotNull( resource );
}
+
+ // ----------------------------------------------------------------------
+ // Exports
+ // ----------------------------------------------------------------------
+
}
From e9c0433589db71bf35b8e05ae5301eb415c5b7cc Mon Sep 17 00:00:00 2001
From: jvanzyl