Package kilim.tools

Class Javac

java.lang.Object
kilim.tools.Javac

public class Javac extends Object
Simple utility class to invoke the java compiler.
  • Field Details

    • publicClassNameRegexp

      static Pattern publicClassNameRegexp
    • classNameRegexp

      static Pattern classNameRegexp
  • Constructor Details

    • Javac

      public Javac()
  • Method Details

    • compile

      public static List<ClassInfo> compile(List<String> srcCodes) throws 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 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

      static void add(ArrayList<String> list, String... vals)
    • getClassPath

      public static Javac.ClassPath getClassPath(Class start, 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 class
      end - 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 List<Javac.SourceInfo> getSourceInfos(List<String> srcCodes)
    • getSourceInfo

      private static Javac.SourceInfo getSourceInfo(String srcCode)
    • getTmpDir

      private static File getTmpDir() throws IOException
      Throws:
      IOException
    • deleteDir

      private static void deleteDir(File rootDir)
    • addClasses

      private static void addClasses(List<ClassInfo> ret, String pkgName, File dir) throws IOException
      Throws:
      IOException
    • readFile

      private static byte[] readFile(File f) throws IOException
      Throws:
      IOException
    • writeFile

      private static void writeFile(File f, byte[] srcCode) throws IOException
      Throws:
      IOException