diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2008-03-09 21:10:20 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2008-03-09 21:10:20 +0000 |
commit | 9ee330b57dcc67406ce26cc60de4fb707ed7fe38 (patch) | |
tree | 5f9142aed3f63879903e1e4e54a2ed9f42f26f99 /src | |
parent | d817beea39b06c0b55fee8fa2b847b30dbe7c8c7 (diff) | |
download | scala-9ee330b57dcc67406ce26cc60de4fb707ed7fe38.tar.gz scala-9ee330b57dcc67406ce26cc60de4fb707ed7fe38.tar.bz2 scala-9ee330b57dcc67406ce26cc60de4fb707ed7fe38.zip |
SuperSABBUS works with files that have spaces i...
SuperSABBUS works with files that have spaces in their path.
Distribution should build on Windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/Compiler.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/CompilerTest.scala | 47 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/Compilers.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala | 11 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/Make.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/Settings.scala (renamed from src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala) | 31 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/Use.scala | 8 |
7 files changed, 34 insertions, 75 deletions
diff --git a/src/compiler/scala/tools/ant/sabbus/Compiler.scala b/src/compiler/scala/tools/ant/sabbus/Compiler.scala index 61f4fedafe..f8bc37a7fd 100644 --- a/src/compiler/scala/tools/ant/sabbus/Compiler.scala +++ b/src/compiler/scala/tools/ant/sabbus/Compiler.scala @@ -12,7 +12,7 @@ import java.io.File import java.net.URL import java.lang.reflect.InvocationTargetException -class Compiler(classpath: Array[URL], val settings: CompilerSettings) { +class Compiler(classpath: Array[URL], val settings: Settings) { private lazy val classLoader: ClassLoader = new java.net.URLClassLoader(classpath, null) @@ -22,7 +22,9 @@ class Compiler(classpath: Array[URL], val settings: CompilerSettings) { private lazy val foreignCompiler: AnyRef = classLoader.loadClass(foreignCompilerName).newInstance.asInstanceOf[AnyRef] - foreignInvoke("args_$eq", Array(classOf[String]), Array(settings.toArgs)) + private def settingsArray: Array[String] = settings.toArgs.toArray + + foreignInvoke("args_$eq", Array(classOf[Array[String]]), Array(settingsArray)) private def foreignInvoke(method: String, types: Array[Class[T] forSome { type T }] , args: Array[AnyRef]) = try { @@ -34,6 +36,7 @@ class Compiler(classpath: Array[URL], val settings: CompilerSettings) { def compile(files: Array[File]): (Int, Int) = //(errors, warnings) try { + foreignInvoke("args_$eq", Array(classOf[Array[String]]), Array(settingsArray)) val result = foreignInvoke("compile", Array(classOf[Array[File]]), Array(files)).asInstanceOf[Int] (result >> 16, result & 0x00FF) diff --git a/src/compiler/scala/tools/ant/sabbus/CompilerTest.scala b/src/compiler/scala/tools/ant/sabbus/CompilerTest.scala deleted file mode 100644 index b165f50b87..0000000000 --- a/src/compiler/scala/tools/ant/sabbus/CompilerTest.scala +++ /dev/null @@ -1,47 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala Ant Tasks ** -** / __/ __// _ | / / / _ | (c) 2005-2008, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.tools.ant.sabbus - -import java.io.File -import java.net.URL - -object CompilerTest { - - def main(args: Array[String]): Unit = { - - implicit def fileToURL(file: File): URL = file.toURL - - val scalalib = new File("/Developer/Scala/latest/lib") - val sabbus = new File("/Users/Dubochet/Documents/Eclipse/FaSabbus") - - val classpath: Array[URL] = Array ( - new File(scalalib, "scala-library.jar"), - new File(scalalib, "scala-compiler.jar"), - new File(sabbus, "bin") - ) - - val settings = new CompilerSettings - settings.d = new File("/Users/Dubochet/Documents/Eclipse/FaSabbus/bin_sabbus") - val compiler = new Compiler(classpath, settings) - - val files: Array[File] = Array ( - new File(sabbus, "src/scala/tools/ant/sabbus/CompilationFailure.scala"), - new File(sabbus, "src/scala/tools/ant/sabbus/Compiler.scala"), - new File(sabbus, "src/scala/tools/ant/sabbus/CompilerTest.scala"), - new File(sabbus, "src/scala/tools/ant/sabbus/ForeignCompiler.scala") - ) - - if (compiler.compile(files)._1 == 0) - println("Everything a-okey, sir!") - else - println("We had some issues, sir!") - - } - -} diff --git a/src/compiler/scala/tools/ant/sabbus/Compilers.scala b/src/compiler/scala/tools/ant/sabbus/Compilers.scala index 76b8876a26..85a3febfaa 100644 --- a/src/compiler/scala/tools/ant/sabbus/Compilers.scala +++ b/src/compiler/scala/tools/ant/sabbus/Compilers.scala @@ -22,7 +22,7 @@ object Compilers extends collection.Map[String, Compiler] { def size = container.size - def make(id: String, classpath: Array[URL], settings: CompilerSettings): Compiler = { + def make(id: String, classpath: Array[URL], settings: Settings): Compiler = { val runtime = Runtime.getRuntime if (debug) println("Making compiler " + id) if (debug) println(" memory before: " + (runtime.freeMemory/1048576.).formatted("%10.2f") + " MB") diff --git a/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala b/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala index c82bcc8d76..9a6ba35ca3 100644 --- a/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala +++ b/src/compiler/scala/tools/ant/sabbus/ForeignCompiler.scala @@ -15,23 +15,22 @@ import scala.tools.nsc.reporters.ConsoleReporter class ForeignCompiler { - private var argsBuffer: String = null - def args: String = argsBuffer - def args_=(a: String): Unit = { - if (args != null) throw new Error("Argument must be set only once") + private var argsBuffer: Array[String] = null + def args: Array[String] = argsBuffer + def args_=(a: Array[String]): Unit = { argsBuffer = a nsc } private val error: (String => Nothing) = { msg => throw new Exception(msg) } - private def settings = new Settings(error) + private def settings = new scala.tools.nsc.Settings(error) private lazy val reporter = new ConsoleReporter(settings) private lazy val nsc: Global = { try { - val command = new CompilerCommand(List.fromString(args, ' '), settings, error, false) + val command = new CompilerCommand(args.toList, settings, error, false) new Global(command.settings, reporter) } catch { diff --git a/src/compiler/scala/tools/ant/sabbus/Make.scala b/src/compiler/scala/tools/ant/sabbus/Make.scala index 1908ab89b8..32ef5e0414 100644 --- a/src/compiler/scala/tools/ant/sabbus/Make.scala +++ b/src/compiler/scala/tools/ant/sabbus/Make.scala @@ -82,8 +82,7 @@ class Make extends Task { override def execute: Unit = { if (id.isEmpty) error("Mandatory attribute 'id' is not set.") if (compilerPath.isEmpty) error("Mandatory attribute 'compilerpath' is not set.") - if (destinationDir.isEmpty) error("Mandatory attribute 'destdir' is not set.") - val settings = new CompilerSettings + val settings = new Settings if (!destinationDir.isEmpty) settings.d = destinationDir.get if (!compilationPath.isEmpty) settings.classpath = compilationPath.get if (!sourcePath.isEmpty) settings.sourcepath = sourcePath.get diff --git a/src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala b/src/compiler/scala/tools/ant/sabbus/Settings.scala index 16db6ac6e0..1e3f96799c 100644 --- a/src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala +++ b/src/compiler/scala/tools/ant/sabbus/Settings.scala @@ -12,7 +12,8 @@ import java.io.File import org.apache.tools.ant.types.{Path, Reference} -class CompilerSettings { +@cloneable +class Settings { private var gBf: Option[String] = None def g = gBf.get @@ -58,22 +59,21 @@ class CompilerSettings { def more = moreBf.get def more_=(s: String): this.type = { moreBf = Some(s); this } - def toArgs: String = ("" + - (if (!gBf.isEmpty) "-g:" + g + " " else "") + - (if (uncheckedBf) "-unchecked " else "") + - (if (!classpathBf.isEmpty) "-classpath " + classpath + " " else "") + - (if (!sourcepathBf.isEmpty) "-sourcepath " + sourcepath + " " else "") + - (if (!bootclasspathBf.isEmpty) "-bootclasspath " + bootclasspath + " " else "") + - (if (!extdirsBf.isEmpty) "-extdirs " + extdirs + " " else "") + - (if (!dBf.isEmpty) "-d " + d + " " else "") + - (if (!encodingBf.isEmpty) "-encoding " + encoding + " " else "") + - (if (!targetBf.isEmpty) "-target:" + target + " " else "") + - (if (optimiseBf) "-optimise " else "") + - (if (!moreBf.isEmpty) more else "") - ) + def toArgs: List[String] = + (if (!gBf.isEmpty) "-g:"+g :: Nil else Nil) ::: + (if (uncheckedBf) "-unchecked" :: Nil else Nil) ::: + (if (!classpathBf.isEmpty) "-classpath" :: classpath.toString :: Nil else Nil) ::: + (if (!sourcepathBf.isEmpty) "-sourcepath" :: sourcepath.toString :: Nil else Nil) ::: + (if (!bootclasspathBf.isEmpty) "-bootclasspath" :: bootclasspath.toString :: Nil else Nil) ::: + (if (!extdirsBf.isEmpty) "-extdirs" :: extdirs.toString :: Nil else Nil) ::: + (if (!dBf.isEmpty) "-d" :: d.getAbsolutePath :: Nil else Nil) ::: + (if (!encodingBf.isEmpty) "-encoding" :: encoding :: Nil else Nil) ::: + (if (!targetBf.isEmpty) "-target:"+target :: Nil else Nil) ::: + (if (optimiseBf) "-optimise" :: Nil else Nil) ::: + (if (!moreBf.isEmpty) List.fromString(more, ' ') else Nil) override def equals(that: Any): Boolean = that match { - case cs: CompilerSettings => + case cs: Settings => this.gBf == cs.gBf && this.uncheckedBf == cs.uncheckedBf && this.classpathBf == cs.classpathBf && @@ -85,6 +85,7 @@ class CompilerSettings { this.targetBf == cs.targetBf && this.optimiseBf == cs.optimiseBf && this.moreBf == cs.moreBf + case _ => false } } diff --git a/src/compiler/scala/tools/ant/sabbus/Use.scala b/src/compiler/scala/tools/ant/sabbus/Use.scala index 748e36f999..8aaedef4f1 100644 --- a/src/compiler/scala/tools/ant/sabbus/Use.scala +++ b/src/compiler/scala/tools/ant/sabbus/Use.scala @@ -24,18 +24,24 @@ class Use extends MatchingTask { sourceDir = Some(input) } + def setDestdir(input: File): Unit = { + destinationDir = Some(input) + } + def setFailOnError(input: Boolean): Unit = { failOnError = input } private var id: Option[String] = None private var sourceDir: Option[File] = None + private var destinationDir: Option[File] = None private var failOnError: Boolean = true override def execute(): Unit = { if (id.isEmpty) error("Mandatory attribute 'id' is not set.") if (sourceDir.isEmpty) error("Mandatory attribute 'srcdir' is not set.") val compiler = Compilers(id.get) + if (!destinationDir.isEmpty) compiler.settings.d = destinationDir.get val mapper = new GlobPatternMapper() mapper.setTo("*.class") mapper.setFrom("*.scala") @@ -49,8 +55,6 @@ class Use extends MatchingTask { if (includedFiles.size > 0) try { log("Compiling " + includedFiles.size + " file" + (if (includedFiles.size > 1) "s" else "") + " to " + compiler.settings.d.getAbsolutePath) - //for (f <- includedFiles) log(" " + f.getAbsolutePath) - //log("Attributes are " + compiler.settings.toArgs) val (errors, warnings) = compiler.compile(includedFiles) if (errors > 0) error("Compilation failed with " + errors + " error" + (if (errors > 1) "s" else "") + ".") |