summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/ant/ScalaTool.scala243
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-unix.tmpl31
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-windows.tmpl28
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala2
4 files changed, 84 insertions, 220 deletions
diff --git a/src/compiler/scala/tools/ant/ScalaTool.scala b/src/compiler/scala/tools/ant/ScalaTool.scala
index f53363623c..bfd78ae4d5 100644
--- a/src/compiler/scala/tools/ant/ScalaTool.scala
+++ b/src/compiler/scala/tools/ant/ScalaTool.scala
@@ -10,39 +10,31 @@
package scala.tools.ant
-import scala.collection.immutable.{Map, ListMap}
-
import java.io.{File, InputStream, FileWriter}
import org.apache.tools.ant.BuildException
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.types.{Path, Reference}
/** <p>
* An Ant task that generates a shell or batch script to execute a
- * <a href="http://scala-lang.org/" target="_top">Scala</a> program.
+ * Scala program.
* This task can take the following parameters as attributes:
* </p><ul>
* <li>file (mandatory),</li>
- * <li>name,</li>
* <li>class (mandatory),</li>
* <li>platforms,</li>
- * <li>version,</li>
- * <li>copyright,</li>
- * <li>bootclasspath,</li>
- * <li>extclasspath,</li>
+ * <li>classpath,</li>
* <li>properties,</li>
* <li>javaflags,</li>
* <li>toolflags.</li></ul>
*
* @author Gilles Dubochet
- * @version 1.0
+ * @version 1.1
*/
class ScalaTool extends MatchingTask {
- /** The unique Ant file utilities instance to use in this task. */
- private val fileUtils = FileUtils.newFileUtils()
+ private def emptyPath = new Path(getProject)
/*============================================================================*\
** Ant user-properties **
@@ -60,89 +52,49 @@ class ScalaTool extends MatchingTask {
}
/** The path to the exec script file. ".bat" will be appended for the
- * Windows BAT file, if generated.
- */
+ * Windows BAT file, if generated. */
private var file: Option[File] = None
/** The main class to run. */
private var mainClass: Option[String] = None
- /** The name of this tool. Can only be set when a main class is defined,
- * default this is equal to the file name.
- */
- private var name: 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"
-
- /** The optional boot classpath */
- private var bootclasspath: List[String] = Nil
+ * Defaults to both. */
+ private var platforms: List[String] = List("unix", "windows")
/** 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 extclasspath: List[String] = Nil
+ * relative to the scala home directory. If not set, all JAR archives and
+ * folders in "lib/" are automatically added. */
+ private var classpath: Option[Path] = None
/** Comma-separated Java system properties to pass to the JRE. Properties
- * are formated as name=value. Properties scala.home, scala.tool.name and
- * scala.tool.version are always set.
- */
- private var properties: List[Pair[String,String]] = Nil
+ * are formated as name=value. Properties scala.home, scala.tool.name and
+ * scala.tool.version are always set. */
+ private var properties: List[(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]"). Can only
- * be set when a main class is defined.
- */
+ * be set when a main class is defined. */
private var toolFlags: String = ""
/*============================================================================*\
** Properties setters **
\*============================================================================*/
- /** Sets the file attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>file</code>.
- */
+ /** Sets the file attribute. */
def setFile(input: File) =
file = Some(input)
- /** Sets the file attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>file</code>.
- */
- def setName(input: String) =
- name = Some(input)
-
- /** Sets the main class attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>mainClass</code>.
- */
+ /** Sets the main class attribute. */
def setClass(input: String) =
mainClass = Some(input)
- /** Sets the platforms attribute. Used by Ant.
- *
- * @param input The value for <code>platforms</code>.
- */
+ /** Sets the platforms attribute. */
def setPlatforms(input: String) = {
platforms = List.fromArray(input.split(",")).flatMap { s: String =>
- val st = s.trim()
+ val st = s.trim
if (Platforms.isPermissible(st))
(if (input != "") List(st) else Nil)
else {
@@ -152,102 +104,55 @@ class ScalaTool extends MatchingTask {
}
}
- /** Sets the version attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>version</code>.
- */
- def setVersion(input: String) =
- version = input
-
- /** Sets the copyright attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>copyright</code>.
- */
- def setCopyright(input: String) =
- copyright = input
-
- /** Sets the boot classpath attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>bootclasspath</code>.
- */
- def setBootclasspath(input: String) =
- bootclasspath = bootclasspath ::: List.fromArray(input.split(":"))
-
- /** Sets the extension classpath attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>extclasspath</code>.
- */
- def setExtclasspath(input: String) =
- extclasspath = extclasspath ::: List.fromArray(input.split(":"))
-
- /** Sets the properties attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value for <code>properties</code>.
- */
+ /** Sets the classpath with which to run the tool. */
+ def setClassPath(input: Path): Unit =
+ if (classpath.isEmpty)
+ classpath = Some(input)
+ else
+ classpath.get.append(input)
+ def createClassPath: Path = {
+ if (classpath.isEmpty) classpath = Some(emptyPath)
+ classpath.get.createPath()
+ }
+ def setClassPathRef(input: Reference): Unit =
+ createClassPath.setRefid(input)
+
+ /** Sets JVM properties that will be set whilst running the tool. */
def setProperties(input: String) = {
properties = List.fromArray(input.split(",")).flatMap { s: String =>
- val st = s.trim(); val stArray = st.split("=", 2)
+ 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.")
+ }
+ else
+ error("Property " + st + " is not formatted properly.")
}
}
- /** Sets the version attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>version</code>.
- */
+ /** Sets flags to be passed to the Java interpreter. */
def setJavaflags(input: String) =
- javaFlags = input
+ javaFlags = input.trim
- /** Sets the version attribute.
- * Used by <a href="http://ant.apache.org/" target="_top">Ant</a>.
- *
- * @param input The value of <code>version</code>.
- */
+ /** Sets flags to be passed to the tool. */
def setToolflags(input: String) =
- toolFlags = input
+ toolFlags = input.trim
/*============================================================================*\
** 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 bootclasspath attribute in a Scala-friendly form.
- * @returns The boot class path as a list of files. */
- private def getUnixBootClasspath: String =
- bootclasspath.mkString("", ":", "")
-
- /** Gets the value of the bootclasspath attribute in a Scala-friendly form.
- * @returns The boot class path as a list of files. */
- private def getWinBootClasspath: String =
- bootclasspath.map(_.replace('/', '\\')).
- mkString("", ";", "")
-
/** Gets the value of the classpath attribute in a Scala-friendly form.
* @returns The class path as a list of files. */
- private def getUnixExtClasspath: String =
- extclasspath.mkString("", ":", "")
+ private def getUnixclasspath: String =
+ classpath.getOrElse(emptyPath).list.mkString("", ":", "")
/** Gets the value of the classpath attribute in a Scala-friendly form.
* @returns The class path as a list of files. */
- private def getWinExtClasspath: String =
- extclasspath.map(_.replace('/', '\\')).
+ private def getWinclasspath: String =
+ classpath.getOrElse(emptyPath).list.map(_.replace('/', '\\')).
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 + "\""
@@ -264,9 +169,7 @@ class ScalaTool extends MatchingTask {
private def error(message: String): Nothing =
throw new BuildException(message, getLocation())
- private def readResource(resource: String,
- tokens: Map[String, String]
- ): String = {
+ private def readAndPatchResource(resource: String, tokens: Map[String, String]): String = {
val chars = new Iterator[Char] {
private val stream =
this.getClass().getClassLoader().getResourceAsStream(resource)
@@ -315,47 +218,35 @@ class ScalaTool extends MatchingTask {
private def expandWinVar(vars: Map[String,String]): Map[String,String] =
vars transform { (x, vari) => vari.replaceAll("#([^#]*)#", "%_$1%") }
- private def pipeTemplate(template: String, patches: Map[String,String]) = {
- val resourceRoot = "scala/tools/ant/templates/"
- if (platforms.contains("unix")) {
- val unixPatches = expandUnixVar(patches.
- update("bootclasspath", getUnixBootClasspath).
- update("extclasspath", getUnixExtClasspath))
- val unixTemplateResource = resourceRoot + template + "-unix.tmpl"
- val unixTemplate = readResource(unixTemplateResource, unixPatches)
- writeFile(getFile, unixTemplate)
- }
- if (platforms.contains("windows")) {
- val winPatches = expandWinVar(patches.
- update("bootclasspath", getWinBootClasspath).
- update("extclasspath", getWinExtClasspath))
- val winTemplateResource = resourceRoot + template + "-windows.tmpl"
- val winTemplate = readResource(winTemplateResource, winPatches)
- writeFile(new File(getFile.getAbsolutePath() + ".bat"), winTemplate)
- }
- }
-
/*============================================================================*\
** The big execute method **
\*============================================================================*/
- /** Performs the compilation. */
+ /** Performs the tool creation. */
override def execute() = {
// Tests if all mandatory attributes are set and valid.
if (file.isEmpty) error("Attribute 'file' is not set.")
if (mainClass.isEmpty) error("Main class must be set.")
- if (platforms.isEmpty) platforms = Platforms.values
- if (name.isEmpty) name = Some(file.get.getName)
- 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)
- pipeTemplate("tool", patches)
+ val resourceRoot = "scala/tools/ant/templates/"
+ val patches = Map (
+ ("class", mainClass.get),
+ ("properties", getProperties),
+ ("javaflags", javaFlags),
+ ("toolflags", toolFlags)
+ )
+ if (platforms.contains("unix")) {
+ val unixPatches = patches + (("classpath", getUnixclasspath))
+ val unixTemplateResource = resourceRoot + "tool-unix.tmpl"
+ val unixTemplate = readAndPatchResource(unixTemplateResource, unixPatches)
+ writeFile(file.get, unixTemplate)
+ }
+ if (platforms.contains("windows")) {
+ val winPatches = patches + (("classpath", getWinclasspath))
+ val winTemplateResource = resourceRoot + "tool-windows.tmpl"
+ val winTemplate = readAndPatchResource(winTemplateResource, winPatches)
+ writeFile(new File(file.get.getAbsolutePath() + ".bat"), winTemplate)
+ }
}
}
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
index d963d18873..0f7cfa7447 100644
--- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
+++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
@@ -1,9 +1,7 @@
#!/bin/sh
##############################################################################
-# @name@ @version@
-##############################################################################
-# @copyright@
+# Copyright 2002-2008, LAMP/EPFL
#
# This is free software; see the distribution for copying conditions.
# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
@@ -11,10 +9,8 @@
##############################################################################
cygwin=false;
-darwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
- Darwin*) darwin=true ;;
esac
# Finding the root folder for this Scala distribution
@@ -38,27 +34,17 @@ if $cygwin; then
fi
# Constructing the extension classpath
-EXTENSION_CLASSPATH="@extclasspath@"
-if [ -z "$EXTENSION_CLASSPATH" ] ; then
+TOOL_CLASSPATH="@classpath@"
+if [ -z "$TOOL_CLASSPATH" ] ; then
for ext in `ls -d "$SCALA_HOME"/lib/*` ; do
- if [ -z "$EXTENSION_CLASSPATH" ] ; then
- EXTENSION_CLASSPATH="$ext"
+ if [ -z "$TOOL_CLASSPATH" ] ; then
+ TOOL_CLASSPATH="$ext"
else
- EXTENSION_CLASSPATH="$EXTENSION_CLASSPATH:$ext"
+ TOOL_CLASSPATH="$TOOL_CLASSPATH:$ext"
fi
done
fi
-# Setting the boot class-path to be the standard library (either as a JAR or a folder)
-BOOT_CLASSPATH="@bootclasspath@"
-if [ -z "$BOOT_CLASSPATH" ] ; then
- if [ -f "$SCALA_HOME/lib/scala-library.jar" ] ; then
- BOOT_CLASSPATH="$SCALA_HOME/lib/scala-library.jar"
- elif [ -d "$SCALA_HOME/lib/library" ] ; then
- BOOT_CLASSPATH="$SCALA_HOME/lib/library"
- fi
-fi
-
if $cygwin; then
if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
format=mixed
@@ -66,11 +52,10 @@ if $cygwin; then
format=windows
fi
SCALA_HOME=`cygpath --$format "$SCALA_HOME"`
- EXTENSION_CLASSPATH=`cygpath --path --$format "$EXTENSION_CLASSPATH"`
- BOOT_CLASSPATH=`cygpath --path --$format "$BOOT_CLASSPATH"`
+ TOOL_CLASSPATH=`cygpath --path --$format "$TOOL_CLASSPATH"`
fi
# Reminder: substitution ${JAVA_OPTS:=-Xmx256M -Xms16M} DO NOT work on Solaris
[ -n "$JAVA_OPTS" ] || JAVA_OPTS="@javaflags@"
-${JAVACMD:=java} $JAVA_OPTS -Xbootclasspath/a:"$BOOT_CLASSPATH" -cp "$EXTENSION_CLASSPATH" -Dscala.home="$SCALA_HOME" -Denv.classpath="$CLASSPATH" -Denv.emacs="$EMACS" @properties@ @class@ @toolflags@ "$@@"
+${JAVACMD:=java} $JAVA_OPTS -cp "$TOOL_CLASSPATH" -Dscala.home="$SCALA_HOME" -Denv.classpath="$CLASSPATH" -Denv.emacs="$EMACS" @properties@ @class@ @toolflags@ "$@@"
diff --git a/src/compiler/scala/tools/ant/templates/tool-windows.tmpl b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl
index 7c16d8d873..11deb440b7 100644
--- a/src/compiler/scala/tools/ant/templates/tool-windows.tmpl
+++ b/src/compiler/scala/tools/ant/templates/tool-windows.tmpl
@@ -1,9 +1,7 @@
@@echo off
rem ##########################################################################
-rem # @name@ @version@
-rem ##########################################################################
-rem # @copyright@
+rem # Copyright 2002-2008, LAMP/EPFL
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
@@ -34,38 +32,28 @@ rem We use the value of the JAVA_OPTS environment variable if defined
set _JAVA_OPTS=%JAVA_OPTS%
if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=@javaflags@
-set _EXTENSION_CLASSPATH=@extclasspath@
-if "%_EXTENSION_CLASSPATH%"=="" (
+set _TOOL_CLASSPATH=@extclasspath@
+if "%_TOOL_CLASSPATH%"=="" (
for %%f in ("%_SCALA_HOME%\lib\*") do call :add_cpath "%%f"
if "%OS%"=="Windows_NT" (
for /d %%f in ("%_SCALA_HOME%\lib\*") do call :add_cpath "%%f"
)
)
-set _BOOT_CLASSPATH=@bootclasspath@
-if "%_BOOT_CLASSPATH%"=="" (
- if exist "%_SCALA_HOME%\lib\scala-library.jar" (
- set _BOOT_CLASSPATH=%_SCALA_HOME%\lib\scala-library.jar
- )
- if exist "%_SCALA_HOME%\lib\library" (
- set _BOOT_CLASSPATH=%_SCALA_HOME%\lib\library
- )
-)
-
set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.classpath="%CLASSPATH%" -Denv.emacs="%EMACS%" @properties@
-rem echo %_JAVACMD% -Xbootclasspath/a:"%_BOOT_CLASSPATH%" %_JAVA_OPTS% %_PROPS% -cp "%_EXTENSION_CLASSPATH%" @class@ @toolflags@ %_ARGS%
-%_JAVACMD% -Xbootclasspath/a:"%_BOOT_CLASSPATH%" %_JAVA_OPTS% %_PROPS% -cp "%_EXTENSION_CLASSPATH%" @class@ @toolflags@ %_ARGS%
+rem echo %_JAVACMD% %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %_ARGS%
+%_JAVACMD% %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %_ARGS%
goto end
rem ##########################################################################
rem # subroutines
:add_cpath
- if "%_EXTENSION_CLASSPATH%"=="" (
- set _EXTENSION_CLASSPATH=%~1
+ if "%_TOOL_CLASSPATH%"=="" (
+ set _TOOL_CLASSPATH=%~1
) else (
- set _EXTENSION_CLASSPATH=%_EXTENSION_CLASSPATH%;%~1
+ set _TOOL_CLASSPATH=%_TOOL_CLASSPATH%;%~1
)
goto :eof
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 9b1567d145..9665a8bf00 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -66,7 +66,7 @@ class Settings(error: String => Unit) {
val guessJar = new File(new File(new File(scalaHome), "lib"), "scala-library.jar")
if (guessJar.isFile()) guessJar.getPath()
else {
- val guessDir = new File(new File(new File(scalaHome), "lib"), "library")
+ val guessDir = new File(new File(new File(scalaHome), "classes"), "library")
if (guessDir.isDirectory()) guessDir.getPath() else null
}
} else null