From 2a6f0c82f569a5945379e5951173a39e62eec9ae Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Wed, 5 Feb 2014 11:45:53 +0900 Subject: [PATCH 1/8] Tune method names --- src/main/java/scalive/Classpath.java | 12 +++++++----- src/main/java/scalive/Server.java | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/scalive/Classpath.java b/src/main/java/scalive/Classpath.java index 95b2349..ca09134 100644 --- a/src/main/java/scalive/Classpath.java +++ b/src/main/java/scalive/Classpath.java @@ -55,22 +55,22 @@ public static void findAndAddJar(URLClassLoader cl, String[] jarpaths, String ja } /** - * Similar to findAndAddJar, but only add the JAR to classpath if the - * representativeClass has not been loaded. + * Similar to findAndAddJar without representativeClass, but only find and + * add the JAR to classpath if the representativeClass has not been loaded. */ - public static void addJarToURLClassLoader( + public static void findAndAddJar( URLClassLoader cl, String[] jarpaths, String jarbase, String representativeClass ) throws Exception { try { Class.forName(representativeClass, true, cl); } catch (ClassNotFoundException e) { System.out.println("[Scalive] Load " + jarbase); - Classpath.findAndAddJar(cl, jarpaths, jarbase); + findAndAddJar(cl, jarpaths, jarbase); } } // http://stackoverflow.com/questions/4121567/embedded-scala-repl-inherits-parent-classpath - public static String getURLClasspath(URLClassLoader cl) { + public static String getClasspath(URLClassLoader cl) { URL[] urls = cl.getURLs(); return join(urls, File.pathSeparator); } @@ -81,6 +81,8 @@ public static String getScalaVersion(ClassLoader cl) throws Exception { return (String) m.invoke(k); } + //-------------------------------------------------------------------------- + private static String join(Object[] xs, String separator) { StringBuffer buf = new StringBuffer(); for (Object x: xs) { diff --git a/src/main/java/scalive/Server.java b/src/main/java/scalive/Server.java index 49e99eb..58e2286 100644 --- a/src/main/java/scalive/Server.java +++ b/src/main/java/scalive/Server.java @@ -27,7 +27,7 @@ public static void serve(Socket client, String[] jarpaths) throws Exception { URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader(); addJarsToURLClassLoader(cl, jarpaths); - String classpath = Classpath.getURLClasspath(cl); + String classpath = Classpath.getClasspath(cl); Class repl = Class.forName("scalive.Repl"); Method method = repl.getMethod("run", ClassLoader.class, String.class, InputStream.class, OutputStream.class); method.invoke(null, cl, classpath, in, out); @@ -42,14 +42,14 @@ public static void serve(Socket client, String[] jarpaths) throws Exception { private static void addJarsToURLClassLoader(URLClassLoader cl, String[] jarpaths) throws Exception { // Try scala-library first - Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-library-" + DEFAULT_SCALA_VERSION, "scala.AnyVal"); + Classpath.findAndAddJar(cl, jarpaths, "scala-library-" + DEFAULT_SCALA_VERSION, "scala.AnyVal"); // So that we can get the actual Scala version being used String version = Classpath.getScalaVersion(cl); - Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-reflect-" + version, "scala.reflect.runtime.JavaUniverse"); - Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-compiler-" + version, "scala.tools.nsc.interpreter.ILoop"); + Classpath.findAndAddJar(cl, jarpaths, "scala-reflect-" + version, "scala.reflect.runtime.JavaUniverse"); + Classpath.findAndAddJar(cl, jarpaths, "scala-compiler-" + version, "scala.tools.nsc.interpreter.ILoop"); - Classpath.addJarToURLClassLoader(cl, jarpaths, "scalive", "scalive.Repl"); + Classpath.findAndAddJar(cl, jarpaths, "scalive", "scalive.Repl"); } } From 41838502266d625b41081177b643937f57120b5b Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Wed, 5 Feb 2014 11:53:50 +0900 Subject: [PATCH 2/8] addPath: Avoid adding same path again and again --- src/main/java/scalive/Classpath.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/scalive/Classpath.java b/src/main/java/scalive/Classpath.java index ca09134..0eab2e0 100644 --- a/src/main/java/scalive/Classpath.java +++ b/src/main/java/scalive/Classpath.java @@ -4,6 +4,7 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; +import java.util.Arrays; public class Classpath { private static Method addURL = getAddURL(); @@ -44,8 +45,9 @@ public static String findJar(String[] jarpaths, String jarbase) throws Exception } public static void addPath(URLClassLoader cl, String path) throws Exception { - URL url = new File(path).toURI().toURL(); - addURL.invoke(cl, url); + URL url = new File(path).toURI().toURL(); + URL[] urls = cl.getURLs(); + if (!Arrays.asList(urls).contains(url)) addURL.invoke(cl, url); } /** Combination of findJar and addPath. */ From 93bf5974b1e2d588436d74aa60bca2fdd07a8947 Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Wed, 5 Feb 2014 12:15:52 +0900 Subject: [PATCH 3/8] zip -r scalive-.zip scalive- --- dev/README.rst | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/dev/README.rst b/dev/README.rst index 745212f..ee00df9 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -1,3 +1,20 @@ +Control flow +------------ + +:: + + AgentLoader ----- attaches Agent ---------------> Target process + passes: * Agent loads Server + * TCP port * Server listens on the + * jarpaths specified TCP port + +:: + + AgentLoader ----- Client connects to the port --> Target process + * Server loads Repl + ----- Keyboard input --> + <---- Repl output --- + zip directory ------------- @@ -24,19 +41,29 @@ While developing: * Add missing JARs as above * Run ``scalive`` to test -Control flow ------------- +Release +------- + +Based on the ``zip`` directory above, prepare a directory to be zipped and +released (remember to remove uneccessary files, like .gitignore): :: - AgentLoader ----- attaches Agent ---------------> Target process - passes: * Agent loads Server - * TCP port * Server listens on the - * jarpaths specified TCP port + scalive-/ + scalive + scalive.bat + scalive-.jar <-- Doesn't depend on Scala, thus doesn't follow Scala JAR naming + + scala-library-2.10.2.jar + scala-compiler-2.10.2.jar + scala-reflect-2.10.2.jar + + scala-library-2.10.3.jar + scala-compiler-2.10.3.jar + scala-reflect-2.10.3.jar + +Then zip it: :: - AgentLoader ----- Client connects to the port --> Target process - * Server loads Repl - ----- Keyboard input --> - <---- Repl output --- + zip -r scalive-.zip scalive- From d019aa2f4b3aa6c0744d6e35da0a8f59b722590a Mon Sep 17 00:00:00 2001 From: John Kozlov Date: Wed, 12 Feb 2014 15:48:35 +0700 Subject: [PATCH 4/8] Fixed variables (removed '$') and added '@' to prevent commands to output themselves --- dev/zip/scalive.bat | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/zip/scalive.bat b/dev/zip/scalive.bat index 80d51e2..ad5be6d 100644 --- a/dev/zip/scalive.bat +++ b/dev/zip/scalive.bat @@ -1,8 +1,8 @@ -set JAVA_OPTS=-Djava.awt.headless=true +@set JAVA_OPTS=-Djava.awt.headless=true -set ROOT_DIR=%~dp0 -cd "%$ROOT_DIR%" +@set ROOT_DIR=%~dp0 +@cd "%ROOT_DIR%" -set CLASS_PATH="%ROOT_DIR%\*;." +@set CLASS_PATH="%ROOT_DIR%\*;." -java %JAVA_OPTS% -cp %CLASS_PATH% scalive.AgentLoader %$ROOT_DIR% %* +@java %JAVA_OPTS% -cp %CLASS_PATH% scalive.AgentLoader %ROOT_DIR% %* From 7f4f192aab3f29ddb62802b90933705f3010437d Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Fri, 14 Feb 2014 12:49:20 +0900 Subject: [PATCH 5/8] Use "@echo off" for brevity --- dev/zip/scalive.bat | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dev/zip/scalive.bat b/dev/zip/scalive.bat index ad5be6d..8eb55dc 100644 --- a/dev/zip/scalive.bat +++ b/dev/zip/scalive.bat @@ -1,8 +1,10 @@ -@set JAVA_OPTS=-Djava.awt.headless=true +@echo off -@set ROOT_DIR=%~dp0 -@cd "%ROOT_DIR%" +set JAVA_OPTS=-Djava.awt.headless=true -@set CLASS_PATH="%ROOT_DIR%\*;." +set ROOT_DIR=%~dp0 +cd "%ROOT_DIR%" -@java %JAVA_OPTS% -cp %CLASS_PATH% scalive.AgentLoader %ROOT_DIR% %* +set CLASS_PATH="%ROOT_DIR%\*;." + +java %JAVA_OPTS% -cp %CLASS_PATH% scalive.AgentLoader %ROOT_DIR% %* From 1ce4157c519e3848656352b392f8533b5caed8cc Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Fri, 14 Feb 2014 12:53:46 +0900 Subject: [PATCH 6/8] Rename scalive.bat to scalive.cmd (http://stackoverflow.com/questions/148968/windows-batch-files-bat-vs-cmd) --- README.md | 4 ++-- dev/README.rst | 4 ++-- dev/zip/{scalive.bat => scalive.cmd} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename dev/zip/{scalive.bat => scalive.cmd} (100%) diff --git a/README.md b/README.md index 6dd006b..9cc6dac 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ you will see: ``` scalive-1.0/ scalive - scalive.bat + scalive.cmd scalive-1.0.jar scala-library-2.10.2.jar @@ -33,7 +33,7 @@ corresponding JARs and save them as above. ## Usage -Run the shell script `scalive` (*nix) or `scalive.bat` (Windows). +Run the shell script `scalive` (*nix) or `scalive.cmd` (Windows). To see a list of running JVM processes and their process IDs: diff --git a/dev/README.rst b/dev/README.rst index ee00df9..546001a 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -24,7 +24,7 @@ This is the directory that will be zipped when Scalive is released. zip/ scalive - scalive.bat + scalive.cmd scalive_2.10-1.0-SNAPSHOT.jar -> ../../target/scala-2.10/scalive_2.10-1.0-SNAPSHOT.jar scala-library-2.10.2.jar @@ -51,7 +51,7 @@ released (remember to remove uneccessary files, like .gitignore): scalive-/ scalive - scalive.bat + scalive.cmd scalive-.jar <-- Doesn't depend on Scala, thus doesn't follow Scala JAR naming scala-library-2.10.2.jar diff --git a/dev/zip/scalive.bat b/dev/zip/scalive.cmd similarity index 100% rename from dev/zip/scalive.bat rename to dev/zip/scalive.cmd From 62c4722ac1f8a4d1252e378a09f27f1b7d8b31e3 Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Thu, 20 Mar 2014 12:51:49 +0900 Subject: [PATCH 7/8] Mention Tomcat --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cc6dac..d45f2c1 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,9 @@ without additional class loaders (Ex: normal standalone JVM processes, like [Play](http://www.playframework.com/) or [Xitrum](http://ngocdaothanh.github.io/xitrum/) in production mode). -Processes with multiple class loaders like -[SBT](http://www.scala-sbt.org/) are not supported. +Processes with multiple class loaders like Tomcat or +[SBT](http://www.scala-sbt.org/) are not supported (with SBT, you already has +the SBT console, so it's not a big deal). 2. From 53602b3ba14d52dce640c3e24a32b43a87007c78 Mon Sep 17 00:00:00 2001 From: Ngoc Dao Date: Fri, 11 Apr 2014 22:23:25 +0900 Subject: [PATCH 8/8] Scala 2.10.4 in, 2.10.2 out --- README.md | 16 ++++++++-------- dev/README.rst | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d45f2c1..856fb17 100644 --- a/README.md +++ b/README.md @@ -6,28 +6,28 @@ JVM processes without any prior setup at the target process. ## Download Download and extract -[scalive-1.0.zip](https://github.com/ngocdaothanh/scalive/releases/download/v1.0/scalive-1.0.zip), +[scalive-1.1.zip](https://github.com/ngocdaothanh/scalive/releases/download/v1.1/scalive-1.1.zip), you will see: ``` -scalive-1.0/ +scalive-1.1/ scalive scalive.cmd - scalive-1.0.jar - - scala-library-2.10.2.jar - scala-compiler-2.10.2.jar - scala-reflect-2.10.2.jar + scalive-1.1.jar scala-library-2.10.3.jar scala-compiler-2.10.3.jar scala-reflect-2.10.3.jar + + scala-library-2.10.4.jar + scala-compiler-2.10.4.jar + scala-reflect-2.10.4.jar ``` scala-library, scala-compiler, and scala-reflect of the appropriate version will be loaded to your running JVM process, if they have not been loaded. -For convenience, Scala 2.10.2 and 2.10.3 JARs are preincluded. If your process +For convenience, Scala 2.10.3 and 2.10.4 JARs are preincluded. If your process is using a different Scala version, you need to manually download the corresponding JARs and save them as above. diff --git a/dev/README.rst b/dev/README.rst index 546001a..d153c4d 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -25,16 +25,16 @@ This is the directory that will be zipped when Scalive is released. zip/ scalive scalive.cmd - scalive_2.10-1.0-SNAPSHOT.jar -> ../../target/scala-2.10/scalive_2.10-1.0-SNAPSHOT.jar - - scala-library-2.10.2.jar - scala-compiler-2.10.2.jar - scala-reflect-2.10.2.jar + scalive_2.10-1.1-SNAPSHOT.jar -> ../../target/scala-2.10/scalive_2.10-1.1-SNAPSHOT.jar scala-library-2.10.3.jar scala-compiler-2.10.3.jar scala-reflect-2.10.3.jar + scala-library-2.10.4.jar + scala-compiler-2.10.4.jar + scala-reflect-2.10.4.jar + While developing: * Run ``sbt package`` to create/update scalive.jar @@ -54,14 +54,14 @@ released (remember to remove uneccessary files, like .gitignore): scalive.cmd scalive-.jar <-- Doesn't depend on Scala, thus doesn't follow Scala JAR naming - scala-library-2.10.2.jar - scala-compiler-2.10.2.jar - scala-reflect-2.10.2.jar - scala-library-2.10.3.jar scala-compiler-2.10.3.jar scala-reflect-2.10.3.jar + scala-library-2.10.4.jar + scala-compiler-2.10.4.jar + scala-reflect-2.10.4.jar + Then zip it: ::