Class JavaSourceClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
-
- org.codehaus.commons.compiler.jdk.JavaSourceClassLoader
-
public class JavaSourceClassLoader extends AbstractJavaSourceClassLoader
AClassLoader
that loads classes by looking for their source files through a 'source path' and compiling them on-the-fly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JavaSourceClassLoader.DiagnosticException
-
Nested classes/interfaces inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
AbstractJavaSourceClassLoader.ProtectionDomainFactory
-
-
Field Summary
Fields Modifier and Type Field Description private javax.tools.JavaCompiler
compiler
private java.util.Collection<java.lang.String>
compilerOptions
private boolean
debuggingInfoLines
private boolean
debuggingInfoSource
private boolean
debuggingInfoVars
private javax.tools.JavaFileManager
fileManager
private java.lang.String
optionalCharacterEncoding
private java.io.File[]
sourcePath
-
Fields inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
optionalProtectionDomainFactory
-
-
Constructor Summary
Constructors Constructor Description JavaSourceClassLoader()
JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Class<?>
findClass(java.lang.String className)
Implementation ofClassLoader.findClass(String)
.(package private) javax.tools.JavaFileManager
getJavaFileManager()
Creates the underlyingJavaFileManager
lazily, becausesetSourcePath(File[])
and consorts are called after initialization.private static java.lang.String
getSourceResourceName(java.lang.String className)
Construct the name of a resource that could contain the source code of the class with the given name.private void
init()
void
setCompilerOptions(java.lang.String[] compilerOptions)
Notice: Don't use the '-g' options - these are controlled throughsetDebuggingInfo(boolean, boolean, boolean)
.void
setDebuggingInfo(boolean lines, boolean vars, boolean source)
void
setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding)
void
setSourcePath(java.io.File[] sourcePath)
-
Methods inherited from class org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
main, setProtectionDomainFactory
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
sourcePath
private java.io.File[] sourcePath
-
optionalCharacterEncoding
private java.lang.String optionalCharacterEncoding
-
debuggingInfoLines
private boolean debuggingInfoLines
-
debuggingInfoVars
private boolean debuggingInfoVars
-
debuggingInfoSource
private boolean debuggingInfoSource
-
compilerOptions
private java.util.Collection<java.lang.String> compilerOptions
-
compiler
private javax.tools.JavaCompiler compiler
-
fileManager
private javax.tools.JavaFileManager fileManager
-
-
Method Detail
-
init
private void init()
-
getJavaFileManager
javax.tools.JavaFileManager getJavaFileManager()
Creates the underlyingJavaFileManager
lazily, becausesetSourcePath(File[])
and consorts are called after initialization.
-
setSourcePath
public void setSourcePath(java.io.File[] sourcePath)
- Specified by:
setSourcePath
in classAbstractJavaSourceClassLoader
- Parameters:
sourcePath
- The sequence of directories to search for Java™ source files
-
setSourceFileCharacterEncoding
public void setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding)
- Specified by:
setSourceFileCharacterEncoding
in classAbstractJavaSourceClassLoader
- Parameters:
optionalCharacterEncoding
- ifnull
, use platform default encoding
-
setDebuggingInfo
public void setDebuggingInfo(boolean lines, boolean vars, boolean source)
- Specified by:
setDebuggingInfo
in classAbstractJavaSourceClassLoader
- 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
-
setCompilerOptions
public void setCompilerOptions(java.lang.String[] compilerOptions)
Notice: Don't use the '-g' options - these are controlled throughsetDebuggingInfo(boolean, boolean, boolean)
.- Parameters:
compilerOptions
- All command line options supported by the JDK JAVAC tool
-
findClass
protected java.lang.Class<?> findClass(java.lang.String className) throws java.lang.ClassNotFoundException
Implementation ofClassLoader.findClass(String)
.- Overrides:
findClass
in classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
-
getSourceResourceName
private static java.lang.String getSourceResourceName(java.lang.String className)
Construct the name of a resource that could contain the source code of the class with the given name.Notice that member types are declared inside a different type, so the relevant source file is that of the outermost declaring class.
- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
- the name of the resource, e.g. "pkg1/pkg2/Outer.java"
-
-