diff options
-rw-r--r-- | config/list/scala4ant.lst | 12 | ||||
-rw-r--r-- | sources/scala/tools/scala4ant/ScalaRuntime.scala | 117 | ||||
-rw-r--r-- | sources/scala/tools/scala4ant/ScalaTask.scala | 39 | ||||
-rw-r--r-- | sources/scala/tools/scala4ant/ScalapTask.scala | 74 |
4 files changed, 242 insertions, 0 deletions
diff --git a/config/list/scala4ant.lst b/config/list/scala4ant.lst new file mode 100644 index 0000000000..83d739369f --- /dev/null +++ b/config/list/scala4ant.lst @@ -0,0 +1,12 @@ +############################################################-*-Makefile-*-#### +# scala4ant source files (paths are relative to ./sources/scala/tools/scala4ant) +############################################################################## +# $Id$ + +AntAdaptor.scala +AntTask.scala +ScalaRuntime.scala +ScalaTask.scala +ScalapTask.scala + +############################################################################## diff --git a/sources/scala/tools/scala4ant/ScalaRuntime.scala b/sources/scala/tools/scala4ant/ScalaRuntime.scala new file mode 100644 index 0000000000..ebb530856c --- /dev/null +++ b/sources/scala/tools/scala4ant/ScalaRuntime.scala @@ -0,0 +1,117 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.tools.scala4ant; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Path; + + +/** + * The <code>ScalaRuntime</code> object provides informations + * about the Scala runtime environment. + * + * @author Stephane Micheloud + * @version 1.0 + */ + +object ScalaRuntime { + + private val SCALA_RUNTIME_LIB = "lib"; + private val SCALA_RUNTIME_SOURCES = "sources"; + + private val SCALA_JAR_SOME_CLASS = "scala.ScalaObject"; + private val TOOLS_JAR_SOME_CLASS = getClass().getName(); // myself ! + private val FJBG_JAR_SOME_CLASS = "ch.epfl.lamp.fjbg.JFieldOrMethod"; + + check(SCALA_JAR_SOME_CLASS, "scala.jar"); + check(TOOLS_JAR_SOME_CLASS, "tools.jar"); + check(FJBG_JAR_SOME_CLASS, "fjbg.jar"); + + val home: Path = { + val p = Path.systemClasspath.createPath(); + val s = getJarFileName(SCALA_JAR_SOME_CLASS).split(SCALA_RUNTIME_LIB); + p.setPath(s(0)); + p + } + + val classpath: Path = { + def getJarPath(classname: String) = { + val name = getJarFileName(classname); + if (name != null) { + val p = Path.systemClasspath.createPath(); + p.setPath(name); + p + } + else + null + } + val scalaPath = getJarPath(SCALA_JAR_SOME_CLASS); + val toolsPath = getJarPath(TOOLS_JAR_SOME_CLASS); + val fjbgPath = getJarPath(FJBG_JAR_SOME_CLASS); + val cp = if (scalaPath != null && toolsPath != null && fjbgPath != null) { + scalaPath.append(toolsPath); + scalaPath.append(fjbgPath); + scalaPath + } + else + Path.systemClasspath; + cp + } + + val sourcepath = { + val p = Path.systemClasspath.createPath(); + val s = home.toString() + java.io.File.pathSeparator + SCALA_RUNTIME_SOURCES; + p.setPath(s); + p + } + + val bootclasspath = { + val p = classpath; + p.append(sourcepath); + p + } + + /** + * Check if the required libraries are present. + */ + private def check(classname: String, jarname: String) = try { + Class.forName(classname) + } catch { + case e: ClassNotFoundException => + throw new BuildException("Cannot run scala4ant.\n" + + "It seems " + jarname + " is not in your CLASSPATH."); + } + + /** + * Return the full path string of the the jar file containing + * the class <code>classname</code>. + * + * @param classname + * @return + */ + private def getJarFileName(classname: String): String = { + def asResourceName(resource: String) = { + val name = + if (! resource.startsWith("/")) "/" + resource else resource; + name.replace('.', '/') + ".class" + } + def findClass(className: String) = + getClass().getResource(asResourceName(className)); + val url = findClass(classname); + if (url != null) { + val s = url.getFile(); + assert(s.startsWith("file:")); + s.substring(s.indexOf("file:") + 5, s.indexOf("!")) + } + else + null + } + +} diff --git a/sources/scala/tools/scala4ant/ScalaTask.scala b/sources/scala/tools/scala4ant/ScalaTask.scala new file mode 100644 index 0000000000..e42c192866 --- /dev/null +++ b/sources/scala/tools/scala4ant/ScalaTask.scala @@ -0,0 +1,39 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.tools.scala4ant; + +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.types.Path; + + +/** + * The <code>ScalaTask</code> class provides an Ant task for + * the <code>scala</code> command. + * i.e.<pre> + * <scala classpath="${build}" classname="examples.sort"/> + * </pre> + * + * @author Stephane Micheloud + * @version 1.0 + */ + +class ScalaTask extends Java { + + private val PRODUCT = "scala"; + + override def getTaskName(): String = PRODUCT; + + override def setClasspath(s: Path): Unit = { + val cp = ScalaRuntime.classpath; + cp.append(s); + super.setClasspath(cp) + } + +} diff --git a/sources/scala/tools/scala4ant/ScalapTask.scala b/sources/scala/tools/scala4ant/ScalapTask.scala new file mode 100644 index 0000000000..80dbb38e40 --- /dev/null +++ b/sources/scala/tools/scala4ant/ScalapTask.scala @@ -0,0 +1,74 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.tools.scala4ant; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; + + +/** + * The <code>ScalapTask</code> class provides an Ant task for + * for the <code>scalap</code> command. + * i.e.<pre> + * <scalap classpath="${build}" classname="examples.sort" private="true"/> + * </pre> + * + * @author Stephane Micheloud + * @version 1.0 + */ + +class ScalapTask extends Task { + + private val PRODUCT = "scalap"; + + private var classpath = ScalaRuntime.classpath; + private var classname = ""; + + private var showPrivateDefs = false; + private var isVerbose = false; + + override def getTaskName(): String = PRODUCT; + + def setClasspath(s: Path): Unit = classpath.append(s); + + def setCp(s: Path) = setClasspath(s); + + def setClassname(name: String): Unit = classname = name; + + def setPrivate(show: Boolean): Unit = showPrivateDefs = show; + + def setVerbose(verbose: Boolean): Unit = isVerbose = verbose; + + override def execute() = try { + System.setProperty("scala.home", ScalaRuntime.home.toString()); + System.setProperty("scala.product", PRODUCT); + System.setProperty("scala.version", scala.tools.scalap.Main.VERSION); + System.setProperty("scala.class.path", "."); + System.setProperty("scala.boot.class.path", ScalaRuntime.bootclasspath.toString()); + + scala.tools.scalap.Main.main(getArgs()); + } + catch { + case e => + throw new BuildException("exception occurred:" + e.getClass()); + } + + private def getArgs() = { + val cmd = new Commandline(); + cmd.createArgument().setValue("-classpath"); + cmd.createArgument().setPath(classpath); + if (showPrivateDefs) cmd.createArgument().setValue("-private"); + if (isVerbose) cmd.createArgument().setValue("-verbose"); + cmd.createArgument().setValue(classname); + cmd.getArguments() + } +} |