Skip to content

Commit 5ead107

Browse files
committed
Fix #2 Add completion
1 parent 5d19093 commit 5ead107

18 files changed

+535
-248
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ libraryDependencies += "jline" % "jline" % "2.14.2"
2020
unmanagedJars in Compile := (file(System.getProperty("java.home")) / ".." / "lib" * "tools.jar").classpath
2121

2222
packageOptions in (Compile, packageBin) += Package.ManifestAttributes(
23-
"Main-Class" -> "scalive.AgentLoader",
24-
"Agent-Class" -> "scalive.Agent"
23+
"Main-Class" -> "scalive.client.AgentLoader",
24+
"Agent-Class" -> "scalive.server.Agent"
2525
)

dev/zip/scalive

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ CLASS_PATH="$ROOT_DIR/*:."
1515

1616
# Use exec to be compatible with daemontools:
1717
# http://cr.yp.to/daemontools.html
18-
exec java $JAVA_OPTS -cp $CLASS_PATH scalive.AgentLoader $ROOT_DIR $@
18+
exec java $JAVA_OPTS -cp $CLASS_PATH scalive.client.AgentLoader $ROOT_DIR $@

dev/zip/scalive.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ cd "%ROOT_DIR%"
77

88
set CLASS_PATH="%ROOT_DIR%\*;."
99

10-
java %JAVA_OPTS% -cp %CLASS_PATH% scalive.AgentLoader %ROOT_DIR% %*
10+
java %JAVA_OPTS% -cp %CLASS_PATH% scalive.client.AgentLoader %ROOT_DIR% %*

src/main/java/scalive/Classpath.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
package scalive;
22

33
import java.io.File;
4+
import java.lang.reflect.InvocationTargetException;
45
import java.lang.reflect.Method;
6+
import java.net.MalformedURLException;
57
import java.net.URL;
68
import java.net.URLClassLoader;
79
import java.util.Arrays;
810

911
public class Classpath {
10-
private static Method addURL = getAddURL();
12+
private static final Method addURL = getAddURL();
1113

1214
// http://stackoverflow.com/questions/8222976/why-urlclassloader-addurl-protected-in-java
1315
private static Method getAddURL() {
1416
try {
1517
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
1618
method.setAccessible(true);
1719
return method;
18-
} catch (Exception e) {
19-
e.printStackTrace();
20-
return null;
20+
} catch (NoSuchMethodException e) {
21+
throw new RuntimeException(e);
2122
}
2223
}
2324

@@ -30,7 +31,7 @@ private static Method getAddURL() {
3031
*
3132
* @param jarPrefix JAR file name prefix to search; example: "scalive-agent" will match "scalive-agent-xxx.jar"
3233
*/
33-
public static String findJar(String[] jarSearchDirs, String jarPrefix) throws Exception {
34+
public static String findJar(String[] jarSearchDirs, String jarPrefix) throws IllegalStateException {
3435
String maxBaseName = null;
3536
File maxFile = null;
3637
for (String jarSearchDir: jarSearchDirs) {
@@ -50,22 +51,26 @@ public static String findJar(String[] jarSearchDirs, String jarPrefix) throws Ex
5051
}
5152

5253
if (maxFile == null)
53-
throw new Exception("Could not find " + jarPrefix + " in " + join(jarSearchDirs, File.pathSeparator));
54+
throw new IllegalStateException("Could not find " + jarPrefix + " in " + join(jarSearchDirs, File.pathSeparator));
5455
else
5556
return maxFile.getPath();
5657
}
5758

58-
public static void addPath(URLClassLoader cl, String path) throws Exception {
59+
public static void addPath(
60+
URLClassLoader cl, String path
61+
) throws MalformedURLException, InvocationTargetException, IllegalAccessException {
5962
URL url = new File(path).toURI().toURL();
6063
URL[] urls = cl.getURLs();
6164
if (!Arrays.asList(urls).contains(url)) addURL.invoke(cl, url);
6265
}
6366

6467
/** Combination of {@link #findJar(String[], String)} and {@link #addPath(URLClassLoader, String)}. */
65-
public static void findAndAddJar(URLClassLoader cl, String[] jarSearchDirs, String jarPrefix) throws Exception {
68+
public static void findAndAddJar(
69+
URLClassLoader cl, String[] jarSearchDirs, String jarPrefix
70+
) throws IllegalAccessException, InvocationTargetException, MalformedURLException {
6671
String jar = findJar(jarSearchDirs, jarPrefix);
6772
addPath(cl, jar);
68-
System.out.println("[Scalive] Load " + jar);
73+
Log.log("Load " + jar);
6974
}
7075

7176
/**
@@ -74,7 +79,7 @@ public static void findAndAddJar(URLClassLoader cl, String[] jarSearchDirs, Stri
7479
*/
7580
public static void findAndAddJar(
7681
URLClassLoader cl, String representativeClass, String[] jarSearchDirs, String jarPrefix
77-
) throws Exception {
82+
) throws IllegalAccessException, MalformedURLException, InvocationTargetException {
7883
try {
7984
Class.forName(representativeClass, true, cl);
8085
} catch (ClassNotFoundException e) {
@@ -88,7 +93,9 @@ public static String getClasspath(URLClassLoader cl) {
8893
return join(urls, File.pathSeparator);
8994
}
9095

91-
public static String getScalaVersion(ClassLoader cl) throws Exception {
96+
public static String getScalaVersion(
97+
ClassLoader cl
98+
) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
9299
Class<?> k = Class.forName("scala.util.Properties", true, cl);
93100
Method m = k.getDeclaredMethod("versionNumberString");
94101
return (String) m.invoke(k);

src/main/java/scalive/Client.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/main/java/scalive/Log.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scalive;
2+
3+
public class Log {
4+
public static void log(String msg) {
5+
System.out.println("[Scalive] " + msg);
6+
}
7+
8+
public static void logNoTag(String msg) {
9+
System.out.println(msg);
10+
}
11+
}

src/main/java/scalive/Net.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package scalive;
2+
3+
import java.net.InetAddress;
4+
import java.net.ServerSocket;
5+
import java.net.UnknownHostException;
6+
7+
public class Net {
8+
public static final InetAddress LOCALHOST = getLocalHostAddress();
9+
10+
public static int getLocalFreePort() throws Exception {
11+
ServerSocket server = new ServerSocket(0, 0, Net.LOCALHOST);
12+
int port = server.getLocalPort();
13+
server.close();
14+
return port;
15+
}
16+
17+
private static InetAddress getLocalHostAddress() {
18+
try {
19+
return InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
20+
} catch (UnknownHostException e) {
21+
throw new RuntimeException(e);
22+
}
23+
}
24+
}

src/main/java/scalive/Repl.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/main/java/scalive/Server.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)