You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2012/07/05 04:48:38 UTC
svn commit: r1357447 [1/4] - in /commons/sandbox/classscan/trunk: ./ api/
api/src/ api/src/main/ api/src/main/java/ api/src/main/java/org/
api/src/main/java/org/apache/ api/src/main/java/org/apache/commons/
api/src/main/java/org/apache/commons/classsca...
Author: chas
Date: Thu Jul 5 02:48:34 2012
New Revision: 1357447
URL: http://svn.apache.org/viewvc?rev=1357447&view=rev
Log:
added service providers for URL handling, ClassLoader inspection, and Class digestion
Added:
commons/sandbox/classscan/trunk/LICENSE.txt
commons/sandbox/classscan/trunk/NOTICE.txt
commons/sandbox/classscan/trunk/api/
commons/sandbox/classscan/trunk/api/pom.xml
commons/sandbox/classscan/trunk/api/src/
commons/sandbox/classscan/trunk/api/src/main/
commons/sandbox/classscan/trunk/api/src/main/java/
commons/sandbox/classscan/trunk/api/src/main/java/org/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPath.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/HasName.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassLoader.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaRegistry.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ResourceFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapClassPath.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapMetaClassLoader.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassFileIterator.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassNameHelper.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultArrayType.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathElementFactory.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathFactory.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaRegistry.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileResourceFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarResourceFile.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/PrimitiveClass.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/UrlClassPath.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/UrlMetaClassLoader.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/package-info.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaAnnotation.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaArray.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaClass.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaField.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaMethod.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaParameter.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/MetaType.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/model/package-info.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/package-info.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/ClassDigesterFactory.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/ClassPathElementFactory.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/ClassPathFactory.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/HasResolve.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiClassDigester.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiClassPath.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaAnnotation.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaArray.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaClass.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaClassLoader.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaClassPathElement.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaField.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaMethod.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaParameter.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/SpiMetaRegistry.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/model/package-info.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/spi/package-info.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/CallStack.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/FactoryCache.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/NameSet.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/ReadOnlySet.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/ReapingHashMap.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/ResolveSet.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/ServiceVisitor.java
commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/util/package-info.java
commons/sandbox/classscan/trunk/api/src/main/resources/
commons/sandbox/classscan/trunk/api/src/main/resources/META-INF/
commons/sandbox/classscan/trunk/api/src/main/resources/META-INF/services/
commons/sandbox/classscan/trunk/api/src/main/resources/META-INF/services/org.apache.commons.classscan.spi.ClassPathElementFactory
commons/sandbox/classscan/trunk/api/src/main/resources/META-INF/services/org.apache.commons.classscan.spi.ClassPathFactory
commons/sandbox/classscan/trunk/api/src/test/
commons/sandbox/classscan/trunk/api/src/test/java/
commons/sandbox/classscan/trunk/api/src/test/java/org/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/AnnotationAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/ConstructorAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/FieldAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/MethodAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/ParameterAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/TestEnum.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/annotations/TypeAnnotation.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/classes/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/classes/BadPackage.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/classes/FullInterface.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/classes/FullyDecorated.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/test/classes/ValidateFullyDecorated.java
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/util/
commons/sandbox/classscan/trunk/api/src/test/java/org/apache/commons/classscan/util/ReapingHashMapTest.java
commons/sandbox/classscan/trunk/api/src/test/resources/
commons/sandbox/classscan/trunk/api/src/test/resources/META-INF/
commons/sandbox/classscan/trunk/api/src/test/resources/META-INF/services/
commons/sandbox/classscan/trunk/api/src/test/resources/META-INF/services/org.apache.commons.classscan.test.classes.FullInterface
commons/sandbox/classscan/trunk/api/src/test/resources/logback.xml
commons/sandbox/classscan/trunk/api/src/test/resources/org/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/classscan/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/classscan/test/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/classscan/test/classes/
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/classscan/test/classes/--InvalidClassName--.class
commons/sandbox/classscan/trunk/api/src/test/resources/org/apache/commons/classscan/test/classes/NotAClass.class
commons/sandbox/classscan/trunk/bcel/
commons/sandbox/classscan/trunk/bcel/pom.xml
commons/sandbox/classscan/trunk/bcel/src/
commons/sandbox/classscan/trunk/bcel/src/main/
commons/sandbox/classscan/trunk/bcel/src/main/java/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/AnnotationMap.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelAnnotation.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelClass.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelClassDigesterFactory.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelEnumProperty.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelField.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelMethod.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelParameter.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/BcelProperty.java
commons/sandbox/classscan/trunk/bcel/src/main/java/org/apache/commons/classscan/bcel/package-info.java
commons/sandbox/classscan/trunk/bcel/src/main/resources/
commons/sandbox/classscan/trunk/bcel/src/main/resources/META-INF/
commons/sandbox/classscan/trunk/bcel/src/main/resources/META-INF/services/
commons/sandbox/classscan/trunk/bcel/src/main/resources/META-INF/services/org.apache.commons.classscan.spi.ClassDigesterFactory
commons/sandbox/classscan/trunk/bcel/src/test/
commons/sandbox/classscan/trunk/bcel/src/test/java/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/bcel/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/bcel/BcelClassTest.java
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/bcel/PrimitiveClassTest.java
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/builtin/
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElementTest.java
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/builtin/UrlClassPathTest.java
commons/sandbox/classscan/trunk/bcel/src/test/java/org/apache/commons/classscan/builtin/UrlMetaClassLoaderTest.java
commons/sandbox/classscan/trunk/bcel/src/test/resources/
commons/sandbox/classscan/trunk/parent/
commons/sandbox/classscan/trunk/parent/pom.xml
commons/sandbox/classscan/trunk/pom.xml
commons/sandbox/classscan/trunk/src/
commons/sandbox/classscan/trunk/src/site/
commons/sandbox/classscan/trunk/src/site/site.xml
commons/sandbox/classscan/trunk/src/site/xdoc/
commons/sandbox/classscan/trunk/src/site/xdoc/building.xml
commons/sandbox/classscan/trunk/src/site/xdoc/index.xml
commons/sandbox/classscan/trunk/src/site/xdoc/userguide.xml
Removed:
commons/sandbox/classscan/trunk/impl-xbf/
Added: commons/sandbox/classscan/trunk/LICENSE.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/LICENSE.txt?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/LICENSE.txt (added)
+++ commons/sandbox/classscan/trunk/LICENSE.txt Thu Jul 5 02:48:34 2012
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: commons/sandbox/classscan/trunk/NOTICE.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/NOTICE.txt?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/NOTICE.txt (added)
+++ commons/sandbox/classscan/trunk/NOTICE.txt Thu Jul 5 02:48:34 2012
@@ -0,0 +1,5 @@
+Apache Commons ClassScan
+Copyright 2012 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
Added: commons/sandbox/classscan/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/pom.xml?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/pom.xml (added)
+++ commons/sandbox/classscan/trunk/api/pom.xml Thu Jul 5 02:48:34 2012
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.commons.classscan</groupId>
+ <artifactId>api</artifactId>
+ <name>ClassScan Application Programming Interface</name>
+ <version>0.2-SNAPSHOT</version>
+ <description>The interface to obtain information about class(es) before the jvm loads the class</description>
+
+ <parent>
+ <groupId>org.apache.commons.classscan</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <build>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+</project>
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassFile.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassFile.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassFile.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,25 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+/**
+ * Information about and access to a location that contains a class.
+ */
+public interface ClassFile extends ResourceFile {
+ /**
+ * Get the name of the class
+ * @return The canonical class name; or null, if not a valid class
+ */
+ String getClassName();
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPath.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPath.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPath.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Information about a ClassPath.
+ * A ClassPath specifies a list of ClassElement(s).
+ * A ClassElement specifies a list of ClassFiles(s).
+ */
+public interface ClassPath {
+ /**
+ * Get the collection of file base locations specified by this instance
+ */
+ List<? extends ClassPathElement> getClassPathElements();
+
+ /**
+ * Get files with a particular name
+ *
+ * @param fileName The name of the desired file (this may be a path such as META-INF/resources/com.example.group.interface)
+ * @return A Map of base locations as the keys and absolute file locations as the values
+ */
+ Map<ClassPathElement, ResourceFile> getResources(String fileName);
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPathElement.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPathElement.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPathElement.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ClassPathElement.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,43 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import java.net.URL;
+import java.util.Iterator;
+
+/**
+ * A single location in a ClassPath. The location might be a jar or a directory.
+ * In enterprise application environments, the location might be an exploded ear or a war.
+ */
+public interface ClassPathElement extends Iterable<ClassFile> {
+ /**
+ * Get a Iterator over the files specified by this instance
+ */
+ @Override
+ Iterator<ClassFile> iterator();
+
+ /**
+ * Get the location of the class bytes.
+ * This value is intended to be used as an argument to the {@link URL#URL(String) URL constructor}.
+ */
+ String getLocation();
+
+ /**
+ * Get a file with a particular name
+ *
+ * @param fileName The name of the desired file (this may be a path such as META-INF/resources/com.example.group.interface)
+ * @return null, if not found; otherwise the ResourceFile
+ */
+ ResourceFile getResource(String fileName);
+}
\ No newline at end of file
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/HasName.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/HasName.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/HasName.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/HasName.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,24 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+/**
+ * This marker interface indicates that instances have a name.
+ */
+public interface HasName {
+ /**
+ * Get the name of the instance
+ */
+ String getName();
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassLoader.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassLoader.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassLoader.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassLoader.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,91 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.classscan.model.MetaClass;
+
+/**
+ * Metadata about a ClassLoader. This includes the jars that a ClassLoader loads
+ * from and the Classes that are potentially available.
+ */
+public interface MetaClassLoader {
+ /**
+ * Get the metadata about the parent of the associated ClassLoader.
+ *
+ * @return The parent metadata. This will be null if the associated
+ * ClassLoader is the primordial ClassLoader.
+ */
+ MetaClassLoader getParent();
+
+ /**
+ * Get metadata about the locations from which the associated ClassLoader
+ * loads Classes.
+ *
+ * @return A read-only set of code locations
+ */
+ Collection<? extends MetaClassPathElement> getClassLocations();
+
+ /**
+ * Get metadata about a class locations
+ *
+ * @param codeLocation
+ * The location of a folder, jar, or compressed code
+ */
+ MetaClassPathElement getClassLocation(String codeLocation);
+
+ /**
+ * Get metadata about the Classes from which the associated ClassLoader can
+ * load.
+ *
+ * @return A read-only set of class information
+ */
+ Iterator<? extends MetaClass> getMetaClasses();
+
+ /**
+ * Get metadata about a particular Class. This method will return only
+ * classes defined by the associated ClassLoader. Classes defined by a
+ * parent ClassLoader can be found using {@link #findMetaClass}.
+ *
+ * @param className
+ * The name of the Class
+ * @return The metadata about the Class; or null, if the class was not
+ * available to the associated ClassLoader
+ */
+ MetaClass getMetaClass(String className);
+
+ /**
+ * Find metadata about a particular Class. This method will first search up
+ * the associated parent ClassLoader chain.
+ *
+ * @param className
+ * The name of the Class
+ * @return The metadata about the Class; or null, if the class was not
+ * available to the associated ClassLoader not its parent chain
+ */
+ MetaClass findMetaClass(String className);
+
+ /**
+ * Find all the implementors of an interface class. This method will search
+ * in the associated ClassLoader and all parents.
+ *
+ * @param interfaceToFind
+ * The non-null MetaClass associated with the
+ *
+ * @return All discovered implementors of the desired interface
+ */
+ Collection<? extends MetaClass> findAllImplementors(String interfaceToFind);
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassPathElement.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassPathElement.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassPathElement.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaClassPathElement.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import java.util.Collection;
+
+import org.apache.commons.classscan.model.MetaClass;
+
+/**
+ * Information about a code location. A code location may be a file folder, or a
+ * jar, or other packaged location
+ */
+public interface MetaClassPathElement extends HasName {
+ /**
+ * Get metadata about the Classes which are available in the code location.
+ *
+ * @return A read-only collection of class information
+ */
+ Collection<? extends MetaClass> getMetaClasses();
+
+ /**
+ * Get metadata about a Class which is available in the code location.
+ *
+ * @param className
+ * The canonical className of the desired Class
+ * @return The class information; or null, if class of given name not
+ * available at this location
+ */
+ MetaClass getMetaClass(String className);
+
+ /**
+ * Get the name of the location of the jar or folder. This name can be used as the parameter
+ * to the {@link java.net.URI URI} or {@link java.net.URL URL} constructor.
+ */
+ String getName();
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaRegistry.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaRegistry.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaRegistry.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/MetaRegistry.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,46 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import org.apache.commons.classscan.builtin.DefaultMetaRegistry;
+
+/**
+ * The entry point from which to find information about the ClassPath and the classes
+ * available from the ClassPath.
+ */
+public interface MetaRegistry {
+
+ public static final MetaRegistry DEFAULT_REGISTRY = new DefaultMetaRegistry();
+
+ /**
+ * Get the MetaClassLoader for a ClassLoader. If possible, an existing
+ * MetaClassLoader is returned. Otherwise, the MetaClassLoader is created.
+ *
+ * @param classLoader
+ * The ClassLoader for which metadata is desired (may be be null,
+ * for the bootstrap ClassLoader)
+ * @return The metadata about a ClassLoader
+ */
+ MetaClassLoader getMetaClassLoader(ClassLoader classLoader);
+
+ /**
+ * Get the ClassPath for a ClassLoader
+ *
+ * @param classLoader
+ * The ClassLoader for which metadata is desired (may be be null,
+ * for the bootstrap ClassLoader)
+ * @return The ClassPath for the ClassLoader
+ */
+ ClassPath getClassPath(ClassLoader classLoader);
+}
\ No newline at end of file
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ResourceFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ResourceFile.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ResourceFile.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/ResourceFile.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Information about and access to a location that contains a class or a resource.
+ * <br/>
+ * IMPORTANT: Do not hold onto instances. There maybe open file or network resources associated with these instances.
+ */
+public interface ResourceFile {
+ /**
+ * Get the relative file name;
+ * @return The resource name relative to the ClassPathElement base
+ */
+ String getFileName();
+
+ /**
+ * Get the stream of bytes for the resource.
+ *
+ * @return The InputStream to read resource bytes. This stream should be closed when all bytes have been read.
+ */
+ InputStream getBytes() throws IOException;
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapClassPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapClassPath.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapClassPath.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapClassPath.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,87 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.commons.classscan.ClassPathElement;
+import org.apache.commons.classscan.ResourceFile;
+import org.apache.commons.classscan.spi.model.SpiClassPath;
+import org.apache.commons.classscan.spi.model.SpiClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaClassLoader;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BootstrapClassPath implements SpiClassPath {
+
+ private static final Logger logger = LoggerFactory.getLogger(BootstrapClassPath.class);
+
+ static Pattern PATH_SPLITTER = Pattern.compile(File.pathSeparator);
+
+ private final SpiMetaRegistry registry;
+
+ public BootstrapClassPath(SpiMetaRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Override
+ public List<? extends ClassPathElement> getClassPathElements() {
+ return getBootstrapLocations();
+ }
+
+ private List<SpiClassPathElement> getBootstrapLocations() {
+ List<SpiClassPathElement> locations= new ArrayList<SpiClassPathElement>();
+ for(String element : parseBootstrapClassPathValues()) {
+ try {
+ SpiClassPathElement location = checkLocation(element);
+ if(location!=null) {
+ locations.add(location);
+ }
+ } catch (IOException e) {
+ logger.info("Bootstrap Classpath element "+element+" ignored", e);
+ }
+ }
+ return locations;
+ }
+
+ String[] parseBootstrapClassPathValues() {
+ return PATH_SPLITTER.split(System.getProperty("sun.boot.class.path"));
+ }
+
+ private SpiClassPathElement checkLocation(String element) throws IOException {
+ File location = new File(element);
+ return registry.createClassPathElement(location.toURI().toURL());
+ }
+
+ @Override
+ public SpiMetaClassLoader createMetaClassLoader(SpiMetaRegistry registry, ClassLoader classLoader) {
+ if(classLoader!=null) {
+ throw new IllegalArgumentException("BootStrap ClassLoader should be null");
+ }
+
+ return new BootstrapMetaClassLoader(registry);
+ }
+
+ @Override
+ public Map<ClassPathElement, ResourceFile> getResources(String fileName) {
+ return Collections.emptyMap();
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapMetaClassLoader.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapMetaClassLoader.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapMetaClassLoader.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/BootstrapMetaClassLoader.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,78 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.util.Collection;
+
+import org.apache.commons.classscan.model.MetaClass;
+import org.apache.commons.classscan.spi.model.SpiMetaClassLoader;
+import org.apache.commons.classscan.spi.model.SpiMetaClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+import org.apache.commons.classscan.util.NameSet;
+
+public class BootstrapMetaClassLoader extends UrlMetaClassLoader {
+
+ BootstrapMetaClassLoader(SpiMetaRegistry registry) {
+ super(registry, null);
+ }
+
+ @Override
+ void addLocations(SpiMetaRegistry registry, ClassLoader classLoader) {
+ SpiMetaClassPathElement primitives= getPrimitiveClassPathElement();
+ addLocation(primitives);
+ super.addLocations(registry, classLoader);
+ }
+
+ private SpiMetaClassPathElement getPrimitiveClassPathElement() {
+ final NameSet<PrimitiveClass> primitives = new NameSet<PrimitiveClass>(PrimitiveClass.values());
+
+ return new SpiMetaClassPathElement() {
+
+ @Override
+ public Collection<? extends MetaClass> getMetaClasses() {
+ return primitives;
+ }
+
+ @Override
+ public MetaClass getMetaClass(String className) {
+ return primitives.getValue(className);
+ }
+
+ @Override
+ public String getName() {
+ return "<builtin-primitives>";
+ }
+
+ @Override
+ public boolean resolve(SpiMetaClassLoader classLoader) {
+ return true;
+ }
+
+ @Override
+ public MetaClass resolveMetaClass(SpiMetaClassLoader classLoader, String className) {
+ return primitives.getValue(className);
+ }
+ };
+ }
+
+ @Override
+ public MetaClass findMetaClass(String className) {
+ return getMetaClass(className);
+ }
+
+ @Override
+ public MetaClass resolveMetaClass(String className) {
+ return resolveInPath(className);
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassFileIterator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassFileIterator.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassFileIterator.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassFileIterator.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.commons.classscan.ClassFile;
+
+public abstract class ClassFileIterator implements Iterator<ClassFile> {
+
+ private ClassFile prefetch;
+
+ abstract ClassFile getNext();
+
+ @Override
+ public boolean hasNext() {
+ if(prefetch==null) {
+ prefetch= getNext();
+ }
+ return prefetch!=null;
+ }
+
+ @Override
+ public ClassFile next() {
+ if(prefetch!=null) {
+ ClassFile rc= prefetch;
+ prefetch= null;
+ return rc;
+ }
+ ClassFile rc= getNext();
+ if(rc==null) {
+ throw new NoSuchElementException();
+ }
+ return rc;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
\ No newline at end of file
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassNameHelper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassNameHelper.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassNameHelper.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/ClassNameHelper.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,100 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Classname helper methods
+ */
+public final class ClassNameHelper {
+ private ClassNameHelper() {
+ }
+
+ private static final String IDENTIFIER_REGEX = "\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*";
+ private static final String FILE_REGEX = "(" + IDENTIFIER_REGEX + ")\\.class";
+
+ private static final String PATH_REGEX = "((" + IDENTIFIER_REGEX + "/)*)" + FILE_REGEX;
+ private static Pattern pathPattern = Pattern.compile(PATH_REGEX);
+
+ /**
+ * Check if supplied path name is a valid pathed file name. The path must
+ * contain valid package names, the file name must be a valid Class name,
+ * and must be followed by ".class"
+ *
+ * @param path
+ * A file name with path
+ * @return The class name without the trailing ".class", with the dotted
+ * package prefix, or null if the supplied filename is invalid
+ */
+ public static String getCannonicalClassNameFromPathName(String path) {
+ Matcher m = pathPattern.matcher(path);
+ if (m.matches()) {
+ String packagePrefix = m.group(1).replace('/', '.');
+ String className = m.group(3);
+ return packagePrefix + className;
+ }
+ else {
+ return null;
+ }
+ }
+
+ private static Pattern IDENTIFIER_PACKAGE = Pattern.compile(IDENTIFIER_REGEX);
+
+ /**
+ * Check if supplied name is a valid java package name portion or class
+ * identifier.
+ *
+ * @param identifier
+ * The name of a package file
+ * @return true if the identifier is a valid part of a package or class name
+ */
+ public static boolean isValidIdentifier(String identifier) {
+ Matcher ipm = IDENTIFIER_PACKAGE.matcher(identifier);
+ return ipm.matches();
+ }
+
+ private static Pattern filePattern = Pattern.compile(FILE_REGEX);
+
+ /**
+ * Check if supplied file name is a valid class file name. The name must be
+ * a valid Class name followed by ".class"
+ *
+ * @param fileName
+ * The name of a file (without path)
+ * @return The class name without the trailing ".class", or null if the
+ * supplied filename is invalid
+ */
+ public static String getClassNameFromFileName(String fileName) {
+ Matcher fpm = filePattern.matcher(fileName);
+ if (fpm.matches()) {
+ return fpm.group(1);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Get the canonical name from the internal name
+ *
+ * @param internalName
+ * The internal name in the form Ljava/lang/Object;
+ * @return The canonical name in the form java.lang.Object
+ */
+ public static String internalToCanonicalName(String internalName) {
+ return internalName.substring(1, internalName.length() - 1).replace('/', '.');
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultArrayType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultArrayType.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultArrayType.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultArrayType.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import org.apache.commons.classscan.model.MetaArray;
+import org.apache.commons.classscan.model.MetaType;
+
+public class DefaultArrayType implements MetaArray {
+
+ private final MetaType arrayType;
+
+ public DefaultArrayType(MetaType arrayType) {
+ this.arrayType = arrayType;
+ }
+
+ @Override
+ public MetaType getArrayType() {
+ return arrayType;
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathElementFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathElementFactory.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathElementFactory.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathElementFactory.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,62 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.classscan.MetaRegistry;
+import org.apache.commons.classscan.spi.ClassPathElementFactory;
+import org.apache.commons.classscan.spi.model.SpiClassPathElement;
+
+public class DefaultClassPathElementFactory implements ClassPathElementFactory {
+
+ @Override
+ public SpiClassPathElement getClassPathElement(MetaRegistry metaRegistry, URL url) throws IOException {
+ String scheme= url.getProtocol();
+ if(scheme.equals("file")) {
+ try {
+ return createFileClassPathElement(url);
+ } catch (URISyntaxException e) {
+ FileNotFoundException ex = new FileNotFoundException(url.toExternalForm()+" not found");
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+ else if(scheme.equals("jar")) {
+ return new JarClassPathElement(url);
+ }
+
+ return null;
+ }
+
+ private SpiClassPathElement createFileClassPathElement(URL url) throws IOException, URISyntaxException {
+ File location = new File(url.toURI());
+ if (!location.canRead()) {
+ throw new FileNotFoundException(location + " can not be read");
+ }
+
+ if (location.isDirectory()) {
+ return new FileClassPathElement(location);
+ }
+
+ URI fileUri = location.toURI();
+ URI jarURI = new URI("jar:" + fileUri.toString() + "!/");
+ return new JarClassPathElement(jarURI.toURL());
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathFactory.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathFactory.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultClassPathFactory.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.net.URLClassLoader;
+
+import org.apache.commons.classscan.spi.ClassPathFactory;
+import org.apache.commons.classscan.spi.model.SpiClassPath;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+
+public class DefaultClassPathFactory implements ClassPathFactory {
+
+ @Override
+ public SpiClassPath getClassPath(SpiMetaRegistry registry, ClassLoader classLoader) {
+ if(classLoader == null) {
+ return new BootstrapClassPath(registry);
+ }
+ if(classLoader instanceof URLClassLoader) {
+ return new UrlClassPath(registry, (URLClassLoader) classLoader);
+ }
+ return null;
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElement.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElement.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElement.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaClassPathElement.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,124 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.classscan.ClassPathElement;
+import org.apache.commons.classscan.ClassFile;
+import org.apache.commons.classscan.model.MetaClass;
+import org.apache.commons.classscan.spi.model.SpiMetaClass;
+import org.apache.commons.classscan.spi.model.SpiMetaClassLoader;
+import org.apache.commons.classscan.spi.model.SpiMetaClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+import org.apache.commons.classscan.util.NameSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultMetaClassPathElement implements SpiMetaClassPathElement {
+
+ private static final Logger logger = LoggerFactory.getLogger(DefaultMetaClassPathElement.class);
+
+ private final String baseUrl;
+ private Map<String, SpiMetaClass> workClasses = new HashMap<String, SpiMetaClass>();
+ private NameSet<SpiMetaClass> sealedClasses;
+
+ public DefaultMetaClassPathElement(SpiMetaRegistry metaRegistry, ClassPathElement classPathElement) {
+ this.baseUrl = classPathElement.getLocation();
+
+ for(ClassFile classPathFile : classPathElement) {
+ addFile(metaRegistry, classPathFile);
+ }
+ }
+
+ private void addFile(SpiMetaRegistry metaRegistry, ClassFile classPathFile) {
+ String className = classPathFile.getClassName();
+ try {
+ InputStream byteStream = classPathFile.getBytes();
+ try {
+ SpiMetaClass mc= metaRegistry.createMetaClass(this, className, byteStream);
+ addMetaClass(mc);
+ }
+ finally {
+ byteStream.close();
+ }
+ } catch (Exception e) {
+ logger.info("Exception while loading "+className, e);
+ }
+ }
+
+ void addMetaClass(SpiMetaClass mc) {
+ String name= mc.getName();
+ if (workClasses.containsKey(name)) {
+ return;
+ }
+ workClasses.put(name, mc);
+ }
+
+ @Override
+ public boolean resolve(SpiMetaClassLoader classLoader) {
+ if( workClasses.isEmpty() ) {
+ sealedClasses = NameSet.emptyNameSet();
+ }
+ else {
+ Iterator<Map.Entry<String, SpiMetaClass>> metaClasses = workClasses.entrySet().iterator();
+ while(metaClasses.hasNext()) {
+ Map.Entry<String, SpiMetaClass> entry = metaClasses.next();
+ if(!entry.getValue().resolve(classLoader)) {
+ logger.info("Could not resolve dependencies of "+entry.getKey());
+ metaClasses.remove();
+ }
+ }
+ sealedClasses = new NameSet<SpiMetaClass>(SpiMetaClass.class, workClasses.values());
+ }
+
+ workClasses = null;
+ if( sealedClasses.isEmpty() ) {
+ logger.info("No classes in "+baseUrl);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public MetaClass resolveMetaClass(SpiMetaClassLoader classLoader, String className) {
+ if(workClasses==null) {
+ return sealedClasses.getValue(className);
+ }
+ SpiMetaClass workClass = workClasses.get(className);
+ if( workClass != null && workClass.resolve(classLoader) ) {
+ return workClass;
+ }
+ return null;
+ }
+
+ @Override
+ public Collection<? extends MetaClass> getMetaClasses() {
+ return sealedClasses;
+ }
+
+ @Override
+ public MetaClass getMetaClass(String className) {
+ return sealedClasses.getValue(className);
+ }
+
+ @Override
+ public String getName() {
+ return baseUrl;
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaRegistry.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaRegistry.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaRegistry.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/DefaultMetaRegistry.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,144 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+import java.util.ServiceConfigurationError;
+
+import org.apache.commons.classscan.ClassPathElement;
+import org.apache.commons.classscan.MetaClassLoader;
+import org.apache.commons.classscan.MetaClassPathElement;
+import org.apache.commons.classscan.spi.ClassDigesterFactory;
+import org.apache.commons.classscan.spi.ClassPathElementFactory;
+import org.apache.commons.classscan.spi.ClassPathFactory;
+import org.apache.commons.classscan.spi.model.SpiClassDigester;
+import org.apache.commons.classscan.spi.model.SpiClassPath;
+import org.apache.commons.classscan.spi.model.SpiClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaClass;
+import org.apache.commons.classscan.spi.model.SpiMetaClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+import org.apache.commons.classscan.util.FactoryCache;
+import org.apache.commons.classscan.util.ReapingHashMap;
+import org.apache.commons.classscan.util.ServiceVisitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The factory for MetaClassLoaders. Wherever possible, an existing
+ * MetaClassLoader is returned for a ClassLoader. The implementation should not
+ * prevent the garbage collection of a ClassLoader.
+ */
+public class DefaultMetaRegistry implements SpiMetaRegistry {
+
+ private static final Logger logger = LoggerFactory.getLogger(DefaultMetaRegistry.class);
+
+ private final Map<ClassLoader, MetaClassLoader> metaClassLoaders;
+ private final FactoryCache<ClassPathFactory> classPathFactories;
+ private final FactoryCache<ClassPathElementFactory> classPathElementFactories;
+ private SpiClassDigester classDigester;
+
+ public DefaultMetaRegistry() {
+ metaClassLoaders = new ReapingHashMap<ClassLoader, MetaClassLoader>();
+ ClassLoader classLoader = getClass().getClassLoader();
+ classPathFactories = new FactoryCache<ClassPathFactory>(ClassPathFactory.class, classLoader);
+ classPathElementFactories = new FactoryCache<ClassPathElementFactory>(ClassPathElementFactory.class, classLoader);
+
+ findClassDigester(classLoader);
+ }
+
+ private void findClassDigester(ClassLoader classLoader) {
+ new ServiceVisitor<ClassDigesterFactory>() {
+ @Override
+ protected boolean visit(ClassDigesterFactory factory) {
+ try {
+ classDigester= factory.createDigester(DefaultMetaRegistry.this);
+ return false;
+ }
+ catch(Throwable error) {
+ logger.warn("Ignoring configuration error", error);
+ return true;
+ }
+ }
+ }.visitProviders(ClassDigesterFactory.class, classLoader);
+
+ if(classDigester==null) {
+ throw new ServiceConfigurationError("Could not load a ClassDigester");
+ }
+ }
+
+ @Override
+ public MetaClassLoader getMetaClassLoader(ClassLoader classLoader) {
+ synchronized(metaClassLoaders) {
+ MetaClassLoader mcl = metaClassLoaders.get(classLoader);
+ if (mcl == null) {
+ mcl = createMetaClassLoader(classLoader);
+ metaClassLoaders.put(classLoader, mcl);
+ }
+ return mcl;
+ }
+ }
+
+ public MetaClassLoader createMetaClassLoader(ClassLoader classLoader) {
+ SpiClassPath cp= getClassPath(classLoader);
+ return cp.createMetaClassLoader(this, classLoader);
+ }
+
+ @Override
+ public SpiClassPath getClassPath(ClassLoader classLoader) {
+
+ for(ClassPathFactory factory : classPathFactories) {
+ SpiClassPath cp= factory.getClassPath(this, classLoader);
+ if(cp!=null) {
+ return cp;
+ }
+ }
+
+ throw new IllegalArgumentException("No ClassPathFactory found for ClassLoader "+classLoader);
+ }
+
+ @Override
+ public SpiClassPathElement createClassPathElement(URL url) throws IOException {
+
+ for(ClassPathElementFactory factory : classPathElementFactories) {
+ SpiClassPathElement cp= factory.getClassPathElement(this, url);
+ if(cp!=null) {
+ return cp;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public SpiMetaClassPathElement createMetaClassPathElement(ClassPathElement pathElement) {
+ return new DefaultMetaClassPathElement(this, pathElement);
+ }
+
+ @Override
+ public SpiMetaClass createMetaClass(MetaClassPathElement location, String className, InputStream byteStream) throws IOException {
+ try {
+ SpiMetaClass smc = classDigester.createMetaClass(location, className, byteStream);
+ if (!className.equals(smc.getName())) {
+ throw new IllegalArgumentException("Expecting classname " + className + " but found " + smc.getName());
+ }
+ return smc;
+ }
+ finally {
+ byteStream.close();
+ }
+ }
+}
\ No newline at end of file
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassFile.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassFile.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassFile.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.File;
+
+import org.apache.commons.classscan.ClassFile;
+
+public class FileClassFile extends FileResourceFile implements ClassFile {
+
+ public FileClassFile(File location, String relativePath) {
+ super(location, relativePath);
+ }
+
+ @Override
+ public String getClassName() {
+ String name= getFileName();
+ return ClassNameHelper.getCannonicalClassNameFromPathName(name);
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassPathElement.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassPathElement.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassPathElement.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileClassPathElement.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,123 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CODITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.classscan.builtin;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.classscan.ClassFile;
+import org.apache.commons.classscan.ResourceFile;
+import org.apache.commons.classscan.spi.model.SpiClassPathElement;
+import org.apache.commons.classscan.spi.model.SpiMetaRegistry;
+
+public class FileClassPathElement implements SpiClassPathElement {
+
+ private final File baseLocation;
+
+ FileClassPathElement(File baseLocation) {
+ this.baseLocation= baseLocation;
+ }
+
+ private static class FileCursor {
+ final private FileCursor prior;
+ final private File[] files;
+ private int fileIdx;
+ private final int priorLength;
+ private final StringBuilder sb;
+
+ FileCursor(FileCursor prior, File dir, StringBuilder sb) {
+ this.prior = prior;
+ files= dir.listFiles();
+ this.sb = sb;
+ if(prior!=null) {
+ sb.append('/');
+ }
+ priorLength = sb.length();
+ }
+
+ File nextFile() {
+ if(fileIdx==files.length) {
+ return null;
+ }
+ File file = files[fileIdx++];
+ sb.setLength(priorLength);
+ sb.append(file.getName());
+ return file;
+ }
+
+ FileCursor pop() {
+ return prior;
+ }
+ }
+
+ @Override
+ public Iterator<ClassFile> iterator() {
+
+ return new ClassFileIterator() {
+ StringBuilder sb = new StringBuilder();
+ FileCursor cursor= new FileCursor(null, baseLocation, sb);
+
+ ClassFile getNext() {
+ for(;;) {
+ File file = cursor.nextFile();
+ if(file == null) {
+ cursor = cursor.pop();
+ if(cursor==null) {
+ return null;
+ }
+ continue;
+ }
+
+ String path = sb.toString();
+ if(file.isDirectory()) {
+ String fileName = file.getName();
+ if( ClassNameHelper.isValidIdentifier(fileName) ) {
+ cursor= new FileCursor(cursor, file, sb);
+ }
+ continue;
+ }
+
+ if(file.canRead()) {
+ String className= ClassNameHelper.getClassNameFromFileName(file.getName());
+ if(className!=null) {
+ return new FileClassFile(file, path);
+ }
+ continue;
+ }
+ }
+ }
+ };
+ }
+
+ @Override
+ public String getLocation() {
+ return baseLocation.toURI().toString();
+ }
+
+ @Override
+ public Collection<SpiClassPathElement> getAdditionalLocations(SpiMetaRegistry registry) {
+ return null;
+ }
+
+ @Override
+ public ResourceFile getResource(String fileName) {
+ File file= new File(baseLocation, fileName);
+ if(file.isFile()) {
+ return new FileResourceFile(file, fileName);
+ }
+ return null;
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileResourceFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileResourceFile.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileResourceFile.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/FileResourceFile.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,43 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.classscan.ResourceFile;
+
+public class FileResourceFile implements ResourceFile {
+
+ private final File location;
+ private final String relativePath;
+
+ public FileResourceFile(File location, String relativePath) {
+ this.location = location;
+ this.relativePath = relativePath;
+ }
+
+ @Override
+ public String getFileName() {
+ return relativePath;
+ }
+
+ @Override
+ public InputStream getBytes() throws IOException {
+ return new BufferedInputStream(new FileInputStream(location));
+ }
+}
Added: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassFile.java?rev=1357447&view=auto
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassFile.java (added)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassFile.java Thu Jul 5 02:48:34 2012
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.classscan.builtin;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.commons.classscan.ClassFile;
+
+public class JarClassFile extends JarResourceFile implements ClassFile {
+
+ public JarClassFile(JarFile jarFile, JarEntry jarEntry) {
+ super(jarFile, jarEntry);
+ }
+
+ @Override
+ public InputStream getBytes() throws IOException {
+ // TODO: prevent closing of stream?
+ return jarFile.getInputStream(jarEntry);
+ }
+
+ @Override
+ public String getClassName() {
+ String name= getFileName();
+ return ClassNameHelper.getCannonicalClassNameFromPathName(name);
+ }
+}