logo

class

build::CompileJava

sys::Obj
  build::Task
    build::JdkTask
      build::CompileJava
  1  //
  2  // Copyright (c) 2006, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   4 Nov 06  Brian Frank  Creation
  7  //
  8  
  9  using compiler
 10  
 11  **
 12  ** Run the Java compiler to produce a directory of Java classfiles.
 13  **
 14  class CompileJava : JdkTask
 15  {
 16  
 17  //////////////////////////////////////////////////////////////////////////
 18  // Construction
 19  //////////////////////////////////////////////////////////////////////////
 20  
 21    **
 22    ** Construct uninitialized javac task
 23    **
 24    new make(BuildScript script)
 25      : super(script)
 26    {
 27      cp.add(rtJar)
 28    }
 29  
 30  //////////////////////////////////////////////////////////////////////////
 31  // Run
 32  //////////////////////////////////////////////////////////////////////////
 33  
 34    **
 35    ** Run the javac task
 36    **
 37    override Void run()
 38    {
 39      log.info("CompileJava")
 40  
 41      try
 42      {
 43        // build command
 44        cmd := [javacExe.osPath]
 45  
 46        // -d outDir
 47        if (outDir != null)
 48        {
 49          cmd.add("-d").add(outDir.osPath)
 50        }
 51  
 52        // -cp <classpath>
 53        cmd.add("-cp")
 54        cmd.add(cp.join(";") |File f->Str| { return f.osPath })
 55  
 56        // src files/dirs
 57        src.each |File f|
 58        {
 59          if (f.isDir)
 60            cmd.add((f + `*.java`).osPath)
 61          else
 62            cmd.add(f.osPath)
 63        }
 64        log.debug(cmd.join(" "))
 65        r := Process.make(cmd).run
 66        if (r != 0) throw Err.make
 67      }
 68      catch (Err err)
 69      {
 70        throw fatal("CompileJava failed")
 71      }
 72    }
 73  
 74  //////////////////////////////////////////////////////////////////////////
 75  // Fields
 76  //////////////////////////////////////////////////////////////////////////
 77  
 78    ** Class path - list of jars to compile against,
 79    ** rt.jar is automatically included
 80    File[] cp := File[,]
 81  
 82    ** List of source files or directories to compile
 83    File[] src := File[,]
 84  
 85    ** Output directory
 86    File outDir
 87  
 88  
 89  }

More Info

Slots