Package kilim.tools
Class Javac
- java.lang.Object
-
- kilim.tools.Javac
-
public class Javac extends java.lang.ObjectSimple utility class to invoke the java compiler.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavac.ClassPatha collection of class path elementsprivate static classJavac.SourceInfo
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.regex.PatternclassNameRegexp(package private) static java.util.regex.PatternpublicClassNameRegexp
-
Constructor Summary
Constructors Constructor Description Javac()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidadd(java.util.ArrayList<java.lang.String> list, java.lang.String... vals)private static voidaddClasses(java.util.List<ClassInfo> ret, java.lang.String pkgName, java.io.File dir)static java.util.List<ClassInfo>compile(java.util.List<java.lang.String> srcCodes)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 ofpairs. private static voiddeleteDir(java.io.File rootDir)static Javac.ClassPathgetClassPath(java.lang.Class start, java.lang.ClassLoader end)get the class path comprising the paths of URL class loaders ancestorsprivate static Javac.SourceInfogetSourceInfo(java.lang.String srcCode)private static java.util.List<Javac.SourceInfo>getSourceInfos(java.util.List<java.lang.String> srcCodes)private static java.io.FilegetTmpDir()private static byte[]readFile(java.io.File f)private static voidwriteFile(java.io.File f, byte[] srcCode)
-
-
-
Method Detail
-
compile
public static java.util.List<ClassInfo> compile(java.util.List<java.lang.String> srcCodes) throws java.io.IOException
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 ofpairs. 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:
- List
. className is fully qualified, and byte[] contains the bytecode of the class. - Throws:
java.io.IOException
-
add
static void add(java.util.ArrayList<java.lang.String> list, java.lang.String... vals)
-
getClassPath
public static Javac.ClassPath getClassPath(java.lang.Class start, java.lang.ClassLoader end)
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
private static java.util.List<Javac.SourceInfo> getSourceInfos(java.util.List<java.lang.String> srcCodes)
-
getSourceInfo
private static Javac.SourceInfo getSourceInfo(java.lang.String srcCode)
-
getTmpDir
private static java.io.File getTmpDir() throws java.io.IOException- Throws:
java.io.IOException
-
deleteDir
private static void deleteDir(java.io.File rootDir)
-
addClasses
private static void addClasses(java.util.List<ClassInfo> ret, java.lang.String pkgName, java.io.File dir) throws java.io.IOException
- Throws:
java.io.IOException
-
readFile
private static byte[] readFile(java.io.File f) throws java.io.IOException- Throws:
java.io.IOException
-
writeFile
private static void writeFile(java.io.File f, byte[] srcCode) throws java.io.IOException- Throws:
java.io.IOException
-
-