Created
March 25, 2014 00:59
-
-
Save bennadel/9753241 to your computer and use it in GitHub Desktop.
Listing All Classes In A Jar File Using ColdFusion And CFZip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction | |
name="GetJarClasses" | |
access="public" | |
returntype="array" | |
output="false" | |
hint="I return an array of classes in the given JAR file (expanded path)."> | |
<!--- Define arguments. ---> | |
<cfargument | |
name="JarFilePath" | |
type="string" | |
required="true" | |
hint="I am the expanded path of the JAR file." | |
/> | |
<!--- Define the local scope. ---> | |
<cfset var LOCAL = {} /> | |
<!--- Create a default array of classes. ---> | |
<cfset LOCAL.Classes = [] /> | |
<!--- Get all of the .class files out of the JAR file. ---> | |
<cfzip | |
action="list" | |
file="#ARGUMENTS.JarFilePath#" | |
recurse="true" | |
filter="*.class" | |
name="LOCAL.JarEntry" | |
/> | |
<!--- | |
Now that we have the .CLASS entries, let's loop over | |
them, clean them up, and add them to our results array. | |
---> | |
<cfloop query="LOCAL.JarEntry"> | |
<!--- Clean up path structure. ---> | |
<cfset LOCAL.ClassName = REReplace( | |
LOCAL.JarEntry.Name, | |
"[\\/]", | |
".", | |
"all" | |
) /> | |
<!--- Strip off the ".class" path item. ---> | |
<cfset LOCAL.ClassName = REReplaceNoCase( | |
LOCAL.ClassName, | |
"\.class$", | |
"", | |
"one" | |
) /> | |
<!--- Add the formatted class name. ---> | |
<cfset ArrayAppend( | |
LOCAL.Classes, | |
LOCAL.ClassName | |
) /> | |
</cfloop> | |
<!--- Return the array of classes. ---> | |
<cfreturn LOCAL.Classes /> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment