org.codehaus.janino.JavaSourceClassLoader that uses a resource storage provided by the application to
cache compiled classes and thus saving unnecessary recompilations.
The application provides access to the resource storage through a pair of a org. and a org. (see CachingJavaSourceClassLoader(ClassLoader, ResourceFinder, String, ResourceFinder, ResourceCreator).
See org. for an example how to use this class.
Notice: You must NOT rely on that this class stores some particular data in some particular resources
through the given classFileCacheResourceFinder/Creator! These serve only as a means for the CachingJavaSourceClassLoader to persistently cache some data between invocations. In other words: If you want to
compile .java files into .class files, then don't use this class but Compiler
instead!
| Modifier and Type | Field and Description |
|---|---|
| private final ResourceCreator | |
| private final ResourceFinder | |
| private final ResourceFinder |
| Access | Constructor and Description |
|---|---|
| public | CachingJavaSourceClassLoader(ClassLoader parentClassLoader, File[]
Directories to scan for source files sourcePath, String characterEncoding, File Directory to use for caching generated class files (see class description) cacheDirectory)See |
| public | CachingJavaSourceClassLoader(ClassLoader
Attempt to load classes through this one before looking for source files parentClassLoader, ResourceFinder Finds Java source for class sourceFinder, String pkg.Cls in resource pkg/Cls.javaEncoding of Java source or characterEncoding, ResourceFinder null for platform default
encodingFinds precompiled class classFileCacheResourceFinder, ResourceCreator pkg.Cls in resource pkg/Cls.class
(see class description)Stores compiled class classFileCacheResourceCreator)pkg.Cls in resource pkg/Cls.class (see
class description)Notice that this class is thread-safe if and only if the classFileCacheResourceCreator stores its
data atomically, i.e. the classFileCacheResourceFinder sees the resource written by the |
| Modifier and Type | Method and Description |
|---|---|
| protected Map | Returns: String name => byte[] bytecode, ornull if no source code could be
foundOverrides org. JavaSourceClassLoader#generateBytecodes(String) to implement class file caching.
|
| private static byte[] | |
| private static void | writeResource(ResourceCreator resourceCreator, String resourceName, byte[] data)
Creates a resource with the given name and store the data in it. |
| classFileCacheResourceCreator | back to summary |
|---|---|
| private final ResourceCreator classFileCacheResourceCreator | |
| classFileCacheResourceFinder | back to summary |
|---|---|
| private final ResourceFinder classFileCacheResourceFinder | |
| sourceFinder | back to summary |
|---|---|
| private final ResourceFinder sourceFinder | |
| CachingJavaSourceClassLoader | back to summary |
|---|---|
| public CachingJavaSourceClassLoader(ClassLoader parentClassLoader, File[] sourcePath, String characterEncoding, File cacheDirectory) See | |
| CachingJavaSourceClassLoader | back to summary |
|---|---|
| public CachingJavaSourceClassLoader(ClassLoader parentClassLoader, ResourceFinder sourceFinder, String characterEncoding, ResourceFinder classFileCacheResourceFinder, ResourceCreator classFileCacheResourceCreator) Notice that this class is thread-safe if and only if the classFileCacheResourceCreator stores its
data atomically, i.e. the classFileCacheResourceFinder sees the resource written by the
In order to make the caching scheme work, both the classFileCacheResourceFinder and the
| |
| generateBytecodes | back to summary |
|---|---|
| protected Map Overrides org. Overrides
| |
| readResource | back to summary |
|---|---|
| private static byte[] readResource(Resource r) throws IOException Reads all bytes from the given resource. | |
| writeResource | back to summary |
|---|---|
| private static void writeResource(ResourceCreator resourceCreator, String resourceName, byte[] data) throws IOException Creates a resource with the given name and store the data in it. | |