Package kilim.tools
Class Javac
java.lang.Object
kilim.tools.Javac
Simple utility class to invoke the java compiler.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classa collection of class path elementsprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static voidprivate static voidaddClasses(List<ClassInfo> ret, String pkgName, File dir) Given a list of file-scope java code (equivalent to a .java file, including package and import declarations), compile() invokes javac to compile them, produce classfiles and return a list of invalid input: '<'className, byte[]> pairs.private static voidstatic Javac.ClassPathgetClassPath(Class start, ClassLoader end) get the class path comprising the paths of URL class loaders ancestorsprivate static Javac.SourceInfogetSourceInfo(String srcCode) private static List<Javac.SourceInfo> getSourceInfos(List<String> srcCodes) private static Fileprivate static byte[]private static void
-
Field Details
-
publicClassNameRegexp
-
classNameRegexp
-
-
Constructor Details
-
Javac
public Javac()
-
-
Method Details
-
compile
Given a list of file-scope java code (equivalent to a .java file, including package and import declarations), compile() invokes javac to compile them, produce classfiles and return a list of invalid input: '<'className, byte[]> pairs. compile() dumps the source strings into their respective files, has javac compile them, then reads back the equivalent class files. The name of the source file is gleaned from the string itself; a string containing "public class Foo" is stored in tmpDir/Foo.java (where tmpDir is a temporary directory that's deleted after the compilation), and if no public class or interface is found, the name of the first class in the string is used. Note that the list of returned classes may be larger than list of sources Note: the java compiler api is ill-defined and this class should not be considered production. specifically, the classpath appears to depend on the execution environment, eg command line maven vs IDE vs the java command line- Parameters:
srcCodes- . List of strings.- Returns:
- Listinvalid input: '<'className,byte[]>. className is fully qualified, and byte[] contains the bytecode of the class.
- Throws:
IOException
-
add
-
getClassPath
get the class path comprising the paths of URL class loaders ancestors- Parameters:
start- start with the class loader that loaded this object, or null for this method's classend- the last classloader to consider, or null to include everything up to but not including the system class loader- Returns:
- the URLs
-
getSourceInfos
-
getSourceInfo
-
getTmpDir
- Throws:
IOException
-
deleteDir
-
addClasses
- Throws:
IOException
-
readFile
- Throws:
IOException
-
writeFile
- Throws:
IOException
-