Package org.eclipse.steady.java.monitor
Class ClassPoolUpdater
- java.lang.Object
-
- org.eclipse.steady.java.monitor.ClassPoolUpdater
-
public class ClassPoolUpdater extends Object
Updates the classpath of the JavassistClassPool, which is needed to ensure that instances ofCtClasscan be created. Example: Consideration of the declaring class in nested class definitions, cf.ClassVisitor(javassist.CtClass).
-
-
Constructor Summary
Constructors Constructor Description ClassPoolUpdater()Constructor for ClassPoolUpdater.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanappendToClasspath(Path _path)If not done already, appends the givenPathto the classpath of thecustomClassPool.voidappendToClasspath(Set<Path> _paths)appendToClasspath.intcountClasspathElements()countClasspathElements.PathgetClasspath(File _class_file)For a given class file, the method returns the directory ....Set<Path>getClasspaths(Set<Path> _files)getClasspaths.javassist.ClassPoolgetCustomClassPool()Returns aClassPoolobject that can be populated using the methodsappendToClasspath(java.nio.file.Path)andappendToClasspath(Set).static ClassPoolUpdatergetInstance()Returns an instance ofClassPoolUpdatermaking use of a custom JavassistClassPool.URLgetJarResourcePath(ConstructId _cid)This method look into the custom ClassPool and return a string with the physical path of the JAR if is present in the resources loaded into the ClassPool.voidreset()Resets theClassPoolUpdaterto its initial state.booleanupdateClasspath(javassist.CtClass _ctclass, File _file)Appends a directory to the classpath of the defaultClassPool.
-
-
-
Method Detail
-
getInstance
public static ClassPoolUpdater getInstance()
Returns an instance ofClassPoolUpdatermaking use of a custom JavassistClassPool. This instance will be created at the time of the first call, later calls will return this instance. If the defaultClassPoolis sufficient, i.e., if no custom resources need to be added to its classpath, one can also create an instance using the public constructor.- Returns:
- a
ClassPoolUpdaterobject.
-
getClasspath
public Path getClasspath(File _class_file)
For a given class file, the method returns the directory ....
-
updateClasspath
public boolean updateClasspath(javassist.CtClass _ctclass, File _file)Appends a directory to the classpath of the defaultClassPool. This directory corresponds to the given file minus the path elements that correspond to the Java package structure of the givenCtClass. Returns true if the path has been appended, false otherwise.- Parameters:
_ctclass- aCtClassobject._file- aFileobject.- Returns:
- a boolean.
-
appendToClasspath
public void appendToClasspath(Set<Path> _paths)
appendToClasspath.
- Parameters:
_paths- aSetobject.
-
appendToClasspath
public boolean appendToClasspath(Path _path)
If not done already, appends the givenPathto the classpath of thecustomClassPool.- Parameters:
_path- aPathobject.- Returns:
- a boolean.
-
countClasspathElements
public int countClasspathElements()
countClasspathElements.
- Returns:
- a int.
-
reset
public void reset()
Resets theClassPoolUpdaterto its initial state. In particular, a new instance of theClassPoolwill be created, and all all thePaths that have been added to its class path will be removed.- See Also:
appendToClasspath(Path)
-
getCustomClassPool
public javassist.ClassPool getCustomClassPool()
Returns aClassPoolobject that can be populated using the methodsappendToClasspath(java.nio.file.Path)andappendToClasspath(Set).- Returns:
- A
ClassPoolobject, can be null if there is none
-
getJarResourcePath
public URL getJarResourcePath(ConstructId _cid)
This method look into the custom ClassPool and return a string with the physical path of the JAR if is present in the resources loaded into the ClassPool. If is not found it returns null PS: We can add to the ClassPool all the resources that we want using the methodsappendToClasspath(java.nio.file.Path)andappendToClasspath(Set).- Parameters:
_cid- the ConstructId that we want to search in the ClassPool- Returns:
- the JAR path or null if is not found
-
-