diff options
author | buraq <buraq@epfl.ch> | 2005-06-20 17:36:29 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2005-06-20 17:36:29 +0000 |
commit | df6b358dcb3bbcbcb4911528373a4aeb25daffc4 (patch) | |
tree | 65e6f363fac695a88a6647126cb17c7cb33377b5 | |
parent | 7ad58e693c67e3fcb79e8f2afa37d4d40ff9a256 (diff) | |
download | scala-df6b358dcb3bbcbcb4911528373a4aeb25daffc4.tar.gz scala-df6b358dcb3bbcbcb4911528373a4aeb25daffc4.tar.bz2 scala-df6b358dcb3bbcbcb4911528373a4aeb25daffc4.zip |
files to call nsc from ant
-rw-r--r-- | sources/scala/tools/scala4ant/NscAdaptor.scala | 72 | ||||
-rw-r--r-- | sources/scala/tools/scala4ant/NscTask.scala | 118 |
2 files changed, 190 insertions, 0 deletions
diff --git a/sources/scala/tools/scala4ant/NscAdaptor.scala b/sources/scala/tools/scala4ant/NscAdaptor.scala new file mode 100644 index 0000000000..b70164ac89 --- /dev/null +++ b/sources/scala/tools/scala4ant/NscAdaptor.scala @@ -0,0 +1,72 @@ + +//import scalac._; +import scala.tools.util.Reporter; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.taskdefs.LogStreamHandler; +import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import java.io.IOException; + +package scala.tools.scala4ant { + + /** Scala compiler adaptor. adapted from (see below for additions to Scala license) + * jaco.framework.ant.AntCompilerAdaptor (c) Matthias Zenger, and + * org.apache.tools.ant.taskdefs.DefaultCompilerAdapter + * (c) the Apache Software Foundation + * + * @author Burak Emir + * @version 1.6 + * $Id$ + */ + + class NscAdaptor extends AntAdaptor { + + override def runCompiler( args:Array[String] ) = { + var ex:Throwable = _; + //Console.println("runCompiler"); + var result = true; + try { + //var moreargs: List[String] = Nil; + + //if(verbose) + // moreargs = "-verbose" :: moreargs; + + val moreargs = this.attributes.asInstanceOf[NscTask].moreArgs(); + + for(val a <- moreargs) + Console.println("NscAdaptor adds argument '"+a+"'"); + + val nargs = new Array[String](moreargs.length + args.length); + //moreargs.copyToArray(nargs, 0); + System.arraycopy(moreargs, 0, nargs, 0, moreargs.length); + System.arraycopy(args, 0, nargs, moreargs.length, args.length); + + + + + scala.tools.nsc.Main.process( nargs ); + } catch { + case e:Throwable => + ex = e; + } + if( null != ex ) { + ex.printStackTrace(); + throw new BuildException("internal error of nsc:"+ex.getClass()); + } + + if( scala.tools.nsc.Main.errors() > 0 ) + throw new BuildException("there were compile errors"); + + true + } + + override def compilerName() = "nsc"; + + } +} + diff --git a/sources/scala/tools/scala4ant/NscTask.scala b/sources/scala/tools/scala4ant/NscTask.scala new file mode 100644 index 0000000000..f977796158 --- /dev/null +++ b/sources/scala/tools/scala4ant/NscTask.scala @@ -0,0 +1,118 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.tools.scala4ant; + +import java.io.File; + +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util._; + + +/** + * The <code>NscTask</code> class provides an Ant task for + * for the as-yet nonexistent <code>nsc</code> command. + * i.e.<pre> + * <nsc srcdir="${src}" destdir="${build}"> + * <include name="test.scala"/> + * </nsc> + * </pre> + * + * @author Burak Emir, Stephane Micheloud + * @version 1.0 + */ + +class NscTask extends Javac { + + private val fileUtils: FileUtils = FileUtils.newFileUtils(); + + private var verbose = false; + private var force = false; + private var nscArgs = ""; + + def setCp(s: Path) = setClasspath(s); + + def setForce(b: Boolean) = this.force = b; + def getForce() = force; + + def setNscArgs(s: String) = this.nscArgs = s; + def getNscArgs() = nscArgs; + + def moreArgs():Array[String] = { + getNscArgs().split(";"); + } + + override def execute() = { + System.setProperty("scala.home", ScalaRuntime.home.toString()); + System.setProperty("scala.product", scala.tools.scalac.Main.PRODUCT); + System.setProperty("scala.version", scala.tools.scalac.Main.VERSION); + System.setProperty("scala.class.path", "."); + System.setProperty("scala.boot.class.path", ScalaRuntime.bootclasspath.toString()); + + getProject().setProperty("build.compiler", + "scala.tools.scala4ant.NscAdaptor$class"); + + super.execute(); + } + + override protected def scanDir(srcDir: File, destDir: File, files: Array[String]): Unit = { + if (force) { + val newCompileList = new Array[File](compileList.length + files.length); + System.arraycopy(compileList, 0, newCompileList, 0, compileList.length); + var j, i = 0; + + def handleFile( theFile:String ):unit = { + /* this, because wile create anon-class -> access violation */ + if (theFile.endsWith(".scala")) { + if (srcDir == null) { + newCompileList(compileList.length + j) = new File(theFile); + j = j + 1; + } + else { + newCompileList(compileList.length + j) = + fileUtils.resolveFile(srcDir, theFile); + j = j + 1 + } + } + } + + while (i < files.length) { + handleFile(files(i)); + i = i + 1; + } + + if (j == files.length) + compileList = newCompileList; + else { + compileList = new Array[File](j); + System.arraycopy(newCompileList, 0, compileList, 0, j); + } + } else { + val m = new GlobPatternMapper(); + + def handleNewFiles(newFiles:Array[File]): Unit = { + if (newFiles.length > 0) { + val newCompileList = + new Array[File](compileList.length + newFiles.length); + System.arraycopy(compileList, 0, newCompileList, 0, + compileList.length); + System.arraycopy(newFiles, 0, newCompileList, + compileList.length, newFiles.length); + compileList = newCompileList; + } + } + m.setFrom("*.scala"); + m.setTo("*.class"); + val sfs = new SourceFileScanner(this); + handleNewFiles(sfs.restrictAsFiles(files, srcDir, destDir, m)); + } + } + +} |