diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/MutableSettings.scala | 5 | ||||
-rw-r--r-- | src/detach/library/scala/remoting/Channel.scala | 6 | ||||
-rw-r--r-- | src/detach/library/scala/remoting/Debug.scala | 2 | ||||
-rw-r--r-- | src/detach/library/scala/remoting/detach.scala | 2 | ||||
-rw-r--r-- | src/detach/plugin/scala/tools/detach/Detach.scala | 2 | ||||
-rw-r--r-- | test/files/detach-run/actor/actor.scala | 185 | ||||
-rw-r--r-- | test/files/detach-run/basic/basic.scala | 216 |
7 files changed, 219 insertions, 199 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index a59bc776aa..9b7b838da4 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -87,7 +87,7 @@ class MutableSettings(val errorFn: String => Unit) extends AbsSettings with Scal /** Returns any unprocessed arguments. */ - def parseParams(args: List[String]): List[String] = { + protected def parseParams(args: List[String]): List[String] = { // verify command exists and call setter def tryToSetIfExists( cmd: String, @@ -95,7 +95,8 @@ class MutableSettings(val errorFn: String => Unit) extends AbsSettings with Scal setter: (Setting) => (List[String] => Option[List[String]]) ): Option[List[String]] = lookupSetting(cmd) match { - case None => errorFn("Parameter '" + cmd + "' is not recognised by Scalac.") ; None + //case None => errorFn("Parameter '" + cmd + "' is not recognised by Scalac.") ; None + case None => None //error reported in processArguments case Some(cmd) => setter(cmd)(args) } diff --git a/src/detach/library/scala/remoting/Channel.scala b/src/detach/library/scala/remoting/Channel.scala index 6b1fbcee4e..8e8b79dea1 100644 --- a/src/detach/library/scala/remoting/Channel.scala +++ b/src/detach/library/scala/remoting/Channel.scala @@ -74,7 +74,7 @@ class Channel protected (socket: Socket) { super.resolveClass(desc) } } -/* + // lazy modifier is required! private lazy val in = try { @@ -94,7 +94,7 @@ class Channel protected (socket: Socket) { error("Output stream undefined: "+e.getMessage+" ("+this+")") null } -*/ + /** <code>receive<primtype></code> methods may throw an * <code>IOException</code>. */ @@ -117,7 +117,6 @@ class Channel protected (socket: Socket) { */ @throws(classOf[ChannelException]) def receive[T](implicit expected: reflect.Manifest[T]): T = { - val in = new CustomObjectInputStream(socket.getInputStream) val found = in.readObject().asInstanceOf[reflect.Manifest[_]] info("receive: found="+found+", expected="+expected) import scala.reflect.Manifest @@ -150,7 +149,6 @@ class Channel protected (socket: Socket) { /** <code>send</code> method may throw an <code>IOException</code>. */ def send[T](x: T)(implicit m: reflect.Manifest[T]) { - val out = new ObjectOutputStream(socket.getOutputStream) out writeObject m x match { case x: Unit => // nop diff --git a/src/detach/library/scala/remoting/Debug.scala b/src/detach/library/scala/remoting/Debug.scala index 6a63b8a25d..7a3f0dd91e 100644 --- a/src/detach/library/scala/remoting/Debug.scala +++ b/src/detach/library/scala/remoting/Debug.scala @@ -22,6 +22,6 @@ object Debug extends runtime.remoting.Debug { def getLocation(obj: AnyRef): String = { val s = obj.getClass().getClassLoader().toString() - s.substring(s.indexOf('[')) + s substring s.indexOf('[') } } diff --git a/src/detach/library/scala/remoting/detach.scala b/src/detach/library/scala/remoting/detach.scala index d0fb694af5..5bb53da708 100644 --- a/src/detach/library/scala/remoting/detach.scala +++ b/src/detach/library/scala/remoting/detach.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** diff --git a/src/detach/plugin/scala/tools/detach/Detach.scala b/src/detach/plugin/scala/tools/detach/Detach.scala index f0b0a2a18d..f3116d033c 100644 --- a/src/detach/plugin/scala/tools/detach/Detach.scala +++ b/src/detach/plugin/scala/tools/detach/Detach.scala @@ -25,7 +25,7 @@ abstract class Detach extends PluginComponent new DetachTransformer(unit) // set with the `-P:detach:enable` plugin option (see DetachPlugin) */ - var isEnabled = false + protected[detach] var isEnabled = false private class DetachTransformer(unit: CompilationUnit) extends TypingTransformer(unit) { diff --git a/test/files/detach-run/actor/actor.scala b/test/files/detach-run/actor/actor.scala index 0cf55462f6..958b209594 100644 --- a/test/files/detach-run/actor/actor.scala +++ b/test/files/detach-run/actor/actor.scala @@ -1,16 +1,6 @@ object Test { - val actors_logLevel = "0" - // = "3" // info+warning+error - val logLevel = "silent" - // = "info" // debug user code only - // = "info,lib" // debug user & library code - - // we assume an Apache server is running locally for deployment - private val sep = java.io.File.separator - val docPath = System.getProperty("user.home")+sep+"public_html" - val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name") - + val name = "actor" val host = "127.0.0.1" val port = 8889 @@ -24,19 +14,7 @@ object Test { } private def setenv() { - import java.io._, java.util.jar._ - - val policyTmpl = - System.getProperty("partest.cwd")+sep+"actor"+sep+"java.policy" - val outPath = System.getProperty("partest.output") - val libPath = System.getProperty("partest.lib") - val policyFile = outPath+sep+"java.policy" - val codebaseDir = outPath+sep+"-" - - assert((new java.io.File(docPath)).isDirectory, - "Root directory \""+docPath+"\" not found") - val deployJar = docPath+sep+"actor_deploy.jar" - val deployUrl = docRoot+"/actor_deploy.jar" + import Env._ // Java properties for server & client System.setProperty("scala.actors.logLevel", actors_logLevel) @@ -48,6 +26,8 @@ object Test { System.setProperty("java.rmi.server.hostname", host) System.setProperty("java.rmi.server.useCodebaseOnly", "true") + // application-specific classes to be deployed and accessed via URL + // (i.e. detached closure, proxy interfaces and proxy stubs) val classNames = List( "$anonfun$main$1$proxy", "$anonfun$main$1$proxyImpl_Stub", @@ -66,75 +46,106 @@ object Test { generatePolicyFile() generateRmiStubs(proxyImplNames) generateJarFile(classNames) + } +} - def generatePolicyFile() { - val in = new BufferedReader(new FileReader(policyTmpl)) - val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile))) - var line = in.readLine() - while (line != null) { - val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir) - out.println(line1) - line = in.readLine() - } - in.close() - out.close() +object Env { + import java.io._, java.util.jar._ + + val actors_logLevel = "0" + // = "3" // info+warning+error + val logLevel = "silent" + // = "info" // debug user code only + // = "info,lib" // debug user & library code + + // we assume an Apache server is running locally for deployment + private val sep = File.separator + val docPath = System.getProperty("user.home")+sep+"public_html" + val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name") + + private val policyTmpl = + System.getProperty("partest.cwd")+sep+Test.name+sep+"java.policy" + val outPath = System.getProperty("partest.output") + val libPath = System.getProperty("partest.lib") + val policyFile = outPath+sep+"java.policy" + val codebaseDir = outPath+sep+"-" + + assert((new File(docPath)).isDirectory, + "Root directory \""+docPath+"\" not found") + val deployJar = docPath+sep+Test.name+"_deploy.jar" + val deployUrl = docRoot+"/"+Test.name+"_deploy.jar" + + def generatePolicyFile() { + val in = new BufferedReader(new FileReader(policyTmpl)) + val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile))) + var line = in.readLine() + while (line != null) { + val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir) + out.println(line1) + line = in.readLine() } - def exec(command: String) { - val proc = Runtime.getRuntime exec command - proc.waitFor() - val out = new BufferedReader(new InputStreamReader(proc.getInputStream)) - var line = out.readLine() - while (line != null) { - println(line) - line = out.readLine() - } - out.close() - val err = new BufferedReader(new InputStreamReader(proc.getErrorStream)) - line = err.readLine() - while (line != null) { - println(line) - line = err.readLine() + in.close() + out.close() + } + + def generateRmiStubs(classNames: List[String]) { + val options = List( + "-v1.2", + "-classpath "+libPath+File.pathSeparator+outPath, + "-d "+outPath) + rmic(options, classNames) + //ls(outPath) + } + + def generateJarFile(classNames: List[String]) { + val out = new JarOutputStream(new FileOutputStream(deployJar)) + classNames foreach (name => { + val classFile = name+".class" + out putNextEntry new JarEntry(classFile) + val in = new FileInputStream(outPath+sep+classFile) + val buf = new Array[Byte](256) + var len = in read buf + while (len != -1) { + out.write(buf, 0, len) + len = in read buf } - err.close() - } + in.close() + }) + out.close() + } - def ls(path: String) { exec("ls -al "+path) } - def rmic(options: List[String], classNames: List[String]) { - val javaHome = scala.util.Properties.javaHome - val jdkHome = - if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4) - else javaHome - val rmicExt = if (scala.util.Properties.isWin) ".exe" else "" - val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt - val cmdLine = rmicCmd+options.mkString(" ", " ", "")+ - classNames.mkString(" "," ","") - // println(cmdLine) - exec(cmdLine) - } - def generateRmiStubs(classNames: List[String]) { - val options = List( - "-v1.2", - "-classpath "+libPath+File.pathSeparator+outPath, - "-d "+outPath) - rmic(options, classNames) - //ls(outPath) + private def ls(path: String) { exec("ls -al "+path) } + + private def rmic(options: List[String], classNames: List[String]) { + val javaHome = scala.util.Properties.javaHome + val jdkHome = + if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4) + else javaHome + val rmicExt = if (scala.util.Properties.isWin) ".exe" else "" + val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt + val cmdLine = rmicCmd+options.mkString(" ", " ", "")+ + classNames.mkString(" "," ","") + // println(cmdLine) + exec(cmdLine) + } + + private def exec(command: String) { + val proc = Runtime.getRuntime exec command + proc.waitFor() + val out = new BufferedReader(new InputStreamReader(proc.getInputStream)) + var line = out.readLine() + while (line != null) { + println(line) + line = out.readLine() } - def generateJarFile(classNames: List[String]) { - val out = new JarOutputStream(new FileOutputStream(deployJar)) - classNames foreach (name => { - val className = name+".class" - out putNextEntry new JarEntry(className) - val in = new FileInputStream(outPath+sep+className) - val buf = new Array[Byte](256) - var len = in read buf - while (len != -1) { - out.write(buf, 0, len) - len = in read buf - } - in.close() - }) - out.close() + out.close() + val err = new BufferedReader(new InputStreamReader(proc.getErrorStream)) + line = err.readLine() + while (line != null) { + println(line) + line = err.readLine() } + err.close() } } diff --git a/test/files/detach-run/basic/basic.scala b/test/files/detach-run/basic/basic.scala index c8a1046d44..1bfb838b21 100644 --- a/test/files/detach-run/basic/basic.scala +++ b/test/files/detach-run/basic/basic.scala @@ -1,58 +1,36 @@ object Test { + val name = "basic" val host = "127.0.0.1" val port = 8889 - val logLevel = "silent" - // = "info" // debug user code only - // = "info,lib" // debug user & library code - - // we assume an Apache server is running locally for deployment - private val sep = java.io.File.separator - val docPath = System.getProperty("user.home")+sep+"public_html" - val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name") - - private var server = new ServerThread(port) - private var client = new ClientThread(host, port) def main(args: Array[String]) { setenv() + println("Server.main "+port) server.start() - Thread.sleep(1000) + println("Client.main "+host+" "+port) client.start() - server.join() - client.join() - System.exit(0) + server.terminate() } - private class ServerThread(port: Int) extends Thread { - override def run() { - println("Server.main "+port) - Server.main(Array(port.toString)) - } + private var server = new ServerThread(port) + private var client = new ClientThread(host, port) + + private class ServerThread(port: Int) extends Runnable { + private var th = new Thread(this) + def start() { th.start(); Thread.sleep(1000) } + def run() { Server.main(Array(port.toString)) } + def terminate() { Server.terminate(); System.exit(0) } } - private class ClientThread(host: String, port: Int) extends Thread { - override def run() { - println("Client.main "+host+" "+port) - Client.main(Array(host, port.toString)) - Server.terminate() - } + private class ClientThread(host: String, port: Int) extends Runnable { + private var th = new Thread(this) + def start() { th.start(); th.join() } + def run() { Client.main(Array(host, port.toString)) } } private def setenv() { - import java.io._, java.util.jar._ - - val policyTmpl = - System.getProperty("partest.cwd")+sep+"basic"+sep+"java.policy" - val outPath = System.getProperty("partest.output") - val libPath = System.getProperty("partest.lib") - val policyFile = outPath+sep+"java.policy" - val codebaseDir = outPath+sep+"-" - - assert((new java.io.File(docPath)).isDirectory, - "Root directory \""+docPath+"\" not found") - val deployJar = docPath+sep+"basic_deploy.jar" - val deployUrl = docRoot+"/basic_deploy.jar" + import Env._ // Java properties for server & client System.setProperty("scala.remoting.logLevel", logLevel) @@ -63,6 +41,8 @@ object Test { System.setProperty("java.rmi.server.hostname", host) System.setProperty("java.rmi.server.useCodebaseOnly", "true") + // application-secific classes to be deployed and accessed via URL + // (i.e. detached closure, proxy interfaces and proxy stubs) val classNames = List( "Bar$proxy", "Bar$proxyImpl_Stub", @@ -79,75 +59,105 @@ object Test { generatePolicyFile() generateRmiStubs(proxyImplNames) generateJarFile(classNames) + } +} - def generatePolicyFile() { - val in = new BufferedReader(new FileReader(policyTmpl)) - val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile))) - var line = in.readLine() - while (line != null) { - val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir) - out.println(line1) - line = in.readLine() - } - in.close() - out.close() +object Env { + import java.io._, java.util.jar._ + + val actors_logLevel = "0" + // = "3" // info+warning+error + val logLevel = "silent" + // = "info" // debug user code only + // = "info,lib" // debug user & library code + + // we assume an Apache server is running locally for deployment + private val sep = File.separator + val docPath = System.getProperty("user.home")+sep+"public_html" + val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name") + + private val policyTmpl = + System.getProperty("partest.cwd")+sep+Test.name+sep+"java.policy" + val outPath = System.getProperty("partest.output") + val libPath = System.getProperty("partest.lib") + val policyFile = outPath+sep+"java.policy" + val codebaseDir = outPath+sep+"-" + + assert((new File(docPath)).isDirectory, + "Root directory \""+docPath+"\" not found") + val deployJar = docPath+sep+Test.name+"_deploy.jar" + val deployUrl = docRoot+"/"+Test.name+"_deploy.jar" + + def generatePolicyFile() { + val in = new BufferedReader(new FileReader(policyTmpl)) + val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile))) + var line = in.readLine() + while (line != null) { + val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir) + out.println(line1) + line = in.readLine() } - def exec(command: String) { - val proc = Runtime.getRuntime exec command - proc.waitFor() - val out = new BufferedReader(new InputStreamReader(proc.getInputStream)) - var line = out.readLine() - while (line != null) { - println(line) - line = out.readLine() - } - out.close() - val err = new BufferedReader(new InputStreamReader(proc.getErrorStream)) - line = err.readLine() - while (line != null) { - println(line) - line = err.readLine() + in.close() + out.close() + } + + def generateRmiStubs(classNames: List[String]) { + val options = List( + "-v1.2", + "-classpath "+libPath+File.pathSeparator+outPath, + "-d "+outPath) + rmic(options, classNames) + //ls(outPath) + } + + def generateJarFile(classNames: List[String]) { + val out = new JarOutputStream(new FileOutputStream(deployJar)) + classNames foreach (name => { + val classFile = name+".class" + out putNextEntry new JarEntry(classFile) + val in = new FileInputStream(outPath+sep+classFile) + val buf = new Array[Byte](256) + var len = in read buf + while (len != -1) { + out.write(buf, 0, len) + len = in read buf } - err.close() - } + in.close() + }) + out.close() + } - def ls(path: String) { exec("ls -al "+path) } - def rmic(options: List[String], classNames: List[String]) { - val javaHome = scala.util.Properties.javaHome - val jdkHome = - if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4) - else javaHome - val rmicExt = if (scala.util.Properties.isWin) ".exe" else "" - val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt - val cmdLine = rmicCmd+options.mkString(" ", " ", "")+ - classNames.mkString(" "," ","") - // println(cmdLine) - exec(cmdLine) - } - def generateRmiStubs(classNames: List[String]) { - val options = List( - "-v1.2", - "-classpath "+libPath+File.pathSeparator+outPath, - "-d "+outPath) - rmic(options, classNames) - // ls(outPath) + private def ls(path: String) { exec("ls -al "+path) } + + private def rmic(options: List[String], classNames: List[String]) { + val javaHome = scala.util.Properties.javaHome + val jdkHome = + if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4) + else javaHome + val rmicExt = if (scala.util.Properties.isWin) ".exe" else "" + val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt + val cmdLine = rmicCmd+options.mkString(" ", " ", "")+ + classNames.mkString(" "," ","") + // println(cmdLine) + exec(cmdLine) + } + + private def exec(command: String) { + val proc = Runtime.getRuntime exec command + proc.waitFor() + val out = new BufferedReader(new InputStreamReader(proc.getInputStream)) + var line = out.readLine() + while (line != null) { + println(line) + line = out.readLine() } - def generateJarFile(classNames: List[String]) { - val out = new JarOutputStream(new FileOutputStream(deployJar)) - classNames foreach (name => { - val className = name+".class" - out putNextEntry new JarEntry(className) - val in = new FileInputStream(outPath+sep+className) - val buf = new Array[Byte](256) - var len = in read buf - while (len != -1) { - out.write(buf, 0, len) - len = in read buf - } - in.close() - }) - out.close() + out.close() + val err = new BufferedReader(new InputStreamReader(proc.getErrorStream)) + line = err.readLine() + while (line != null) { + println(line) + line = err.readLine() } + err.close() } } - |