├── .gitignore
├── LICENSE-2.0.txt
├── LICENSE.txt
├── README.md
├── pom.xml
└── src
├── main
├── aspect
│ └── org
│ │ └── codehaus
│ │ └── plexus
│ │ └── classworlds
│ │ └── event
│ │ └── ListenerAspect.aj
└── java
│ └── org
│ └── codehaus
│ ├── classworlds
│ ├── BytesURLConnection.java
│ ├── BytesURLStreamHandler.java
│ ├── ClassRealm.java
│ ├── ClassRealmAdapter.java
│ ├── ClassRealmReverseAdapter.java
│ ├── ClassWorld.java
│ ├── ClassWorldAdapter.java
│ ├── ClassWorldException.java
│ ├── ClassWorldReverseAdapter.java
│ ├── ConfigurationException.java
│ ├── Configurator.java
│ ├── ConfiguratorAdapter.java
│ ├── DefaultClassRealm.java
│ ├── DuplicateRealmException.java
│ ├── Launcher.java
│ └── NoSuchRealmException.java
│ └── plexus
│ └── classworlds
│ ├── ClassWorld.java
│ ├── ClassWorldException.java
│ ├── ClassWorldListener.java
│ ├── UrlUtils.java
│ ├── launcher
│ ├── ConfigurationException.java
│ ├── ConfigurationHandler.java
│ ├── ConfigurationParser.java
│ ├── Configurator.java
│ └── Launcher.java
│ ├── realm
│ ├── ClassRealm.java
│ ├── DuplicateRealmException.java
│ ├── Entry.java
│ └── NoSuchRealmException.java
│ └── strategy
│ ├── AbstractStrategy.java
│ ├── OsgiBundleStrategy.java
│ ├── ParentFirstStrategy.java
│ ├── SelfFirstStrategy.java
│ ├── Strategy.java
│ └── StrategyFactory.java
├── site
└── site.xml
└── test
├── java
└── org
│ └── codehaus
│ └── plexus
│ └── classworlds
│ ├── AbstractClassWorldsTestCase.java
│ ├── ClassView.java
│ ├── ClassWorldTest.java
│ ├── TestUtil.java
│ ├── UrlUtilsTest.java
│ ├── launcher
│ ├── ConfigurationParserTest.java
│ ├── ConfiguratorTest.java
│ └── LauncherTest.java
│ ├── realm
│ ├── ClassRealmImplTest.java
│ ├── DefaultClassRealmTest.java
│ └── EntryTest.java
│ └── strategy
│ └── StrategyTest.java
└── test-data
├── a.jar
├── a.properties
├── b.jar
├── b_old.jar
├── c.jar
├── circular-0.1.jar
├── component0-1.0.jar
├── component1-1.0.jar
├── component2-1.0.jar
├── component3-1.0.jar
├── component4-1.0.jar
├── component5-1.0.jar
├── component5-2.0.jar
├── d.jar
├── deadlock.jar
├── dupe-main.conf
├── dupe-realm.conf
├── early-import.conf
├── inheritance.conf
├── launch-noclass.conf
├── launch-nomethod.conf
├── nested.jar
├── nested.properties
├── optionally-existent.conf
├── optionally-nonexistent.conf
├── realm-syntax.conf
├── resources
├── classworlds.conf
└── werkflow.jar
├── set-using-existent.conf
├── set-using-existent.properties
├── set-using-missing.conf
├── set-using-nonexistent.conf
├── unhandled.conf
├── valid-enh-launch-exitCode.conf
├── valid-enh-launch.conf
├── valid-launch-exitCode.conf
├── valid-launch.conf
└── valid.conf
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .project
3 | .classpath
4 | .settings/
5 | bin
6 | .idea
7 | *.iml
8 | .java-version
9 |
--------------------------------------------------------------------------------
/LICENSE-2.0.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | /*
4 | $Id$
5 |
6 | Copyright 2002 (C) The Codehaus. All Rights Reserved.
7 |
8 | Redistribution and use of this software and associated documentation
9 | ("Software"), with or without modification, are permitted provided
10 | that the following conditions are met:
11 |
12 | 1. Redistributions of source code must retain copyright
13 | statements and notices. Redistributions must also contain a
14 | copy of this document.
15 |
16 | 2. Redistributions in binary form must reproduce the
17 | above copyright notice, this list of conditions and the
18 | following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | 3. The name "classworlds" must not be used to endorse or promote
22 | products derived from this Software without prior written
23 | permission of The Codehaus. For written permission, please
24 | contact bob@codehaus.org.
25 |
26 | 4. Products derived from this Software may not be called "classworlds"
27 | nor may "classworlds" appear in their names without prior written
28 | permission of The Codehaus. "classworlds" is a registered
29 | trademark of The Codehaus.
30 |
31 | 5. Due credit should be given to The Codehaus.
32 | (http://classworlds.codehaus.org/).
33 |
34 | THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
35 | ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
36 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
37 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
38 | THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
39 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
45 | OF THE POSSIBILITY OF SUCH DAMAGE.
46 |
47 | */
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # plexus-classworlds
2 | Current master is now at https://github.com/codehaus-plexus/plexus-classworlds
3 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
ClassWorld
.
55 | *
56 | *
57 | * This class most closed maps to the ClassLoader
58 | * role from Java and in facts can provide a ClassLoader
59 | * view of itself using {@link #getClassLoader}.
60 | *
61 | *
62 | * @author bob mcwhirter
63 | * @author Jason van Zyl
64 | */
65 | @Deprecated
66 | public interface ClassRealm
67 | {
68 | String getId();
69 |
70 | ClassWorld getWorld();
71 |
72 | void importFrom( String realmId, String pkgName )
73 | throws NoSuchRealmException;
74 |
75 | void addConstituent( URL constituent );
76 |
77 | ClassRealm locateSourceRealm( String className );
78 |
79 | void setParent( ClassRealm classRealm );
80 |
81 | ClassRealm createChildRealm( String id )
82 | throws DuplicateRealmException;
83 |
84 | ClassLoader getClassLoader();
85 |
86 | ClassRealm getParent();
87 |
88 | URL[] getConstituents();
89 |
90 | // ----------------------------------------------------------------------
91 | // Classloading
92 | // ----------------------------------------------------------------------
93 |
94 | Class loadClass( String name )
95 | throws ClassNotFoundException;
96 |
97 | // ----------------------------------------------------------------------
98 | // Resource handling
99 | // ----------------------------------------------------------------------
100 |
101 | URL getResource( String name );
102 |
103 | Enumeration findResources( String name )
104 | throws IOException;
105 |
106 | InputStream getResourceAsStream( String name );
107 |
108 | void display();
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassRealmAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.net.URL;
20 | import java.util.Enumeration;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 |
24 | /**
25 | * An adapter for ClassRealms
26 | *
27 | * @author Andrew Williams
28 | */
29 | @Deprecated
30 | public class ClassRealmAdapter
31 | implements ClassRealm
32 | {
33 |
34 | public static ClassRealmAdapter getInstance( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm )
35 | {
36 | ClassRealmAdapter adapter = new ClassRealmAdapter( newRealm );
37 |
38 | return adapter;
39 | }
40 |
41 | private org.codehaus.plexus.classworlds.realm.ClassRealm realm;
42 |
43 | private ClassRealmAdapter( org.codehaus.plexus.classworlds.realm.ClassRealm newRealm )
44 | {
45 | this.realm = newRealm;
46 | }
47 |
48 | public String getId()
49 | {
50 | return realm.getId();
51 | }
52 |
53 | public ClassWorld getWorld()
54 | {
55 | return ClassWorldAdapter.getInstance( realm.getWorld() );
56 | }
57 |
58 | public void importFrom( String realmId,
59 | String pkgName )
60 | throws NoSuchRealmException
61 | {
62 | try
63 | {
64 | realm.importFrom( realmId, pkgName );
65 | }
66 | catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
67 | {
68 | throw new NoSuchRealmException( getWorld(), e.getId() );
69 | }
70 | }
71 |
72 | public void addConstituent( URL constituent )
73 | {
74 | realm.addURL( constituent );
75 | }
76 |
77 | public ClassRealm locateSourceRealm( String className )
78 | {
79 | ClassLoader importLoader = realm.getImportClassLoader( className );
80 |
81 | if ( importLoader instanceof org.codehaus.plexus.classworlds.realm.ClassRealm )
82 | {
83 | return ClassRealmAdapter.getInstance( (org.codehaus.plexus.classworlds.realm.ClassRealm) importLoader );
84 | }
85 | else
86 | {
87 | return null;
88 | }
89 | }
90 |
91 | public void setParent( ClassRealm classRealm )
92 | {
93 | if ( classRealm != null )
94 | {
95 | realm.setParentRealm( ClassRealmReverseAdapter.getInstance( classRealm ) );
96 | }
97 | }
98 |
99 | public ClassRealm createChildRealm( String id )
100 | throws DuplicateRealmException
101 | {
102 | try
103 | {
104 | return ClassRealmAdapter.getInstance( realm.createChildRealm( id ) );
105 | }
106 | catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
107 | {
108 | throw new DuplicateRealmException( getWorld(), e.getId() );
109 | }
110 | }
111 |
112 | public ClassLoader getClassLoader()
113 | {
114 | return realm;
115 | }
116 |
117 | public ClassRealm getParent()
118 | {
119 | return ClassRealmAdapter.getInstance( realm.getParentRealm() );
120 | }
121 |
122 | public ClassRealm getParentRealm()
123 | {
124 | return ClassRealmAdapter.getInstance( realm.getParentRealm() );
125 | }
126 |
127 | public URL[] getConstituents()
128 | {
129 | return realm.getURLs();
130 | }
131 |
132 | public Class loadClass( String name )
133 | throws ClassNotFoundException
134 | {
135 | return realm.loadClass( name );
136 | }
137 |
138 | public URL getResource( String name )
139 | {
140 | return realm.getResource( trimLeadingSlash( name ) );
141 | }
142 |
143 | public Enumeration findResources( String name )
144 | throws IOException
145 | {
146 | return realm.findResources( trimLeadingSlash( name ) );
147 | }
148 |
149 | public InputStream getResourceAsStream( String name )
150 | {
151 | return realm.getResourceAsStream( trimLeadingSlash( name ) );
152 | }
153 |
154 | public void display()
155 | {
156 | realm.display();
157 | }
158 |
159 | public boolean equals(Object o)
160 | {
161 | if ( !( o instanceof ClassRealm ) )
162 | return false;
163 |
164 | return getId().equals( ( (ClassRealm) o ).getId() );
165 | }
166 |
167 | /**
168 | * Provides backward-compat with the old classworlds which accepted resource names with leading slashes.
169 | */
170 | private String trimLeadingSlash( String resource )
171 | {
172 | if ( resource != null && resource.startsWith( "/" ) )
173 | {
174 | return resource.substring( 1 );
175 | }
176 | else
177 | {
178 | return resource;
179 | }
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassRealmReverseAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.Enumeration;
20 | import java.net.URL;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 |
24 | /**
25 | * A reverse adapter for ClassRealms
26 | *
27 | * @author Andrew Williams
28 | */
29 | @Deprecated
30 | public class ClassRealmReverseAdapter
31 | extends org.codehaus.plexus.classworlds.realm.ClassRealm
32 | {
33 |
34 | public static ClassRealmReverseAdapter getInstance( ClassRealm oldRealm )
35 | {
36 | ClassRealmReverseAdapter adapter = new ClassRealmReverseAdapter( oldRealm );
37 |
38 | return adapter;
39 | }
40 |
41 | private ClassRealm realm;
42 |
43 | private ClassRealmReverseAdapter( ClassRealm oldRealm )
44 | {
45 | super( ClassWorldReverseAdapter.getInstance( oldRealm.getWorld() ),
46 | oldRealm.getId(), oldRealm.getClassLoader() );
47 | this.realm = oldRealm;
48 | }
49 |
50 | public String getId()
51 | {
52 | return realm.getId();
53 | }
54 |
55 | public org.codehaus.plexus.classworlds.ClassWorld getWorld()
56 | {
57 | return ClassWorldReverseAdapter.getInstance( realm.getWorld() );
58 | }
59 |
60 | public void importFrom( String realmId,
61 | String pkgName )
62 | throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
63 | {
64 | try
65 | {
66 | realm.importFrom( realmId, pkgName );
67 | }
68 | catch ( NoSuchRealmException e )
69 | {
70 | throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( getWorld(), e.getId() );
71 | }
72 | }
73 |
74 | public void addURL( URL constituent )
75 | {
76 | realm.addConstituent( constituent );
77 | }
78 |
79 | public org.codehaus.plexus.classworlds.realm.ClassRealm locateSourceRealm( String className )
80 | {
81 | return getInstance( realm.locateSourceRealm(
82 | className ) );
83 | }
84 |
85 | public void setParentRealm( org.codehaus.plexus.classworlds.realm.ClassRealm classRealm )
86 | {
87 | realm.setParent( ClassRealmAdapter.getInstance( classRealm ) );
88 | }
89 |
90 | public org.codehaus.plexus.classworlds.realm.ClassRealm createChildRealm( String id )
91 | throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
92 | {
93 | try
94 | {
95 | return getInstance( realm.createChildRealm( id ) );
96 | }
97 | catch ( DuplicateRealmException e )
98 | {
99 | throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( getWorld(), e.getId() );
100 | }
101 | }
102 |
103 | public ClassLoader getClassLoader()
104 | {
105 | return realm.getClassLoader();
106 | }
107 |
108 | public org.codehaus.plexus.classworlds.realm.ClassRealm getParentRealm()
109 | {
110 | return getInstance( realm.getParent() );
111 | }
112 |
113 | public URL[] getURLs()
114 | {
115 | return realm.getConstituents();
116 | }
117 |
118 | public Class loadClass( String name )
119 | throws ClassNotFoundException
120 | {
121 | return realm.loadClass( name );
122 | }
123 |
124 | public URL getResource( String name )
125 | {
126 | return realm.getResource( name );
127 | }
128 |
129 | public Enumeration findResources( String name )
130 | throws IOException
131 | {
132 | return realm.findResources( name );
133 | }
134 |
135 | public InputStream getResourceAsStream( String name )
136 | {
137 | return realm.getResourceAsStream( name );
138 | }
139 |
140 | public void display()
141 | {
142 | realm.display();
143 | }
144 |
145 | public boolean equals(Object o)
146 | {
147 | if ( !( o instanceof ClassRealm ) )
148 | return false;
149 |
150 | return getId().equals( ( (ClassRealm) o ).getId() );
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassWorld.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.Collection;
20 |
21 | /**
22 | * A compatibility wrapper for org.codehaus.plexus.classworlds.ClassWorld
23 | * provided for legacy code
24 | *
25 | * @author Andrew Williams
26 | */
27 | @Deprecated
28 | public class ClassWorld
29 | {
30 | private ClassWorldAdapter adapter;
31 |
32 | public ClassWorld( String realmId,
33 | ClassLoader classLoader )
34 | {
35 | adapter = ClassWorldAdapter.getInstance(
36 | new org.codehaus.plexus.classworlds.ClassWorld( realmId, classLoader ) );
37 | }
38 |
39 | public ClassWorld()
40 | {
41 | adapter = ClassWorldAdapter.getInstance(
42 | new org.codehaus.plexus.classworlds.ClassWorld( ) );
43 | }
44 |
45 | public ClassWorld( boolean ignore )
46 | {
47 | /* fake */
48 | }
49 |
50 | public ClassRealm newRealm( String id )
51 | throws DuplicateRealmException
52 | {
53 | return adapter.newRealm( id );
54 | }
55 |
56 | public ClassRealm newRealm( String id,
57 | ClassLoader classLoader )
58 | throws DuplicateRealmException
59 | {
60 | return adapter.newRealm( id, classLoader );
61 | }
62 |
63 | public void disposeRealm( String id )
64 | throws NoSuchRealmException
65 | {
66 | adapter.disposeRealm( id );
67 | }
68 |
69 | public ClassRealm getRealm( String id )
70 | throws NoSuchRealmException
71 | {
72 | return adapter.getRealm( id );
73 | }
74 |
75 | public Collection getRealms()
76 | {
77 | return adapter.getRealms();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassWorldAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.Collection;
20 | import java.util.Vector;
21 | import java.util.Iterator;
22 |
23 | /**
24 | * An adapter for ClassWorlds
25 | *
26 | * @author Andrew Williams
27 | */
28 | @Deprecated
29 | public class ClassWorldAdapter
30 | extends ClassWorld
31 | {
32 |
33 | public static ClassWorldAdapter getInstance( org.codehaus.plexus.classworlds.ClassWorld newWorld )
34 | {
35 | ClassWorldAdapter adapter = new ClassWorldAdapter( newWorld );
36 |
37 | return adapter;
38 | }
39 |
40 | private org.codehaus.plexus.classworlds.ClassWorld world;
41 |
42 | private ClassWorldAdapter( org.codehaus.plexus.classworlds.ClassWorld newWorld )
43 | {
44 | super( false );
45 | this.world = newWorld;
46 | }
47 |
48 | public ClassRealm newRealm( String id )
49 | throws DuplicateRealmException
50 | {
51 | try
52 | {
53 | return ClassRealmAdapter.getInstance( world.newRealm( id ) );
54 | }
55 | catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
56 | {
57 | throw new DuplicateRealmException( this, e.getId() );
58 | }
59 | }
60 |
61 | public ClassRealm newRealm( String id,
62 | ClassLoader classLoader )
63 | throws DuplicateRealmException
64 | {
65 | try
66 | {
67 | return ClassRealmAdapter.getInstance( world.newRealm( id,
68 | classLoader ) );
69 | }
70 | catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
71 | {
72 | throw new DuplicateRealmException( this, e.getId() );
73 | }
74 | }
75 |
76 | public void disposeRealm( String id )
77 | throws NoSuchRealmException
78 | {
79 | try
80 | {
81 | world.disposeRealm( id );
82 | }
83 | catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
84 | {
85 | throw new NoSuchRealmException( this, e.getId() );
86 | }
87 | }
88 |
89 | public ClassRealm getRealm( String id )
90 | throws NoSuchRealmException
91 | {
92 | try
93 | {
94 | return ClassRealmAdapter.getInstance( world.getRealm( id ) );
95 | }
96 | catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
97 | {
98 | throw new NoSuchRealmException( this, e.getId() );
99 | }
100 | }
101 |
102 | public Collection getRealms()
103 | {
104 | Collection realms = world.getRealms();
105 | Vector ret = new Vector();
106 |
107 | Iterator it = realms.iterator();
108 | while ( it.hasNext() )
109 | {
110 | org.codehaus.plexus.classworlds.realm.ClassRealm realm =
111 | (org.codehaus.plexus.classworlds.realm.ClassRealm) it.next();
112 | ret.add( ClassRealmAdapter.getInstance( realm ) );
113 | }
114 |
115 | return ret;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassWorldException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 |
5 | Copyright 2002 (C) The Werken Company. All Rights Reserved.
6 |
7 | Redistribution and use of this software and associated documentation
8 | ("Software"), with or without modification, are permitted provided
9 | that the following conditions are met:
10 |
11 | 1. Redistributions of source code must retain copyright
12 | statements and notices. Redistributions must also contain a
13 | copy of this document.
14 |
15 | 2. Redistributions in binary form must reproduce the
16 | above copyright notice, this list of conditions and the
17 | following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | 3. The name "classworlds" must not be used to endorse or promote
21 | products derived from this Software without prior written
22 | permission of The Werken Company. For written permission,
23 | please contact bob@werken.com.
24 |
25 | 4. Products derived from this Software may not be called "classworlds"
26 | nor may "classworlds" appear in their names without prior written
27 | permission of The Werken Company. "classworlds" is a registered
28 | trademark of The Werken Company.
29 |
30 | 5. Due credit should be given to The Werken Company.
31 | (http://classworlds.werken.com/).
32 |
33 | THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
34 | ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
35 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
37 | THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
44 | OF THE POSSIBILITY OF SUCH DAMAGE.
45 |
46 | */
47 |
48 | /**
49 | * Base exception for ClassWorld
errors.
50 | *
51 | * @author bob mcwhirter
52 | */
53 | @Deprecated
54 | public class ClassWorldException extends Exception
55 | {
56 | // ------------------------------------------------------------
57 | // Instance members
58 | // ------------------------------------------------------------
59 |
60 | /**
61 | * The world.
62 | */
63 | private ClassWorld world;
64 |
65 | // ------------------------------------------------------------
66 | // Constructors
67 | // ------------------------------------------------------------
68 |
69 | /**
70 | * Construct.
71 | *
72 | * @param world The world.
73 | */
74 | public ClassWorldException( final ClassWorld world )
75 | {
76 | this.world = world;
77 | }
78 |
79 | /**
80 | * Construct.
81 | *
82 | * @param world The world.
83 | * @param msg The detail message.
84 | */
85 | public ClassWorldException( final ClassWorld world, final String msg )
86 | {
87 | super( msg );
88 | this.world = world;
89 | }
90 |
91 | // ------------------------------------------------------------
92 | // Instance methods
93 | // ------------------------------------------------------------
94 |
95 | /**
96 | * Retrieve the world.
97 | *
98 | * @return The world.
99 | */
100 | public ClassWorld getWorld()
101 | {
102 | return this.world;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ClassWorldReverseAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.HashMap;
20 | import java.util.Collection;
21 | import java.util.Vector;
22 | import java.util.Iterator;
23 |
24 | /**
25 | * A reverse adapter for ClassWorlds
26 | *
27 | * @author Andrew Williams
28 | */
29 | @Deprecated
30 | public class ClassWorldReverseAdapter
31 | extends org.codehaus.plexus.classworlds.ClassWorld
32 | {
33 | private static HashMap instances = new HashMap();
34 |
35 | public static ClassWorldReverseAdapter getInstance( ClassWorld oldWorld )
36 | {
37 | if ( instances.containsKey( oldWorld ) )
38 | return (ClassWorldReverseAdapter) instances.get( oldWorld );
39 |
40 | ClassWorldReverseAdapter adapter = new ClassWorldReverseAdapter( oldWorld );
41 | instances.put( oldWorld, adapter );
42 |
43 | return adapter;
44 | }
45 |
46 | private ClassWorld world;
47 |
48 | private ClassWorldReverseAdapter( ClassWorld newWorld )
49 | {
50 | super();
51 | this.world = newWorld;
52 | }
53 |
54 | public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id )
55 | throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
56 | {
57 | try
58 | {
59 | return ClassRealmReverseAdapter.getInstance( world.newRealm( id ) );
60 | }
61 | catch ( DuplicateRealmException e )
62 | {
63 | throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() );
64 | }
65 | }
66 |
67 | public org.codehaus.plexus.classworlds.realm.ClassRealm newRealm( String id,
68 | ClassLoader classLoader )
69 | throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
70 | {
71 | try
72 | {
73 | return ClassRealmReverseAdapter.getInstance( world.newRealm( id,
74 | classLoader ) );
75 | }
76 | catch ( DuplicateRealmException e )
77 | {
78 | throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( this, e.getId() );
79 | }
80 | }
81 |
82 | public void disposeRealm( String id )
83 | throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
84 | {
85 | try
86 | {
87 | world.disposeRealm( id );
88 | }
89 | catch ( NoSuchRealmException e )
90 | {
91 | throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() );
92 | }
93 | }
94 |
95 | public org.codehaus.plexus.classworlds.realm.ClassRealm getRealm( String id )
96 | throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
97 | {
98 | try
99 | {
100 | return ClassRealmReverseAdapter.getInstance( world.getRealm( id ) );
101 | }
102 | catch ( NoSuchRealmException e )
103 | {
104 | throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() );
105 | }
106 | }
107 |
108 | public Collection getRealms()
109 | {
110 | Collection realms = world.getRealms();
111 | Vector ret = new Vector();
112 |
113 | Iterator it = realms.iterator();
114 | while ( it.hasNext() )
115 | {
116 | ClassRealm realm = (ClassRealm) it.next();
117 | ret.add( ClassRealmReverseAdapter.getInstance( realm ) );
118 | }
119 |
120 | return ret;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ConfigurationException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 |
5 | Copyright 2002 (C) The Werken Company. All Rights Reserved.
6 |
7 | Redistribution and use of this software and associated documentation
8 | ("Software"), with or without modification, are permitted provided
9 | that the following conditions are met:
10 |
11 | 1. Redistributions of source code must retain copyright
12 | statements and notices. Redistributions must also contain a
13 | copy of this document.
14 |
15 | 2. Redistributions in binary form must reproduce the
16 | above copyright notice, this list of conditions and the
17 | following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | 3. The name "classworlds" must not be used to endorse or promote
21 | products derived from this Software without prior written
22 | permission of The Werken Company. For written permission,
23 | please contact bob@werken.com.
24 |
25 | 4. Products derived from this Software may not be called "classworlds"
26 | nor may "classworlds" appear in their names without prior written
27 | permission of The Werken Company. "classworlds" is a registered
28 | trademark of The Werken Company.
29 |
30 | 5. Due credit should be given to The Werken Company.
31 | (http://classworlds.werken.com/).
32 |
33 | THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
34 | ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
35 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
37 | THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
44 | OF THE POSSIBILITY OF SUCH DAMAGE.
45 |
46 | */
47 |
48 | /**
49 | * Indicates an error during Launcher
configuration.
50 | *
51 | * @author bob mcwhirter
52 | */
53 | @Deprecated
54 | public class ConfigurationException extends Exception
55 | {
56 | /**
57 | * Construct.
58 | *
59 | * @param msg The message.
60 | */
61 | public ConfigurationException( String msg )
62 | {
63 | super( msg );
64 | }
65 |
66 | /**
67 | * Construct.
68 | *
69 | * @param msg The message.
70 | * @param lineNo The number of configuraton line where the problem occured.
71 | * @param line The configuration line where the problem occured.
72 | */
73 | public ConfigurationException( String msg, int lineNo, String line )
74 | {
75 | super( msg + " (" + lineNo + "): " + line );
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/Configurator.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.FileNotFoundException;
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.MalformedURLException;
23 |
24 | /**
25 | * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Configurator
26 | * provided for legacy code
27 | *
28 | * @author Andrew Williams
29 | */
30 | @Deprecated
31 | public class Configurator
32 | {
33 | private ConfiguratorAdapter config;
34 |
35 | /** Construct.
36 | *
37 | * @param launcher The launcher to configure.
38 | */
39 | public Configurator( Launcher launcher )
40 | {
41 | config = ConfiguratorAdapter.getInstance(
42 | new org.codehaus.plexus.classworlds.launcher.Configurator( launcher ), launcher );
43 | }
44 |
45 | /** Construct.
46 | *
47 | * @param world The classWorld to configure.
48 | */
49 | public Configurator( ClassWorld world )
50 | {
51 | config = ConfiguratorAdapter.getInstance(
52 | new org.codehaus.plexus.classworlds.launcher.Configurator(
53 | ClassWorldReverseAdapter.getInstance( world ) ), world );
54 | }
55 |
56 | /** set world.
57 | * this setter is provided so you can use the same configurator to configure several "worlds"
58 | *
59 | * @param world The classWorld to configure.
60 | */
61 | public void setClassWorld( ClassWorld world )
62 | {
63 | config.setClassWorld( world );
64 | }
65 |
66 | /**
67 | * Configure from a file.
68 | *
69 | * @param is The config input stream
70 | * @throws IOException If an error occurs reading the config file.
71 | * @throws MalformedURLException If the config file contains invalid URLs.
72 | * @throws ConfigurationException If the config file is corrupt.
73 | * @throws DuplicateRealmException If the config file defines two realms with the same id.
74 | * @throws NoSuchRealmException If the config file defines a main entry point in
75 | * a non-existent realm.
76 | */
77 | public void configure( InputStream is )
78 | throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
79 | {
80 | config.configureAdapter( is );
81 | }
82 |
83 | /**
84 | * Associate parent realms with their children.
85 | */
86 | protected void associateRealms()
87 | {
88 | config.associateRealms();
89 | }
90 |
91 | /**
92 | * Load a glob into the specified classloader.
93 | *
94 | * @param line The path configuration line.
95 | * @param realm The realm to populate
96 | * @throws MalformedURLException If the line does not represent
97 | * a valid path element.
98 | * @throws FileNotFoundException If the line does not represent
99 | * a valid path element in the filesystem.
100 | */
101 | protected void loadGlob( String line, ClassRealm realm )
102 | throws MalformedURLException, FileNotFoundException
103 | {
104 | loadGlob( line, realm, false );
105 | }
106 |
107 | /**
108 | * Load a glob into the specified classloader.
109 | *
110 | * @param line The path configuration line.
111 | * @param realm The realm to populate
112 | * @param optionally Whether the path is optional or required
113 | * @throws MalformedURLException If the line does not represent
114 | * a valid path element.
115 | * @throws FileNotFoundException If the line does not represent
116 | * a valid path element in the filesystem.
117 | */
118 | protected void loadGlob( String line, ClassRealm realm, boolean optionally )
119 | throws MalformedURLException, FileNotFoundException
120 | {
121 | config.loadGlob( line, realm, optionally );
122 | }
123 |
124 | /**
125 | * Filter a string for system properties.
126 | *
127 | * @param text The text to filter.
128 | * @return The filtered text.
129 | * @throws ConfigurationException If the property does not
130 | * exist or if there is a syntax error.
131 | */
132 | protected String filter( String text )
133 | throws ConfigurationException
134 | {
135 | return config.filter( text );
136 | }
137 |
138 | }
139 |
140 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/ConfiguratorAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.InputStream;
20 | import java.io.IOException;
21 | import java.net.MalformedURLException;
22 |
23 | /**
24 | * Created by IntelliJ IDEA.
25 | *
26 | * @uthor: Andrew Williams
27 | * @since: Nov 25, 2006
28 | */
29 | @Deprecated
30 | public class ConfiguratorAdapter
31 | extends Configurator
32 | {
33 |
34 | public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig,
35 | Launcher launcher )
36 | {
37 | ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, launcher );
38 |
39 | return adapter;
40 | }
41 |
42 | public static ConfiguratorAdapter getInstance( org.codehaus.plexus.classworlds.launcher.Configurator newConfig,
43 | ClassWorld world )
44 | {
45 | ConfiguratorAdapter adapter = new ConfiguratorAdapter( newConfig, world );
46 |
47 | return adapter;
48 | }
49 |
50 | private org.codehaus.plexus.classworlds.launcher.Configurator config;
51 |
52 | private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, Launcher launcher )
53 | {
54 | super( launcher );
55 | this.config = config;
56 | }
57 |
58 | private ConfiguratorAdapter( org.codehaus.plexus.classworlds.launcher.Configurator config, ClassWorld world )
59 | {
60 | super( world );
61 | this.config = config;
62 | }
63 |
64 | public void associateRealms()
65 | {
66 | config.associateRealms();
67 | }
68 |
69 | public void configureAdapter( InputStream is )
70 | throws IOException, MalformedURLException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
71 | {
72 | try
73 | {
74 | config.configure( is );
75 | }
76 | catch ( org.codehaus.plexus.classworlds.launcher.ConfigurationException e )
77 | {
78 | throw new ConfigurationException( e.getMessage() );
79 | }
80 | catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
81 | {
82 | throw new DuplicateRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() );
83 | }
84 | catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
85 | {
86 | throw new NoSuchRealmException( ClassWorldAdapter.getInstance( e.getWorld() ), e.getId() );
87 | }
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/DefaultClassRealm.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * A compatibility wrapper for org.codehaus.plexus.classworlds.realm.ClassRealm
21 | * provided for legacy code
22 | *
23 | * @author Andrew Williams
24 | * @version $Id$
25 | */
26 |
27 | import java.io.File;
28 | import java.io.IOException;
29 | import java.io.InputStream;
30 | import java.net.URL;
31 | import java.util.Enumeration;
32 |
33 | @Deprecated
34 | public class DefaultClassRealm
35 | implements ClassRealm
36 | {
37 | private ClassRealmAdapter adapter;
38 |
39 | public DefaultClassRealm( ClassWorld world, String id )
40 | {
41 | this( world, id, null );
42 | }
43 |
44 | public DefaultClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader )
45 | {
46 | this.adapter = ClassRealmAdapter.getInstance(
47 | new org.codehaus.plexus.classworlds.realm.ClassRealm(
48 | ClassWorldReverseAdapter.getInstance( world ), id, foreignClassLoader ) );
49 | }
50 |
51 | public URL[] getConstituents()
52 | {
53 | return adapter.getConstituents();
54 | }
55 |
56 | public ClassRealm getParent()
57 | {
58 | return adapter.getParentRealm();
59 | }
60 |
61 | public void setParent( ClassRealm parent )
62 | {
63 | adapter.setParent( parent );
64 | }
65 |
66 | public String getId()
67 | {
68 | return adapter.getId();
69 | }
70 |
71 | public ClassWorld getWorld()
72 | {
73 | return adapter.getWorld();
74 | }
75 |
76 | public void importFrom( String realmId, String packageName )
77 | throws NoSuchRealmException
78 | {
79 | adapter.importFrom( realmId, packageName );
80 | }
81 |
82 | public void addConstituent( URL constituent )
83 | {
84 | adapter.addConstituent( constituent );
85 | }
86 |
87 | /**
88 | * Adds a byte[] class definition as a constituent for locating classes.
89 | * Currently uses BytesURLStreamHandler to hold a reference of the byte[] in memory.
90 | * This ensures we have a unifed URL resource model for all constituents.
91 | * The code to cache to disk is commented out - maybe a property to choose which method?
92 | *
93 | * @param constituent class name
94 | * @param b the class definition as a byte[]
95 | */
96 | public void addConstituent(String constituent,
97 | byte[] b) throws ClassNotFoundException
98 | {
99 | try
100 | {
101 | File path, file;
102 | if (constituent.lastIndexOf('.') != -1)
103 | {
104 | path = new File("byteclass/" + constituent.substring(0, constituent.lastIndexOf('.') + 1).replace('.', File.separatorChar));
105 |
106 | file = new File(path, constituent.substring(constituent.lastIndexOf('.') + 1) + ".class");
107 | }
108 | else
109 | {
110 | path = new File("byteclass/");
111 |
112 | file = new File(path, constituent + ".class");
113 | }
114 |
115 | addConstituent( new URL( null,
116 | file.toURI().toURL().toExternalForm(),
117 | new BytesURLStreamHandler(b) ) );
118 | }
119 | catch (java.io.IOException e)
120 | {
121 | throw new ClassNotFoundException( "Couldn't load byte stream.", e );
122 | }
123 | }
124 |
125 | public ClassRealm locateSourceRealm( String classname )
126 | {
127 | return adapter.locateSourceRealm( classname );
128 | }
129 |
130 | public ClassLoader getClassLoader()
131 | {
132 | return adapter.getClassLoader();
133 | }
134 |
135 | public ClassRealm createChildRealm( String id )
136 | throws DuplicateRealmException
137 | {
138 | return adapter.createChildRealm( id );
139 | }
140 |
141 | // ----------------------------------------------------------------------
142 | // ClassLoader API
143 | // ----------------------------------------------------------------------
144 |
145 | public Class loadClass( String name )
146 | throws ClassNotFoundException
147 | {
148 | return adapter.loadClass( name );
149 | }
150 |
151 | public URL getResource( String name )
152 | {
153 | return adapter.getResource( name );
154 | }
155 |
156 | public InputStream getResourceAsStream( String name )
157 | {
158 | return adapter.getResourceAsStream( name );
159 | }
160 |
161 | public Enumeration findResources(String name)
162 | throws IOException
163 | {
164 | return adapter.findResources( name );
165 | }
166 |
167 | public void display()
168 | {
169 | adapter.display();
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/DuplicateRealmException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 |
5 | Copyright 2002 (C) The Werken Company. All Rights Reserved.
6 |
7 | Redistribution and use of this software and associated documentation
8 | ("Software"), with or without modification, are permitted provided
9 | that the following conditions are met:
10 |
11 | 1. Redistributions of source code must retain copyright
12 | statements and notices. Redistributions must also contain a
13 | copy of this document.
14 |
15 | 2. Redistributions in binary form must reproduce the
16 | above copyright notice, this list of conditions and the
17 | following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | 3. The name "classworlds" must not be used to endorse or promote
21 | products derived from this Software without prior written
22 | permission of The Werken Company. For written permission,
23 | please contact bob@werken.com.
24 |
25 | 4. Products derived from this Software may not be called "classworlds"
26 | nor may "classworlds" appear in their names without prior written
27 | permission of The Werken Company. "classworlds" is a registered
28 | trademark of The Werken Company.
29 |
30 | 5. Due credit should be given to The Werken Company.
31 | (http://classworlds.werken.com/).
32 |
33 | THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
34 | ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
35 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
37 | THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
44 | OF THE POSSIBILITY OF SUCH DAMAGE.
45 |
46 | */
47 |
48 | /**
49 | * Indicates an attempt to add a ClassRealm
to a
50 | * ClassWorld
with a duplicate id.
51 | *
52 | * @author bob mcwhirter
53 | */
54 | @Deprecated
55 | public class DuplicateRealmException extends ClassWorldException
56 | {
57 | // ------------------------------------------------------------
58 | // Instance members
59 | // ------------------------------------------------------------
60 |
61 | /**
62 | * The realm id.
63 | */
64 | private String id;
65 |
66 | // ------------------------------------------------------------
67 | // Constructors
68 | // ------------------------------------------------------------
69 |
70 | /**
71 | * Construct.
72 | *
73 | * @param world The world.
74 | * @param id The realm id.
75 | */
76 | public DuplicateRealmException( ClassWorld world,
77 | String id )
78 | {
79 | super( world, id );
80 | this.id = id;
81 | }
82 |
83 | // ------------------------------------------------------------
84 | // Instance methods
85 | // ------------------------------------------------------------
86 |
87 | /**
88 | * Retrieve the duplicate realm id.
89 | *
90 | * @return The id.
91 | */
92 | public String getId()
93 | {
94 | return this.id;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/Launcher.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2010 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * A compatibility wrapper for org.codehaus.plexus.classworlds.launcher.Launcher
21 | * provided for legacy code
22 | *
23 | * @author Andrew Williams
24 | */
25 | @Deprecated
26 | public class Launcher
27 | extends org.codehaus.plexus.classworlds.launcher.Launcher
28 | {
29 | public Launcher()
30 | {
31 | }
32 |
33 |
34 | // ------------------------------------------------------------
35 | // Class methods
36 | // ------------------------------------------------------------
37 |
38 | /**
39 | * Launch the launcher from the command line.
40 | * Will exit using System.exit with an exit code of 0 for success, 100 if there was an unknown exception,
41 | * or some other code for an application error.
42 | *
43 | * @param args The application command-line arguments.
44 | */
45 | public static void main( String[] args )
46 | {
47 | org.codehaus.plexus.classworlds.launcher.Launcher.main( args );
48 | }
49 |
50 | /**
51 | * Launch the launcher.
52 | *
53 | * @param args The application command-line arguments.
54 | * @return an integer exit code
55 | * @throws Exception If an error occurs.
56 | */
57 | public static int mainWithExitCode( String[] args )
58 | throws Exception
59 | {
60 | return org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode( args );
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/classworlds/NoSuchRealmException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.classworlds;
2 |
3 | /*
4 |
5 | Copyright 2002 (C) The Werken Company. All Rights Reserved.
6 |
7 | Redistribution and use of this software and associated documentation
8 | ("Software"), with or without modification, are permitted provided
9 | that the following conditions are met:
10 |
11 | 1. Redistributions of source code must retain copyright
12 | statements and notices. Redistributions must also contain a
13 | copy of this document.
14 |
15 | 2. Redistributions in binary form must reproduce the
16 | above copyright notice, this list of conditions and the
17 | following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | 3. The name "classworlds" must not be used to endorse or promote
21 | products derived from this Software without prior written
22 | permission of The Werken Company. For written permission,
23 | please contact bob@werken.com.
24 |
25 | 4. Products derived from this Software may not be called "classworlds"
26 | nor may "classworlds" appear in their names without prior written
27 | permission of The Werken Company. "classworlds" is a registered
28 | trademark of The Werken Company.
29 |
30 | 5. Due credit should be given to The Werken Company.
31 | (http://classworlds.werken.com/).
32 |
33 | THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
34 | ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
35 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
37 | THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
44 | OF THE POSSIBILITY OF SUCH DAMAGE.
45 |
46 | */
47 |
48 | /**
49 | * Indicates an attempt to retrieve a ClassRealm
from a
50 | * ClassWorld
with an invalid id.
51 | *
52 | * @author bob mcwhirter
53 | */
54 | @Deprecated
55 | public class NoSuchRealmException extends ClassWorldException
56 | {
57 | // ------------------------------------------------------------
58 | // Instance members
59 | // ------------------------------------------------------------
60 |
61 | /**
62 | * The realm id.
63 | */
64 | private String id;
65 |
66 | // ------------------------------------------------------------
67 | // Constructors
68 | // ------------------------------------------------------------
69 |
70 | /**
71 | * Construct.
72 | *
73 | * @param world The world.
74 | * @param id The realm id.
75 | */
76 | public NoSuchRealmException( ClassWorld world,
77 | String id )
78 | {
79 | super( world, id );
80 | this.id = id;
81 | }
82 |
83 | // ------------------------------------------------------------
84 | // Instance methods
85 | // ------------------------------------------------------------
86 |
87 | /**
88 | * Retrieve the invalid realm id.
89 | *
90 | * @return The id.
91 | */
92 | public String getId()
93 | {
94 | return this.id;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/ClassWorld.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.Closeable;
20 | import java.io.IOException;
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 | import java.util.Collections;
24 | import java.util.LinkedHashMap;
25 | import java.util.List;
26 | import java.util.Map;
27 |
28 | import org.codehaus.plexus.classworlds.realm.ClassRealm;
29 | import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
30 | import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
31 |
32 | /**
33 | * A collection of ClassRealm
s, indexed by id.
34 | *
35 | * @author bob mcwhirter
36 | */
37 | public class ClassWorld
38 | {
39 | private MapClassWorld
errors.
21 | *
22 | * @author bob mcwhirter
23 | */
24 | public class ClassWorldException
25 | extends Exception
26 | {
27 | // ------------------------------------------------------------
28 | // Instance members
29 | // ------------------------------------------------------------
30 |
31 | /**
32 | * The world.
33 | */
34 | private ClassWorld world;
35 |
36 | // ------------------------------------------------------------
37 | // Constructors
38 | // ------------------------------------------------------------
39 |
40 | /**
41 | * Construct.
42 | *
43 | * @param world The world.
44 | */
45 | public ClassWorldException( final ClassWorld world )
46 | {
47 | this.world = world;
48 | }
49 |
50 | /**
51 | * Construct.
52 | *
53 | * @param world The world.
54 | * @param msg The detail message.
55 | */
56 | public ClassWorldException( final ClassWorld world, final String msg )
57 | {
58 | super( msg );
59 | this.world = world;
60 | }
61 |
62 | // ------------------------------------------------------------
63 | // Instance methods
64 | // ------------------------------------------------------------
65 |
66 | /**
67 | * Retrieve the world.
68 | *
69 | * @return The world.
70 | */
71 | public ClassWorld getWorld()
72 | {
73 | return this.world;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/ClassWorldListener.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import org.codehaus.plexus.classworlds.realm.ClassRealm;
20 |
21 | public interface ClassWorldListener
22 | {
23 | public void realmCreated( ClassRealm realm );
24 |
25 | public void realmDisposed( ClassRealm realm );
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/UrlUtils.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.net.URL;
20 | import java.net.URLClassLoader;
21 | import java.util.HashSet;
22 | import java.util.Set;
23 |
24 | /**
25 | * @author Jason van Zyl
26 | */
27 | public class UrlUtils
28 | {
29 | public static String normalizeUrlPath( String name )
30 | {
31 | if ( name.startsWith( "/" ) )
32 | {
33 | name = name.substring( 1 );
34 | }
35 |
36 | // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml
37 | // | i |
38 | // +-------+ remove
39 | //
40 | int i = name.indexOf( "/.." );
41 |
42 | // Can't be at the beginning because we have no root to refer to so
43 | // we start at 1.
44 | if ( i > 0 )
45 | {
46 | int j = name.lastIndexOf( "/", i - 1 );
47 |
48 | if ( j >= 0 )
49 | {
50 | name = name.substring( 0, j ) + name.substring( i + 3 );
51 | }
52 | }
53 |
54 | return name;
55 | }
56 |
57 | public static SetLauncher
configuration.
21 | *
22 | * @author bob mcwhirter
23 | */
24 | public class ConfigurationException
25 | extends Exception
26 | {
27 | /**
28 | * Construct.
29 | *
30 | * @param msg The message.
31 | */
32 | public ConfigurationException( String msg )
33 | {
34 | super( msg );
35 | }
36 |
37 | /**
38 | * Construct.
39 | *
40 | * @param msg The message.
41 | * @param lineNo The number of configuraton line where the problem occured.
42 | * @param line The configuration line where the problem occured.
43 | */
44 | public ConfigurationException( String msg, int lineNo, String line )
45 | {
46 | super( msg + " (" + lineNo + "): " + line );
47 | }
48 |
49 | protected ConfigurationException( Exception cause )
50 | {
51 | super( cause );
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/launcher/ConfigurationHandler.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.launcher;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.File;
20 | import java.net.URL;
21 |
22 | import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
23 | import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
24 |
25 | /**
26 | * Receive notification of the logical content of launcher configuration, independently from parsing.
27 | *
28 | * @author Igor Fedorenko
29 | */
30 | public interface ConfigurationHandler
31 | {
32 |
33 | /**
34 | * Define the main class name
35 | * @param mainClassName the main class name
36 | * @param mainRealmName the main realm from which the main class is loaded
37 | */
38 | void setAppMain( String mainClassName, String mainRealmName );
39 |
40 | /**
41 | * Define a new realm
42 | * @param realmName the new realm name
43 | * @throws DuplicateRealmException
44 | */
45 | void addRealm( String realmName )
46 | throws DuplicateRealmException;
47 |
48 | /**
49 | * Add an import specification from a realm
50 | * @param relamName the realm name
51 | * @param importSpec the import specification
52 | * @throws NoSuchRealmException
53 | */
54 | void addImportFrom( String relamName, String importSpec )
55 | throws NoSuchRealmException;
56 |
57 | /**
58 | * Add a file to the realm
59 | * @param file the file to load content from
60 | */
61 | void addLoadFile( File file );
62 |
63 | /**
64 | * Add an URL to the realm
65 | * @param url the url to load content from
66 | */
67 | void addLoadURL( URL url );
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/launcher/ConfigurationParser.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.launcher;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.BufferedReader;
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileNotFoundException;
23 | import java.io.FilenameFilter;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.io.InputStreamReader;
27 | import java.net.MalformedURLException;
28 | import java.net.URL;
29 | import java.util.Properties;
30 |
31 | import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
32 | import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
33 |
34 | /**
35 | * Event based launcher configuration parser, delegating effective configuration handling to ConfigurationHandler.
36 | *
37 | * @author bob mcwhirter
38 | * @author Jason van Zyl
39 | * @author Igor Fedorenko
40 | * @see ConfigurationHandler
41 | */
42 | public class ConfigurationParser
43 | {
44 | public static final String MAIN_PREFIX = "main is";
45 |
46 | public static final String SET_PREFIX = "set";
47 |
48 | public static final String IMPORT_PREFIX = "import";
49 |
50 | public static final String LOAD_PREFIX = "load";
51 |
52 | /**
53 | * Optionally spec prefix.
54 | */
55 | public static final String OPTIONALLY_PREFIX = "optionally";
56 |
57 | private ConfigurationHandler handler;
58 |
59 | private Properties systemProperties;
60 |
61 | public ConfigurationParser( ConfigurationHandler handler, Properties systemProperties )
62 | {
63 | this.handler = handler;
64 | this.systemProperties = systemProperties;
65 | }
66 |
67 | /**
68 | * Parse launcher configuration file and send events to the handler.
69 | */
70 | public void parse( InputStream is )
71 | throws IOException, ConfigurationException, DuplicateRealmException, NoSuchRealmException
72 | {
73 | BufferedReader reader = new BufferedReader( new InputStreamReader( is, "UTF-8" ) );
74 |
75 | String line = null;
76 |
77 | int lineNo = 0;
78 |
79 | boolean mainSet = false;
80 |
81 | String curRealm = null;
82 |
83 | while ( true )
84 | {
85 | line = reader.readLine();
86 |
87 | if ( line == null )
88 | {
89 | break;
90 | }
91 |
92 | ++lineNo;
93 | line = line.trim();
94 |
95 | if ( canIgnore( line ) )
96 | {
97 | continue;
98 | }
99 |
100 | if ( line.startsWith( MAIN_PREFIX ) )
101 | {
102 | if ( mainSet )
103 | {
104 | throw new ConfigurationException( "Duplicate main configuration", lineNo, line );
105 | }
106 |
107 | String conf = line.substring( MAIN_PREFIX.length() ).trim();
108 |
109 | int fromLoc = conf.indexOf( "from" );
110 |
111 | if ( fromLoc < 0 )
112 | {
113 | throw new ConfigurationException( "Missing from clause", lineNo, line );
114 | }
115 |
116 | String mainClassName = filter( conf.substring( 0, fromLoc ).trim() );
117 |
118 | String mainRealmName = filter( conf.substring( fromLoc + 4 ).trim() );
119 |
120 | this.handler.setAppMain( mainClassName, mainRealmName );
121 |
122 | mainSet = true;
123 | }
124 | else if ( line.startsWith( SET_PREFIX ) )
125 | {
126 | String conf = line.substring( SET_PREFIX.length() ).trim();
127 |
128 | int usingLoc = conf.indexOf( " using" ) + 1;
129 |
130 | String property = null;
131 |
132 | String propertiesFileName = null;
133 |
134 | if ( usingLoc > 0 )
135 | {
136 | property = conf.substring( 0, usingLoc ).trim();
137 |
138 | propertiesFileName = filter( conf.substring( usingLoc + 5 ).trim() );
139 |
140 | conf = propertiesFileName;
141 | }
142 |
143 | String defaultValue = null;
144 |
145 | int defaultLoc = conf.indexOf( " default" ) + 1;
146 |
147 | if ( defaultLoc > 0 )
148 | {
149 | defaultValue = filter( conf.substring( defaultLoc + 7 ).trim() );
150 |
151 | if ( property == null )
152 | {
153 | property = conf.substring( 0, defaultLoc ).trim();
154 | }
155 | else
156 | {
157 | propertiesFileName = conf.substring( 0, defaultLoc ).trim();
158 | }
159 | }
160 |
161 | String value = systemProperties.getProperty( property );
162 |
163 | if ( value != null )
164 | {
165 | continue;
166 | }
167 |
168 | if ( propertiesFileName != null )
169 | {
170 | File propertiesFile = new File( propertiesFileName );
171 |
172 | if ( propertiesFile.exists() )
173 | {
174 | Properties properties = new Properties();
175 |
176 | try
177 | {
178 | properties.load( new FileInputStream( propertiesFileName ) );
179 |
180 | value = properties.getProperty( property );
181 | }
182 | catch ( Exception e )
183 | {
184 | // do nothing
185 | }
186 | }
187 | }
188 |
189 | if ( value == null && defaultValue != null )
190 | {
191 | value = defaultValue;
192 | }
193 |
194 | if ( value != null )
195 | {
196 | value = filter( value );
197 | systemProperties.setProperty( property, value );
198 | }
199 | }
200 | else if ( line.startsWith( "[" ) )
201 | {
202 | int rbrack = line.indexOf( "]" );
203 |
204 | if ( rbrack < 0 )
205 | {
206 | throw new ConfigurationException( "Invalid realm specifier", lineNo, line );
207 | }
208 |
209 | String realmName = line.substring( 1, rbrack );
210 |
211 | handler.addRealm( realmName );
212 |
213 | curRealm = realmName;
214 | }
215 | else if ( line.startsWith( IMPORT_PREFIX ) )
216 | {
217 | if ( curRealm == null )
218 | {
219 | throw new ConfigurationException( "Unhandled import", lineNo, line );
220 | }
221 |
222 | String conf = line.substring( IMPORT_PREFIX.length() ).trim();
223 |
224 | int fromLoc = conf.indexOf( "from" );
225 |
226 | if ( fromLoc < 0 )
227 | {
228 | throw new ConfigurationException( "Missing from clause", lineNo, line );
229 | }
230 |
231 | String importSpec = conf.substring( 0, fromLoc ).trim();
232 |
233 | String relamName = conf.substring( fromLoc + 4 ).trim();
234 |
235 | handler.addImportFrom( relamName, importSpec );
236 |
237 | }
238 | else if ( line.startsWith( LOAD_PREFIX ) )
239 | {
240 | String constituent = line.substring( LOAD_PREFIX.length() ).trim();
241 |
242 | constituent = filter( constituent );
243 |
244 | if ( constituent.indexOf( "*" ) >= 0 )
245 | {
246 | loadGlob( constituent, false /*not optionally*/ );
247 | }
248 | else
249 | {
250 | File file = new File( constituent );
251 |
252 | if ( file.exists() )
253 | {
254 | handler.addLoadFile( file );
255 | }
256 | else
257 | {
258 | try
259 | {
260 | handler.addLoadURL( new URL( constituent ) );
261 | }
262 | catch ( MalformedURLException e )
263 | {
264 | throw new FileNotFoundException( constituent );
265 | }
266 | }
267 | }
268 | }
269 | else if ( line.startsWith( OPTIONALLY_PREFIX ) )
270 | {
271 | String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim();
272 |
273 | constituent = filter( constituent );
274 |
275 | if ( constituent.indexOf( "*" ) >= 0 )
276 | {
277 | loadGlob( constituent, true /*optionally*/ );
278 | }
279 | else
280 | {
281 | File file = new File( constituent );
282 |
283 | if ( file.exists() )
284 | {
285 | handler.addLoadFile( file );
286 | }
287 | else
288 | {
289 | try
290 | {
291 | handler.addLoadURL( new URL( constituent ) );
292 | }
293 | catch ( MalformedURLException e )
294 | {
295 | // swallow
296 | }
297 | }
298 | }
299 | }
300 | else
301 | {
302 | throw new ConfigurationException( "Unhandled configuration", lineNo, line );
303 | }
304 | }
305 |
306 | reader.close();
307 | }
308 |
309 | /**
310 | * Load a glob into the specified classloader.
311 | *
312 | * @param line The path configuration line.
313 | * @param optionally Whether the path is optional or required
314 | * @throws MalformedURLException If the line does not represent
315 | * a valid path element.
316 | * @throws FileNotFoundException If the line does not represent
317 | * a valid path element in the filesystem.
318 | * @throws ConfigurationException
319 | */
320 | protected void loadGlob( String line,
321 | boolean optionally )
322 | throws MalformedURLException, FileNotFoundException, ConfigurationException
323 | {
324 | File globFile = new File( line );
325 |
326 | File dir = globFile.getParentFile();
327 | if ( !dir.exists() )
328 | {
329 | if ( optionally )
330 | {
331 | return;
332 | }
333 | else
334 | {
335 | throw new FileNotFoundException( dir.toString() );
336 | }
337 | }
338 |
339 | String localName = globFile.getName();
340 |
341 | int starLoc = localName.indexOf( "*" );
342 |
343 | final String prefix = localName.substring( 0, starLoc );
344 |
345 | final String suffix = localName.substring( starLoc + 1 );
346 |
347 | File[] matches = dir.listFiles( new FilenameFilter()
348 | {
349 | public boolean accept( File dir,
350 | String name )
351 | {
352 | if ( !name.startsWith( prefix ) )
353 | {
354 | return false;
355 | }
356 |
357 | if ( !name.endsWith( suffix ) )
358 | {
359 | return false;
360 | }
361 |
362 | return true;
363 | }
364 | } );
365 |
366 | for ( File match : matches )
367 | {
368 | handler.addLoadFile( match );
369 | }
370 | }
371 |
372 | /**
373 | * Filter a string for system properties.
374 | *
375 | * @param text The text to filter.
376 | * @return The filtered text.
377 | * @throws ConfigurationException If the property does not
378 | * exist or if there is a syntax error.
379 | */
380 | protected String filter( String text )
381 | throws ConfigurationException
382 | {
383 | String result = "";
384 |
385 | int cur = 0;
386 | int textLen = text.length();
387 |
388 | int propStart = -1;
389 | int propStop = -1;
390 |
391 | String propName = null;
392 | String propValue = null;
393 |
394 | while ( cur < textLen )
395 | {
396 | propStart = text.indexOf( "${", cur );
397 |
398 | if ( propStart < 0 )
399 | {
400 | break;
401 | }
402 |
403 | result += text.substring( cur, propStart );
404 |
405 | propStop = text.indexOf( "}", propStart );
406 |
407 | if ( propStop < 0 )
408 | {
409 | throw new ConfigurationException( "Unterminated property: " + text.substring( propStart ) );
410 | }
411 |
412 | propName = text.substring( propStart + 2, propStop );
413 |
414 | propValue = systemProperties.getProperty( propName );
415 |
416 | /* do our best if we are not running from surefire */
417 | if ( propName.equals( "basedir" ) && ( propValue == null || propValue.equals( "" ) ) )
418 | {
419 | propValue = ( new File( "" ) ).getAbsolutePath();
420 |
421 | }
422 |
423 | if ( propValue == null )
424 | {
425 | throw new ConfigurationException( "No such property: " + propName );
426 | }
427 | result += propValue;
428 |
429 | cur = propStop + 1;
430 | }
431 |
432 | result += text.substring( cur );
433 |
434 | return result;
435 | }
436 |
437 | /**
438 | * Determine if a line can be ignored because it is
439 | * a comment or simply blank.
440 | *
441 | * @param line The line to test.
442 | * @return true
if the line is ignorable,
443 | * otherwise false
.
444 | */
445 | private boolean canIgnore( String line )
446 | {
447 | return ( line.length() == 0 || line.startsWith( "#" ) );
448 | }
449 | }
450 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/launcher/Configurator.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.launcher;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.net.MalformedURLException;
23 | import java.net.URL;
24 | import java.util.ArrayList;
25 | import java.util.Collections;
26 | import java.util.Comparator;
27 | import java.util.HashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | import org.codehaus.plexus.classworlds.ClassWorld;
32 | import org.codehaus.plexus.classworlds.realm.ClassRealm;
33 | import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
34 | import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
35 |
36 | /**
37 | * Launcher
configurator.
38 | *
39 | * @author bob mcwhirter
40 | * @author Jason van Zyl
41 | */
42 | public class Configurator implements ConfigurationHandler
43 | {
44 | /**
45 | * The launcher to configure.
46 | */
47 | private Launcher launcher;
48 |
49 | private ClassWorld world;
50 |
51 | /**
52 | * Processed Realms.
53 | */
54 | private MapClassRealm
to a
24 | * ClassWorld
with a duplicate id.
25 | *
26 | * @author bob mcwhirter
27 | */
28 | public class DuplicateRealmException
29 | extends ClassWorldException
30 | {
31 | // ------------------------------------------------------------
32 | // Instance members
33 | // ------------------------------------------------------------
34 |
35 | /**
36 | * The realm id.
37 | */
38 | private String id;
39 |
40 | // ------------------------------------------------------------
41 | // Constructors
42 | // ------------------------------------------------------------
43 |
44 | /**
45 | * Construct.
46 | *
47 | * @param world The world.
48 | * @param id The realm id.
49 | */
50 | public DuplicateRealmException( ClassWorld world, String id )
51 | {
52 | super( world, id );
53 | this.id = id;
54 | }
55 |
56 | // ------------------------------------------------------------
57 | // Instance methods
58 | // ------------------------------------------------------------
59 |
60 | /**
61 | * Retrieve the duplicate realm id.
62 | *
63 | * @return The id.
64 | */
65 | public String getId()
66 | {
67 | return this.id;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/realm/Entry.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.realm;
2 |
3 | /*
4 | * Copyright 2001-2006 Codehaus Foundation.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * Import description entry.
21 | *
22 | * @author bob mcwhirter
23 | */
24 | class Entry
25 | implements Comparablenull
.
68 | * @return true
if this entry matches the
69 | * classname, otherwise false
.
70 | */
71 | boolean matches( String name )
72 | {
73 | String pkg = getPackageName();
74 |
75 | if ( pkg.endsWith( ".*" ) )
76 | {
77 | String pkgName;
78 |
79 | if ( name.indexOf( '/' ) < 0 )
80 | {
81 | // a binary class name, e.g. java.lang.Object
82 |
83 | int index = name.lastIndexOf( '.' );
84 | pkgName = ( index < 0 ) ? "" : name.substring( 0, index );
85 | }
86 | else
87 | {
88 | // a resource name, e.g. java/lang/Object.class
89 |
90 | int index = name.lastIndexOf( '/' );
91 | pkgName = ( index < 0 ) ? "" : name.substring( 0, index ).replace( '/', '.' );
92 | }
93 |
94 | return pkgName.length() == pkg.length() - 2 && pkg.regionMatches( 0, pkgName, 0, pkgName.length() );
95 | }
96 | else if ( pkg.length() > 0 )
97 | {
98 | if ( name.indexOf( '/' ) < 0 )
99 | {
100 | // a binary class name, e.g. java.lang.Object
101 |
102 | if ( name.startsWith( pkg ) )
103 | {
104 | if ( name.length() == pkg.length() )
105 | {
106 | // exact match of class name
107 | return true;
108 | }
109 | else if ( name.charAt( pkg.length() ) == '.' )
110 | {
111 | // prefix match of package name
112 | return true;
113 | }
114 | else if ( name.charAt( pkg.length() ) == '$' )
115 | {
116 | // prefix match of enclosing type
117 | return true;
118 | }
119 | }
120 | }
121 | else
122 | {
123 | // a resource name, e.g. java/lang/Object.class
124 |
125 | if ( name.equals( pkg ) )
126 | {
127 | // exact match of resource name
128 | return true;
129 | }
130 |
131 | pkg = pkg.replace( '.', '/' );
132 |
133 | if ( name.startsWith( pkg ) && name.length() > pkg.length() )
134 | {
135 | if ( name.charAt( pkg.length() ) == '/' )
136 | {
137 | // prefix match of package directory
138 | return true;
139 | }
140 | else if ( name.charAt( pkg.length() ) == '$' )
141 | {
142 | // prefix match of nested class file
143 | return true;
144 | }
145 | else if ( name.length() == pkg.length() + 6 && name.endsWith( ".class" ) )
146 | {
147 | // exact match of class file
148 | return true;
149 | }
150 | }
151 | }
152 |
153 | return false;
154 | }
155 | else
156 | {
157 | return true;
158 | }
159 | }
160 |
161 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 | // java.lang.Comparable
163 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
164 |
165 | /**
166 | * Compare this entry to another for relative ordering.
167 | *
168 | *
169 | * The natural ordering of Entry objects is reverse-alphabetical
170 | * based upon package name.
171 | *
172 | *
173 | * @param thatObj The object to compare.
174 | * @return -1 if this object sorts before that object, 0
175 | * if they are equal, or 1 if this object sorts
176 | * after that object.
177 | */
178 | public int compareTo( Entry that )
179 | {
180 | // We are reverse sorting this list, so that
181 | // we get longer matches first:
182 | //
183 | // com.werken.foo.bar
184 | // com.werken.foo
185 | // com.werken
186 |
187 | return - ( getPackageName().compareTo( that.getPackageName() ) );
188 | }
189 |
190 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
191 | // java.lang.Object
192 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193 |
194 | /**
195 | * Test this entry for equality to another.
196 | *
197 | *
198 | * Consistent with {@link #compareTo}, this method tests
199 | * for equality purely on the package name.
200 | *
201 | *
202 | * @param thatObj The object to compare
203 | * @return true
if the two objects are
204 | * semantically equivalent, otherwise false
.
205 | */
206 | public boolean equals( Object thatObj )
207 | {
208 | Entry that = (Entry) thatObj;
209 |
210 | return getPackageName().equals( that.getPackageName() );
211 | }
212 |
213 | /**
214 | *
215 | * Consistent with {@link #equals}, this method creates a hashCode
216 | * based on the packagename.
217 | *
218 | */
219 | public int hashCode()
220 | {
221 | return getPackageName().hashCode();
222 | }
223 |
224 | public String toString()
225 | {
226 | return "Entry[import " + getPackageName() + " from realm " + getClassLoader() + "]";
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/realm/NoSuchRealmException.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.realm;
2 |
3 | import org.codehaus.plexus.classworlds.ClassWorld;
4 | import org.codehaus.plexus.classworlds.ClassWorldException;
5 |
6 | /*
7 | * Copyright 2001-2006 Codehaus Foundation.
8 | *
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | */
21 |
22 | /**
23 | * Indicates an attempt to retrieve a ClassRealm
from a
24 | * ClassWorld
with an invalid id.
25 | *
26 | * @author bob mcwhirter
27 | */
28 | public class NoSuchRealmException
29 | extends ClassWorldException
30 | {
31 | // ------------------------------------------------------------
32 | // Instance members
33 | // ------------------------------------------------------------
34 |
35 | /**
36 | * The realm id.
37 | */
38 | private String id;
39 |
40 | // ------------------------------------------------------------
41 | // Constructors
42 | // ------------------------------------------------------------
43 |
44 | /**
45 | * Construct.
46 | *
47 | * @param world The world.
48 | * @param id The realm id.
49 | */
50 | public NoSuchRealmException( ClassWorld world, String id )
51 | {
52 | super( world, id );
53 | this.id = id;
54 | }
55 |
56 | // ------------------------------------------------------------
57 | // Instance methods
58 | // ------------------------------------------------------------
59 |
60 | /**
61 | * Retrieve the invalid realm id.
62 | *
63 | * @return The id.
64 | */
65 | public String getId()
66 | {
67 | return this.id;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/plexus/classworlds/strategy/AbstractStrategy.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.plexus.classworlds.strategy;
2 |
3 | import java.net.URL;
4 | import java.util.Collection;
5 | import java.util.Collections;
6 | import java.util.Enumeration;
7 | import java.util.LinkedHashSet;
8 |
9 | import org.codehaus.plexus.classworlds.UrlUtils;
10 | import org.codehaus.plexus.classworlds.realm.ClassRealm;
11 |
12 | /*
13 | * Copyright 2001-2006 Codehaus Foundation.
14 | *
15 | * Licensed under the Apache License, Version 2.0 (the "License");
16 | * you may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at
18 | *
19 | * http://www.apache.org/licenses/LICENSE-2.0
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an "AS IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | */
27 |
28 | /**
29 | * @author Jason van Zyl
30 | */
31 | public abstract class AbstractStrategy
32 | implements Strategy
33 | {
34 |
35 | protected ClassRealm realm;
36 |
37 | public AbstractStrategy( ClassRealm realm )
38 | {
39 | this.realm = realm;
40 | }
41 |
42 | protected String getNormalizedResource( String name )
43 | {
44 | return UrlUtils.normalizeUrlPath( name );
45 | }
46 |
47 | protected Enumeration