summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.xml84
-rw-r--r--src/compiler/scala/tools/ant/ScalaTool.scala304
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala11
-rw-r--r--src/compiler/scala/tools/ant/antlib.xml12
-rw-r--r--src/compiler/scala/tools/ant/templates/generic-unix.tmpl60
-rw-r--r--src/compiler/scala/tools/ant/templates/generic-windows.tmpl42
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-unix.tmpl59
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-windows.tmpl42
-rw-r--r--src/compiler/scala/tools/nsc/ant/NSC.scala640
9 files changed, 585 insertions, 669 deletions
diff --git a/build.xml b/build.xml
index 4184bf0c4b..51098bf584 100644
--- a/build.xml
+++ b/build.xml
@@ -97,7 +97,7 @@ INITIALISATION
<echo level="verbose">starr.comp.jar=${starr.comp.jar}</echo>
<fail message="STARR compiler in 'lib/' is not available">
<condition><not>
- <available classname="scala.tools.nsc.ant.NSC"
+ <available classname="scala.tools.ant.Scalac"
classpath="${starr.comp.jar}:${starr.lib.jar}"/>
</not></condition>
</fail>
@@ -141,7 +141,7 @@ INITIALISATION
</path>
<!-- Creating boot-level tasks -->
<taskdef name="starr"
- classname="scala.tools.nsc.ant.NSC"
+ classname="scala.tools.ant.Scalac"
classpathref="starr.classpath"/>
<taskdef name="pico"
classname="jaco.pizza.ant.Pico"
@@ -159,7 +159,7 @@ INITIALISATION
<available classname="scala.List" classpath="${locker.lib.dir}"/>
<available classname="scala.runtime.ObjectRef"
classpath="${locker.lib.dir}"/>
- <available classname="scala.tools.nsc.ant.NSC"
+ <available classname="scala.tools.ant.Scalac"
classpath="${locker.comp.dir}:${locker.lib.dir}"/>
<available file="${locker.dir}/${exec.dir.name}/${scalac.exec.name}"/>
</and>
@@ -216,6 +216,9 @@ INITIALISATION
<taskdef name="locker"
classname="scala.tools.ant.Scalac"
classpathref="locker.classpath"/>
+ <taskdef name="lockertool"
+ classname="scala.tools.ant.ScalaTool"
+ classpathref="locker.classpath"/>
</target>
<target name="init.quick" depends="init, build">
@@ -227,6 +230,9 @@ INITIALISATION
<taskdef name="quick"
classname="scala.tools.ant.Scalac"
classpathref="quick.classpath"/>
+ <taskdef name="quicktool"
+ classname="scala.tools.ant.ScalaTool"
+ classpathref="quick.classpath"/>
</target>
<!-- ===========================================================================
@@ -297,6 +303,24 @@ BUILD SUPPORT MACROS
</copy>
</sequential>
</macrodef>
+
+ <macrodef name="build.support">
+ <attribute name="build.dir"/>
+ <sequential>
+ <copy todir="@{build.dir}/${lib.dir.name}">
+ <fileset dir="${src.dir}/${lib.dir.name}">
+ <include name="**/*.tmpl"/>
+ <include name="**/*.xml"/>
+ </fileset>
+ </copy>
+ <copy todir="@{build.dir}/${comp.dir.name}">
+ <fileset dir="${src.dir}/${comp.dir.name}">
+ <include name="**/*.tmpl"/>
+ <include name="**/*.xml"/>
+ </fileset>
+ </copy>
+ </sequential>
+ </macrodef>
<!-- ===========================================================================
BUILD LOCAL REFERENCE (LOCKER) LAYER
@@ -355,6 +379,8 @@ BUILD LOCAL REFERENCE (LOCKER) LAYER
<include name="**/*.scala"/>
<excludesfile name="${nsc.excludes}" if="excludes.avail"/>
</starr>
+ <!-- Copy support files to build folder -->
+ <build.support build.dir="${locker.dir}"/>
<!-- Link to libraries -->
<symlink link="${locker.dir}/${fjbg.name}"
resource="${fjbg.jar}"
@@ -433,6 +459,8 @@ BUILD QUICK-TEST LAYER
<include name="**/*.scala"/>
<excludesfile name="${nsc.excludes}" if="excludes.avail"/>
</locker>
+ <!-- Copy templates to build -->
+ <build.support build.dir="${quick.dir}"/>
<!-- Link to libraries -->
<symlink link="${quick.dir}/${fjbg.name}"
resource="${fjbg.jar}"
@@ -443,16 +471,20 @@ BUILD QUICK-TEST LAYER
overwrite="yes"
failonerror="no"/>
<!-- Build executable files -->
- <build.exec.unix lib.path="$$PREFIX/${lib.dir.name}"
- comp.path="$$PREFIX/${comp.dir.name}"
- fjbg.path="$$PREFIX/${fjbg.name}"
- msil.path="$$PREFIX/${msil.name}"
- exec.dir="${quick.dir}/${exec.dir.name}"/>
- <build.exec.win lib.path="%SCALA_HOME%\${lib.dir.name}"
- comp.path="%SCALA_HOME%\${comp.dir.name}"
- fjbg.path="%SCALA_HOME%\${fjbg.name}"
- msil.path="%SCALA_HOME%\${msil.name}"
- exec.dir="${quick.dir}\${exec.dir.name}"/>
+ <mkdir dir="${quick.dir}/${exec.dir.name}"/>
+ <lockertool file="${quick.dir}/${exec.dir.name}/${scalac.exec.name}"
+ genericFile="${quick.dir}/${exec.dir.name}/${scala.exec.name}"
+ name="Scala compiler"
+ class="scala.tools.nsc.Main"
+ version="${version.number}"
+ copyright="${copyright}"
+ classpath="$$PREFIX/${lib.dir.name}:$$PREFIX/${comp.dir.name}:$$PREFIX/${fjbg.name}:$$PREFIX/${msil.name}"
+ properties="scala.boot.class.path=$$CP"
+ javaFlags="-Xmx256M -Xms16M"/>
+ <chmod file="${quick.dir}/${exec.dir.name}/${scalac.exec.name}"
+ perm="ugo+rx"/>
+ <chmod file="${quick.dir}/${exec.dir.name}/${scala.exec.name}"
+ perm="ugo+rx"/>
</target>
<!-- ===========================================================================
@@ -512,6 +544,8 @@ TEST
<include name="**/*.scala"/>
<excludesfile name="${nsc.excludes}" if="excludes.avail"/>
</quick>
+ <!-- Copy templates to build -->
+ <build.support build.dir="${strap.dir}"/>
<!-- Link to libraries -->
<symlink link="${strap.dir}/${fjbg.name}"
resource="${fjbg.jar}"
@@ -522,16 +556,20 @@ TEST
overwrite="yes"
failonerror="no"/>
<!-- Build executable files -->
- <build.exec.unix lib.path="$$$PREFIX/${lib.dir.name}"
- comp.path="$$PREFIX/${comp.dir.name}"
- fjbg.path="$$PREFIX/${fjbg.name}"
- msil.path="$$PREFIX/${msil.name}"
- exec.dir="${strap.dir}/${exec.dir.name}"/>
- <build.exec.win lib.path="%SCALA_HOME%\${lib.dir.name}"
- comp.path="%SCALA_HOME%\${comp.dir.name}"
- fjbg.path="%SCALA_HOME%\${fjbg.name}"
- msil.path="%SCALA_HOME%\${msil.name}"
- exec.dir="${strap.dir}\${exec.dir.name}"/>
+ <mkdir dir="${strap.dir}/${exec.dir.name}"/>
+ <quicktool file="${strap.dir}/${exec.dir.name}/${scalac.exec.name}"
+ genericFile="${strap.dir}/${exec.dir.name}/${scala.exec.name}"
+ name="Scala compiler"
+ class="scala.tools.nsc.Main"
+ version="${version.number}"
+ copyright="${copyright}"
+ classpath="$$PREFIX/${lib.dir.name}:$$PREFIX/${comp.dir.name}:$$PREFIX/${fjbg.name}:$$PREFIX/${msil.name}"
+ properties="scala.boot.class.path=$$CP"
+ javaFlags="-Xmx256M -Xms16M"/>
+ <chmod file="${strap.dir}/${exec.dir.name}/${scalac.exec.name}"
+ perm="ugo+rx"/>
+ <chmod file="${strap.dir}/${exec.dir.name}/${scala.exec.name}"
+ perm="ugo+rx"/>
<!-- Compares quick and test level -->
<checksum totalproperty="quick.md5">
<fileset dir="${quick.dir}">
diff --git a/src/compiler/scala/tools/ant/ScalaTool.scala b/src/compiler/scala/tools/ant/ScalaTool.scala
new file mode 100644
index 0000000000..b079fde680
--- /dev/null
+++ b/src/compiler/scala/tools/ant/ScalaTool.scala
@@ -0,0 +1,304 @@
+/* __ ______________ *\
+** / |/ / ____/ ____/ **
+** / | | /___ / /___ **
+** /_/|__/_____/_____/ Copyright 2005-2006 LAMP/EPFL **
+**
+** $Id$
+\* */
+
+package scala.tools.ant {
+
+ import scala.collection.immutable.{Map, ListMap}
+
+ import java.io.{File, InputStream, FileWriter}
+ import java.net.{URL, URLClassLoader}
+ import java.util.{ArrayList, Vector}
+
+ import org.apache.tools.ant.{AntClassLoader, BuildException,
+ DirectoryScanner, Project}
+ import org.apache.tools.ant.taskdefs.MatchingTask
+ import org.apache.tools.ant.types.Path
+ import org.apache.tools.ant.util.{FileUtils, GlobPatternMapper,
+ SourceFileScanner}
+ import org.apache.tools.ant.types.{EnumeratedAttribute, Reference}
+
+ /** An Ant task that generates a SH or BAT script to execute a Scala program.
+ * This task can take the following parameters as attributes:<ul>
+ * <li>file (mandatory),</li>
+ * <li>name,</li>
+ * <li>class (mandatory),</li>
+ * <li>platforms,</li>
+ * <li>version,</li>
+ * <li>copyright,</li>
+ * <li>classpath,</li>
+ * <li>properties,</li>
+ * <li>javaFlags,</li>
+ * <li>toolFlags,</li>
+ * <li>genericFile.</li></ul>
+ *
+ * @author Gilles Dubochet */
+ class ScalaTool extends MatchingTask {
+
+ /** The unique Ant file utilities instance to use in this task. */
+ private val fileUtils = FileUtils.newFileUtils()
+
+/******************************************************************************\
+** Ant user-properties **
+\******************************************************************************/
+
+ abstract class PermissibleValue {
+ val values: List[String]
+ def isPermissible(value: String): Boolean =
+ (value == "") || values.exists(.startsWith(value))
+ }
+
+ /** Defines valid values for the platforms property. */
+ object Platforms extends PermissibleValue {
+ val values = List("unix", "windows")
+ }
+
+ /** The path to the exec script file. ".bat" will be appended for the
+ * Windows BAT file, if generated. */
+ private var file: Option[File] = None
+ /** The name of this tool. By default this is equal to the file name. */
+ private var name: Option[String] = None
+ /** The main class to run. */
+ private var mainClass: Option[String] = None
+ /** Supported platforms for the script. Either "unix" or "windows". Defaults
+ * to both. */
+ private var platforms: List[String] = Nil
+ /** The optional version number. If set, when "-version" is passed to the
+ * script, this value will be printed. */
+ private var version: String = ""
+ /** The optional copyright notice, that will be printed in the script. */
+ private var copyright: String = "This file is copyrighted by its owner"
+ /** An (optional) path to all JARs that this script depend on. Paths must be
+ * relative to the scala home directory. If not set, all JAR archives in
+ * "lib/" are automatically added. */
+ private var classpath: List[String] = Nil
+ /** Comma-separated Java system properties to pass to the JRE. Properties
+ * are formated as name=value. Properties scala.home and scala.tool.name
+ * are always set. */
+ private var properties: List[Pair[String,String]] = Nil
+ /** Additional flags passed to the JRE ("java [javaFlags] class"). */
+ private var javaFlags: String = ""
+ /** Additional flags passed to the tool ("java class [toolFlags]"). */
+ private var toolFlags: String = ""
+ /** The path to the generic runtime script file. ".bat" will be appended for
+ * the Windows BAT file, if generated. If not set, no generic runtime
+ * script will be generated. */
+ private var genericFile: Option[File] = None
+
+/******************************************************************************\
+** Properties setters **
+\******************************************************************************/
+
+ /** Sets the file attribute. Used by Ant.
+ * @param input The value of <code>file</code>. */
+ def setFile(input: File) =
+ file = Some(input)
+
+ /** Sets the file attribute. Used by Ant.
+ * @param input The value of <code>file</code>. */
+ def setName(input: String) =
+ name = Some(input)
+
+ /** Sets the main class attribute. Used by Ant.
+ * @param input The value of <code>mainClass</code>. */
+ def setClass(input: String) =
+ mainClass = Some(input)
+
+ /** Sets the platforms attribute. Used by Ant.
+ * @param input The value for <code>platforms</code>. */
+ def setPlatforms(input: String) = {
+ platforms = List.fromArray(input.split(",")).flatMap(s: String => {
+ val st = s.trim()
+ if (Platforms.isPermissible(st))
+ (if (input != "") List(st) else Nil)
+ else {
+ error("Platform " + st + " does not exist.")
+ Nil
+ }
+ })
+ }
+
+ /** Sets the version attribute. Used by Ant.
+ * @param input The value of <code>version</code>. */
+ def setVersion(input: String) =
+ version = input
+
+ /** Sets the copyright attribute. Used by Ant.
+ * @param input The value of <code>copyright</code>. */
+ def setCopyright(input: String) =
+ copyright = input
+
+ /** Sets the classpath attribute. Used by Ant.
+ * @param input The value of <code>classpath</code>. */
+ def setClasspath(input: String) =
+ classpath = classpath ::: List.fromArray(input.split(":"))
+
+ /** Sets the properties attribute. Used by Ant.
+ * @param input The value for <code>properties</code>. */
+ def setProperties(input: String) = {
+ properties = List.fromArray(input.split(",")).flatMap(s: String => {
+ val st = s.trim(); val stArray = st.split("=", 2)
+ if (stArray.length == 2) {
+ if (input != "") List(Pair(stArray(0), stArray(1))) else Nil
+ } else error("Property " + st + " does not conform to specification.")
+ })
+ }
+
+ /** Sets the version attribute. Used by Ant.
+ * @param input The value of <code>version</code>. */
+ def setJavaFlags(input: String) =
+ javaFlags = input
+
+ /** Sets the version attribute. Used by Ant.
+ * @param input The value of <code>version</code>. */
+ def setToolFlags(input: String) =
+ toolFlags = input
+
+ /** Sets the version attribute. Used by Ant.
+ * @param input The value of <code>version</code>. */
+ def setGenericFile(input: File) =
+ genericFile = Some(input)
+
+/******************************************************************************\
+** Properties getters **
+\******************************************************************************/
+
+ /** Gets the value of the file attribute in a Scala-friendly form.
+ * @returns The file as a file. */
+ private def getFile: File =
+ if (file.isEmpty) error("Member 'file' is empty.")
+ else getProject().resolveFile(file.get.toString())
+
+ /** Gets the value of the classpath attribute in a Scala-friendly form.
+ * @returns The class path as a list of files. */
+ private def getUnixClasspath: String =
+ classpath.mkString("", ":", "")
+
+ /** Gets the value of the classpath attribute in a Scala-friendly form.
+ * @returns The class path as a list of files. */
+ private def getWinClasspath: String =
+ classpath.mkString("", ";", "")
+
+ /** Gets the value of the classpath attribute in a Scala-friendly form.
+ * @returns The class path as a list of files. */
+ private def getProperties: String =
+ properties.map({
+ case Pair(name,value) => "-D" + name + "=\"" + value + "\""
+ }).mkString("", " ", "")
+
+ /** Gets the value of the file attribute in a Scala-friendly form.
+ * @returns The file as a file. */
+ private def getGenericFile: File =
+ if (genericFile.isEmpty) error("Member 'file' is empty.")
+ else getProject().resolveFile(genericFile.get.toString())
+
+/******************************************************************************\
+** Compilation and support methods **
+\******************************************************************************/
+
+ /** Generates a build error. Error location will be the current task in the
+ * ant file.
+ * @param message A message describing the error.
+ * @throws BuildException A build error exception thrown in every case. */
+ private def error(message: String): All =
+ throw new BuildException(message, getLocation())
+
+ private def readResource(resource: String,
+ tokens: Map[String, String]
+ ): String = {
+ val chars = new Iterator[Char] {
+ private val stream =
+ this.getClass().getClassLoader().getResourceAsStream(resource)
+ private def readStream(): Char = stream.read().asInstanceOf[Char]
+ private var buf: Char = readStream()
+ def hasNext: Boolean = (buf != (-1.).asInstanceOf[Char])
+ def next: Char = {
+ val bufbuf = buf
+ buf = readStream()
+ bufbuf
+ }
+ }
+ val builder = new StringBuffer()
+ while (chars.hasNext) {
+ val char = chars.next
+ if (char == '@') {
+ var char = chars.next
+ val token = new StringBuffer()
+ while (chars.hasNext && char != '@') {
+ token.append(char)
+ char = chars.next
+ }
+ if (tokens.contains(token.toString()))
+ builder.append(tokens(token.toString()))
+ else if (token.toString() == "")
+ builder.append('@')
+ else
+ builder.append("@" + token.toString() + "@")
+ } else builder.append(char)
+ }
+ builder.toString()
+ }
+
+ private def writeFile(file: File, content: String) =
+ if (file.exists() && !file.canWrite())
+ error("File " + file + " is not writable")
+ else {
+ val writer = new FileWriter(file, false)
+ writer.write(content)
+ writer.close()
+ }
+
+
+/******************************************************************************\
+** The big execute method **
+\******************************************************************************/
+
+ /** Performs the compilation. */
+ override def execute() = {
+ // Tests if all mandatory attributes are set and valid.
+ if (file.isEmpty) error("Attribute 'file' is not set.")
+ if (name.isEmpty) name = Some(file.get.getName())
+ if (mainClass.isEmpty) error("Attribute 'mainclass' is not set.")
+ if (platforms.isEmpty) platforms = Platforms.values
+ // Gets the input streams for the script templates.
+ val resourceRoot = "scala/tools/ant/templates/"
+ val patches = ListMap.Empty.
+ update("name", name.get).
+ update("class", mainClass.get).
+ update("version", version).
+ update("copyright", copyright).
+ update("properties", getProperties).
+ update("javaflags", javaFlags).
+ update("toolflags", toolFlags)
+ if (platforms.contains("unix")) {
+ val unixPatches = patches.update("classpath", getUnixClasspath)
+ val unixTemplateResource = resourceRoot + "tool-unix.tmpl"
+ val unixTemplate = readResource(unixTemplateResource, unixPatches)
+ writeFile(getFile, unixTemplate)
+ if (!genericFile.isEmpty) {
+ val unixTemplateResource = resourceRoot + "generic-unix.tmpl"
+ val unixTemplate = readResource(unixTemplateResource, unixPatches)
+ writeFile(getGenericFile, unixTemplate)
+ }
+ }
+ if (platforms.contains("windows")) {
+ val winPatches = patches.update("classpath", getWinClasspath)
+ val winTemplateResource = resourceRoot + "tool-windows.tmpl"
+ val winTemplate = readResource(winTemplateResource, winPatches)
+ writeFile(new File(getFile.getAbsolutePath() + ".bat"), winTemplate)
+ if (!genericFile.isEmpty) {
+ val winTemplateResource = resourceRoot + "generic-windows.tmpl"
+ val winTemplate = readResource(winTemplateResource, winPatches)
+ writeFile(new File(getGenericFile.getAbsolutePath() + ".bat"),
+ winTemplate)
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index 6967e7d794..203566c52b 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -282,15 +282,13 @@ package scala.tools.ant {
* @returns The source path as a list of files. */
private def getSourcepath: List[File] =
if (sourcepath.isEmpty) error("Member 'sourcepath' is empty.")
- else
- List.fromArray(sourcepath.get.list()).map(nameToFile)
+ else List.fromArray(sourcepath.get.list()).map(nameToFile)
/** Gets the value of the bootclasspath attribute in a Scala-friendly form.
* @returns The boot class path as a list of files. */
private def getBootclasspath: List[File] =
if (bootclasspath.isEmpty) error("Member 'bootclasspath' is empty.")
- else
- List.fromArray(bootclasspath.get.list()).map(nameToFile)
+ else List.fromArray(bootclasspath.get.list()).map(nameToFile)
/** Gets the value of the extdirs attribute in a Scala-friendly form.
* @returns The extensions path as a list of files. */
@@ -391,7 +389,8 @@ package scala.tools.ant {
originFile
}
- if (sourceFiles.length == 0) log("No files selected for compilation")
+ if (sourceFiles.length == 0)
+ log("No files selected for compilation", Project.MSG_VERBOSE)
else log("Compiling " + sourceFiles.length + " source file" +
(if (sourceFiles.length > 1) "s" else "") +
(" to " + getDestination.toString()))
@@ -442,7 +441,7 @@ package scala.tools.ant {
}
if (reporter.warnings > 0)
log("Compile suceeded with " +
- reporter.errors + " warning" +
+ reporter.warnings + " warning" +
(if (reporter.warnings > 1) "s" else "") +
"; see the compiler output for details."
)
diff --git a/src/compiler/scala/tools/ant/antlib.xml b/src/compiler/scala/tools/ant/antlib.xml
new file mode 100644
index 0000000000..7c8c9f00fd
--- /dev/null
+++ b/src/compiler/scala/tools/ant/antlib.xml
@@ -0,0 +1,12 @@
+<antlib>
+ <!--<taskdef name="scala"
+ classname="scala.tools.ant.Scala"/>-->
+ <taskdef name="scalac"
+ classname="scala.tools.ant.Scalac"/>
+ <taskdef name="scalascript"
+ classname="scala.tools.ant.ScalaTool"/>
+ <!--<taskdef name="scalatest"
+ classname="scala.tools.ant.ScalaTest"/>-->
+ <!--<taskdef name="scalatest"
+ classname="scala.tools.ant.ScalaDoc"/>-->
+</antlib>
diff --git a/src/compiler/scala/tools/ant/templates/generic-unix.tmpl b/src/compiler/scala/tools/ant/templates/generic-unix.tmpl
new file mode 100644
index 0000000000..066d623854
--- /dev/null
+++ b/src/compiler/scala/tools/ant/templates/generic-unix.tmpl
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+##############################################################################
+# Scala runtime @version@
+##############################################################################
+# @copyright@
+# This is free software; see the distribution for copying conditions.
+# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+##############################################################################
+
+cygwin=false;
+darwin=false;
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ Darwin*) darwin=true ;;
+esac
+
+SOURCE=$0;
+SCRIPT=`basename "$SOURCE"`;
+while [ -h "$SOURCE" ]; do
+ SCRIPT=`basename "$SOURCE"`;
+ LOOKUP=`ls -ld "$SOURCE"`;
+ TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`;
+ if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then
+ SOURCE=${TARGET:-.};
+ else
+ SOURCE=`dirname "$SOURCE"`/${TARGET:-.};
+ fi;
+done;
+PREFIX=`dirname "$SOURCE"`/..;
+prefix=$PREFIX;
+PREFIX=`cd "$PREFIX"; pwd`;
+
+CP=@classpath@
+if [ "$CP" == "" ] ; then
+ for jar in `ls $PREFIX/lib/*.jar` ; do
+ CP=$CP:$jar
+ done
+ CP=${CP:1}
+fi
+
+if $cygwin; then
+ if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
+ format=mixed
+ else
+ format=windows
+ fi
+ CP=`cygpath --path --$format "$CP"`
+fi
+
+for flag in "$@@" ; do
+ if [ $flag == '-version' ] ; then
+ echo "Scala runtime version @version@"
+ ${JAVACMD:=java} -version
+ exit 0
+ fi
+done
+
+${JAVACMD:=java} @javaflags@ -cp "$CP" "$@@" \ No newline at end of file
diff --git a/src/compiler/scala/tools/ant/templates/generic-windows.tmpl b/src/compiler/scala/tools/ant/templates/generic-windows.tmpl
new file mode 100644
index 0000000000..7b87904f9a
--- /dev/null
+++ b/src/compiler/scala/tools/ant/templates/generic-windows.tmpl
@@ -0,0 +1,42 @@
+@echo off
+
+rem ##########################################################################
+rem # Copyright @copyright@
+rem #
+rem # This is free software; see the distribution for copying conditions.
+rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
+rem # PARTICULAR PURPOSE.
+rem ##########################################################################
+
+if "%OS%"=="Windows_NT" @setlocal
+if "%OS%"=="Windows_NT" @set SCALA_HOME=%~dp0..
+
+if "%SCALA_HOME%"=="" goto error1
+
+set _ARGS=
+:loop
+if '%1' == '' goto exec
+set _ARGS=%_ARGS% %1
+shift
+goto loop
+
+:exec
+set _JAVACMD=java
+set _MAIN=@tool.class@
+set _TOOLS_CPATH=@fjbg.jar@;@msil.jar@;@comp.path@;@lib.path@
+set _LIB_CPATH=@lib.path@
+set _PROPS=-Dscala.version=@version@ -Dscala.home="%SCALA_HOME%" -Dscala.boot.class.path="%_LIB_CPATH%"
+
+rem echo %_JAVACMD% %_PROPS% -cp %_TOOLS_CPATH% %_MAIN% %_ARGS%
+%_JAVACMD% %_PROPS% -cp %_TOOLS_CPATH% %_MAIN% %_ARGS%
+goto end
+
+rem ##########################################################################
+rem # errors
+
+:error1
+echo ERROR: environment variable SCALA_HOME is undefined. It should point to the directory containing the file "VERSION-@version@".
+goto end
+
+:end
+if "%OS%"=="Windows_NT" @endlocal
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
new file mode 100644
index 0000000000..081b0219da
--- /dev/null
+++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+##############################################################################
+# @name@ @version@
+##############################################################################
+# @copyright@
+# This is free software; see the distribution for copying conditions.
+# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+##############################################################################
+
+cygwin=false;
+darwin=false;
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ Darwin*) darwin=true ;;
+esac
+
+SOURCE=$0;
+SCRIPT=`basename "$SOURCE"`;
+while [ -h "$SOURCE" ]; do
+ SCRIPT=`basename "$SOURCE"`;
+ LOOKUP=`ls -ld "$SOURCE"`;
+ TARGET=`expr "$LOOKUP" : '.*-> \(.*\)$'`;
+ if expr "${TARGET:-.}/" : '/.*/$' > /dev/null; then
+ SOURCE=${TARGET:-.};
+ else
+ SOURCE=`dirname "$SOURCE"`/${TARGET:-.};
+ fi;
+done;
+PREFIX=`dirname "$SOURCE"`/..;
+prefix=$PREFIX;
+PREFIX=`cd "$PREFIX"; pwd`;
+
+CP=@classpath@
+if [ "$CP" == "" ] ; then
+ for jar in `ls $PREFIX/lib/*.jar` ; do
+ CP=$CP:$jar
+ done
+ CP=${CP:1}
+fi
+
+if $cygwin; then
+ if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
+ format=mixed
+ else
+ format=windows
+ fi
+ CP=`cygpath --path --$format "$CP"`
+fi
+
+for flag in "$@@" ; do
+ if [ $flag == '-version' ] ; then
+ echo "@name@ version @version@"
+ exit 0
+ fi
+done
+
+${JAVACMD:=java} @javaflags@ -Dscala.home="$PREFIX" -Dscala.tool.name="@name@" -Dscala.tool.version="@version@" @properties@ -cp "$CP" @class@ @toolflags@ "$@@" \ No newline at end of file
diff --git a/src/compiler/scala/tools/ant/templates/tool-windows.tmpl b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl
new file mode 100644
index 0000000000..7b87904f9a
--- /dev/null
+++ b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl
@@ -0,0 +1,42 @@
+@echo off
+
+rem ##########################################################################
+rem # Copyright @copyright@
+rem #
+rem # This is free software; see the distribution for copying conditions.
+rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
+rem # PARTICULAR PURPOSE.
+rem ##########################################################################
+
+if "%OS%"=="Windows_NT" @setlocal
+if "%OS%"=="Windows_NT" @set SCALA_HOME=%~dp0..
+
+if "%SCALA_HOME%"=="" goto error1
+
+set _ARGS=
+:loop
+if '%1' == '' goto exec
+set _ARGS=%_ARGS% %1
+shift
+goto loop
+
+:exec
+set _JAVACMD=java
+set _MAIN=@tool.class@
+set _TOOLS_CPATH=@fjbg.jar@;@msil.jar@;@comp.path@;@lib.path@
+set _LIB_CPATH=@lib.path@
+set _PROPS=-Dscala.version=@version@ -Dscala.home="%SCALA_HOME%" -Dscala.boot.class.path="%_LIB_CPATH%"
+
+rem echo %_JAVACMD% %_PROPS% -cp %_TOOLS_CPATH% %_MAIN% %_ARGS%
+%_JAVACMD% %_PROPS% -cp %_TOOLS_CPATH% %_MAIN% %_ARGS%
+goto end
+
+rem ##########################################################################
+rem # errors
+
+:error1
+echo ERROR: environment variable SCALA_HOME is undefined. It should point to the directory containing the file "VERSION-@version@".
+goto end
+
+:end
+if "%OS%"=="Windows_NT" @endlocal
diff --git a/src/compiler/scala/tools/nsc/ant/NSC.scala b/src/compiler/scala/tools/nsc/ant/NSC.scala
deleted file mode 100644
index 33ae7d4f03..0000000000
--- a/src/compiler/scala/tools/nsc/ant/NSC.scala
+++ /dev/null
@@ -1,640 +0,0 @@
-/* __ ______________ *\
-** / |/ / ____/ ____/ **
-** / | | /___ / /___ **
-** /_/|__/_____/_____/ Copyright 2005-2006 LAMP/EPFL **
-\* */
-
-// $Id$
-
-
-package scala.tools.nsc.ant {
-
- import java.io.File;
- import java.net.URL;
- import java.net.URLClassLoader;
- import java.util.ArrayList;
- import java.util.Vector;
-
- import org.apache.tools.ant.AntClassLoader;
- import org.apache.tools.ant.BuildException;
- import org.apache.tools.ant.DirectoryScanner;
- import org.apache.tools.ant.Project;
- import org.apache.tools.ant.taskdefs.MatchingTask;
- import org.apache.tools.ant.types.Path;
- import org.apache.tools.ant.util.FileUtils;
- import org.apache.tools.ant.util.GlobPatternMapper;
- import org.apache.tools.ant.util.SourceFileScanner;
- import org.apache.tools.ant.types.EnumeratedAttribute;
- import org.apache.tools.ant.types.Reference;
-
- import scala.tools.nsc.reporters.{Reporter,ConsoleReporter};
-
- /**
- * An Ant task to compile with the new Scala compiler (NSC).
- * This task can take the following parameters as attributes:<ul>
- * <li>srcdir (mandatory),</li>
- * <li>srcref,</li>
- * <li>destdir,</li>
- * <li>classpath,</li>
- * <li>classpathref,</li>
- * <li>sourcepath,</li>
- * <li>sourcepathref,</li>
- * <li>bootclasspath,</li>
- * <li>bootclasspathref,</li>
- * <li>extdirs,</li>
- * <li>extdirsref,</li>
- * <li>encoding,</li>
- * <li>verbose,</li>
- * <li>debug,</li>
- * <li>usepredefs,</li>
- * <li>useimports,</li>
- * <li>force,</li>
- * <li>stop,</li>
- * <li>skip,</li>
- * <li>check,</li>
- * <li>print,</li>
- * <li>showicode,</li>
- * <li>log,</li>
- * <li>debuginfo.</li>
- * </ul>
- * It also takes the following parameters as nested elements:<ul>
- * <li>src (for srcdir),</li>
- * <li>classpath,</li>
- * <li>sourcepath,</li>
- * <li>bootclasspath,</li>
- * <li>extdirs.</li>
- * </ul>
- *
- * @author Gilles Dubochet
- */
- class NSC extends MatchingTask {
-
- private val SCALA_PRODUCT: String =
- System.getProperty("scala.product", "Scalac Ant compiler");
- private val SCALA_VERSION: String =
- System.getProperty("scala.version", "Unknown version");
-
- /** The unique Ant file utilities instance to use in this task. */
- private val fileUtils = FileUtils.newFileUtils();
-
- // ###################################################################
- // ##### Ant Properties #####
- // ###################################################################
-
- abstract class PermissibleValue {
- val values: List[String];
- def isPermissible(value: String): Boolean = (
- (value == "") ||
- values.exists(v: String => v startsWith value)
- )
- }
-
- /** Defines valid values for the logging property. */
- object LoggingLevel extends PermissibleValue {
- val values = List("none", "verbose", "debug");
- }
-
- /** Defines valid values for properties that refer to compiler phases. */
- object CompilerPhase extends PermissibleValue {
- val values = List(
- "namer", "typer", "pickler", "uncurry", "tailcalls",
- "transmatch", "explicitouter", "erasure", "lambdalift",
- "flatten", "constructors", "mixin", "icode", "jvm", "terminal");
- }
-
- /** The directories that contain source files to compile. */
- private var origin: Option[Path] = None;
- /** The directory to put the compiled files in. */
- private var destination: Option[File] = None;
-
- /** The class path to use for this compilation. */
- private var classpath: Option[Path] = None;
- /** The source path to use for this compilation. */
- private var sourcepath: Option[Path] = None;
- /** The boot class path to use for this compilation. */
- private var bootclasspath: Option[Path] = None;
- /** The external extensions path to use for this compilation. */
- private var extpath: Option[Path] = None;
-
- /** The text encoding of the files to compile. */
- private var encoding: Option[String] = None;
-
- /** How much logging output to print. Either none (default), verbose or debug. */
- private var logging: Option[String] = None;
- /** Whether to use implicit predefined values or not. */
- private var usepredefs: Boolean = true;
- /** Whether to implicitly import or not. */
- private var useimports: Boolean = true;
- /** Whether to force compilation of all files or not. */
- private var force: Boolean = false;
- /** After which phase the compilation should stop. */
- private var stop: Option[String] = None;
- /** Which compilation phases should be skipped during compilation. */
- private var skip: List[String] = Nil;
- /** Which compilation phases should be logged during compilation. */
- private var logPhase: List[String] = Nil;
- /** Which compilation phases results should be checked for consistency. */
- private var check: List[String] = Nil;
- /** Which compilation phases results should be printed-out. */
- private var print: List[String] = Nil;
- /** Print ICode files along with class files (debug option). */
- private var showICode: Boolean = false;
-
- /** Instruct the compiler to generate debugging information (pass '-g') */
- private var debugInfo: Boolean = false;
-
-
- // ###################################################################
- // ##### Properties setters #####
- // ###################################################################
-
- /**
- * Sets the srcdir attribute. Used by Ant.
- * @param input The value of <code>origin</code>.
- */
- def setSrcdir(input: Path) =
- if (origin.isEmpty)
- origin = Some(input);
- else
- origin.get.append(input);
-
- /**
- * Sets the <code>origin</code> as a nested src Ant parameter.
- * @return An origin path to be configured.
- */
- def createSrc(): Path = {
- if (origin.isEmpty) {
- origin = Some(new Path(getProject()))
- }
- origin.get.createPath()
- }
-
- /**
- * Sets the <code>origin</code> as an external reference Ant parameter.
- * @param input A reference to an origin path.
- */
- def setSrcref(input: Reference) =
- createSrc().setRefid(input);
-
- /**
- * Gets the value of the origin attribute in a Scala-friendly form.
- * @returns The origin path as a list of files.
- */
- private def getOrigin: List[File] =
- if (origin.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'origin' is empty.");
- else
- List.fromArray(origin.get.list()).map(nameToFile("src"));
-
- /**
- * Sets the destdir attribute. Used by Ant.
- * @param input The value of <code>destination</code>.
- */
- def setDestdir(input: File) =
- destination = Some(input);
-
- /**
- * Gets the value of the destination attribute in a Scala-friendly form.
- * @returns The destination as a file.
- */
- private def getDestination: File =
- if (destination.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'destination' is empty.");
- else
- testReadableFile("destdir")(getProject().resolveFile(destination.get.toString()));
-
- /**
- * Sets the classpath attribute. Used by Ant.
- * @param input The value of <code>classpath</code>.
- */
- def setClasspath(input: Path) =
- if (classpath.isEmpty)
- classpath = Some(input);
- else
- classpath.get.append(input);
-
- /**
- * Sets the <code>classpath</code> as a nested classpath Ant parameter.
- * @return A class path to be configured.
- */
- def createClasspath(): Path = {
- if (classpath.isEmpty) {
- classpath = Some(new Path(getProject()))
- }
- classpath.get.createPath()
- }
-
- /**
- * Sets the <code>classpath</code> as an external reference Ant parameter.
- * @param input A reference to a class path.
- */
- def setClasspathref(input: Reference) =
- createClasspath().setRefid(input);
-
- /**
- * Gets the value of the classpath attribute in a Scala-friendly form.
- * @returns The class path as a list of files.
- */
- private def getClasspath: List[File] =
- if (classpath.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'classpath' is empty.");
- else
- List.fromArray(classpath.get.list()).map(nameToFile("classpath"));
-
- /**
- * Sets the sourcepath attribute. Used by Ant.
- * @param input The value of <code>sourcepath</code>.
- */
- def setSourcepath(input: Path) =
- if (sourcepath.isEmpty)
- sourcepath = Some(input);
- else
- sourcepath.get.append(input);
-
- /**
- * Sets the <code>sourcepath</code> as a nested sourcepath Ant parameter.
- * @return A source path to be configured.
- */
- def createSourcepath(): Path = {
- if (sourcepath.isEmpty) {
- sourcepath = Some(new Path(getProject()))
- }
- sourcepath.get.createPath()
- }
-
- /**
- * Sets the <code>sourcepath</code> as an external reference Ant parameter.
- * @param input A reference to a source path.
- */
- def setSourcepathref(input: Reference) =
- createSourcepath().setRefid(input);
-
- /**
- * Gets the value of the sourcepath attribute in a Scala-friendly form.
- * @returns The source path as a list of files.
- */
- private def getSourcepath: List[File] =
- if (sourcepath.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'sourcepath' is empty.");
- else
- List.fromArray(sourcepath.get.list()).map(nameToFile("sourcepath"));
-
- /**
- * Sets the boot classpath attribute. Used by Ant.
- * @param input The value of <code>bootclasspath</code>.
- */
- def setBootclasspath(input: Path) =
- if (bootclasspath.isEmpty)
- bootclasspath = Some(input);
- else
- bootclasspath.get.append(input);
-
- /**
- * Sets the <code>bootclasspath</code> as a nested sourcepath Ant parameter.
- * @return A source path to be configured.
- */
- def createBootclasspath(): Path = {
- if (bootclasspath.isEmpty) {
- bootclasspath = Some(new Path(getProject()))
- }
- bootclasspath.get.createPath()
- }
-
- /**
- * Sets the <code>bootclasspath</code> as an external reference Ant parameter.
- * @param input A reference to a source path.
- */
- def setBootclasspathref(input: Reference) =
- createBootclasspath().setRefid(input);
-
- /**
- * Gets the value of the bootclasspath attribute in a Scala-friendly form.
- * @returns The boot class path as a list of files.
- */
- private def getBootclasspath: List[File] =
- if (bootclasspath.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'bootclasspath' is empty.");
- else
- List.fromArray(bootclasspath.get.list()).map(nameToFile("bootclasspath"));
-
- /**
- * Sets the external extensions path attribute. Used by Ant.
- * @param input The value of <code>extpath</code>.
- */
- def setExtdirs(input: Path) =
- if (extpath.isEmpty)
- extpath = Some(input);
- else
- extpath.get.append(input);
-
- /**
- * Sets the <code>extpath</code> as a nested sourcepath Ant parameter.
- * @return An extensions path to be configured.
- */
- def createExtdirs(): Path = {
- if (extpath.isEmpty) {
- extpath = Some(new Path(getProject()))
- }
- extpath.get.createPath()
- }
-
- /**
- * Sets the <code>extpath</code> as an external reference Ant parameter.
- * @param input A reference to an extensions path.
- */
- def setExtdirsref(input: Reference) =
- createExtdirs().setRefid(input);
-
- /**
- * Gets the value of the extpath attribute in a Scala-friendly form.
- * @returns The extensions path as a list of files.
- */
- private def getExtpath: List[File] =
- if (extpath.isEmpty)
- throw new ArrayIndexOutOfBoundsException("Member 'extdirs' is empty.");
- else
- List.fromArray(extpath.get.list()).map(nameToFile("extdirs"));
-
- /**
- * Sets the encoding attribute. Used by Ant.
- * @param input The value of <code>encoding</code>.
- */
- def setEncoding(input: String): Unit =
- encoding = Some(input);
-
- /**
- * Sets the logging level attribute. Used by Ant.
- * @param input The value for <code>logging</code>.
- */
- def setLogging(input: String) =
- if (LoggingLevel.isPermissible(input))
- logging = Some(input);
- else
- error("Logging level '" + input + "' does not exist.");
-
- /**
- * Sets the use predefs attribute. Used by Ant.
- * @param input The value for <code>usepredefs</code>.
- */
- def setUsepredefs(input: Boolean): Unit =
- usepredefs = input;
-
- /**
- * Sets the use imports attribute. Used by Ant.
- * @param input The value for <code>useimport</code>.
- */
- def setUseimports(input: Boolean): Unit =
- useimports = input;
-
- /**
- * Sets the force attribute. Used by Ant.
- * @param input The value for <code>force</code>.
- */
- def setForce(input: Boolean): Unit =
- force = input;
-
- /**
- * Sets the force attribute. Used by Ant.
- * @param input The value for <code>force</code>.
- */
- def setStop(input: String) =
- if (CompilerPhase.isPermissible(input)) {
- if (input != "")
- stop = Some(input);
- }
- else
- error("Phase '" + input + "' in stop does not exist.");
-
- /**
- * Sets the force attribute. Used by Ant.
- * @param input The value for <code>force</code>.
- */
- def setSkip(input: String) = {
- skip = List.fromArray(input.split(",")).flatMap(s: String => {
- val st = s.trim();
- if (CompilerPhase.isPermissible(st)) (if (input != "") List(st) else Nil)
- else {error("Phase '" + st + "' in skip does not exist."); Nil}
- });
- }
-
- /**
- * Sets the log attribute. Used by Ant.
- * @param input The value for <code>logPhase</code>.
- */
- def setLog(input: String) = {
- logPhase = List.fromArray(input.split(",")).flatMap(s: String => {
- val st = s.trim();
- if (CompilerPhase.isPermissible(st)) (if (input != "") List(st) else Nil)
- else {error("Phase " + st + " in log does not exist."); Nil}
- });
- }
-
- /**
- * Sets the check attribute. Used by Ant.
- * @param input The value for <code>check</code>.
- */
- def setCheck(input: String) = {
- check = List.fromArray(input.split(",")).flatMap(s: String => {
- val st = s.trim();
- if (CompilerPhase.isPermissible(st)) (if (input != "") List(st) else Nil)
- else {error("Phase " + st + " in check does not exist."); Nil}
- });
- }
-
- /**
- * Sets the print attribute. Used by Ant.
- * @param input The value for <code>print</code>.
- */
- def setPrint(input: String) = {
- print = List.fromArray(input.split(",")).flatMap(s: String => {
- val st = s.trim();
- if (CompilerPhase.isPermissible(st)) (if (input != "") List(st) else Nil)
- else {error("Phase " + st + " in print does not exist."); Nil}
- });
- }
-
- def setShowicode(input: Boolean): Unit =
- showICode = input;
-
- /**
- * Set the debug info attribute.
- */
- def setDebuginfo(input: Boolean): Unit =
- debugInfo = input;
-
- // ###################################################################
- // ##### Compilation and support methods #####
- // ###################################################################
-
- override protected def getDirectoryScanner (baseDir: java.io.File) =
- super.getDirectoryScanner(baseDir);
-
- /**
- * Creates a file from a given string.
- * @param test A method to test whether the file is valid.
- * @param name The path of the file as a string.
- * @return The file corresponding to the provided name.
- */
- private def nameToFile(test: File=>File)(name: String): File =
- test(getProject().resolveFile(name));
-
- /**
- * Creates a file from a given string.
- * @param test A method to test whether the file is valid.
- * @param name The path of the file as a string.
- * @return The file corresponding to the provided name.
- */
- private def nameToFile(test: File=>File, origin: File)(name: String): File =
- test(fileUtils.resolveFile(origin, name));
-
- /**
- * Creates a file from a given string and tests its validity using the <code>testReadableFile</code> method.
- * @param pathName The name of the path in which the file is.
- * @param name The path of the file as a string.
- * @return The file corresponding to the provided name.
- */
- private def nameToFile(pathName: String, origin: File)(name: String): File = {
- nameToFile((f: File) => testReadableFile(pathName)(f), origin)(name);
- }
-
- /**
- * Creates a file from a given string and tests its validity using the <code>testReadableFile</code> method.
- * @param pathName The name of the path in which the file is.
- * @param name The path of the file as a string.
- * @return The file corresponding to the provided name.
- */
- private def nameToFile(pathName: String)(name: String): File = {
- nameToFile((f: File) => testReadableFile(pathName)(f))(name);
- }
-
- /**
- * Tests whether a file is readable (if it does not exist, it is not readable.
- * If it is not readable, prints a warning message.
- * @param pathName The name of the path in which the file is (used for printing-out warning message).
- * @param file The file to test.
- * @return The same file as provided.
- */
- private def testReadableFile(pathName: String)(file: File): File = {
- if (!file.exists())
- log("Element '" + file.toString() + "' in " + pathName + " does not exist.", Project.MSG_WARN);
- file
- }
-
- private def asString(path: List[File]): String = {
- path.map(file: File => asString(file)).mkString("", File.pathSeparator, "")
- }
-
- private def asString(file: File): String =
- file.getAbsolutePath();
-
- /**
- * Generates a build error. Error location will be the current task in the ant file.
- * @param message The message of the error. This message should be end-user readable.
- * @throws org.apache.tools.ant.BuildException The build error exception. Will be thrown in all conditions.
- */
- private def error(message: String) = {
- throw new BuildException(message, getLocation());
- }
-
- /**
- * Performs the compilation.
- */
- override def execute() = {
-
- // Tests if all mandatory attributes are set and valid.
- if (origin.isEmpty) error("Attribute 'srcdir' is not set.");
- if (getOrigin.isEmpty) error("Attribute 'srcdir' is not set.");
- if (!destination.isEmpty && !destination.get.isDirectory())
- error("Attribute 'destdir' does not refer to an existing directory.");
- if (destination.isEmpty) {
- destination = Some(getOrigin.head);
- }
-
- val mapper = new GlobPatternMapper();
- mapper.setTo("*.class");
- mapper.setFrom("*.scala");
-
- // Scans source directories to build up a compile lists.
- // If force is false, only files were the .class file in destination is older than
- // the .scala file will be used.
- val sourceFiles: List[File] =
- for (val originDir <- getOrigin;
- val originFile <- {
- var includedFiles = getDirectoryScanner(originDir).getIncludedFiles();
- if (!force) {
- includedFiles = new SourceFileScanner(this)
- .restrict(includedFiles, originDir, destination.get, mapper)
- }
- (List.fromArray(includedFiles)).map(nameToFile("srcdir", originDir))
- }
- ) yield {
- log(originFile.toString(), Project.MSG_VERBOSE);
- originFile
- }
-
- if (sourceFiles.length == 0)
- log("No files selected for compilation")
- else
- log("Compiling " + sourceFiles.length + " source file"
- + (if (sourceFiles.length > 1) "s" else "")
- + (" to " + getDestination.toString()));
-
- System.setProperty("scala.library.class.path", "");
- System.setProperty("scala.library.source.path", "");
-
- // Builds-up the compilation settings for Scalac with the existing Ant parameters.
- val reporter = new ConsoleReporter();
- val settings = new Settings(error);
- settings.outdir.value = asString(destination.get);
- if (!classpath.isEmpty) settings.classpath.value = asString(getClasspath);
- if (!sourcepath.isEmpty) settings.sourcepath.value = asString(getSourcepath)
- else if (origin.get.size() > 0) settings.sourcepath.value = origin.get.list()(0);
- if (!bootclasspath.isEmpty) settings.bootclasspath.value = asString(getBootclasspath);
- if (!extpath.isEmpty) settings.extdirs.value = asString(getExtpath);
- if (!encoding.isEmpty) settings.encoding.value = encoding.get;
- if (!logging.isEmpty && logging.get == "verbose") {
- settings.verbose.value = true;
- }
- else if (!logging.isEmpty && logging.get == "debug") {
- settings.verbose.value = true;
- settings.debug.value = true;
- }
- settings.noimports.value = !useimports;
- settings.nopredefs.value = !usepredefs;
- if (!stop.isEmpty) settings.stop.value = List(stop.get);
- if (!skip.isEmpty) settings.skip.value = skip;
- if (!check.isEmpty) settings.check.value = check;
- if (!print.isEmpty) settings.print.value = print;
- settings.Xshowicode.value = showICode;
- settings.debuginfo.value = debugInfo;
- if (!logPhase.isEmpty) settings.log.value = logPhase;
-
- // Compiles the actual code
- val compiler = new Global(settings, reporter);
- try {
- (new compiler.Run).compile(sourceFiles.map(f:File=>f.toString()));
- if (reporter.errors > 0)
- error("Compile failed with "
- + reporter.errors + " error"
- + (if (reporter.errors > 1) "s" else "")
- + "; see the compiler error output for details.");
- }
- catch {
- case exception @ FatalError(msg) => {
- exception.printStackTrace();
- if (settings.debug.value) exception.printStackTrace();
- error("Compile failed because of an internal compiler error ("
- + msg + "); see the error output for details.");
- }
- }
- if (reporter.warnings > 0)
- log("Compile suceeded with "
- + reporter.errors + " warning"
- + (if (reporter.warnings > 1) "s" else "")
- + "; see the compiler output for details.");
- reporter.printSummary()
- }
-
- }
-
-}