- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getClassLoader()
- isClassloaderSupported()
- isAgentAvailable()
- getBootClasspath()
- getClasspath()
- getClasspath(String)
- getPackageArray()
- getLoadedPackageArray()
- getClasspathFromPackages()
- getResources(String)
- getResourcepathSet(Collection)
- whichResource(String)
- isLoaded(String)
- toString()
- getLoadedClasses()
- getLoadedResources()
- getClasses()
Class ClasspathDigger
- Direct Known Subclasses:
ResourcepathDigger
Originally this class was part of the PatternTesting project where it was moved into an internal package. It is not intended for external use.
- Author:
- oliver
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new classpath digger.ClasspathDigger
(ClassLoader cloader) Instantiates a new classpath digger. -
Method Summary
Modifier and TypeMethodDescriptionString[]
To get the boot classpath the sytem property "sun.boot.class.path" is used to get them.Digs into the classpath and returns the found classes.Gets the class loader.String[]
We can use the system property "java.class.path" to get the classpath.protected static String[]
getClasspath
(String key) Gets the classpath.protected String[]
Here we use the loaded packages to calculate the classpath.Returns a list of classes which were loaded by the given classloader.Package[]
Returns the packages which were loaded by the classloader.Asks the classloader for the resources which it already loaded - either directly or because the corresponding package was already loaded.String[]
Get all packages found in the classpath.getResourcepathSet
(Collection<String> resources) Gets the resourcepathes which belongs to the given collection of resources.getResources
(String name) Gets the resources of the given name.static boolean
Checks if the ClasspathAgent is available as MBean.boolean
Checks if is classloader supported.boolean
Checks if the given classname is loaded.toString()
Puts also the classloader in the toString representation.whichResource
(String name) Returns the URI of the given resource and the given classloader.Methods inherited from class clazzfish.monitor.internal.AbstractDigger
readElementsFromNestedArchive
-
Field Details
-
Constructor Details
-
Method Details
-
getClassLoader
-
isClassloaderSupported
public boolean isClassloaderSupported()Checks if is classloader supported.- Returns:
- true, if is classloader supported
-
isAgentAvailable
public static boolean isAgentAvailable()Checks if the ClasspathAgent is available as MBean. The ClasspathAgent is needed for classloaders which are not directly supported (e.g. IBM's classloader of their JDK).- Returns:
- true, if is agent available
-
getBootClasspath
To get the boot classpath the sytem property "sun.boot.class.path" is used to get them. This will work of course only for the SunVM.- Returns:
- the boot classpath as String array
-
getClasspath
We can use the system property "java.class.path" to get the classpath. But this works not inside an application server or servlet engine (e.g. inside Tomcat) because they have their own classloader to load the classes.In the past we tried to use the private (and undocoumented) attribute "domains" of the classloader. This works for a normal application but Tomcat's WebappClassLoader listed also classes in the "domains"-Set. Now we will try to detect the different classloader to access some private and secret attributes of this classloader.
At the moment only org.apache.catalina.loader.WebappClassLoader is supported. For all other classloaders the standard approach using the system property "java.class.path" is used.
- Returns:
- the classpath as String array
-
getClasspath
-
getPackageArray
Get all packages found in the classpath.In contradiction to
getLoadedPackageArray()
we don't ask the classloader (e.g. by callingclassLoader.getResourceAsStream("")
) for the packages because the classloader would return only these packages it has already loaded.- Returns:
- the packages
-
getLoadedPackageArray
Returns the packages which were loaded by the classloader.- Returns:
- array with the loaded packages
-
getClasspathFromPackages
Here we use the loaded packages to calculate the classpath. For each loaded package we will look from which jar file or directory this package is loaded.- Returns:
- the found classpath as string array
- Since:
- 27-Jul-2009
-
getResources
Gets the resources of the given name. Normally that would only be one element but some resources (like the MANIFEST.MF file) can appear several times in the classpath.- Specified by:
getResources
in classAbstractDigger
- Parameters:
name
- the name of the resource- Returns:
- all resources with the given name
-
getResourcepathSet
Gets the resourcepathes which belongs to the given collection of resources.- Parameters:
resources
- the resources- Returns:
- the resourcepath set
- Since:
- 1.6.3
-
whichResource
Returns the URI of the given resource and the given classloader. If the resource is not found it will be tried again with/without a leading "/" and with the parent classloader.- Parameters:
name
- resource name (e.g. "log4j.properties")- Returns:
- URI of the given resource (or null if resource was not found)
-
isLoaded
Checks if the given classname is loaded. Why does we use not Class as parameter here? If you would allow a parameter of type "Class" this class will be problably loaded before and this method will return always true!- Parameters:
classname
- name of the class- Returns:
- true if class is loaded
-
toString
-
getLoadedClasses
Returns a list of classes which were loaded by the given classloader.Ok, we must do some hacks here: there is an undocumented attribute "classes" which contains the loaded classes.
HANDLE WITH CARE (it's a hack and it depends on the used classloader)
- Returns:
- set of classes
-
getLoadedResources
-
getClasses
-