Package org.codehaus.commons.compiler
Class AbstractJavaSourceClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
-
- Direct Known Subclasses:
JavaSourceClassLoader,JavaSourceClassLoader
public abstract class AbstractJavaSourceClassLoader extends java.lang.ClassLoaderAClassLoaderthat, unlike usualClassLoaders, does not load byte code, but reads Java source code and then scans, parses, compiles and loads it into the virtual machine.As with any
ClassLoader, it is not possible to "update" classes after they've been loaded. The way to achieve this is to give up on theAbstractJavaSourceClassLoaderand create a new one.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractJavaSourceClassLoader.ProtectionDomainFactory
-
Field Summary
Fields Modifier and Type Field Description protected AbstractJavaSourceClassLoader.ProtectionDomainFactoryprotectionDomainFactory
-
Constructor Summary
Constructors Constructor Description AbstractJavaSourceClassLoader()AbstractJavaSourceClassLoader(java.lang.ClassLoader parentClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.io.InputStreamgetResourceAsStream(java.lang.String name)static voidmain(java.lang.String[] args)Reads Java source code for a given class name, scan, parse, compile and load it into the virtual machine, and invoke its "main()" method with the given arguments.abstract voidsetDebuggingInfo(boolean lines, boolean vars, boolean source)voidsetProtectionDomainFactory(AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)abstract voidsetSourceCharset(java.nio.charset.Charset charset)voidsetSourceFileCharacterEncoding(java.lang.String charsetName)abstract voidsetSourceFinder(ResourceFinder sourceFinder)abstract voidsetSourcePath(java.io.File[] sourcePath)-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
protectionDomainFactory
@Nullable protected AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory
- See Also:
ClassLoader.defineClass(String, byte[], int, int, ProtectionDomain)
-
-
Method Detail
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
- Overrides:
getResourceAsStreamin classjava.lang.ClassLoader
-
setSourcePath
public abstract void setSourcePath(java.io.File[] sourcePath)
- Parameters:
sourcePath- The sequence of directories to search for Java source files
-
setSourceFinder
public abstract void setSourceFinder(ResourceFinder sourceFinder)
- Parameters:
sourceFinder- Is used when searching for Java source files
-
setSourceFileCharacterEncoding
public void setSourceFileCharacterEncoding(@Nullable java.lang.String charsetName)
- Parameters:
charsetName- ifnull, use platform default encoding
-
setSourceCharset
public abstract void setSourceCharset(java.nio.charset.Charset charset)
- Parameters:
charset- The character set to using when reading characters from a source file
-
setDebuggingInfo
public abstract void setDebuggingInfo(boolean lines, boolean vars, boolean source)- Parameters:
lines- Whether line number debugging information should be generatedvars- Whether variables debugging information should be generatedsource- Whether source file debugging information should be generated
-
setProtectionDomainFactory
public final void setProtectionDomainFactory(@Nullable AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory)
- See Also:
ClassLoader.defineClass(String, byte[], int, int, ProtectionDomain)
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionReads Java source code for a given class name, scan, parse, compile and load it into the virtual machine, and invoke its "main()" method with the given arguments.Usage is as follows:
java
AbstractJavaSourceClassLoader[ option ] ... class-name [ argument ] ... option: -sourcepath colon-separated-list-of-source-directories -encoding character-encoding -g Generate all debugging info -g:none Generate no debugging info -g:{source,lines,vars} Generate only some debugging info- Throws:
java.lang.Exception
-
-