pax_global_header00006660000000000000000000000064122032044220014501gustar00rootroot0000000000000052 comment=96885e26448b8c550603d9a8d72c07e023e246ef plexus-classworlds-plexus-classworlds-2.5.1/000077500000000000000000000000001220320442200212405ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/.gitignore000066400000000000000000000001051220320442200232240ustar00rootroot00000000000000target/ .project .classpath .settings/ bin .idea *.iml .java-version plexus-classworlds-plexus-classworlds-2.5.1/LICENSE-2.0.txt000066400000000000000000000261361220320442200233700ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. plexus-classworlds-plexus-classworlds-2.5.1/LICENSE.txt000066400000000000000000000036221220320442200230660ustar00rootroot00000000000000 /* $Id$ Copyright 2002 (C) The Codehaus. 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 Codehaus. For written permission, please contact bob@codehaus.org. 4. Products derived from this Software may not be called "classworlds" nor may "classworlds" appear in their names without prior written permission of The Codehaus. "classworlds" is a registered trademark of The Codehaus. 5. Due credit should be given to The Codehaus. (http://classworlds.codehaus.org/). THIS SOFTWARE IS PROVIDED BY THE CODEHAUS 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 CODEHAUS 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. */ plexus-classworlds-plexus-classworlds-2.5.1/pom.xml000066400000000000000000000116211220320442200225560ustar00rootroot00000000000000 4.0.0 org.codehaus.plexus plexus 3.3.1 plexus-classworlds 2.5.1 bundle Plexus Classworlds A class loader framework 2002 scm:git:git@github.com:sonatype/plexus-classworlds.git scm:git:git@github.com:sonatype/plexus-classworlds.git http://github.com/sonatype/plexus-classworlds plexus-classworlds-2.5.1 org.apache.felix maven-bundle-plugin true <_nouses>true org.codehaus.classworlds.*;org.codehaus.plexus.classworlds.* org.apache.maven.plugins maven-jar-plugin org.codehaus.plexus.classworlds.launcher.Launcher org.apache.maven.plugins maven-surefire-plugin true -ea:org.codehaus.classworlds:org.codehaus.plexus.classworlds once org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org/codehaus/plexus/classworlds/event/* org.apache.maven.plugins maven-dependency-plugin 2.0 generate-test-resources copy org.apache.ant ant 1.9.0 commons-logging commons-logging 1.0.3 xml-apis xml-apis 1.3.02 ${project.build.directory}/test-lib org.apache.maven.plugins maven-enforcer-plugin 1.3.1 enforce-java enforce 1.7.0 plexus-classworlds-plexus-classworlds-2.5.1/src/000077500000000000000000000000001220320442200220275ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/000077500000000000000000000000001220320442200227535ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/000077500000000000000000000000001220320442200242325ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/000077500000000000000000000000001220320442200250215ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/codehaus/000077500000000000000000000000001220320442200266145ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/codehaus/plexus/000077500000000000000000000000001220320442200301345ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/codehaus/plexus/classworlds/000077500000000000000000000000001220320442200324745ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/codehaus/plexus/classworlds/event/000077500000000000000000000000001220320442200336155ustar00rootroot00000000000000ListenerAspect.aj000066400000000000000000000034201220320442200367760ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/aspect/org/codehaus/plexus/classworlds/eventpackage org.codehaus.plexus.classworlds.event; import java.net.URL; import org.codehaus.plexus.classworlds.strategy.Strategy; /** * A simple aspect to hook event code in when compiling with debug enabled * * @uthor: Andrew Williams * @since: 1.2-alpha-15 * @version: $Id$ */ aspect ListenerAspect { // TODO: here we want a proper listener registering system, not just a debugger private ClassEventDebug classDebugger = new ClassEventDebug(); private ResourceEventDebug resourceDebugger = new ResourceEventDebug(); pointcut loadClass( String name, Strategy strategy ): args( name ) && target( strategy ) && call( Class Strategy.loadClass( String ) ); before( String name, Strategy strategy ): loadClass( name, strategy ) { classDebugger.lookup( name, strategy ); } after( String name, Strategy strategy ) returning( Class result ): loadClass( name, strategy ) { classDebugger.found( name, strategy, result ); } after( String name, Strategy strategy ) throwing( Exception e ): loadClass( name, strategy ) { classDebugger.failed( name, strategy, e ); } pointcut getResource( String name, Strategy strategy ): args( name ) && target( strategy ) && call( URL Strategy.getResource( String ) ); before( String name, Strategy strategy ): getResource( name, strategy ) { resourceDebugger.lookup( name, strategy ); } after( String name, Strategy strategy ) returning( URL result ): getResource( name, strategy ) { if ( result == null ) { resourceDebugger.failed( name, strategy ); } else { resourceDebugger.found( name, strategy, result ); } } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/000077500000000000000000000000001220320442200236745ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/000077500000000000000000000000001220320442200244635ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/000077500000000000000000000000001220320442200262565ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworlds/000077500000000000000000000000001220320442200306165ustar00rootroot00000000000000BytesURLConnection.java000066400000000000000000000024261220320442200350770ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.net.URLConnection; import java.net.URL; import java.io.InputStream; import java.io.ByteArrayInputStream; /** * @author Hani Suleiman (hani@formicary.net) *

* Date: Oct 20, 2003 * Time: 12:46:01 AM */ public class BytesURLConnection extends URLConnection { protected byte[] content; protected int offset; protected int length; public BytesURLConnection( URL url, byte[] content ) { super( url ); this.content = content; } public void connect() { } public InputStream getInputStream() { return new ByteArrayInputStream( content ); } }BytesURLStreamHandler.java000066400000000000000000000022321220320442200355240ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.net.URLStreamHandler; import java.net.URLConnection; import java.net.URL; /** * @author Hani Suleiman (hani@formicary.net) * Date: Oct 20, 2003 * Time: 12:45:18 AM */ public class BytesURLStreamHandler extends URLStreamHandler { byte[] content; int offset; int length; public BytesURLStreamHandler( byte[] content ) { this.content = content; } public URLConnection openConnection( URL url ) { return new BytesURLConnection( url, content ); } }plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworlds/ClassRealm.java000066400000000000000000000070501220320442200335110ustar00rootroot00000000000000package org.codehaus.classworlds; /* 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 java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Enumeration; /** * Autonomous sub-portion of a 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}. *

* * @author bob mcwhirter * @author Jason van Zyl */ public interface ClassRealm { String getId(); ClassWorld getWorld(); void importFrom( String realmId, String pkgName ) throws NoSuchRealmException; void addConstituent( URL constituent ); ClassRealm locateSourceRealm( String className ); void setParent( ClassRealm classRealm ); ClassRealm createChildRealm( String id ) throws DuplicateRealmException; ClassLoader getClassLoader(); ClassRealm getParent(); URL[] getConstituents(); // ---------------------------------------------------------------------- // Classloading // ---------------------------------------------------------------------- Class loadClass( String name ) throws ClassNotFoundException; // ---------------------------------------------------------------------- // Resource handling // ---------------------------------------------------------------------- URL getResource( String name ); Enumeration findResources( String name ) throws IOException; InputStream getResourceAsStream( String name ); void display(); } ClassRealmAdapter.java000066400000000000000000000107411220320442200347340ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.net.URL; import java.util.Enumeration; import java.io.IOException; import java.io.InputStream; /** * An adapter for ClassRealms * * @author Andrew Williams */ public class ClassRealmAdapter implements ClassRealm { public static ClassRealmAdapter getInstance( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm ) { ClassRealmAdapter adapter = new ClassRealmAdapter( newRealm ); return adapter; } private org.codehaus.plexus.classworlds.realm.ClassRealm realm; private ClassRealmAdapter( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm ) { this.realm = newRealm; } public String getId() { return realm.getId(); } public ClassWorld getWorld() { return ClassWorldAdapter.getInstance( realm.getWorld() ); } public void importFrom( String realmId, String pkgName ) throws NoSuchRealmException { try { realm.importFrom( realmId, pkgName ); } catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) { throw new NoSuchRealmException( getWorld(), e.getId() ); } } public void addConstituent( URL constituent ) { realm.addURL( constituent ); } public ClassRealm locateSourceRealm( String className ) { ClassLoader importLoader = realm.getImportClassLoader( className ); if ( importLoader instanceof org.codehaus.plexus.classworlds.realm.ClassRealm ) { return ClassRealmAdapter.getInstance( (org.codehaus.plexus.classworlds.realm.ClassRealm) importLoader ); } else { return null; } } public void setParent( ClassRealm classRealm ) { if ( classRealm != null ) { realm.setParentRealm( ClassRealmReverseAdapter.getInstance( classRealm ) ); } } public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { try { return ClassRealmAdapter.getInstance( realm.createChildRealm( id ) ); } catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) { throw new DuplicateRealmException( getWorld(), e.getId() ); } } public ClassLoader getClassLoader() { return realm; } public ClassRealm getParent() { return ClassRealmAdapter.getInstance( realm.getParentRealm() ); } public ClassRealm getParentRealm() { return ClassRealmAdapter.getInstance( realm.getParentRealm() ); } public URL[] getConstituents() { return realm.getURLs(); } public Class loadClass( String name ) throws ClassNotFoundException { return realm.loadClass( name ); } public URL getResource( String name ) { return realm.getResource( trimLeadingSlash( name ) ); } public Enumeration findResources( String name ) throws IOException { return realm.findResources( trimLeadingSlash( name ) ); } public InputStream getResourceAsStream( String name ) { return realm.getResourceAsStream( trimLeadingSlash( name ) ); } public void display() { realm.display(); } public boolean equals(Object o) { if ( !( o instanceof ClassRealm ) ) return false; return getId().equals( ( (ClassRealm) o ).getId() ); } /** * Provides backward-compat with the old classworlds which accepted resource names with leading slashes. */ private String trimLeadingSlash( String resource ) { if ( resource != null && resource.startsWith( "/" ) ) { return resource.substring( 1 ); } else { return resource; } } } ClassRealmReverseAdapter.java000066400000000000000000000076571220320442200363040ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.util.Enumeration; import java.net.URL; import java.io.IOException; import java.io.InputStream; /** * A reverse adapter for ClassRealms * * @author Andrew Williams */ public class ClassRealmReverseAdapter extends org.codehaus.plexus.classworlds.realm.ClassRealm { public static ClassRealmReverseAdapter getInstance( ClassRealm oldRealm ) { ClassRealmReverseAdapter adapter = new ClassRealmReverseAdapter( oldRealm ); return adapter; } private ClassRealm realm; private ClassRealmReverseAdapter( ClassRealm oldRealm ) { super( ClassWorldReverseAdapter.getInstance( oldRealm.getWorld() ), oldRealm.getId(), oldRealm.getClassLoader() ); this.realm = oldRealm; } public String getId() { return realm.getId(); } public org.codehaus.plexus.classworlds.ClassWorld getWorld() { return ClassWorldReverseAdapter.getInstance( realm.getWorld() ); } public void importFrom( String realmId, String pkgName ) throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException { try { realm.importFrom( realmId, pkgName ); } catch ( NoSuchRealmException e ) { throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( getWorld(), e.getId() ); } } public void addURL( URL constituent ) { realm.addConstituent( constituent ); } public org.codehaus.plexus.classworlds.realm.ClassRealm locateSourceRealm( String className ) { return getInstance( realm.locateSourceRealm( className ) ); } public void setParentRealm( org.codehaus.plexus.classworlds.realm.ClassRealm classRealm ) { realm.setParent( ClassRealmAdapter.getInstance( classRealm ) ); } public org.codehaus.plexus.classworlds.realm.ClassRealm createChildRealm( String id ) throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException { try { return getInstance( realm.createChildRealm( id ) ); } catch ( DuplicateRealmException e ) { throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( getWorld(), e.getId() ); } } public ClassLoader getClassLoader() { return realm.getClassLoader(); } public org.codehaus.plexus.classworlds.realm.ClassRealm getParentRealm() { return getInstance( realm.getParent() ); } public URL[] getURLs() { return realm.getConstituents(); } public Class loadClass( String name ) throws ClassNotFoundException { return realm.loadClass( name ); } public URL getResource( String name ) { return realm.getResource( name ); } public Enumeration findResources( String name ) throws IOException { return realm.findResources( name ); } public InputStream getResourceAsStream( String name ) { return realm.getResourceAsStream( name ); } public void display() { realm.display(); } public boolean equals(Object o) { if ( !( o instanceof ClassRealm ) ) return false; return getId().equals( ( (ClassRealm) o ).getId() ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworlds/ClassWorld.java000066400000000000000000000037501220320442200335430ustar00rootroot00000000000000package org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.util.Collection; /** * A compatibility wrapper for org.codehaus.plexus.classworlds.ClassWorld * provided for legacy code * * @author Andrew Williams */ public class ClassWorld { private ClassWorldAdapter adapter; public ClassWorld( String realmId, ClassLoader classLoader ) { adapter = ClassWorldAdapter.getInstance( new org.codehaus.plexus.classworlds.ClassWorld( realmId, classLoader ) ); } public ClassWorld() { adapter = ClassWorldAdapter.getInstance( new org.codehaus.plexus.classworlds.ClassWorld( ) ); } public ClassWorld( boolean ignore ) { /* fake */ } public ClassRealm newRealm( String id ) throws DuplicateRealmException { return adapter.newRealm( id ); } public ClassRealm newRealm( String id, ClassLoader classLoader ) throws DuplicateRealmException { return adapter.newRealm( id, classLoader ); } public void disposeRealm( String id ) throws NoSuchRealmException { adapter.disposeRealm( id ); } public ClassRealm getRealm( String id ) throws NoSuchRealmException { return adapter.getRealm( id ); } public Collection getRealms() { return adapter.getRealms(); } } ClassWorldAdapter.java000066400000000000000000000063531220320442200347670ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.util.Collection; import java.util.Vector; import java.util.Iterator; /** * An adapter for ClassWorlds * * @author Andrew Williams */ public class ClassWorldAdapter extends ClassWorld { public static ClassWorldAdapter getInstance( org.codehaus.plexus.classworlds.ClassWorld newWorld ) { ClassWorldAdapter adapter = new ClassWorldAdapter( newWorld ); return adapter; } private org.codehaus.plexus.classworlds.ClassWorld world; private ClassWorldAdapter( org.codehaus.plexus.classworlds.ClassWorld newWorld ) { super( false ); this.world = newWorld; } public ClassRealm newRealm( String id ) throws DuplicateRealmException { try { return ClassRealmAdapter.getInstance( world.newRealm( id ) ); } catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) { throw new DuplicateRealmException( this, e.getId() ); } } public ClassRealm newRealm( String id, ClassLoader classLoader ) throws DuplicateRealmException { try { return ClassRealmAdapter.getInstance( world.newRealm( id, classLoader ) ); } catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e ) { throw new DuplicateRealmException( this, e.getId() ); } } public void disposeRealm( String id ) throws NoSuchRealmException { try { world.disposeRealm( id ); } catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) { throw new NoSuchRealmException( this, e.getId() ); } } public ClassRealm getRealm( String id ) throws NoSuchRealmException { try { return ClassRealmAdapter.getInstance( world.getRealm( id ) ); } catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e ) { throw new NoSuchRealmException( this, e.getId() ); } } public Collection getRealms() { Collection realms = world.getRealms(); Vector ret = new Vector(); Iterator it = realms.iterator(); while ( it.hasNext() ) { org.codehaus.plexus.classworlds.realm.ClassRealm realm = (org.codehaus.plexus.classworlds.realm.ClassRealm) it.next(); ret.add( ClassRealmAdapter.getInstance( realm ) ); } return ret; } } ClassWorldException.java000066400000000000000000000063511220320442200353430ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* 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. */ /** * Base exception for ClassWorld errors. * * @author bob mcwhirter */ 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; } } ClassWorldReverseAdapter.java000066400000000000000000000072031220320442200363160ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.util.HashMap; import java.util.Collection; import java.util.Vector; import java.util.Iterator; /** * A reverse adapter for ClassWorlds * * @author Andrew Williams */ 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; } } ConfigurationException.java000066400000000000000000000052331220320442200360730ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* 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 */ 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 ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworlds/Configurator.java000066400000000000000000000107511220320442200341270ustar00rootroot00000000000000package org.codehaus.classworlds; /* * Copyright 2001-2010 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 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 */ 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 ); } } ConfiguratorAdapter.java000066400000000000000000000054651220320442200353570ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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 java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; /** * Created by IntelliJ IDEA. * * @uthor: Andrew Williams * @since: Nov 25, 2006 */ public class ConfiguratorAdapter extends Configurator { public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig, Launcher launcher ) { ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, launcher ); return adapter; } public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig, ClassWorld world ) { ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, world ); 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() ); } } } DefaultClassRealm.java000066400000000000000000000111671220320442200347430ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* * Copyright 2001-2010 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. */ /** * 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(); } } DuplicateRealmException.java000066400000000000000000000062261220320442200361620ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* 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 */ 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; } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworlds/Launcher.java000066400000000000000000000035261220320442200332300ustar00rootroot00000000000000package org.codehaus.classworlds; /* * Copyright 2001-2010 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. */ /** * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Launcher * provided for legacy code * * @author Andrew Williams */ 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 ); } } NoSuchRealmException.java000066400000000000000000000062211220320442200354420ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/classworldspackage org.codehaus.classworlds; /* 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 */ 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; } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/000077500000000000000000000000001220320442200275765ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/000077500000000000000000000000001220320442200321365ustar00rootroot00000000000000ClassWorld.java000066400000000000000000000102011220320442200347710ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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 java.io.Closeable; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; /** * A collection of ClassRealms, indexed by id. * * @author bob mcwhirter */ public class ClassWorld { private Map realms; private final List listeners = new ArrayList(); public ClassWorld( String realmId, ClassLoader classLoader ) { this(); try { newRealm( realmId, classLoader ); } catch ( DuplicateRealmException e ) { // Will never happen as we are just creating the world. } } public ClassWorld() { this.realms = new LinkedHashMap(); } public ClassRealm newRealm( String id ) throws DuplicateRealmException { return newRealm( id, getClass().getClassLoader() ); } public synchronized ClassRealm newRealm( String id, ClassLoader classLoader ) throws DuplicateRealmException { if ( realms.containsKey( id ) ) { throw new DuplicateRealmException( this, id ); } ClassRealm realm; realm = new ClassRealm( this, id, classLoader ); realms.put( id, realm ); for ( ClassWorldListener listener : listeners ) { listener.realmCreated( realm ); } return realm; } public synchronized void disposeRealm( String id ) throws NoSuchRealmException { ClassRealm realm = (ClassRealm) realms.remove( id ); if ( realm != null ) { closeIfJava7( realm ); for ( ClassWorldListener listener : listeners ) { listener.realmDisposed( realm ); } } } private void closeIfJava7( ClassRealm realm ) { try { //noinspection ConstantConditions if ( realm instanceof Closeable ) { //noinspection RedundantCast ( (Closeable) realm ).close(); } } catch ( IOException ignore ) { } } public synchronized ClassRealm getRealm( String id ) throws NoSuchRealmException { if ( realms.containsKey( id ) ) { return (ClassRealm) realms.get( id ); } throw new NoSuchRealmException( this, id ); } public synchronized Collection getRealms() { return Collections.unmodifiableList( new ArrayList( realms.values() ) ); } // from exports branch public synchronized ClassRealm getClassRealm( String id ) { if ( realms.containsKey( id ) ) { return realms.get( id ); } return null; } public synchronized void addListener( ClassWorldListener listener ) { // TODO ideally, use object identity, not equals if ( !listeners.contains( listener ) ) { listeners.add( listener ); } } public synchronized void removeListener( ClassWorldListener listener ) { listeners.remove( listener ); } } ClassWorldException.java000066400000000000000000000036561220320442200366700ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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. */ /** * Base exception for ClassWorld errors. * * @author bob mcwhirter */ 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; } } ClassWorldListener.java000066400000000000000000000015251220320442200365100ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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; public interface ClassWorldListener { public void realmCreated( ClassRealm realm ); public void realmDisposed( ClassRealm realm ); } UrlUtils.java000066400000000000000000000035221220320442200345070ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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 java.net.URL; import java.net.URLClassLoader; import java.util.HashSet; import java.util.Set; /** * @author Jason van Zyl */ public class UrlUtils { public static String normalizeUrlPath( String name ) { if ( name.startsWith( "/" ) ) { name = name.substring( 1 ); } // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml // | i | // +-------+ remove // int i = name.indexOf( "/.." ); // Can't be at the beginning because we have no root to refer to so // we start at 1. if ( i > 0 ) { int j = name.lastIndexOf( "/", i - 1 ); if ( j >= 0 ) { name = name.substring( 0, j ) + name.substring( i + 3 ); } } return name; } public static Set getURLs( URLClassLoader loader ) { Set ret = new HashSet(); for ( URL url : loader.getURLs() ) { ret.add( url ); } return ret; } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcher/000077500000000000000000000000001220320442200337375ustar00rootroot00000000000000ConfigurationException.java000066400000000000000000000027061220320442200412160ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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. */ /** * Indicates an error during Launcher configuration. * * @author bob mcwhirter */ 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 ); } protected ConfigurationException( Exception cause ) { super( cause ); } } ConfigurationHandler.java000066400000000000000000000037451220320442200406410ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.File; import java.net.URL; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; /** * Receive notification of the logical content of launcher configuration, independently from parsing. * * @author Igor Fedorenko */ public interface ConfigurationHandler { /** * Define the main class name * @param mainClassName the main class name * @param mainRealmName the main realm from which the main class is loaded */ void setAppMain( String mainClassName, String mainRealmName ); /** * Define a new realm * @param realmName the new realm name * @throws DuplicateRealmException */ void addRealm( String realmName ) throws DuplicateRealmException; /** * Add an import specification from a realm * @param relamName the realm name * @param importSpec the import specification * @throws NoSuchRealmException */ void addImportFrom( String relamName, String importSpec ) throws NoSuchRealmException; /** * Add a file to the realm * @param file the file to load content from */ void addLoadFile( File file ); /** * Add an URL to the realm * @param url the url to load content from */ void addLoadURL( URL url ); } ConfigurationParser.java000066400000000000000000000321521220320442200405120ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; /** * Event based launcher configuration parser, delegating effective configuration handling to ConfigurationHandler. * * @author bob mcwhirter * @author Jason van Zyl * @author Igor Fedorenko * @see ConfigurationHandler */ public class ConfigurationParser { 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"; private ConfigurationHandler handler; private Properties systemProperties; public ConfigurationParser( ConfigurationHandler handler, Properties systemProperties ) { this.handler = handler; this.systemProperties = systemProperties; } /** * Parse launcher configuration file and send events to the handler. */ public void parse( InputStream is ) throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException { BufferedReader reader = new BufferedReader( new InputStreamReader( is, "UTF-8" ) ); String line = null; int lineNo = 0; boolean mainSet = false; String curRealm = null; while ( true ) { line = reader.readLine(); if ( line == null ) { break; } ++lineNo; line = line.trim(); if ( canIgnore( line ) ) { continue; } if ( line.startsWith( MAIN_PREFIX ) ) { if ( mainSet ) { throw new ConfigurationException( "Duplicate main configuration", lineNo, line ); } String conf = line.substring( MAIN_PREFIX.length() ).trim(); int fromLoc = conf.indexOf( "from" ); if ( fromLoc < 0 ) { throw new ConfigurationException( "Missing from clause", lineNo, line ); } String mainClassName = filter( conf.substring( 0, fromLoc ).trim() ); String mainRealmName = filter( conf.substring( fromLoc + 4 ).trim() ); this.handler.setAppMain( mainClassName, mainRealmName ); mainSet = true; } else if ( line.startsWith( SET_PREFIX ) ) { String conf = line.substring( SET_PREFIX.length() ).trim(); int usingLoc = conf.indexOf( " using" ) + 1; String property = null; String propertiesFileName = null; if ( usingLoc > 0 ) { property = conf.substring( 0, usingLoc ).trim(); propertiesFileName = filter( conf.substring( usingLoc + 5 ).trim() ); conf = propertiesFileName; } String defaultValue = null; int defaultLoc = conf.indexOf( " default" ) + 1; if ( defaultLoc > 0 ) { defaultValue = filter( conf.substring( defaultLoc + 7 ).trim() ); if ( property == null ) { property = conf.substring( 0, defaultLoc ).trim(); } else { propertiesFileName = conf.substring( 0, defaultLoc ).trim(); } } String value = systemProperties.getProperty( property ); if ( value != null ) { continue; } if ( propertiesFileName != null ) { File propertiesFile = new File( propertiesFileName ); if ( propertiesFile.exists() ) { Properties properties = new Properties(); try { properties.load( new FileInputStream( propertiesFileName ) ); value = properties.getProperty( property ); } catch ( Exception e ) { // do nothing } } } if ( value == null && defaultValue != null ) { value = defaultValue; } if ( value != null ) { value = filter( value ); systemProperties.setProperty( property, value ); } } else if ( line.startsWith( "[" ) ) { int rbrack = line.indexOf( "]" ); if ( rbrack < 0 ) { throw new ConfigurationException( "Invalid realm specifier", lineNo, line ); } String realmName = line.substring( 1, rbrack ); handler.addRealm( realmName ); curRealm = realmName; } else if ( line.startsWith( IMPORT_PREFIX ) ) { if ( curRealm == null ) { throw new ConfigurationException( "Unhandled import", lineNo, line ); } String conf = line.substring( IMPORT_PREFIX.length() ).trim(); int fromLoc = conf.indexOf( "from" ); if ( fromLoc < 0 ) { throw new ConfigurationException( "Missing from clause", lineNo, line ); } String importSpec = conf.substring( 0, fromLoc ).trim(); String relamName = conf.substring( fromLoc + 4 ).trim(); handler.addImportFrom( relamName, importSpec ); } else if ( line.startsWith( LOAD_PREFIX ) ) { String constituent = line.substring( LOAD_PREFIX.length() ).trim(); constituent = filter( constituent ); if ( constituent.indexOf( "*" ) >= 0 ) { loadGlob( constituent, false /*not optionally*/ ); } else { File file = new File( constituent ); if ( file.exists() ) { handler.addLoadFile( file ); } else { try { handler.addLoadURL( new URL( constituent ) ); } catch ( MalformedURLException e ) { throw new FileNotFoundException( constituent ); } } } } else if ( line.startsWith( OPTIONALLY_PREFIX ) ) { String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim(); constituent = filter( constituent ); if ( constituent.indexOf( "*" ) >= 0 ) { loadGlob( constituent, true /*optionally*/ ); } else { File file = new File( constituent ); if ( file.exists() ) { handler.addLoadFile( file ); } else { try { handler.addLoadURL( new URL( constituent ) ); } catch ( MalformedURLException e ) { // swallow } } } } else { throw new ConfigurationException( "Unhandled configuration", lineNo, line ); } } reader.close(); } /** * Load a glob into the specified classloader. * * @param line The path configuration line. * @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 ConfigurationException */ protected void loadGlob( String line, boolean optionally ) throws MalformedURLException, FileNotFoundException, ConfigurationException { File globFile = new File( line ); File dir = globFile.getParentFile(); if ( !dir.exists() ) { if ( optionally ) { return; } else { throw new FileNotFoundException( dir.toString() ); } } String localName = globFile.getName(); int starLoc = localName.indexOf( "*" ); final String prefix = localName.substring( 0, starLoc ); final String suffix = localName.substring( starLoc + 1 ); File[] matches = dir.listFiles( new FilenameFilter() { public boolean accept( File dir, String name ) { if ( !name.startsWith( prefix ) ) { return false; } if ( !name.endsWith( suffix ) ) { return false; } return true; } } ); for ( File match : matches ) { handler.addLoadFile( match ); } } /** * 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 { String result = ""; int cur = 0; int textLen = text.length(); int propStart = -1; int propStop = -1; String propName = null; String propValue = null; while ( cur < textLen ) { propStart = text.indexOf( "${", cur ); if ( propStart < 0 ) { break; } result += text.substring( cur, propStart ); propStop = text.indexOf( "}", propStart ); if ( propStop < 0 ) { throw new ConfigurationException( "Unterminated property: " + text.substring( propStart ) ); } propName = text.substring( propStart + 2, propStop ); propValue = systemProperties.getProperty( propName ); /* do our best if we are not running from surefire */ if ( propName.equals( "basedir" ) && ( propValue == null || propValue.equals( "" ) ) ) { propValue = ( new File( "" ) ).getAbsolutePath(); } if ( propValue == null ) { throw new ConfigurationException( "No such property: " + propName ); } result += propValue; cur = propStop + 1; } result += text.substring( cur ); return result; } /** * 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. */ private boolean canIgnore( String line ) { return ( line.length() == 0 || line.startsWith( "#" ) ); } } Configurator.java000066400000000000000000000145341220320442200371740ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; /** * Launcher configurator. * * @author bob mcwhirter * @author Jason van Zyl */ public class Configurator implements ConfigurationHandler { /** * The launcher to configure. */ private Launcher launcher; private ClassWorld world; /** * Processed Realms. */ private Map configuredRealms; /** * Current Realm. */ private ClassRealm curRealm; private ClassLoader foreignClassLoader = null; /** * Construct. * * @param launcher The launcher to configure. */ public Configurator( Launcher launcher ) { this.launcher = launcher; configuredRealms = new HashMap(); if ( launcher != null ) { this.foreignClassLoader = launcher.getSystemClassLoader(); } } /** * 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(); } /** * 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. */ public void configure( InputStream is ) throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException { if ( world == null ) { world = new ClassWorld(); } curRealm = null; foreignClassLoader = null; if ( this.launcher != null ) { foreignClassLoader = this.launcher.getSystemClassLoader(); } ConfigurationParser parser = new ConfigurationParser( this, System.getProperties() ); parser.parse( is ); // Associate child realms to their parents. associateRealms(); if ( this.launcher != null ) { this.launcher.setWorld( world ); } } // TODO return this to protected when the legacy wrappers can be removed. /** * Associate parent realms with their children. */ public void associateRealms() { List sortRealmNames = new ArrayList( configuredRealms.keySet() ); // sort by name Comparator comparator = new Comparator() { public int compare( String g1, String g2 ) { return g1.compareTo( g2 ); } }; Collections.sort( sortRealmNames, comparator ); // So now we have something like the following for defined // realms: // // root // root.maven // root.maven.plugin // // Now if the name of a realm is a superset of an existing realm // the we want to make child/parent associations. for ( String realmName : sortRealmNames ) { int j = realmName.lastIndexOf( '.' ); if ( j > 0 ) { String parentRealmName = realmName.substring( 0, j ); ClassRealm parentRealm = configuredRealms.get( parentRealmName ); if ( parentRealm != null ) { ClassRealm realm = configuredRealms.get( realmName ); realm.setParentRealm( parentRealm ); } } } } public void addImportFrom( String relamName, String importSpec ) throws NoSuchRealmException { curRealm.importFrom( relamName, importSpec ); } public void addLoadFile( File file ) { try { curRealm.addURL( file.toURI().toURL() ); } catch ( MalformedURLException e ) { // can't really happen... or can it? } } public void addLoadURL( URL url ) { curRealm.addURL( url ); } public void addRealm( String realmName ) throws DuplicateRealmException { curRealm = world.newRealm( realmName, foreignClassLoader ); // Stash the configured realm for subsequent association processing. configuredRealms.put( realmName, curRealm ); } public void setAppMain( String mainClassName, String mainRealmName ) { if ( this.launcher != null ) { this.launcher.setAppMain( mainClassName, mainRealmName ); } } } Launcher.java000066400000000000000000000337311220320442200362730ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.MalformedURLException; import java.net.URL; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; /** * Command-line invokable application launcher. *

*

* This launcher class assists in the creation of classloaders and ClassRealms * from a configuration file and the launching of the application's main * method from the correct class loaded through the correct classloader. *

*

*

* The path to the configuration file is specified using the classworlds.conf * system property, typically specified using the -D switch to * java. *

* * @author bob mcwhirter */ public class Launcher { protected static final String CLASSWORLDS_CONF = "classworlds.conf"; protected static final String UBERJAR_CONF_DIR = "WORLDS-INF/conf/"; protected ClassLoader systemClassLoader; protected String mainClassName; protected String mainRealmName; protected ClassWorld world; private int exitCode = 0; public Launcher() { this.systemClassLoader = Thread.currentThread().getContextClassLoader(); } public void setSystemClassLoader( ClassLoader loader ) { this.systemClassLoader = loader; } public ClassLoader getSystemClassLoader() { return this.systemClassLoader; } public int getExitCode() { return exitCode; } public void setAppMain( String mainClassName, String mainRealmName ) { this.mainClassName = mainClassName; this.mainRealmName = mainRealmName; } public String getMainRealmName() { return this.mainRealmName; } public String getMainClassName() { return this.mainClassName; } public void setWorld( ClassWorld world ) { this.world = world; } public ClassWorld getWorld() { return this.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. */ public void configure( InputStream is ) throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException { Configurator configurator = new Configurator( this ); configurator.configure( is ); } /** * Retrieve the main entry class. * * @return The main entry class. * @throws ClassNotFoundException If the class cannot be found. * @throws NoSuchRealmException If the specified main entry realm does not exist. */ public Class getMainClass() throws ClassNotFoundException, NoSuchRealmException { return getMainRealm().loadClass( getMainClassName() ); } /** * Retrieve the main entry realm. * * @return The main entry realm. * @throws NoSuchRealmException If the specified main entry realm does not exist. */ public ClassRealm getMainRealm() throws NoSuchRealmException { return getWorld().getRealm( getMainRealmName() ); } /** * Retrieve the enhanced main entry method. * * @return The enhanced main entry method. * @throws ClassNotFoundException If the main entry class cannot be found. * @throws NoSuchMethodException If the main entry method cannot be found. * @throws NoSuchRealmException If the main entry realm cannot be found. */ protected Method getEnhancedMainMethod() throws ClassNotFoundException, NoSuchMethodException, NoSuchRealmException { Class cwClass = getMainRealm().loadClass( ClassWorld.class.getName() ); Method m = getMainClass().getMethod( "main", new Class[]{String[].class, cwClass} ); int modifiers = m.getModifiers(); if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) ) { if ( m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE ) { return m; } } throw new NoSuchMethodException( "public static void main(String[] args, ClassWorld world)" ); } /** * Retrieve the main entry method. * * @return The main entry method. * @throws ClassNotFoundException If the main entry class cannot be found. * @throws NoSuchMethodException If the main entry method cannot be found. * @throws NoSuchRealmException If the main entry realm cannot be found. */ protected Method getMainMethod() throws ClassNotFoundException, NoSuchMethodException, NoSuchRealmException { Method m = getMainClass().getMethod( "main", new Class[]{String[].class} ); int modifiers = m.getModifiers(); if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) ) { if ( m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE ) { return m; } } throw new NoSuchMethodException( "public static void main(String[] args) in " + getMainClass() ); } /** * Launch the application. * * @param args The application args. * @throws ClassNotFoundException If the main entry class cannot be found. * @throws IllegalAccessException If the method cannot be accessed. * @throws InvocationTargetException If the target of the invokation is invalid. * @throws NoSuchMethodException If the main entry method cannot be found. * @throws NoSuchRealmException If the main entry realm cannot be found. */ public void launch( String[] args ) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchRealmException { try { launchEnhanced( args ); return; } catch ( NoSuchMethodException e ) { // ignore } launchStandard( args ); } /** * Attempt to launch the application through the enhanced main method. *

*

* This will seek a method with the exact signature of: *

*

*

     *  public static void main(String[] args, ClassWorld world)
     *  
* * @param args The application args. * @throws ClassNotFoundException If the main entry class cannot be found. * @throws IllegalAccessException If the method cannot be accessed. * @throws InvocationTargetException If the target of the invokation is * invalid. * @throws NoSuchMethodException If the main entry method cannot be found. * @throws NoSuchRealmException If the main entry realm cannot be found. */ protected void launchEnhanced( String[] args ) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchRealmException { ClassRealm mainRealm = getMainRealm(); Class mainClass = getMainClass(); Method mainMethod = getEnhancedMainMethod(); ClassLoader cl = mainRealm; // ---------------------------------------------------------------------- // This is what the classloader for the main realm looks like when we // boot from the command line: // ---------------------------------------------------------------------- // [ AppLauncher$AppClassLoader ] : $CLASSPATH envar // ^ // | // | // [ AppLauncher$ExtClassLoader ] : ${java.home}/jre/lib/ext/*.jar // ^ // | // | // [ Strategy ] // ---------------------------------------------------------------------- Thread.currentThread().setContextClassLoader( cl ); Object ret = mainMethod.invoke( mainClass, new Object[]{args, getWorld()} ); if ( ret instanceof Integer ) { exitCode = ( (Integer) ret ).intValue(); } Thread.currentThread().setContextClassLoader( systemClassLoader ); } /** * Attempt to launch the application through the standard main method. *

*

* This will seek a method with the exact signature of: *

*

*

     *  public static void main(String[] args)
     *  
* * @param args The application args. * @throws ClassNotFoundException If the main entry class cannot be found. * @throws IllegalAccessException If the method cannot be accessed. * @throws InvocationTargetException If the target of the invokation is * invalid. * @throws NoSuchMethodException If the main entry method cannot be found. * @throws NoSuchRealmException If the main entry realm cannot be found. */ protected void launchStandard( String[] args ) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NoSuchRealmException { ClassRealm mainRealm = getMainRealm(); Class mainClass = getMainClass(); Method mainMethod = getMainMethod(); Thread.currentThread().setContextClassLoader( mainRealm ); Object ret = mainMethod.invoke( mainClass, new Object[]{args} ); if ( ret instanceof Integer ) { exitCode = ( (Integer) ret ).intValue(); } Thread.currentThread().setContextClassLoader( systemClassLoader ); } // ------------------------------------------------------------ // 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 ) { try { int exitCode = mainWithExitCode( args ); System.exit( exitCode ); } catch ( Exception e ) { e.printStackTrace(); System.exit( 100 ); } } /** * 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 { String classworldsConf = System.getProperty( CLASSWORLDS_CONF ); InputStream is; Launcher launcher = new Launcher(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); launcher.setSystemClassLoader( cl ); if ( classworldsConf != null ) { is = new FileInputStream( classworldsConf ); } else { if ( "true".equals( System.getProperty( "classworlds.bootstrapped" ) ) ) { is = cl.getResourceAsStream( UBERJAR_CONF_DIR + CLASSWORLDS_CONF ); } else { is = cl.getResourceAsStream( CLASSWORLDS_CONF ); } } if ( is == null ) { throw new Exception( "classworlds configuration not specified nor found in the classpath" ); } launcher.configure( is ); is.close(); try { launcher.launch( args ); } catch ( InvocationTargetException e ) { ClassRealm realm = launcher.getWorld().getRealm( launcher.getMainRealmName() ); URL[] constituents = realm.getURLs(); System.out.println( "---------------------------------------------------" ); for ( int i = 0; i < constituents.length; i++ ) { System.out.println( "constituent[" + i + "]: " + constituents[i] ); } System.out.println( "---------------------------------------------------" ); // Decode ITE (if we can) Throwable t = e.getTargetException(); if ( t instanceof Exception ) { throw (Exception) t; } if ( t instanceof Error ) { throw (Error) t; } // Else just toss the ITE throw e; } return launcher.getExitCode(); } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/realm/000077500000000000000000000000001220320442200332365ustar00rootroot00000000000000ClassRealm.java000066400000000000000000000342041220320442200360530ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/realmpackage 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 org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.strategy.Strategy; import org.codehaus.plexus.classworlds.strategy.StrategyFactory; import java.io.Closeable; import java.io.IOException; import java.io.PrintStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.SortedSet; import java.util.TreeSet; /** * The class loading gateway. Each class realm has access to a base class loader, imports form zero or more other class * loaders, an optional parent class loader and of course its own class path. When queried for a class/resource, a class * realm will always query its base class loader first before it delegates to a pluggable strategy. The strategy in turn * controls the order in which imported class loaders, the parent class loader and the realm itself are searched. The * base class loader is assumed to be capable of loading of the bootstrap classes. * * @author bob mcwhirter * @author Jason van Zyl */ public class ClassRealm extends URLClassLoader { private ClassWorld world; private String id; private SortedSet foreignImports; private SortedSet parentImports; private Strategy strategy; private ClassLoader parentClassLoader; private static final boolean isParallelCapable = Closeable.class.isAssignableFrom( URLClassLoader.class ); /** * Creates a new class realm. * * @param world The class world this realm belongs to, must not be null. * @param id The identifier for this realm, must not be null. * @param baseClassLoader The base class loader for this realm, may be null to use the bootstrap class * loader. */ public ClassRealm( ClassWorld world, String id, ClassLoader baseClassLoader ) { super( new URL[0], baseClassLoader ); this.world = world; this.id = id; foreignImports = new TreeSet(); strategy = StrategyFactory.getStrategy( this ); } public String getId() { return this.id; } public ClassWorld getWorld() { return this.world; } public void importFromParent( String packageName ) { if ( parentImports == null ) { parentImports = new TreeSet(); } parentImports.add( new Entry( null, packageName ) ); } boolean isImportedFromParent( String name ) { if ( parentImports != null && !parentImports.isEmpty() ) { for ( Entry entry : parentImports ) { if ( entry.matches( name ) ) { return true; } } return false; } return true; } public void importFrom( String realmId, String packageName ) throws NoSuchRealmException { importFrom( getWorld().getRealm( realmId ), packageName ); } public void importFrom( ClassLoader classLoader, String packageName ) { foreignImports.add( new Entry( classLoader, packageName ) ); } public ClassLoader getImportClassLoader( String name ) { for ( Entry entry : foreignImports ) { if ( entry.matches( name ) ) { return entry.getClassLoader(); } } return null; } public Collection getImportRealms() { Collection importRealms = new HashSet(); for ( Entry entry : foreignImports ) { if ( entry.getClassLoader() instanceof ClassRealm ) { importRealms.add( (ClassRealm) entry.getClassLoader() ); } } return importRealms; } public Strategy getStrategy() { return strategy; } public void setParentClassLoader( ClassLoader parentClassLoader ) { this.parentClassLoader = parentClassLoader; } public ClassLoader getParentClassLoader() { return parentClassLoader; } public void setParentRealm( ClassRealm realm ) { this.parentClassLoader = realm; } public ClassRealm getParentRealm() { return ( parentClassLoader instanceof ClassRealm ) ? (ClassRealm) parentClassLoader : null; } public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { ClassRealm childRealm = getWorld().newRealm( id, null ); childRealm.setParentRealm( this ); return childRealm; } public void addURL( URL url ) { String urlStr = url.toExternalForm(); if ( urlStr.startsWith( "jar:" ) && urlStr.endsWith( "!/" ) ) { urlStr = urlStr.substring( 4, urlStr.length() - 2 ); try { url = new URL( urlStr ); } catch ( MalformedURLException e ) { e.printStackTrace(); } } super.addURL( url ); } // ---------------------------------------------------------------------- // We delegate to the Strategy here so that we can change the behavior // of any existing ClassRealm. // ---------------------------------------------------------------------- public Class loadClass( String name ) throws ClassNotFoundException { return loadClass( name, false ); } protected Class loadClass( String name, boolean resolve ) throws ClassNotFoundException { if ( isParallelCapable ) { return unsynchronizedLoadClass( name, resolve ); } else { synchronized ( this ) { return unsynchronizedLoadClass( name, resolve ); } } } private Class unsynchronizedLoadClass( String name, boolean resolve ) throws ClassNotFoundException { try { // first, try loading bootstrap classes return super.loadClass( name, resolve ); } catch ( ClassNotFoundException e ) { // next, try loading via imports, self and parent as controlled by strategy return strategy.loadClass( name ); } } protected Class findClass( String name ) throws ClassNotFoundException { /* * NOTE: This gets only called from ClassLoader.loadClass(Class, boolean) while we try to check for bootstrap * stuff. Don't scan our class path yet, loadClassFromSelf() will do this later when called by the strategy. */ throw new ClassNotFoundException( name ); } public URL getResource( String name ) { URL resource = super.getResource( name ); return resource != null ? resource : strategy.getResource( name ); } public URL findResource( String name ) { return super.findResource( name ); } public Enumeration getResources( String name ) throws IOException { Collection resources = new LinkedHashSet( Collections.list( super.getResources( name ) ) ); resources.addAll( Collections.list( strategy.getResources( name ) ) ); return Collections.enumeration( resources ); } public Enumeration findResources( String name ) throws IOException { return super.findResources( name ); } // ---------------------------------------------------------------------------- // Display methods // ---------------------------------------------------------------------------- public void display() { display( System.out ); } public void display( PrintStream out ) { out.println( "-----------------------------------------------------" ); for ( ClassRealm cr = this; cr != null; cr = cr.getParentRealm() ) { out.println( "realm = " + cr.getId() ); out.println( "strategy = " + cr.getStrategy().getClass().getName() ); showUrls( cr, out ); out.println(); } out.println( "-----------------------------------------------------" ); } private static void showUrls( ClassRealm classRealm, PrintStream out ) { URL[] urls = classRealm.getURLs(); for ( int i = 0; i < urls.length; i++ ) { out.println( "urls[" + i + "] = " + urls[i] ); } out.println( "Number of foreign imports: " + classRealm.foreignImports.size() ); for ( Entry entry : classRealm.foreignImports ) { out.println( "import: " + entry ); } if ( classRealm.parentImports != null ) { out.println( "Number of parent imports: " + classRealm.parentImports.size() ); for ( Entry entry : classRealm.parentImports ) { out.println( "import: " + entry ); } } } public String toString() { return "ClassRealm[" + getId() + ", parent: " + getParentClassLoader() + "]"; } //--------------------------------------------------------------------------------------------- // Search methods that can be ordered by strategies to load a class //--------------------------------------------------------------------------------------------- public Class loadClassFromImport( String name ) { ClassLoader importClassLoader = getImportClassLoader( name ); if ( importClassLoader != null ) { try { return importClassLoader.loadClass( name ); } catch ( ClassNotFoundException e ) { return null; } } return null; } public Class loadClassFromSelf( String name ) { synchronized ( getClassRealmLoadingLock( name ) ) { try { Class clazz = findLoadedClass( name ); if ( clazz == null ) { clazz = super.findClass( name ); } return clazz; } catch ( ClassNotFoundException e ) { return null; } } } private Object getClassRealmLoadingLock( String name ) { if ( isParallelCapable ) { return getClassLoadingLock( name ); } else { return this; } } public Class loadClassFromParent( String name ) { ClassLoader parent = getParentClassLoader(); if ( parent != null && isImportedFromParent( name ) ) { try { return parent.loadClass( name ); } catch ( ClassNotFoundException e ) { return null; } } return null; } //--------------------------------------------------------------------------------------------- // Search methods that can be ordered by strategies to get a resource //--------------------------------------------------------------------------------------------- public URL loadResourceFromImport( String name ) { ClassLoader importClassLoader = getImportClassLoader( name ); if ( importClassLoader != null ) { return importClassLoader.getResource( name ); } return null; } public URL loadResourceFromSelf( String name ) { return super.findResource( name ); } public URL loadResourceFromParent( String name ) { ClassLoader parent = getParentClassLoader(); if ( parent != null && isImportedFromParent( name ) ) { return parent.getResource( name ); } else { return null; } } //--------------------------------------------------------------------------------------------- // Search methods that can be ordered by strategies to get resources //--------------------------------------------------------------------------------------------- public Enumeration loadResourcesFromImport( String name ) { ClassLoader importClassLoader = getImportClassLoader( name ); if ( importClassLoader != null ) { try { return importClassLoader.getResources( name ); } catch ( IOException e ) { return null; } } return null; } public Enumeration loadResourcesFromSelf( String name ) { try { return super.findResources( name ); } catch ( IOException e ) { return null; } } public Enumeration loadResourcesFromParent( String name ) { ClassLoader parent = getParentClassLoader(); if ( parent != null && isImportedFromParent( name ) ) { try { return parent.getResources( name ); } catch ( IOException e ) { // eat it } } return null; } static { if (isParallelCapable) // Avoid running this method on older jdks { registerAsParallelCapable(); } } } DuplicateRealmException.java000066400000000000000000000036551220320442200406050ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/realmpackage org.codehaus.plexus.classworlds.realm; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.ClassWorldException; /* * 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. */ /** * Indicates an attempt to add a ClassRealm to a * ClassWorld with a duplicate id. * * @author bob mcwhirter */ 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; } } Entry.java000066400000000000000000000147661220320442200351410ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/realmpackage 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 */ class Entry implements Comparable { final ClassLoader classLoader; final String pkgName; Entry( ClassLoader realm, String pkgName ) { this.classLoader = realm; this.pkgName = pkgName; } // ------------------------------------------------------------ // Instance methods // ------------------------------------------------------------ /** * Retrieve the class loader. * * @return The class loader. */ ClassLoader getClassLoader() { return this.classLoader; } /** * Retrieve the package name. * * @return The package name. */ String getPackageName() { return this.pkgName; } /** * Determine if the class/resource name matches the package * described by this entry. * * @param name The class or resource name to test, must not be null. * @return true if this entry matches the * classname, otherwise false. */ boolean matches( String name ) { String pkg = getPackageName(); if ( pkg.endsWith( ".*" ) ) { String pkgName; if ( name.indexOf( '/' ) < 0 ) { // a binary class name, e.g. java.lang.Object int index = name.lastIndexOf( '.' ); pkgName = ( index < 0 ) ? "" : name.substring( 0, index ); } else { // a resource name, e.g. java/lang/Object.class int index = name.lastIndexOf( '/' ); pkgName = ( index < 0 ) ? "" : name.substring( 0, index ).replace( '/', '.' ); } return pkgName.length() == pkg.length() - 2 && pkg.regionMatches( 0, pkgName, 0, pkgName.length() ); } else if ( pkg.length() > 0 ) { if ( name.indexOf( '/' ) < 0 ) { // a binary class name, e.g. java.lang.Object if ( name.startsWith( pkg ) ) { if ( name.length() == pkg.length() ) { // exact match of class name return true; } else if ( name.charAt( pkg.length() ) == '.' ) { // prefix match of package name return true; } else if ( name.charAt( pkg.length() ) == '$' ) { // prefix match of enclosing type return true; } } } else { // a resource name, e.g. java/lang/Object.class if ( name.equals( pkg ) ) { // exact match of resource name return true; } pkg = pkg.replace( '.', '/' ); if ( name.startsWith( pkg ) && name.length() > pkg.length() ) { if ( name.charAt( pkg.length() ) == '/' ) { // prefix match of package directory return true; } else if ( name.charAt( pkg.length() ) == '$' ) { // prefix match of nested class file return true; } else if ( name.length() == pkg.length() + 6 && name.endsWith( ".class" ) ) { // exact match of class file return true; } } } return false; } else { return true; } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 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( Entry that ) { // 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() ) ); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 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 " + getClassLoader() + "]"; } } NoSuchRealmException.java000066400000000000000000000036531220320442200400700ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/realmpackage org.codehaus.plexus.classworlds.realm; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.ClassWorldException; /* * 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. */ /** * Indicates an attempt to retrieve a ClassRealm from a * ClassWorld with an invalid id. * * @author bob mcwhirter */ 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; } } plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategy/000077500000000000000000000000001220320442200340005ustar00rootroot00000000000000AbstractStrategy.java000066400000000000000000000035541220320442200400610ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage org.codehaus.plexus.classworlds.strategy; import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedHashSet; import org.codehaus.plexus.classworlds.UrlUtils; import org.codehaus.plexus.classworlds.realm.ClassRealm; /* * 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. */ /** * @author Jason van Zyl */ public abstract class AbstractStrategy implements Strategy { protected ClassRealm realm; public AbstractStrategy( ClassRealm realm ) { this.realm = realm; } protected String getNormalizedResource( String name ) { return UrlUtils.normalizeUrlPath( name ); } protected Enumeration combineResources( Enumeration en1, Enumeration en2, Enumeration en3 ) { Collection urls = new LinkedHashSet(); addAll( urls, en1 ); addAll( urls, en2 ); addAll( urls, en3 ); return Collections.enumeration( urls ); } private void addAll( Collection target, Enumeration en ) { if ( en != null ) { while ( en.hasMoreElements() ) { target.add( en.nextElement() ); } } } public ClassRealm getRealm() { return realm; } } OsgiBundleStrategy.java000066400000000000000000000051601220320442200403440ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage org.codehaus.plexus.classworlds.strategy; /* * Copyright 2001-2010 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 java.io.IOException; import java.net.URL; import java.util.Enumeration; import org.codehaus.plexus.classworlds.realm.ClassRealm; public class OsgiBundleStrategy extends AbstractStrategy { // java.* from parent // imported packages [Import-Package header with explicit constraints on the exporter] // requires bundle [Required-Bundle] // self [Bundle-Classpath header] // attached fragments // // We need to trya and be OSGi r4 compliant in the loading of all the bundles so that we can try to // load eclipse without requiring equinox. Or any other OSGi container for that matter. public OsgiBundleStrategy( ClassRealm realm ) { super( realm ); } public Class loadClass( String name ) throws ClassNotFoundException { Class clazz = realm.loadClassFromImport( name ); if ( clazz == null ) { clazz = realm.loadClassFromSelf( name ); if ( clazz == null ) { clazz = realm.loadClassFromParent( name ); if ( clazz == null ) { throw new ClassNotFoundException( name ); } } } return clazz; } public URL getResource( String name ) { URL resource = realm.loadResourceFromImport( name ); if ( resource == null ) { resource = realm.loadResourceFromSelf( name ); if ( resource == null ) { resource = realm.loadResourceFromParent( name ); } } return resource; } public Enumeration getResources( String name ) throws IOException { Enumeration imports = realm.loadResourcesFromImport( name ); Enumeration self = realm.loadResourcesFromSelf( name ); Enumeration parent = realm.loadResourcesFromParent( name ); return combineResources( imports, self, parent ); } } ParentFirstStrategy.java000066400000000000000000000043421220320442200405530ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage 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 java.io.IOException; import java.net.URL; import java.util.Enumeration; import org.codehaus.plexus.classworlds.realm.ClassRealm; /** * @author Jason van Zyl */ public class ParentFirstStrategy extends AbstractStrategy { public ParentFirstStrategy( ClassRealm realm ) { super( realm ); } public Class loadClass( String name ) throws ClassNotFoundException { Class clazz = realm.loadClassFromImport( name ); if ( clazz == null ) { clazz = realm.loadClassFromParent( name ); if ( clazz == null ) { clazz = realm.loadClassFromSelf( name ); if ( clazz == null ) { throw new ClassNotFoundException( name ); } } } return clazz; } public URL getResource( String name ) { URL resource = realm.loadResourceFromImport( name ); if ( resource == null ) { resource = realm.loadResourceFromParent( name ); if ( resource == null ) { resource = realm.loadResourceFromSelf( name ); } } return resource; } public Enumeration getResources( String name ) throws IOException { Enumeration imports = realm.loadResourcesFromImport( name ); Enumeration parent = realm.loadResourcesFromParent( name ); Enumeration self = realm.loadResourcesFromSelf( name ); return combineResources( imports, parent, self ); } } SelfFirstStrategy.java000066400000000000000000000043361220320442200402160ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage 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 java.io.IOException; import java.net.URL; import java.util.Enumeration; import org.codehaus.plexus.classworlds.realm.ClassRealm; /** * @author Jason van Zyl */ public class SelfFirstStrategy extends AbstractStrategy { public SelfFirstStrategy( ClassRealm realm ) { super( realm ); } public Class loadClass( String name ) throws ClassNotFoundException { Class clazz = realm.loadClassFromImport( name ); if ( clazz == null ) { clazz = realm.loadClassFromSelf( name ); if ( clazz == null ) { clazz = realm.loadClassFromParent( name ); if ( clazz == null ) { throw new ClassNotFoundException( name ); } } } return clazz; } public URL getResource( String name ) { URL resource = realm.loadResourceFromImport( name ); if ( resource == null ) { resource = realm.loadResourceFromSelf( name ); if ( resource == null ) { resource = realm.loadResourceFromParent( name ); } } return resource; } public Enumeration getResources( String name ) throws IOException { Enumeration imports = realm.loadResourcesFromImport( name ); Enumeration self = realm.loadResourcesFromSelf( name ); Enumeration parent = realm.loadResourcesFromParent( name ); return combineResources( imports, self, parent ); } } Strategy.java000066400000000000000000000022711220320442200363700ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage 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 java.io.IOException; import java.net.URL; import java.util.Enumeration; import org.codehaus.plexus.classworlds.realm.ClassRealm; /** * A strategy is a class for defining how classes and resources are located * in classworlds. * * @uthor: Andrew Williams * @since: Nov 19, 2006 */ public interface Strategy { Class loadClass( String name ) throws ClassNotFoundException; URL getResource( String name ); Enumeration getResources( String name ) throws IOException; ClassRealm getRealm(); } StrategyFactory.java000066400000000000000000000023001220320442200377110ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/main/java/org/codehaus/plexus/classworlds/strategypackage 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 */ public class StrategyFactory { public static Strategy getStrategy( ClassRealm realm ) { return getStrategy( realm, "default" ); } public static Strategy getStrategy( ClassRealm realm, String hint ) { // TODO: Here we shall check hint to load non-default strategies return new SelfFirstStrategy( realm ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/site/000077500000000000000000000000001220320442200227735ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/site/site.xml000066400000000000000000000011271220320442200244620ustar00rootroot00000000000000 plexus-classworlds-plexus-classworlds-2.5.1/src/test/000077500000000000000000000000001220320442200230065ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/000077500000000000000000000000001220320442200237275ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/000077500000000000000000000000001220320442200245165ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/000077500000000000000000000000001220320442200263115ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/000077500000000000000000000000001220320442200276315ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/000077500000000000000000000000001220320442200321715ustar00rootroot00000000000000AbstractClassWorldsTestCase.java000066400000000000000000000020021220320442200403270ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; import java.net.URL; import junit.framework.TestCase; /* * 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. */ /** * @author Jason van Zyl */ public abstract class AbstractClassWorldsTestCase extends TestCase { public AbstractClassWorldsTestCase( String string ) { super( string ); } protected URL getJarUrl( String jarName ) { return TestUtil.getTestResourceUrl( jarName ); } } ClassView.java000066400000000000000000000074041220320442200346620ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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. */ public class ClassView { /** * * Formats Class information for debug output purposes. * * * * @param clz the Class to print information for * * * * @return a String describing the Class in detail */ public static String toString( Class clz ) { if ( clz.isPrimitive() ) { return clz.toString(); } else if ( clz.isArray() ) { return "Array of " + toString( clz.getComponentType() ); } else if ( clz.isInterface() ) { return toInterfaceString( clz, "" ); } else { return toClassString( clz, "" ); } } /** * * Formats Class information for debug output purposes. * * * * @param clz the Class to print information for * * @param sIndent the indentation to precede each line of output * * * * @return a String describing the Class in detail */ private static String toClassString( Class clz, String sIndent ) { StringBuffer sb = new StringBuffer(); sb.append( sIndent ) .append( "Class " ) .append( clz.getName() ) .append( " (" ) .append( toString( clz.getClassLoader() ) ) .append( ')' ); sIndent += " "; Class[] aclz = clz.getInterfaces(); for ( int i = 0, c = aclz.length; i < c; ++i ) { sb.append( '\n' ) .append( toInterfaceString( aclz[i], sIndent ) ); } clz = clz.getSuperclass(); if ( clz != null ) { sb.append( '\n' ) .append( toClassString( clz, sIndent ) ); } return sb.toString(); } /** * * Formats interface information for debug output purposes. * * * * @param clz the interface Class to print information for * * @param sIndent the indentation to precede each line of output * * * * @return a String describing the interface Class in detail */ private static String toInterfaceString( Class clz, String sIndent ) { StringBuffer sb = new StringBuffer(); sb.append( sIndent ) .append( "Interface " ) .append( clz.getName() ) .append( " (" ) .append( toString( clz.getClassLoader() ) ) .append( ')' ); Class[] aclz = clz.getInterfaces(); for ( int i = 0, c = aclz.length; i < c; ++i ) { clz = aclz[i]; sb.append( '\n' ) .append( toInterfaceString( clz, sIndent + " " ) ); } return sb.toString(); } /** * * Format a description for the specified ClassLoader object. * * * * @param loader the ClassLoader instance (or null) * * * * @return a String description of the ClassLoader */ private static String toString( ClassLoader loader ) { if ( loader == null ) { return "System ClassLoader"; } return "ClassLoader class=" + loader.getClass().getName() + ", hashCode=" + loader.hashCode(); } } ClassWorldTest.java000066400000000000000000000106471220320442200357020ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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 java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; public class ClassWorldTest extends AbstractClassWorldsTestCase { 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 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 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 ) ); } public void testPLX334() throws Exception { ClassLoader loader = new URLClassLoader( new URL[] { getJarUrl( "component1-1.0.jar" ) } ); world.newRealm( "netbeans", loader ); ClassRealm plexus = world.newRealm( "plexus" ); plexus.importFrom( "netbeans", "META-INF/plexus" ); plexus.importFrom( "netbeans", "org.codehaus.plexus" ); Enumeration e = plexus.getResources( "META-INF/plexus/components.xml" ); assertNotNull( e ); int resourceCount = 0; for ( Enumeration resources = e; resources.hasMoreElements(); ) { URL obj = resources.nextElement(); assertTrue( obj.getPath().indexOf( "/component1-1.0.jar!/META-INF/plexus/components.xml" ) >= 0 ); resourceCount++; } // assertEquals( 2, resourceCount ); // for some reason surefire-plugin 2.3 returned 2 items there: // for example: //jar:file:/home/mkleint/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.jar!/META-INF/plexus/components.xml //jar:file:/home/mkleint/src/plexus-trunk/plexus-classworlds/src/test-jars/component1-1.0.jar!/META-INF/plexus/components.xml // However only 1 is correct, which is actually returned by the 2.4 surefire-plugin assertEquals( 1, resourceCount ); Class c = plexus.loadClass( "org.codehaus.plexus.Component1" ); assertNotNull( c ); } } TestUtil.java000066400000000000000000000031071220320442200345330ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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 java.io.File; import java.net.MalformedURLException; import java.net.URL; /** * @author Ben Walding */ public class TestUtil { public static URL getTestResourceUrl( String resourceName ) { File baseDir = new File( getBasedir() ); File testDir = new File( baseDir, "src/test/test-data" ); File resourceFile = new File( testDir, resourceName ); try { return resourceFile.toURI().toURL(); } catch ( MalformedURLException e ) { throw new RuntimeException( e ); } } public static String getBasedir() { String basedir = System.getProperty( "basedir" ); /* do our best if we are not running from surefire */ if ( basedir == null || basedir.length() <= 0 ) { basedir = ( new File( "" ) ).getAbsolutePath(); } return basedir; } } UrlUtilsTest.java000066400000000000000000000021361220320442200354020ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworldspackage org.codehaus.plexus.classworlds; /* * 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 junit.framework.TestCase; public class UrlUtilsTest extends TestCase { public void testNormalizeUrlPath() { assertEquals( "org/codehaus/Test.class", UrlUtils.normalizeUrlPath( "org/codehaus/Test.class" ) ); assertEquals( "org/Test.class", UrlUtils.normalizeUrlPath( "org/codehaus/../Test.class" ) ); assertEquals( "../../some.jar/org/Test.class", UrlUtils.normalizeUrlPath( "../../some.jar/org/Test.class" ) ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/launcher/000077500000000000000000000000001220320442200337725ustar00rootroot00000000000000ConfigurationParserTest.java000066400000000000000000000054171220320442200414110ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; public class ConfigurationParserTest extends AbstractClassWorldsTestCase { ConfigurationParser configurator = new ConfigurationParser( null, System.getProperties() ); public ConfigurationParserTest( String string ) { super( string ); } public void testFilter_Unterminated() throws Exception { try { this.configurator.filter( "${cheese" ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "Unterminated" ) ); } } public void testFilter_Solitary() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); String result = this.configurator.filter( "${classworlds.test.prop}" ); assertEquals( "test prop value", result ); } public void testFilter_AtStart() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); String result = this.configurator.filter( "${classworlds.test.prop}cheese" ); assertEquals( "test prop valuecheese", result ); } public void testFilter_AtEnd() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); String result = this.configurator.filter( "cheese${classworlds.test.prop}" ); assertEquals( "cheesetest prop value", result ); } public void testFilter_Multiple() throws Exception { System.setProperty( "classworlds.test.prop.one", "test prop value one" ); System.setProperty( "classworlds.test.prop.two", "test prop value two" ); String result = this.configurator.filter( "I like ${classworlds.test.prop.one} and ${classworlds.test.prop.two} a lot" ); assertEquals( "I like test prop value one and test prop value two a lot", result ); } public void testFilter_NonExistent() throws Exception { try { this.configurator.filter( "${gollygeewillikers}" ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "No such property" ) ); } } public void testFilter_InMiddle() throws Exception { System.setProperty( "classworlds.test.prop", "test prop value" ); String result = this.configurator.filter( "cheese${classworlds.test.prop}toast" ); assertEquals( "cheesetest prop valuetoast", result ); } } ConfiguratorTest.java000066400000000000000000000263251220320442200400700ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.net.URL; import java.util.Collection; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.TestUtil; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; public class ConfiguratorTest extends AbstractClassWorldsTestCase { private Launcher launcher; private Configurator configurator; public ConfiguratorTest( String name ) { super( name ); } public void setUp() { this.launcher = new Launcher(); this.configurator = new Configurator( this.launcher ); } public void tearDown() { this.launcher = null; this.configurator = null; System.getProperties().remove( "set.using.existent" ); System.getProperties().remove( "set.using.default" ); System.getProperties().remove( "set.using.nonexistent" ); System.getProperties().remove( "set.using.nonexistent.default" ); System.getProperties().remove( "set.using.missing" ); System.getProperties().remove( "set.using.filtered.default" ); } public void testConfigure_Nonexistent() throws Exception { try { this.configurator.configure( getConfigPath( "notfound.conf" ) ); fail( "throw FileNotFoundException" ); } catch ( FileNotFoundException e ) { // expected and correct } } public void testConfigure_DuplicateMain() throws Exception { try { this.configurator.configure( getConfigPath( "dupe-main.conf" ) ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "Duplicate main" ) ); } } public void testConfigure_DuplicateRealm() throws Exception { try { this.configurator.configure( getConfigPath( "dupe-realm.conf" ) ); fail( "throw DuplicateRealmException" ); } catch ( DuplicateRealmException e ) { // expected and correct assertEquals( "dupe.realm", e.getId() ); } } public void testConfigure_EarlyImport() throws Exception { try { this.configurator.configure( getConfigPath( "early-import.conf" ) ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "Unhandled import" ) ); } } public void testConfigure_RealmSyntax() throws Exception { try { this.configurator.configure( getConfigPath( "realm-syntax.conf" ) ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "Invalid realm" ) ); } } public void testConfigure_Valid() throws Exception { this.configurator.configure( getConfigPath( "valid.conf" ) ); assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); assertEquals( "maven", this.launcher.getMainRealmName() ); ClassWorld world = this.launcher.getWorld(); Collection realms = world.getRealms(); assertEquals( 4, realms.size() ); assertNotNull( world.getRealm( "ant" ) ); assertNotNull( world.getRealm( "maven" ) ); assertNotNull( world.getRealm( "xml" ) ); ClassRealm antRealm = world.getRealm( "ant" ); ClassRealm mavenRealm = world.getRealm( "maven" ); ClassRealm xmlRealm = world.getRealm( "xml" ); ClassRealm globRealm = world.getRealm( "glob" ); assertSame( null, antRealm.getImportClassLoader( "org.apache.tools.Ant" ) ); assertSame( xmlRealm, antRealm.getImportClassLoader( "org.xml.sax.SAXException" ) ); assertSame( null, mavenRealm.getImportClassLoader( "org.apache.maven.app.App" ) ); assertSame( xmlRealm, mavenRealm.getImportClassLoader( "org.xml.sax.SAXException" ) ); URL[] urls = globRealm.getURLs(); String basedir = TestUtil.getBasedir(); assertArrayContains( urls, new File( basedir, "src/test/test-data/nested.jar" ).toURI().toURL() ); assertArrayContains( urls, new File( basedir, "src/test/test-data/a.jar" ).toURI().toURL() ); assertArrayContains( urls, new File( basedir, "src/test/test-data/b.jar" ).toURI().toURL() ); assertArrayContains( urls, new File( basedir, "src/test/test-data/c.jar" ).toURI().toURL() ); } public void testConfigure_Optionally_NonExistent() throws Exception { this.configurator.configure( getConfigPath( "optionally-nonexistent.conf" ) ); assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); assertEquals( "opt", this.launcher.getMainRealmName() ); ClassWorld world = this.launcher.getWorld(); Collection realms = world.getRealms(); assertEquals( 1, realms.size() ); assertNotNull( world.getRealm( "opt" ) ); ClassRealm optRealm = world.getRealm( "opt" ); URL[] urls = optRealm.getURLs(); assertEquals( "no urls", 0, urls.length ); } public void testConfigure_Optionally_Existent() throws Exception { this.configurator.configure( getConfigPath( "optionally-existent.conf" ) ); assertEquals( "org.apache.maven.app.App", this.launcher.getMainClassName() ); assertEquals( "opt", this.launcher.getMainRealmName() ); ClassWorld world = this.launcher.getWorld(); Collection realms = world.getRealms(); assertEquals( 1, realms.size() ); assertNotNull( world.getRealm( "opt" ) ); ClassRealm optRealm = world.getRealm( "opt" ); URL[] urls = optRealm.getURLs(); assertEquals( "one url", 1, urls.length ); assertSame( null, optRealm.getImportClassLoader( "org.xml.sax.SAXException" ) ); } public void testConfigure_Unhandled() throws Exception { try { this.configurator.configure( getConfigPath( "unhandled.conf" ) ); fail( "throw ConfigurationException" ); } catch ( ConfigurationException e ) { // expected and correct assertTrue( e.getMessage().startsWith( "Unhandled configuration" ) ); } } public void testSet_Using_Existent() throws Exception { assertNull( System.getProperty( "set.using.existent" ) ); this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); assertEquals( "testSet_Using_Existent", System.getProperty( "set.using.existent" ) ); } public void testSet_Using_NonExistent() throws Exception { assertNull( System.getProperty( "set.using.nonexistent" ) ); this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); assertNull( System.getProperty( "set.using.nonexistent" ) ); } public void testSet_Using_NonExistent_Default() throws Exception { assertNull( System.getProperty( "set.using.nonexistent.default" ) ); this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); assertEquals( "testSet_Using_NonExistent_Default", System.getProperty( "set.using.nonexistent.default" ) ); } public void testSet_Using_NonExistent_Override() throws Exception { assertNull( System.getProperty( "set.using.default" ) ); System.setProperty( "set.using.default", "testSet_Using_NonExistent_Override" ); this.configurator.configure( getConfigPath( "set-using-nonexistent.conf" ) ); assertEquals( "testSet_Using_NonExistent_Override", System.getProperty( "set.using.default" ) ); } public void testSet_Using_Existent_Override() throws Exception { assertNull( System.getProperty( "set.using.existent" ) ); System.setProperty( "set.using.existent", "testSet_Using_Existent_Override" ); this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); assertEquals( "testSet_Using_Existent_Override", System.getProperty( "set.using.existent" ) ); } public void testSet_Using_Existent_Default() throws Exception { assertNull( System.getProperty( "set.using.default" ) ); this.configurator.configure( getConfigPath( "set-using-existent.conf" ) ); assertEquals( "testSet_Using_Existent_Default", System.getProperty( "set.using.default" ) ); } public void testSet_Using_Missing_Default() throws Exception { assertNull( System.getProperty( "set.using.missing" ) ); this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); assertEquals( "testSet_Using_Missing_Default", System.getProperty( "set.using.missing" ) ); } public void testSet_Using_Missing_Override() throws Exception { assertNull( System.getProperty( "set.using.missing" ) ); System.setProperty( "set.using.missing", "testSet_Using_Missing_Override" ); this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); assertEquals( "testSet_Using_Missing_Override", System.getProperty( "set.using.missing" ) ); } public void testSet_Using_Filtered_Default() throws Exception { assertNull( System.getProperty( "set.using.filtered.default" ) ); this.configurator.configure( getConfigPath( "set-using-missing.conf" ) ); assertEquals( System.getProperty( "user.home" ) + "/m2", System.getProperty( "set.using.filtered.default" ) ); } private FileInputStream getConfigPath( String name ) throws Exception { return new FileInputStream( new File( new File( TestUtil.getBasedir(), "src/test/test-data" ), name ) ); } private void assertArrayContains( URL[] array, URL url ) throws Exception { for ( int i = 0; i < array.length; ++i ) { if ( url.equals( array[i] ) ) { return; } } fail( "URL (" + url + ") not found in array of URLs" ); } } LauncherTest.java000066400000000000000000000071401220320442200371610ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/launcherpackage org.codehaus.plexus.classworlds.launcher; /* * 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 java.io.File; import java.io.FileInputStream; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.TestUtil; public class LauncherTest extends AbstractClassWorldsTestCase { 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(); this.launcher.setSystemClassLoader( Thread.currentThread().getContextClassLoader() ); } 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 { String basedir = TestUtil.getBasedir(); return new FileInputStream( new File( new File( basedir, "src/test/test-data" ), name ) ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/realm/000077500000000000000000000000001220320442200332715ustar00rootroot00000000000000ClassRealmImplTest.java000066400000000000000000000332621220320442200375730ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/realmpackage 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 java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; public class ClassRealmImplTest extends AbstractClassWorldsTestCase { private ClassWorld world; public ClassRealmImplTest( String name ) { super( name ); } public void setUp() { this.world = new ClassWorld(); } public void tearDown() { this.world = null; } public void testNewRealm() throws Exception { ClassRealm realm = this.world.newRealm( "foo" ); assertNotNull( realm ); assertSame( this.world, realm.getWorld() ); assertEquals( "foo", realm.getId() ); } public void testLocateSourceRealm_NoImports() throws Exception { ClassRealm realm = new ClassRealm( this.world, "foo", null ); assertSame( null, realm.getImportClassLoader( "com.werken.Stuff" ) ); } public void testLocateSourceRealm_SimpleImport() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); assertSame( werkflowRealm, mainRealm.getImportClassLoader( "com.werken.werkflow.WerkflowEngine" ) ); assertSame( werkflowRealm, mainRealm.getImportClassLoader( "com/werken/werkflow/some.properties" ) ); assertSame( werkflowRealm, mainRealm.getImportClassLoader( "com.werken.werkflow.process.ProcessManager" ) ); assertSame( null, mainRealm.getImportClassLoader( "com.werken.blissed.Process" ) ); assertSame( null, mainRealm.getImportClassLoader( "java.lang.Object" ) ); assertSame( null, mainRealm.getImportClassLoader( "NoviceProgrammerClass" ) ); } public void testLocateSourceRealm_MultipleImport() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm werkflowRealm = this.world.newRealm( "werkflow" ); ClassRealm blissedRealm = this.world.newRealm( "blissed" ); mainRealm.importFrom( "werkflow", "com.werken.werkflow" ); mainRealm.importFrom( "blissed", "com.werken.blissed" ); assertSame( werkflowRealm, mainRealm.getImportClassLoader( "com.werken.werkflow.WerkflowEngine" ) ); assertSame( werkflowRealm, mainRealm.getImportClassLoader( "com.werken.werkflow.process.ProcessManager" ) ); assertSame( blissedRealm, mainRealm.getImportClassLoader( "com.werken.blissed.Process" ) ); assertSame( blissedRealm, mainRealm.getImportClassLoader( "com.werken.blissed.guard.BooleanGuard" ) ); assertSame( null, mainRealm.getImportClassLoader( "java.lang.Object" ) ); assertSame( null, mainRealm.getImportClassLoader( "NoviceProgrammerClass" ) ); } public void testLocateSourceRealm_Hierachy() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm fooRealm = this.world.newRealm( "foo" ); ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); mainRealm.importFrom( "foo", "foo" ); mainRealm.importFrom( "fooBar", "foo.bar" ); mainRealm.importFrom( "fooBarBaz", "foo.bar.baz" ); assertSame( fooRealm, mainRealm.getImportClassLoader( "foo.Goober" ) ); assertSame( fooRealm, mainRealm.getImportClassLoader( "foo.cheese.Goober" ) ); assertSame( fooBarRealm, mainRealm.getImportClassLoader( "foo.bar.Goober" ) ); assertSame( fooBarRealm, mainRealm.getImportClassLoader( "foo.bar.cheese.Goober" ) ); assertSame( fooBarBazRealm, mainRealm.getImportClassLoader( "foo.bar.baz.Goober" ) ); assertSame( fooBarBazRealm, mainRealm.getImportClassLoader( "foo.bar.baz.cheese.Goober" ) ); assertSame( null, mainRealm.getImportClassLoader( "java.lang.Object" ) ); assertSame( null, mainRealm.getImportClassLoader( "NoviceProgrammerClass" ) ); } public void testLocateSourceRealm_Hierachy_Reverse() throws Exception { ClassRealm fooBarBazRealm = this.world.newRealm( "fooBarBaz" ); ClassRealm fooBarRealm = this.world.newRealm( "fooBar" ); ClassRealm fooRealm = this.world.newRealm( "foo" ); ClassRealm mainRealm = this.world.newRealm( "main" ); mainRealm.importFrom( "fooBarBaz", "foo.bar.baz" ); mainRealm.importFrom( "fooBar", "foo.bar" ); mainRealm.importFrom( "foo", "foo" ); assertSame( fooRealm, mainRealm.getImportClassLoader( "foo.Goober" ) ); assertSame( fooRealm, mainRealm.getImportClassLoader( "foo.cheese.Goober" ) ); assertSame( fooBarRealm, mainRealm.getImportClassLoader( "foo.bar.Goober" ) ); assertSame( fooBarRealm, mainRealm.getImportClassLoader( "foo.bar.cheese.Goober" ) ); assertSame( fooBarBazRealm, mainRealm.getImportClassLoader( "foo.bar.baz.Goober" ) ); assertSame( fooBarBazRealm, mainRealm.getImportClassLoader( "foo.bar.baz.cheese.Goober" ) ); assertSame( null, mainRealm.getImportClassLoader( "java.lang.Object" ) ); assertSame( null, mainRealm.getImportClassLoader( "NoviceProgrammerClass" ) ); } public void testLoadClass_SystemClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); Class cls = mainRealm.loadClass( "java.lang.Object" ); assertNotNull( cls ); } public void testLoadClass_NonSystemClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); try { Class c = mainRealm.loadClass( "com.werken.projectz.UberThing" ); System.out.println( "c = " + c ); fail( "A ClassNotFoundException should be thrown!" ); } catch ( ClassNotFoundException e ) { // expected and correct } } public void testLoadClass_ClassWorldsClass() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); Class cls = mainRealm.loadClass( "org.codehaus.plexus.classworlds.ClassWorld" ); assertNotNull( cls ); assertSame( ClassWorld.class, cls ); } public void testLoadClass_Local() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); try { mainRealm.loadClass( "a.A" ); } catch ( ClassNotFoundException e ) { // expected and correct } mainRealm.addURL( getJarUrl( "a.jar" ) ); Class classA = mainRealm.loadClass( "a.A" ); assertNotNull( classA ); ClassRealm otherRealm = this.world.newRealm( "other" ); try { otherRealm.loadClass( "a.A" ); } catch ( ClassNotFoundException e ) { // expected and correct } } public void testLoadClass_Imported() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); ClassRealm realmA = this.world.newRealm( "realmA" ); try { realmA.loadClass( "a.A" ); fail( "realmA.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) { // expected and correct } realmA.addURL( getJarUrl( "a.jar" ) ); try { mainRealm.loadClass( "a.A" ); fail( "mainRealm.loadClass(a.A) should have thrown a ClassNotFoundException" ); } catch ( ClassNotFoundException e ) { // expected and correct } mainRealm.importFrom( "realmA", "a" ); Class classA = realmA.loadClass( "a.A" ); assertNotNull( classA ); assertEquals( realmA, classA.getClassLoader() ); Class classMain = mainRealm.loadClass( "a.A" ); assertNotNull( classMain ); assertEquals( realmA, classMain.getClassLoader() ); assertSame( classA, classMain ); } public void testLoadClass_Package() throws Exception { ClassRealm realmA = this.world.newRealm( "realmA" ); realmA.addURL( getJarUrl( "a.jar" ) ); Class clazz = realmA.loadClass( "a.A" ); assertNotNull( clazz ); assertEquals( "a.A", clazz.getName() ); Package p = clazz.getPackage(); assertNotNull( p ); assertEquals( "p.getName()", "a", p.getName() ); } public void testLoadClass_Complex() throws Exception { ClassRealm realmA = this.world.newRealm( "realmA" ); ClassRealm realmB = this.world.newRealm( "realmB" ); ClassRealm realmC = this.world.newRealm( "realmC" ); realmA.addURL( getJarUrl( "a.jar" ) ); realmB.addURL( getJarUrl( "b.jar" ) ); realmC.addURL( getJarUrl( "c.jar" ) ); realmC.importFrom( "realmA", "a" ); realmC.importFrom( "realmB", "b" ); realmA.importFrom( "realmC", "c" ); Class classA_A = realmA.loadClass( "a.A" ); Class classB_B = realmB.loadClass( "b.B" ); Class classC_C = realmC.loadClass( "c.C" ); assertNotNull( classA_A ); assertNotNull( classB_B ); assertNotNull( classC_C ); assertEquals( realmA, classA_A.getClassLoader() ); assertEquals( realmB, classB_B.getClassLoader() ); assertEquals( realmC, classC_C.getClassLoader() ); // load from C Class classA_C = realmC.loadClass( "a.A" ); assertNotNull( classA_C ); assertSame( classA_A, classA_C ); assertEquals( realmA, classA_C.getClassLoader() ); Class classB_C = realmC.loadClass( "b.B" ); assertNotNull( classB_C ); assertSame( classB_B, classB_C ); assertEquals( realmB, classB_C.getClassLoader() ); // load from A Class classC_A = realmA.loadClass( "c.C" ); assertNotNull( classC_A ); assertSame( classC_C, classC_A ); assertEquals( realmC, classC_A.getClassLoader() ); try { realmA.loadClass( "b.B" ); fail( "throw ClassNotFoundException" ); } catch ( ClassNotFoundException e ) { // expected and correct } // load from B try { realmB.loadClass( "a.A" ); fail( "throw ClassNotFoundException" ); } catch ( ClassNotFoundException e ) { // expected and correct } try { realmB.loadClass( "c.C" ); fail( "throw ClassNotFoundException" ); } catch ( ClassNotFoundException e ) { // expected and correct } } public void testLoadClass_ClassWorldsClassRepeatedly() throws Exception { ClassRealm mainRealm = this.world.newRealm( "main" ); for ( int i = 0; i < 100; i++ ) { Class cls = mainRealm.loadClass( "org.codehaus.plexus.classworlds.ClassWorld" ); assertNotNull( cls ); assertSame( ClassWorld.class, cls ); } } public void testGetResources_BaseBeforeSelf() throws Exception { String resource = "common.properties"; ClassRealm base = this.world.newRealm( "realmA" ); base.addURL( getJarUrl( "a.jar" ) ); URL baseUrl = base.getResource( resource ); assertNotNull( baseUrl ); ClassRealm sub = this.world.newRealm( "realmB", base ); sub.addURL( getJarUrl( "b.jar" ) ); URL subUrl = sub.getResource( resource ); assertNotNull( subUrl ); assertEquals( baseUrl, subUrl ); List urls = new ArrayList(); for ( Iterator it = Collections.list( sub.getResources( resource ) ).iterator(); it.hasNext(); ) { String path = it.next().toString(); path = path.substring( path.lastIndexOf( '/', path.lastIndexOf( ".jar!" ) ) ); urls.add( path ); } assertEquals( Arrays.asList( new String[] { "/a.jar!/common.properties", "/b.jar!/common.properties" } ), urls ); } public void testGetResources_SelfBeforeParent() throws Exception { String resource = "common.properties"; ClassRealm parent = this.world.newRealm( "realmA" ); parent.addURL( getJarUrl( "a.jar" ) ); URL parentUrl = parent.getResource( resource ); assertNotNull( parentUrl ); ClassRealm child = parent.createChildRealm( "realmB" ); child.addURL( getJarUrl( "b.jar" ) ); URL childUrl = child.getResource( resource ); assertNotNull( childUrl ); List urls = Collections.list( child.getResources( resource ) ); assertNotNull( urls ); assertEquals( Arrays.asList( new URL[] { childUrl, parentUrl } ), urls ); } } DefaultClassRealmTest.java000066400000000000000000000310001220320442200402420ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/realmpackage 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 java.net.URL; import java.net.URLClassLoader; import java.util.Collections; import java.util.concurrent.CountDownLatch; import org.codehaus.classworlds.ClassRealmAdapter; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; public class DefaultClassRealmTest extends AbstractClassWorldsTestCase { public DefaultClassRealmTest( String name ) { super( name ); } // ---------------------------------------------------------------------- // Class testing // ---------------------------------------------------------------------- public void testLoadClassFromRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); loadClass( mainRealm, "org.codehaus.plexus.Component0" ); } public void testLoadClassFromChildRealmWhereClassIsLocatedInParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); loadClass( childRealm, "org.codehaus.plexus.Component0" ); } public void testLoadClassFromChildRealmWhereClassIsLocatedInGrantParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); ClassRealm grandchildRealm = childRealm.createChildRealm( "grandchild" ); loadClass( grandchildRealm, "org.codehaus.plexus.Component0" ); } public void testLoadClassFromChildRealmWhereClassIsLocatedInBothChildRealmAndParentRealm() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "parent", null ); mainRealm.addURL( getJarUrl( "component5-1.0.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); childRealm.addURL( getJarUrl( "component5-2.0.jar" ) ); Class cls = loadClass( childRealm, "test.Component5" ); assertSame( childRealm, cls.getClassLoader() ); assertEquals( 1, cls.getMethods().length ); assertEquals( "printNew", cls.getMethods()[0].getName() ); } public void testLoadNonExistentClass() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); try { mainRealm.loadClass( "org.foo.bar.NonExistentClass" ); fail( "A ClassNotFoundException should have been thrown!" ); } catch ( ClassNotFoundException e ) { // expected } } public void testImport() throws Exception { ClassWorld world = new ClassWorld(); ClassRealm r0 = world.newRealm( "r0" ); ClassRealm r1 = world.newRealm( "r1" ); r0.addURL( getJarUrl( "component0-1.0.jar" ) ); r1.importFrom( "r0", "org.codehaus.plexus" ); loadClass( r1, "org.codehaus.plexus.Component0" ); } public void testParentImport() throws Exception { ClassWorld world = new ClassWorld(); ClassRealm parent = world.newRealm( "parent" ); ClassRealm child = world.newRealm( "child" ); parent.addURL( getJarUrl( "component0-1.0.jar" ) ); child.setParentRealm( parent ); Class type = loadClass( child, "org.codehaus.plexus.Component0" ); child.importFromParent( "non-existing" ); assertSame( null, loadClassOrNull( child, "org.codehaus.plexus.Component0" ) ); child.importFromParent( "org.codehaus.plexus" ); assertSame( type, loadClass( child, "org.codehaus.plexus.Component0" ) ); } public void testLoadClassFromBaseClassLoaderBeforeSelf() throws Exception { ClassWorld world = new ClassWorld(); ClassRealm base = world.newRealm( "base" ); base.addURL( getJarUrl( "a.jar" ) ); ClassRealm child = world.newRealm( "child", base ); child.addURL( getJarUrl( "a.jar" ) ); Class baseClass = loadClass( base, "a.A" ); Class childClass = loadClass( child, "a.A" ); assertSame( base, baseClass.getClassLoader() ); assertSame( base, childClass.getClassLoader() ); assertSame( baseClass, childClass ); } public void testLoadClassFromRealmWithCircularClassReferences() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "circular-0.1.jar" ) ); /* * This was reported to fail with a ClassCircularityError in IBM JDK 1.5.0-SR2, 1.5.0-SR7 and 1.6.0-SR2. It * works in IBM JDK 1.5.0-SR10 and 1.6.0-SR6. */ loadClass( mainRealm, "A$C" ); } // ---------------------------------------------------------------------- // Resource testing // ---------------------------------------------------------------------- public void testResource() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "component0-1.0.jar" ) ); getResource( mainRealm, "META-INF/plexus/components.xml" ); } public void testMalformedResource() throws Exception { URL jarUrl = getJarUrl( "component0-1.0.jar" ); ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( jarUrl ); ClassLoader officialClassLoader = new URLClassLoader( new URL[] { jarUrl } ); String resource = "META-INF/plexus/components.xml"; assertNotNull( mainRealm.getResource( resource ) ); assertNotNull( officialClassLoader.getResource( resource ) ); /* * NOTE: Resource names with a leading slash are invalid when passed to a class loader and must not be found! * One can use a leading slash in Class.getResource() but not in ClassLoader.getResource(). */ assertSame( null, mainRealm.getResource( "/" + resource ) ); assertSame( null, officialClassLoader.getResource( "/" + resource ) ); /* * For backward-compat, legacy class realms have to support leading slashes. */ org.codehaus.classworlds.ClassRealm legacyRealm = ClassRealmAdapter.getInstance( mainRealm ); assertNotNull( legacyRealm.getResource( "/" + resource ) ); assertNotNull( legacyRealm.getResourceAsStream( "/" + resource ) ); assertTrue( legacyRealm.findResources( "/" + resource ).hasMoreElements() ); } public void testFindResourceOnlyScansSelf() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "a.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); childRealm.addURL( getJarUrl( "b.jar" ) ); assertNotNull( childRealm.getResource( "a.properties" ) ); assertNotNull( childRealm.getResource( "b.properties" ) ); assertNull( childRealm.findResource( "a.properties" ) ); assertNotNull( childRealm.findResource( "b.properties" ) ); } public void testFindResourcesOnlyScansSelf() throws Exception { ClassRealm mainRealm = new ClassRealm( new ClassWorld(), "main", null ); mainRealm.addURL( getJarUrl( "a.jar" ) ); ClassRealm childRealm = mainRealm.createChildRealm( "child" ); childRealm.addURL( getJarUrl( "b.jar" ) ); assertTrue( childRealm.getResources( "a.properties" ).hasMoreElements() ); assertTrue( childRealm.getResources( "b.properties" ).hasMoreElements() ); assertFalse( childRealm.findResources( "a.properties" ).hasMoreElements() ); assertTrue( childRealm.findResources( "b.properties" ).hasMoreElements() ); } /** Should never deadlock. Ever */ public void testParallelDeadlockClassRealm() throws InterruptedException { for (int i = 0; i < 100; i++){ doOneDeadlockAttempt(); } } private void doOneDeadlockAttempt() throws InterruptedException { // Deadlock sample graciously ripped from http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html final ClassRealm cl1 = new ClassRealm( new ClassWorld(), "cl1", null ); final ClassRealm cl2 = new ClassRealm( new ClassWorld(), "cl2", cl1 ); cl1.setParentRealm( cl2 ); cl1.addURL( getJarUrl( "deadlock.jar" ) ); cl2.addURL( getJarUrl( "deadlock.jar" ) ); final CountDownLatch latch = new CountDownLatch( 1 ); Runnable r1 = new Runnable() { public void run() { try { latch.await(); cl1.loadClass( "deadlock.A" ); } catch ( ClassNotFoundException e ) { throw new RuntimeException( e ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } } }; Runnable r2 = new Runnable() { public void run() { try { latch.await(); cl1.loadClass( "deadlock.C" ); } catch ( ClassNotFoundException e ) { throw new RuntimeException( e ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); } } }; Thread thread = new Thread( r1 ); thread.start(); Thread thread1 = new Thread( r2 ); thread1.start(); latch.countDown(); thread.join(); thread1.join(); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private Class loadClassOrNull( ClassRealm realm, String name ) { try { return loadClass( realm, name ); } catch ( ClassNotFoundException e ) { return null; } } private Class loadClass( ClassRealm realm, String name ) throws ClassNotFoundException { Class cls = realm.loadClass( name ); /* * NOTE: Load the class both directly from the realm and indirectly from an (ordinary) child class loader which * uses the specified class realm for parent delegation. The child class loader itself has no additional class * path entries but relies entirely on the provided class realm. Hence, the created child class loader should in * theory be able to load exactly the same classes/resources as the underlying class realm. In practice, it will * test that class realms properly integrate into the standard Java class loader hierarchy. */ ClassLoader childLoader = new URLClassLoader( new URL[0], realm ); assertEquals( cls, childLoader.loadClass( name ) ); return cls; } private void getResource( ClassRealm realm, String name ) throws Exception { ClassLoader childLoader = new URLClassLoader( new URL[0], realm ); assertNotNull( realm.getResource( name ) ); assertEquals( realm.getResource( name ), childLoader.getResource( name ) ); assertEquals( Collections.list( realm.getResources( name ) ), Collections.list( childLoader.getResources( name ) ) ); } } EntryTest.java000066400000000000000000000143041220320442200360200ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/realmpackage 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 org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; /** * @author Ben Walding */ public class EntryTest extends AbstractClassWorldsTestCase { /** * Constructor for EntryTest. * * @param name */ public EntryTest( String name ) { super( name ); } public void testCompareTo() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry1 = new Entry( r, "org.test" ); Entry entry2 = new Entry( r, "org.test.impl" ); assertTrue( "org.test > org.test.impl", entry1.compareTo( entry2 ) > 0 ); } /** * Tests the equality is realm independant * * @throws Exception */ public void testEquals() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r1 = cw.newRealm( "test1" ); ClassRealm r2 = cw.newRealm( "test2" ); Entry entry1 = new Entry( r1, "org.test" ); Entry entry2 = new Entry( r2, "org.test" ); assertTrue( "entry1 == entry2", entry1.equals( entry2 ) ); assertTrue( "entry1.hashCode() == entry2.hashCode()", entry1.hashCode() == entry2.hashCode() ); } public void testMatchesClassByPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test" ); assertTrue( entry.matches( "org.test.MyClass" ) ); assertTrue( entry.matches( "org.test.MyClass$NestedClass" ) ); assertTrue( entry.matches( "org.test.MyClassUtils" ) ); assertTrue( entry.matches( "org.test.impl.MyClass" ) ); assertFalse( entry.matches( "org.tests.AnotherClass" ) ); } public void testMatchesClassByClassImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test.MyClass" ); assertTrue( entry.matches( "org.test.MyClass" ) ); assertTrue( entry.matches( "org.test.MyClass$NestedClass" ) ); assertFalse( entry.matches( "org.test.MyClassUtils" ) ); assertFalse( entry.matches( "org.test.AnotherClass" ) ); } public void testMatchesResourceByPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test" ); assertTrue( entry.matches( "org/test/MyClass.class" ) ); assertTrue( entry.matches( "org/test/MyClass$NestedClass.class" ) ); assertTrue( entry.matches( "org/test/MyClasses.properties" ) ); assertTrue( entry.matches( "org/test/impl/MyClass.class" ) ); assertFalse( entry.matches( "org/tests/AnotherClass.class" ) ); } public void testMatchesResourceByClassImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test.MyClass" ); assertTrue( entry.matches( "org/test/MyClass.class" ) ); assertTrue( entry.matches( "org/test/MyClass$NestedClass.class" ) ); assertFalse( entry.matches( "org/test/MyClass.properties" ) ); assertFalse( entry.matches( "org/test/AnotherClass" ) ); } public void testMatchesAllImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "" ); assertTrue( entry.matches( "org.test.MyClass" ) ); assertTrue( entry.matches( "org.test.MyClass$NestedClass" ) ); assertTrue( entry.matches( "org/test/MyClass.class" ) ); assertTrue( entry.matches( "org/test/MyClass.properties" ) ); } public void testMatchesResourceByResourceImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry1 = new Entry( r, "some.properties" ); assertTrue( entry1.matches( "some.properties" ) ); assertFalse( entry1.matches( "other.properties" ) ); Entry entry2 = new Entry( r, "org/test/some.properties" ); assertTrue( entry2.matches( "org/test/some.properties" ) ); assertFalse( entry2.matches( "org/test/other.properties" ) ); } public void testMatchesClassByExactPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test.*" ); assertTrue( entry.matches( "org.test.MyClass" ) ); assertTrue( entry.matches( "org.test.MyClass$NestedClass" ) ); assertTrue( entry.matches( "org.test.MyClassUtils" ) ); assertFalse( entry.matches( "org.test.impl.MyClass" ) ); assertFalse( entry.matches( "org.tests.AnotherClass" ) ); } public void testMatchesResourceByExactPackageImport() throws Exception { ClassWorld cw = new ClassWorld(); ClassRealm r = cw.newRealm( "test1" ); Entry entry = new Entry( r, "org.test.*" ); assertTrue( entry.matches( "org/test/MyClass.class" ) ); assertTrue( entry.matches( "org/test/MyClass$NestedClass.class" ) ); assertTrue( entry.matches( "org/test/MyClasses.properties" ) ); assertFalse( entry.matches( "org/test/impl/MyClass.class" ) ); assertFalse( entry.matches( "org/tests/AnotherClass.class" ) ); } } plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/strategy/000077500000000000000000000000001220320442200340335ustar00rootroot00000000000000StrategyTest.java000066400000000000000000000075121220320442200372660ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/java/org/codehaus/plexus/classworlds/strategypackage 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 java.io.InputStream; import java.net.URL; import java.util.Enumeration; import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; // jars within jars // hierarchy vs graph public class StrategyTest extends AbstractClassWorldsTestCase { private ClassWorld world; private ClassRealm realm; private Strategy strategy; public StrategyTest( String name ) { super( name ); } public void setUp() throws Exception { this.world = new ClassWorld(); this.realm = this.world.newRealm( "realm" ); this.strategy = this.realm.getStrategy(); realm.addURL( getJarUrl( "component0-1.0.jar" ) ); } public void testLoadingOfApplicationClass() throws Exception { Class c = strategy.loadClass( "org.codehaus.plexus.Component0" ); assertNotNull( c ); } public void testLoadingOfApplicationClassThenDoingItAgain() throws Exception { Class c = strategy.loadClass( "org.codehaus.plexus.Component0" ); assertNotNull( c ); c = strategy.loadClass( "org.codehaus.plexus.Component0" ); assertNotNull( c ); } public void testLoadingOfSystemClass() throws Exception { Class c = strategy.getRealm().loadClass( "java.lang.Object" ); assertNotNull( c ); } public void testLoadingOfNonExistentClass() throws Exception { try { strategy.loadClass( "org.codehaus.plexus.NonExistentComponent" ); fail( "Should have thrown a ClassNotFoundException!" ); } catch ( ClassNotFoundException e ) { // do nothing } } public void testGetApplicationResource() throws Exception { URL resource = strategy.getResource( "META-INF/plexus/components.xml" ); assertNotNull( resource ); String content = getContent( resource.openStream() ); assertTrue( content.startsWith( "" ) ); } public void testGetSystemResource() throws Exception { URL resource = strategy.getRealm().getResource( "java/lang/Object.class" ); assertNotNull( resource ); } public void testFindResources() throws Exception { realm.addURL( getJarUrl( "component1-1.0.jar" ) ); Enumeration e = strategy.getResources( "META-INF/plexus/components.xml" ); assertNotNull( e ); int resourceCount = 0; for ( Enumeration resources = e; resources.hasMoreElements(); ) { resources.nextElement(); resourceCount++; } assertEquals( 2, resourceCount ); } protected String getContent( InputStream in ) throws Exception { byte[] buffer = new byte[1024]; int read = 0; StringBuffer content = new StringBuffer(); while ( ( read = in.read( buffer, 0, 1024 ) ) >= 0 ) { content.append( new String( buffer, 0, read ) ); } return content.toString(); } } plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/000077500000000000000000000000001220320442200246745ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/a.jar000066400000000000000000000030601220320442200256110ustar00rootroot00000000000000PK܉; META-INF/PKPK܉;META-INF/MANIFEST.MFMLK-. K-*ϳR03r.JM,IMu +h)f&W+x%irrPK[GGPK ;a/PK#84 a/A.classmQJ1=c3u5u1 uQjPҍ2I ~%L UhpONιI>x8a`Bml`Ėm\2`ȻC2y @zj xJ~FG9f(ﴩ}0y<񰝙s5$ym6M&j 66:80Q2`{$xnľ4info#1HQݗq*" xG4Am`>.{EBEz]r`z`u>!#,}f6U##Dՙ  -<;|\5&N(􏉅 V 2ePKFPK#84 a/Aa.classmQJAkķ16xPAXTi8a2=(x(g|@EWTW|~haDTQc* `P' icȜFP\LP׼S{\IL|'Ǥq۔\ 5<XpnS!Wn4Qq&-c@-l3XE=iACxүe$?8E@{ S2rh|L&DeMnujUgf=4'-S,P2sR6)rE{@@X"G` UN"S*>HM:#c%B PKW OPKk70 a.propertiesKT((/H-*L-PK PK։;common.propertiesK+(/H-*L-PK oPK܉; META-INF/PK܉;[GG=META-INF/MANIFEST.MFPK ;a/PK#84F a/A.classPK#84W O ca/Aa.classPKk70 a.propertiesPK։; o3common.propertiesPKplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/a.properties000066400000000000000000000012771220320442200272410ustar00rootroot00000000000000################################################################################ # # Copyright 2001-2006 The 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. # a properties plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/b.jar000066400000000000000000000025741220320442200256230ustar00rootroot00000000000000PKWZ; META-INF/PKPKWZ;META-INF/MANIFEST.MFMLK-. K-*ϳR03r.JM,IMu +h)f&W+x%irrPK[GGPK .Z;b/PK4y5 b/B.classMNN0צ v-Kխ0PĐJL`Vp:IbBbQ0|ww~1 EKBx!X[Eڪf)(3?^jKHft'ߤ0b];mEZB"JYU3J,~zq>8L>p=" atv*1EVƐ_Sfb|>Y"ƘmW}Ƹ-PK'o)PK4y5 b/Bb.classENAN0mB[D"T)C8٩\ rQpBxTźH`3Yo?LO0!4ih|OgR)MVIe) 1[), h)iVBIx)_+gyt<'$u6>8N'{HaVt`۟{#=HƄm1O=Sf? ?sK8cLv?PKg.-PKIZ; b.propertiesKMUUH+(/H-*L-PK~\PKMZ;common.propertiesKMUUH+(/H-*L-PKaPKWZ; META-INF/PKWZ;[GG=META-INF/MANIFEST.MFPK .Z;b/PK4y5'o) b/B.classPK4y5g.- b/Bb.classPKIZ;~\ )b.propertiesPKMZ;axcommon.propertiesPKplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/b_old.jar000066400000000000000000000023111220320442200264460ustar00rootroot00000000000000PK $84 META-INF/PK#84META-INF/MANIFEST.MFMLK-. K-*ϳR03rCq,HLHU%MxRKRSt*AL ,u L4K|3+KRs<4yxPKf_kPK #84b/PK#84 b/B.classQN0=BBwP)C+1E0IUHN ńQk xsν?? DDZ7RoLyJ8TޭWqdsgR+z*br h)eiUQ3B+䲪^J+11Ckv ["_LkʬF._'e8Eɜ@z]'ն}{ᨵa;`g+F`h9M,xdM8'ж3, PKd4PK#84 b/Bb.classP=K@~IV;`o蠐Ђ *up!&pIO8 U r_yuq\VW V0g"ah2Onu{e4E,PR?CZʒ4ˆO9C WIL)UJi*1/E]8e\lQt nHDDh0x["44+j'RNnF .Z%q4ki,EeFyj.E2pAKPڀKP3`Z/16k[h7PK:M!%PK $84 AMETA-INF/PK#84f_k'META-INF/MANIFEST.MFPK #84Ab/PK#84d4 b/B.classPK#84:M!% >b/Bb.classPKplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/c.jar000066400000000000000000000013221220320442200256120ustar00rootroot00000000000000PK $84 META-INF/PK#84META-INF/MANIFEST.MFMLK-. K-*ϳR03rCq,HLHU%MxRKRSt*AL ,u L4K|3+KRs<4yxPKf_kPK #84c/PK#84 c/C.class-PTB&V b[7\6{YI,<s19e2 GAmL B}00KLs,SvzQt' 4ʣ( Uȥ;+O*\0:vTd`dR8j5`5\)*#jb6+9`;7،V)PctԹ~\b/PK kc;jͩA.classuNPƿv鱰 ª Dᒍqلd;[+6. O Ix͡,F̜o~3pr+5}Wb^7*B1ϓ025Pp[bzcu<g)^9Qh<96HOf13/b2wtG_ӡP$9_Ba"ȎqLy-B;) #ۧՉjWqvlӘrPbuLb*@-h3x%BP#SL^#q}w/l` /^?; kxa,+9PK kc;THecB.class]NAN0$@K•[yR)G'*RHy*xb3cp0g($A B0յn/yO<*B?׵YE07vH}֯6)$d !sE ,Y5dK&D+f2ri%Ez[,U> BF#6qyJ蝮An5p$!lt)=5?[LJoNPK kc;N$*pom.xmlTn8 ?L"nEVq1V."g=4El%RKR!-&̛fL 6B$zܫ0r7 : ^&xag}nM 3E(n*A%Ց})R8 uZ\u]BD 5r_(Ɋ =]65*hn,~XaY=ʩM0;FQH4!#x;˳ >f?w+8-VU[x\Vr_s->plF;Qb7C}~*LlC[liɡTҭEu-Ay.B-_<%aLJh3 xq?,oȫd.qv~q/'su54֭fqa$zܫ0r7 : ^&xag}nM 3E(n*A%Ց})R8 uZ\u]BD 5r_(Ɋ =]65*hn,~XaY=ʩM0;FQH4!#x;˳ >f?w+8-VU[x\Vr_s->plF;Qb7C}~*LlC[liɡTҭEu-Ay.B-_<%aLJh3 xq?,oȫd.qv~q/'su54֭fqaP(?'.(]/9?%5#X 'H9ÔtdU%K2uIMK,)A6M9(A݋ăPK4hPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0$org/codehaus/plexus/Component0.class;o>=vvVv6FҢT̜TF~܂ԼIJDFtԌb P R\4$ PK2\ 7qɩDnEDc}P(?'.(]/9?%5#X 'H9ÔtdU%K2uIMK,)A6M9(A݋ăPKOphPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0$org/codehaus/plexus/Component1.class;o>=vvVv6FҢT̜TF~܂ԼCIJDFtԌb P R\4$ PKǰpiyPK0+org/codehaus/plexus/DefaultComponent1.classm?`ƟSZd#1H0hb!&a R+Պe|J\%wy{~<QahdlB0tׄXo$:GW+ܱ:=9Qȭh'r0 mE|vNr!qv=H/"4_-d?gqX5R zw-9i3A \3?PK PK0 META-INF/PK0LэJDD=META-INF/MANIFEST.MFPK 0META-INF/plexus/PK0OphMETA-INF/plexus/components.xmlPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0ǰpiy$$org/codehaus/plexus/Component1.classPK0 +org/codehaus/plexus/DefaultComponent1.classPK aplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/component2-1.0.jar000066400000000000000000000031631220320442200277550ustar00rootroot00000000000000PK0 META-INF/PKPK0META-INF/MANIFEST.MFMLK-. K-*ϳR03r.JM,IMu )h)f&W+x%irrPKLэJDDPK 0META-INF/plexus/PK0META-INF/plexus/components.xmlI-K+-N-RP>P(?'.(]/9?%5#X 'H9ÔtdU%K2uIMK,)A6M9(A݋ăPKhPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0$org/codehaus/plexus/Component2.class;o>=vvVv6FҢT̜TF~܂Լ#IJDFtԌb P R\4$ PKliyPK0+org/codehaus/plexus/DefaultComponent2.classm?`ƟSZd#1H0hb 1 z_V|-P@.ss E % e 9F&dz# ՙ<>2\ 7qɩDnEDc}P(?'.(]/9?%5#X 'H9ÔtdU%K2uIMK,)A6M9(A݋ăPKhPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0$org/codehaus/plexus/Component3.class;o>=vvVv6FҢT̜TF~܂ԼcIJDFtԌb P R\4$ PKpiyPK0+org/codehaus/plexus/DefaultComponent3.classm?`ƟSZd#1H0` 1 z_V|-P@.ss E % e 9F&dz# ՙ<>2\ 7qɩDnEDc}P(?'.(]/9?%5#X 'H9ÔtdU%K2uIMK,)A6M9(A݋ăPK5G hPK 0org/PK 0 org/codehaus/PK 0org/codehaus/plexus/PK0$org/codehaus/plexus/Component4.class;o>=vvVv6FҢT̜TF~܂ԼIJDFtԌb P R\4$ PK2\ 7qɩDnEDc}H|PPKɦ\PK q:test/PKq:test/Component5.class;o>NvvvF̼F MIJDļtD5#Wp~iQr[fN*#s~nA~^j^H-P$D! 0?)+5YX@,V PK9|PK[q:test/Component5.java+HLNLOU(I-.*(MLV+I-JKLNUp-K+1P̼t Y⟓ 6 PK< zLWPKq:test/DefaultComponent5.classeAO@ߴbL=J?PK6oPKq: META-INF/PKq:[GG=META-INF/MANIFEST.MFPK q:META-INF/plexus/PKq:ɦ\META-INF/plexus/components.xmlPK q:test/PKq:9|test/Component5.classPK[q:< zLW~test/Component5.javaPKq:hr@ test/DefaultComponent5.classPKxq:6o?test/DefaultComponent5.javaPK Rplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/component5-2.0.jar000066400000000000000000000035361220320442200277650ustar00rootroot00000000000000PKq: META-INF/PKPKq:META-INF/MANIFEST.MFMLK-. K-*ϳR03r.JM,IMu +h)f&W+x%irrPK[GGPK q:META-INF/plexus/PKq:META-INF/plexus/components.xmlI-K+-N-RP "PPQ~N]Ijq3LF, W[ I,σvIMK,)Aք j>H|PPKɦ\PK q:test/PKq:test/Component5.class;o>NvvvF̼rF MIJDļtD5#Wp~iQr[fN*#s~nA~^j^H-P$D! 0?)+5YX@,V PKjm|PKq:test/Component5.java+HLNLOU(I-.*(MLV+I-JKLNUp-K+1P̼t YZ 6 PK! LWPKq:test/DefaultComponent5.classe1OAppwX؁GC%X( {8%9oiebG.$$Ҽ7;۝>Zʨ{hx$Cm}"8ނP%LI8(M~'t{ګ0Vfά V`d_tMe%mbC~ e @B>ּ=A#*YI\rE}9݊x )B-h#9NEEPKX@PKq:test/DefaultComponent5.javaELA 0>G2+eqhxnK! 3;`I+8oYޤe>$#C TN?_%:ځ ˂g?jRQr$nj]O =PKCoPKq: META-INF/PKq:[GG=META-INF/MANIFEST.MFPK q:META-INF/plexus/PKq:ɦ\META-INF/plexus/components.xmlPK q:test/PKq:jm|test/Component5.classPKq:! LW~test/Component5.javaPKq:X@ test/DefaultComponent5.classPKq:Co>test/DefaultComponent5.javaPK Rplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/d.jar000066400000000000000000000013161220320442200256160ustar00rootroot00000000000000PK $84 META-INF/PK#84META-INF/MANIFEST.MFMLK-. K-*ϳR03rCq,HLHU%MxRKRSt*AL ,u L4K|3+KRs<4yxPKf_kPK #84d/PK#84 d/D.class-=@ ?(ةZc"Zh{YXxeЙeߛo6<_|x6ZY[p \ZZqDЗAPrs=Dz܋8d"QC: jFwŵLZ3s&0w&^ȏ6NeRae5tl)ڬ@vm( PKDPK $84 AMETA-INF/PK#84f_k'META-INF/MANIFEST.MFPK #84Ad/PK#84D d/D.classPKplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/deadlock.jar000066400000000000000000000030501220320442200271360ustar00rootroot00000000000000PK8qC META-INF/PKPK8qCMETA-INF/MANIFEST.MFMLK-. K-*ϳR03r.JM,IMu *h%&*8%krrPKѕCDPK#qCdeadlock/A.classM PEK}YFЮZ$VҦp2UТ裢т;g`= :&&>W* p0, R)Ow"L(Y$@P/`qEGכ1X۬#V½A\ ~Yb}U&skؕLR^MR>oהPKpCrGPK#qCdeadlock/B.classENP=uK# 5 jX[&UJb|Lr2xc@BB :`;HCEh{:QWV1+]/ d.O4>/T2'{^@-uQ$ҁ*[ Sn,#¿C`ܒtQ@P]ePK=2½PK#qCdeadlock/C.classM PZfAj.Me WECE59gy3mZYpBe\2q`y"@erS"YDR2X(TQՙ )4?gyUrjӃLZ}U&ؕ )oBІݜwyPKIPK#qCdeadlock/D.classENP=uK# 5!V bpڤYI,|ӒIN漒yOctlhZhYhT':`G0imO'ju9*J?f륁w2f~gJqń`oK."b1U:0Qe$t Íew~=Tb:n|T`1R1:zL9PKPK8qC META-INF/PK8qCѕCD=META-INF/MANIFEST.MFPK#qCpCrGdeadlock/A.classPK#qC=2½deadlock/B.classPK#qCIdeadlock/C.classPK#qCdeadlock/D.classPKuplexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/dupe-main.conf000066400000000000000000000001041220320442200274150ustar00rootroot00000000000000 main is com.werken.Foo from foo main is com.werken.Bar from bar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/dupe-realm.conf000066400000000000000000000000741220320442200275770ustar00rootroot00000000000000 [cheese] [dupe.realm] [potatoes] [dupe.realm] plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/early-import.conf000066400000000000000000000000401220320442200301610ustar00rootroot00000000000000 import org.xml.sax from root plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/inheritance.conf000066400000000000000000000010351220320442200300330ustar00rootroot00000000000000# ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from root.maven # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [root] load ${basedir}/src/test/test-data/a.jar [root.maven] load ${basedir}/src/test/test-data/b.jar [root.maven.plugin] load ${basedir}/src/test/test-data/c.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/launch-noclass.conf000066400000000000000000000001761220320442200304610ustar00rootroot00000000000000 main is b.Goober from app [app] load ${basedir}/src/test/test-data/a.jar load ${basedir}/src/test/test-data/b.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/launch-nomethod.conf000066400000000000000000000002451220320442200306310ustar00rootroot00000000000000 main is c.C from app [app] load ${basedir}/src/test/test-data/a.jar load ${basedir}/src/test/test-data/b.jar load ${basedir}/src/test/test-data/c.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/nested.jar000066400000000000000000000033171220320442200266600ustar00rootroot00000000000000PK $84 META-INF/PK#84META-INF/MANIFEST.MFMLK-. K-*ϳR03rCq,HLHU%MxRKRSt*AL ,u L4K|3+KRs<4yxPKf_kPKk70nested.propertiesK-.IM+(/H-*L-PKlPK #84lib/PK#84 lib/a.jar ffbI& H}]Cu=D8PM2_G?O7=_ϾgNx]:w +q*9ŨGb aZR>_zN5i,Rcܡb WobKbY'^k9 Le{sho‰kU 5Ǘ<,~6Ǥ?e#nɂyVl<@B.>Խ|ށe9{\YmfJ}K_֫}_ۢաٍgpI{WrVh4[ Ků. x&dt=Afτ\o9p8Ե{D^PJZv=f`E%?A&g?0 !r4A( $3;DC㔾IgLg@e$Œ؀ H"! _$#4(T-ƖzT%'/Ktmȁȅ- 9"1r{Ìެl 6 dPK-y$PK $84 AMETA-INF/PK#84f_k'META-INF/MANIFEST.MFPKk70lnested.propertiesPK #84Alib/PK#84-y$ =lib/a.jarPK!plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/nested.properties000066400000000000000000000013041220320442200302720ustar00rootroot00000000000000################################################################################ # # Copyright 2001-2006 The 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. # nested.properties plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/optionally-existent.conf000066400000000000000000000006611220320442200316010ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [opt] optionally ${basedir}/target/test-lib/xml-apis-1.3.02.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/optionally-nonexistent.conf000066400000000000000000000006311220320442200323110ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [opt] optionally /non/existant/path/*.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/realm-syntax.conf000066400000000000000000000000131220320442200301610ustar00rootroot00000000000000 [foo ] plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/resources/000077500000000000000000000000001220320442200267065ustar00rootroot00000000000000plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/resources/classworlds.conf000066400000000000000000000006301220320442200321140ustar00rootroot00000000000000# ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is foo from root # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [root] load ${basedir}/src/test/test-data/resources/werkflow.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/resources/werkflow.jar000066400000000000000000000124161220320442200312500ustar00rootroot00000000000000PK k5/ META-INF/PKk5/META-INF/MANIFEST.MFuAn0E|#hi$PvY $qƑc" gl jzZ9SH A|Ay dԬ?%V" R_u@+,)L{C;ܷYG*N$&s 1juҶ@϶r$Ǐ4&]CLnAO1IE8@:RD|sfU-#)~PKdPK k5/org/PK k5/ org/codehaus/PK k5/org/codehaus/werkflow/PK k5/"org/codehaus/werkflow/personality/PK k5/(org/codehaus/werkflow/personality/basic/PK k5/*org/codehaus/werkflow/personality/bpel4ws/PK k5/)org/codehaus/werkflow/personality/common/PKk5/8org/codehaus/werkflow/personality/basic/basic-syntax.xmlWn SXV/֋QiŸ!4;`:-/(L^]~!T7}B.^چqI\ 1Bf!B]rh0V2 ,:v\(EQb޶Crs.DJF*yG3Zv'W+}i TFA#\E3_axִaa5Sx.0_H"(Q/H0[ZgHS/'LP YW^.b,Ve?߼t?Zi*Z U)j f3#"f5m2FM8J ?.H84@,&",&)bSZÇYL)ۮ݆jEDKR5,qTgjO5$欢cLYa `*|2;{|+ L:(|_ IC$MA6Un# m#Ϟ( GK3h̬q0c k=_7&\,z4|E nIxD\h dX[%QG?7U.V?Zy).F-xƍtsu þ{ƍtsU(Z%akUzGl7n`O.&>wʮ1&@T.ܿSy2XE}3KGH6 څ Gp?Epi߼4ԫ@ܶ>oЫq K0ݻk }tP VҡC;znP.޿aPK\8PKk5/<org/codehaus/werkflow/personality/bpel4ws/bpel4ws-syntax.xmlMn0F9E%Fl*EE;$S@&&DHk~EٸT[Y{SR$sI )mjO9TXNIWK+ro>ƋMX2 /- X.F-f7d"4QT((RjE@LJYP3l^93ۂ3cqu*Pf%/gڜac V|Ø1qN-Z'B=oVrOFpY% 1H{pB~V p4 9kLʼ]h~ZHuG:C %‡mІj}j/LSecrN5EyAE١[pg|FOɞM?F,ߎH%ot}%DI U1Ţsgf Vv~7]d;T]yáh+$l{BĿV^`_0EovmV…n\ʖ;4 Ax9j+Ps} Ө9L{ Kw}V;Wi&!0*y>*":Ls?PKw;}]dPKT.META-INF/LICENSE.txtU]O8}ϯB# -]}4qtc KiqasPu{׽  (1ٟ6|ф.'?Ǔ z5A-} 4k+4>#Vx\uGm6T + U756i++릧^se^/ʪjܵ D OBzn운zguj6$UmԪWY)ZF?7#-uW7]W|1,ZjzKF٪`L@xP;m |@զN<{M琂 *4=4]e^`ɴUp\V=bԛ̽p`'݇޷TMu1c$7Ʒ4p:anȆ6eVɳ2?V`= A.=(4Iu6nmz Rp9Xdend!ʩ\u'Nr@g#4>R2@VyZ SdEQ.$ϳrL?EV0=1eR"E)ۘp d9q!Bq5GDowd=b&q`s"3a^+8AZ} G<&`cōLg^3 %#FMm 9a Z3U9&@CnHڏRD]LмPK xPK k5/ AMETA-INF/PKk5/d'META-INF/MANIFEST.MFPK k5/ARorg/PK k5/ Atorg/codehaus/PK k5/Aorg/codehaus/werkflow/PK k5/"Aorg/codehaus/werkflow/personality/PK k5/(Aorg/codehaus/werkflow/personality/basic/PK k5/*AYorg/codehaus/werkflow/personality/bpel4ws/PK k5/)Aorg/codehaus/werkflow/personality/common/PKk5/\88org/codehaus/werkflow/personality/basic/basic-syntax.xmlPKk5//E[<org/codehaus/werkflow/personality/bpel4ws/bpel4ws-syntax.xmlPKk5/w;}]d85org/codehaus/werkflow/personality/common/core-idioms.xmlPKT.'2 META-INF/LICENSE.txtPKk5/ x`META-INF/INDEX.LISTPK8plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/set-using-existent.conf000066400000000000000000000013421220320442200313220ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Set properties # ------------------------------------------------------------ set set.using.existent using ${basedir}/src/test/test-data/set-using-existent.properties set set.using.default using ${basedir}/src/test/test-data/set-using-existent.properties default testSet_Using_Existent_Default # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [opt] plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/set-using-existent.properties000066400000000000000000000013351220320442200325730ustar00rootroot00000000000000################################################################################ # # Copyright 2001-2006 The 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. # set.using.existent=testSet_Using_Existent plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/set-using-missing.conf000066400000000000000000000011751220320442200311340ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Set properties # ------------------------------------------------------------ set set.using.missing default testSet_Using_Missing_Default set set.using.filtered.default default ${user.home}/m2 # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [opt] plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/set-using-nonexistent.conf000066400000000000000000000013721220320442200320400ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from opt # ------------------------------------------------------------ # Set properties # ------------------------------------------------------------ set set.using.nonexistent using ${basedir}/src/test/test-data/set-using-nonexistent.properties set set.using.nonexistent.default using ${basedir}/src/test/test-data/set-using-nonexistent.properties default testSet_Using_NonExistent_Default # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [opt] plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/unhandled.conf000066400000000000000000000000071220320442200275020ustar00rootroot00000000000000 foo plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/valid-enh-launch-exitCode.conf000066400000000000000000000001721220320442200324240ustar00rootroot00000000000000 main is b.Bb from app [app] load ${basedir}/src/test/test-data/a.jar load ${basedir}/src/test/test-data/b.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/valid-enh-launch.conf000066400000000000000000000001711220320442200306610ustar00rootroot00000000000000 main is b.B from app [app] load ${basedir}/src/test/test-data/a.jar load ${basedir}/src/test/test-data/b.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/valid-launch-exitCode.conf000066400000000000000000000001161220320442200316520ustar00rootroot00000000000000 main is a.Aa from app [app] load ${basedir}/src/test/test-data/a.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/valid-launch.conf000066400000000000000000000001151220320442200301070ustar00rootroot00000000000000 main is a.A from app [app] load ${basedir}/src/test/test-data/a.jar plexus-classworlds-plexus-classworlds-2.5.1/src/test/test-data/valid.conf000066400000000000000000000012411220320442200266400ustar00rootroot00000000000000 # ------------------------------------------------------------ # Define the main entry-point # ------------------------------------------------------------ main is org.apache.maven.app.App from maven # ------------------------------------------------------------ # Start defining realms # ------------------------------------------------------------ [xml] load ${basedir}/target/test-lib/xml-apis-1.3.02.jar [ant] import org.xml.sax from xml load ${basedir}/target/test-lib/ant-1.9.0.jar [maven] import org.xml.sax from xml load ${basedir}/target/test-lib/commons-logging-1.0.3.jar [glob] load ${basedir}/src/test/test-data/*.jar