summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2004-07-14 13:06:49 +0000
committermichelou <michelou@epfl.ch>2004-07-14 13:06:49 +0000
commit932f642e9ed46ae4c2a88475186699ca6c50c0d6 (patch)
tree0815c30103a7d4deada3389d1093325c70070522
parent5a1117d93a2f2ca3d9f90661eb4e91d7b93bef06 (diff)
downloadscala-932f642e9ed46ae4c2a88475186699ca6c50c0d6.tar.gz
scala-932f642e9ed46ae4c2a88475186699ca6c50c0d6.tar.bz2
scala-932f642e9ed46ae4c2a88475186699ca6c50c0d6.zip
*** empty log message ***
-rw-r--r--sources/scala/tools/scala4ant/ScalacTask.scala109
1 files changed, 109 insertions, 0 deletions
diff --git a/sources/scala/tools/scala4ant/ScalacTask.scala b/sources/scala/tools/scala4ant/ScalacTask.scala
new file mode 100644
index 0000000000..76d130e0fa
--- /dev/null
+++ b/sources/scala/tools/scala4ant/ScalacTask.scala
@@ -0,0 +1,109 @@
+/* __ *\
+** ________ ___ / / ___ 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>ScalacTask</code> class provides an Ant task for
+ * for the <code>scalac</code> command.
+ * i.e.<pre>
+ * &lt;scalac srcdir="${src}" destdir="${build}"&gt;
+ * &lt;include name="test.scala"/&gt;
+ * &lt;/scalac&gt;
+ * </pre>
+ *
+ * @author Burak Emir, Stephane Micheloud
+ * @version 1.0
+ */
+
+class ScalacTask extends Javac {
+
+ private val fileUtils: FileUtils = FileUtils.newFileUtils();
+
+ private var force = false;
+
+ def setCp(s: Path) = setClasspath(s);
+
+ def setForce(b: Boolean) = this.force = b;
+ def getForce() = force;
+
+ 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.AntAdaptor$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));
+ }
+ }
+
+}