Skip to content

Commit 42163d8

Browse files
committed
Merge branch 'dev'
2 parents bfea1f9 + 53602b3 commit 42163d8

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ JVM processes without any prior setup at the target process.
66
## Download
77

88
Download and extract
9-
[scalive-1.0.zip](https://github.com/ngocdaothanh/scalive/releases/download/v1.0/scalive-1.0.zip),
9+
[scalive-1.1.zip](https://github.com/ngocdaothanh/scalive/releases/download/v1.1/scalive-1.1.zip),
1010
you will see:
1111

1212
```
13-
scalive-1.0/
13+
scalive-1.1/
1414
scalive
1515
scalive.cmd
16-
scalive-1.0.jar
17-
18-
scala-library-2.10.2.jar
19-
scala-compiler-2.10.2.jar
20-
scala-reflect-2.10.2.jar
16+
scalive-1.1.jar
2117
2218
scala-library-2.10.3.jar
2319
scala-compiler-2.10.3.jar
2420
scala-reflect-2.10.3.jar
21+
22+
scala-library-2.10.4.jar
23+
scala-compiler-2.10.4.jar
24+
scala-reflect-2.10.4.jar
2525
```
2626

2727
scala-library, scala-compiler, and scala-reflect of the appropriate version
2828
will be loaded to your running JVM process, if they have not been loaded.
2929

30-
For convenience, Scala 2.10.2 and 2.10.3 JARs are preincluded. If your process
30+
For convenience, Scala 2.10.3 and 2.10.4 JARs are preincluded. If your process
3131
is using a different Scala version, you need to manually download the
3232
corresponding JARs and save them as above.
3333

dev/README.rst

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Control flow
2+
------------
3+
4+
::
5+
6+
AgentLoader ----- attaches Agent ---------------> Target process
7+
passes: * Agent loads Server
8+
* TCP port * Server listens on the
9+
* jarpaths specified TCP port
10+
11+
::
12+
13+
AgentLoader ----- Client connects to the port --> Target process
14+
* Server loads Repl
15+
----- Keyboard input -->
16+
<---- Repl output ---
17+
118
zip directory
219
-------------
320

@@ -8,35 +25,45 @@ This is the directory that will be zipped when Scalive is released.
825
zip/
926
scalive
1027
scalive.cmd
11-
scalive_2.10-1.0-SNAPSHOT.jar -> ../../target/scala-2.10/scalive_2.10-1.0-SNAPSHOT.jar
12-
13-
scala-library-2.10.2.jar
14-
scala-compiler-2.10.2.jar
15-
scala-reflect-2.10.2.jar
28+
scalive_2.10-1.1-SNAPSHOT.jar -> ../../target/scala-2.10/scalive_2.10-1.1-SNAPSHOT.jar
1629

1730
scala-library-2.10.3.jar
1831
scala-compiler-2.10.3.jar
1932
scala-reflect-2.10.3.jar
2033

34+
scala-library-2.10.4.jar
35+
scala-compiler-2.10.4.jar
36+
scala-reflect-2.10.4.jar
37+
2138
While developing:
2239

2340
* Run ``sbt package`` to create/update scalive.jar
2441
* Add missing JARs as above
2542
* Run ``scalive`` to test
2643

27-
Control flow
28-
------------
44+
Release
45+
-------
46+
47+
Based on the ``zip`` directory above, prepare a directory to be zipped and
48+
released (remember to remove uneccessary files, like .gitignore):
2949

3050
::
3151

32-
AgentLoader ----- attaches Agent ---------------> Target process
33-
passes: * Agent loads Server
34-
* TCP port * Server listens on the
35-
* jarpaths specified TCP port
52+
scalive-<version>/
53+
scalive
54+
scalive.cmd
55+
scalive-<version>.jar <-- Doesn't depend on Scala, thus doesn't follow Scala JAR naming
56+
57+
scala-library-2.10.3.jar
58+
scala-compiler-2.10.3.jar
59+
scala-reflect-2.10.3.jar
60+
61+
scala-library-2.10.4.jar
62+
scala-compiler-2.10.4.jar
63+
scala-reflect-2.10.4.jar
64+
65+
Then zip it:
3666

3767
::
3868

39-
AgentLoader ----- Client connects to the port --> Target process
40-
* Server loads Repl
41-
----- Keyboard input -->
42-
<---- Repl output ---
69+
zip -r scalive-<version>.zip scalive-<version>

src/main/java/scalive/Classpath.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.reflect.Method;
55
import java.net.URL;
66
import java.net.URLClassLoader;
7+
import java.util.Arrays;
78

89
public class Classpath {
910
private static Method addURL = getAddURL();
@@ -44,8 +45,9 @@ public static String findJar(String[] jarpaths, String jarbase) throws Exception
4445
}
4546

4647
public static void addPath(URLClassLoader cl, String path) throws Exception {
47-
URL url = new File(path).toURI().toURL();
48-
addURL.invoke(cl, url);
48+
URL url = new File(path).toURI().toURL();
49+
URL[] urls = cl.getURLs();
50+
if (!Arrays.asList(urls).contains(url)) addURL.invoke(cl, url);
4951
}
5052

5153
/** Combination of findJar and addPath. */
@@ -55,22 +57,22 @@ public static void findAndAddJar(URLClassLoader cl, String[] jarpaths, String ja
5557
}
5658

5759
/**
58-
* Similar to findAndAddJar, but only add the JAR to classpath if the
59-
* representativeClass has not been loaded.
60+
* Similar to findAndAddJar without representativeClass, but only find and
61+
* add the JAR to classpath if the representativeClass has not been loaded.
6062
*/
61-
public static void addJarToURLClassLoader(
63+
public static void findAndAddJar(
6264
URLClassLoader cl, String[] jarpaths, String jarbase, String representativeClass
6365
) throws Exception {
6466
try {
6567
Class.forName(representativeClass, true, cl);
6668
} catch (ClassNotFoundException e) {
6769
System.out.println("[Scalive] Load " + jarbase);
68-
Classpath.findAndAddJar(cl, jarpaths, jarbase);
70+
findAndAddJar(cl, jarpaths, jarbase);
6971
}
7072
}
7173

7274
// http://stackoverflow.com/questions/4121567/embedded-scala-repl-inherits-parent-classpath
73-
public static String getURLClasspath(URLClassLoader cl) {
75+
public static String getClasspath(URLClassLoader cl) {
7476
URL[] urls = cl.getURLs();
7577
return join(urls, File.pathSeparator);
7678
}
@@ -81,6 +83,8 @@ public static String getScalaVersion(ClassLoader cl) throws Exception {
8183
return (String) m.invoke(k);
8284
}
8385

86+
//--------------------------------------------------------------------------
87+
8488
private static String join(Object[] xs, String separator) {
8589
StringBuffer buf = new StringBuffer();
8690
for (Object x: xs) {

src/main/java/scalive/Server.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void serve(Socket client, String[] jarpaths) throws Exception {
2727
URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader();
2828
addJarsToURLClassLoader(cl, jarpaths);
2929

30-
String classpath = Classpath.getURLClasspath(cl);
30+
String classpath = Classpath.getClasspath(cl);
3131
Class<?> repl = Class.forName("scalive.Repl");
3232
Method method = repl.getMethod("run", ClassLoader.class, String.class, InputStream.class, OutputStream.class);
3333
method.invoke(null, cl, classpath, in, out);
@@ -42,14 +42,14 @@ public static void serve(Socket client, String[] jarpaths) throws Exception {
4242

4343
private static void addJarsToURLClassLoader(URLClassLoader cl, String[] jarpaths) throws Exception {
4444
// Try scala-library first
45-
Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-library-" + DEFAULT_SCALA_VERSION, "scala.AnyVal");
45+
Classpath.findAndAddJar(cl, jarpaths, "scala-library-" + DEFAULT_SCALA_VERSION, "scala.AnyVal");
4646

4747
// So that we can get the actual Scala version being used
4848
String version = Classpath.getScalaVersion(cl);
4949

50-
Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-reflect-" + version, "scala.reflect.runtime.JavaUniverse");
51-
Classpath.addJarToURLClassLoader(cl, jarpaths, "scala-compiler-" + version, "scala.tools.nsc.interpreter.ILoop");
50+
Classpath.findAndAddJar(cl, jarpaths, "scala-reflect-" + version, "scala.reflect.runtime.JavaUniverse");
51+
Classpath.findAndAddJar(cl, jarpaths, "scala-compiler-" + version, "scala.tools.nsc.interpreter.ILoop");
5252

53-
Classpath.addJarToURLClassLoader(cl, jarpaths, "scalive", "scalive.Repl");
53+
Classpath.findAndAddJar(cl, jarpaths, "scalive", "scalive.Repl");
5454
}
5555
}

0 commit comments

Comments
 (0)