From 9ee330b57dcc67406ce26cc60de4fb707ed7fe38 Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Sun, 9 Mar 2008 21:10:20 +0000 Subject: SuperSABBUS works with files that have spaces i... SuperSABBUS works with files that have spaces in their path. Distribution should build on Windows. --- src/compiler/scala/tools/ant/sabbus/Compiler.scala | 7 +- .../scala/tools/ant/sabbus/CompilerSettings.scala | 90 --------------------- .../scala/tools/ant/sabbus/CompilerTest.scala | 47 ----------- .../scala/tools/ant/sabbus/Compilers.scala | 2 +- .../scala/tools/ant/sabbus/ForeignCompiler.scala | 11 ++- src/compiler/scala/tools/ant/sabbus/Make.scala | 3 +- src/compiler/scala/tools/ant/sabbus/Settings.scala | 91 ++++++++++++++++++++++ src/compiler/scala/tools/ant/sabbus/Use.scala | 8 +- 8 files changed, 109 insertions(+), 150 deletions(-) delete mode 100644 src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala delete mode 100644 src/compiler/scala/tools/ant/sabbus/CompilerTest.scala create mode 100644 src/compiler/scala/tools/ant/sabbus/Settings.scala (limited to 'src') 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/CompilerSettings.scala b/src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala deleted file mode 100644 index 16db6ac6e0..0000000000 --- a/src/compiler/scala/tools/ant/sabbus/CompilerSettings.scala +++ /dev/null @@ -1,90 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala Ant Tasks ** -** / __/ __// _ | / / / _ | (c) 2005-2008, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.tools.ant.sabbus - -import java.io.File - -import org.apache.tools.ant.types.{Path, Reference} - -class CompilerSettings { - - private var gBf: Option[String] = None - def g = gBf.get - def g_=(s: String): this.type = { gBf = Some(s); this } - - private var uncheckedBf: Boolean = false - def unchecked = uncheckedBf - def unchecked_=(b: Boolean): this.type = { uncheckedBf = b; this } - - private var classpathBf: Option[Path] = None - def classpath = classpathBf.get - def classpath_=(p: Path): this.type = { classpathBf = Some(p); this } - - private var sourcepathBf: Option[Path] = None - def sourcepath = sourcepathBf.get - def sourcepath_=(p: Path): this.type = { sourcepathBf = Some(p); this } - - private var bootclasspathBf: Option[Path] = None - def bootclasspath = bootclasspathBf.get - def bootclasspath_=(p: Path): this.type = { bootclasspathBf = Some(p); this } - - private var extdirsBf: Option[Path] = None - def extdirs = extdirsBf.get - def extdirs_=(p: Path): this.type = { extdirsBf = Some(p); this } - - private var dBf: Option[File] = None - def d = dBf.get - def d_=(f: File): this.type = { dBf = Some(f); this } - - private var encodingBf: Option[String] = None - def encoding = encodingBf.get - def encoding_=(s: String): this.type = { encodingBf = Some(s); this } - - private var targetBf: Option[String] = None - def target = targetBf.get - def target_=(s: String): this.type = { targetBf = Some(s); this } - - private var optimiseBf: Boolean = false - def optimise = optimiseBf - def optimise_=(b: Boolean): Unit = { optimiseBf = b } - - private var moreBf: Option[String] = None - 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 "") - ) - - override def equals(that: Any): Boolean = that match { - case cs: CompilerSettings => - this.gBf == cs.gBf && - this.uncheckedBf == cs.uncheckedBf && - this.classpathBf == cs.classpathBf && - this.sourcepathBf == cs.sourcepathBf && - this.bootclasspathBf == cs.bootclasspathBf && - this.extdirsBf == cs.extdirsBf && - this.dBf == cs.dBf && - this.encodingBf == cs.encodingBf && - this.targetBf == cs.targetBf && - this.optimiseBf == cs.optimiseBf && - this.moreBf == cs.moreBf - } - -} 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/Settings.scala b/src/compiler/scala/tools/ant/sabbus/Settings.scala new file mode 100644 index 0000000000..1e3f96799c --- /dev/null +++ b/src/compiler/scala/tools/ant/sabbus/Settings.scala @@ -0,0 +1,91 @@ +/* __ *\ +** ________ ___ / / ___ Scala Ant Tasks ** +** / __/ __// _ | / / / _ | (c) 2005-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.tools.ant.sabbus + +import java.io.File + +import org.apache.tools.ant.types.{Path, Reference} + +@cloneable +class Settings { + + private var gBf: Option[String] = None + def g = gBf.get + def g_=(s: String): this.type = { gBf = Some(s); this } + + private var uncheckedBf: Boolean = false + def unchecked = uncheckedBf + def unchecked_=(b: Boolean): this.type = { uncheckedBf = b; this } + + private var classpathBf: Option[Path] = None + def classpath = classpathBf.get + def classpath_=(p: Path): this.type = { classpathBf = Some(p); this } + + private var sourcepathBf: Option[Path] = None + def sourcepath = sourcepathBf.get + def sourcepath_=(p: Path): this.type = { sourcepathBf = Some(p); this } + + private var bootclasspathBf: Option[Path] = None + def bootclasspath = bootclasspathBf.get + def bootclasspath_=(p: Path): this.type = { bootclasspathBf = Some(p); this } + + private var extdirsBf: Option[Path] = None + def extdirs = extdirsBf.get + def extdirs_=(p: Path): this.type = { extdirsBf = Some(p); this } + + private var dBf: Option[File] = None + def d = dBf.get + def d_=(f: File): this.type = { dBf = Some(f); this } + + private var encodingBf: Option[String] = None + def encoding = encodingBf.get + def encoding_=(s: String): this.type = { encodingBf = Some(s); this } + + private var targetBf: Option[String] = None + def target = targetBf.get + def target_=(s: String): this.type = { targetBf = Some(s); this } + + private var optimiseBf: Boolean = false + def optimise = optimiseBf + def optimise_=(b: Boolean): Unit = { optimiseBf = b } + + private var moreBf: Option[String] = None + def more = moreBf.get + def more_=(s: String): this.type = { moreBf = Some(s); this } + + 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: Settings => + this.gBf == cs.gBf && + this.uncheckedBf == cs.uncheckedBf && + this.classpathBf == cs.classpathBf && + this.sourcepathBf == cs.sourcepathBf && + this.bootclasspathBf == cs.bootclasspathBf && + this.extdirsBf == cs.extdirsBf && + this.dBf == cs.dBf && + this.encodingBf == cs.encodingBf && + 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 "") + ".") -- cgit v1.2.3