|
From: <cr...@us...> - 2009-05-05 14:12:52
|
Revision: 5410
http://jnode.svn.sourceforge.net/jnode/?rev=5410&view=rev
Author: crawley
Date: 2009-05-05 14:12:11 +0000 (Tue, 05 May 2009)
Log Message:
-----------
The isolate invoker now passes the 'environment' to the isolate that
runs the command.
Modified Paths:
--------------
trunk/core/src/openjdk/vm/java/lang/NativeProcessEnvironment.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandInvoker.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java
trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
Modified: trunk/core/src/openjdk/vm/java/lang/NativeProcessEnvironment.java
===================================================================
--- trunk/core/src/openjdk/vm/java/lang/NativeProcessEnvironment.java 2009-05-04 16:54:44 UTC (rev 5409)
+++ trunk/core/src/openjdk/vm/java/lang/NativeProcessEnvironment.java 2009-05-05 14:12:11 UTC (rev 5410)
@@ -22,29 +22,79 @@
import org.jnode.vm.VmSystem;
import org.jnode.vm.VmIOContext;
+
import java.util.Map;
/**
+ * This class implements the native methods defined in ProcessEnvironment.
+ *
* @see java.lang.ProcessEnvironment
*/
-class NativeProcessEnvironment {
+public class NativeProcessEnvironment {
+ // This is the initial environment encoded in a format that matches
+ // the expectations of the ProcessEnvironment static initializer.
+ private static byte[][] isolateInitialEnv;
+
/**
+ * Set the 'binary' environment that will be returned by {@link #environ()}.
+ * This can only be done once, and only
+ *
+ * @param env
+ */
+ public static void setIsolateInitialEnv(byte[][] env) {
+ if (isolateInitialEnv != null) {
+ throw new IllegalStateException("isolate initial env already set");
+ }
+ isolateInitialEnv = env;
+ }
+
+ /**
+ * This method gets called just once (per isolate) by the static initializer
+ * for ProcessEnvironment. It returns the bootstrap environment to be for
+ * the current isolate, or an empty bootstrap environment if none has been
+ * provided.
+ *
* @see java.lang.ProcessEnvironment#environ()
*/
+ @SuppressWarnings("unused")
private static byte[][] environ() {
- //todo implement it
- //throw new UnsupportedOperationException();
- return new byte[0][];
+ if (isolateInitialEnv == null) {
+ isolateInitialEnv = new byte[0][];
+ }
+ return isolateInitialEnv;
}
+ /**
+ * Fetch a named environment variable from the 'current' context
+ * via the IOContext switch
+ *
+ * @param name
+ * @return
+ */
+ @SuppressWarnings("unused")
private static String getenv(String name) {
return VmSystem.getIOContext().getEnv().get(name);
}
+ /**
+ * Fetch the environment map from the 'current' context
+ * via the IOContext switch
+ *
+ * @param name
+ * @return
+ */
+ @SuppressWarnings("unused")
private static Map<String,String> getenv() {
return VmSystem.getIOContext().getEnv();
}
+ /**
+ * Set the global (to the isolate) environment map.
+ *
+ * @param name
+ * @return
+ */
+ @SuppressWarnings("unused")
private static void setGlobalEnv0(Map<String,String> env) {
VmIOContext.setGlobalEnv(env);
}
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandInvoker.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandInvoker.java 2009-05-04 16:54:44 UTC (rev 5409)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandInvoker.java 2009-05-05 14:12:11 UTC (rev 5410)
@@ -21,12 +21,18 @@
package org.jnode.shell.isolate;
import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
import org.jnode.shell.AsyncCommandInvoker;
+import org.jnode.shell.CommandInfo;
+import org.jnode.shell.CommandInvoker;
+import org.jnode.shell.CommandLine;
import org.jnode.shell.CommandRunner;
import org.jnode.shell.CommandShell;
import org.jnode.shell.CommandThread;
import org.jnode.shell.CommandThreadImpl;
+import org.jnode.shell.ShellException;
import org.jnode.shell.ShellInvocationException;
import org.jnode.shell.SimpleCommandInvoker;
@@ -35,7 +41,7 @@
*
* @author cr...@jn...
*/
-public class IsolateCommandInvoker extends AsyncCommandInvoker {
+public class IsolateCommandInvoker extends AsyncCommandInvoker implements CommandInvoker {
public static final Factory FACTORY = new Factory() {
public SimpleCommandInvoker create(CommandShell shell) {
@@ -56,6 +62,20 @@
return "isolate";
}
+ public int invoke(CommandLine cmdLine, CommandInfo cmdInfo,
+ Properties sysProps, Map<String, String> env)
+ throws ShellException {
+ CommandRunner cr = setup(cmdLine, cmdInfo, sysProps, env);
+ return runIt(cmdLine, cmdInfo, cr);
+ }
+
+ public CommandThread invokeAsynchronous(CommandLine cmdLine, CommandInfo cmdInfo,
+ Properties sysProps, Map<String, String> env)
+ throws ShellException {
+ CommandRunner cr = setup(cmdLine, cmdInfo, sysProps, env);
+ return forkIt(cmdLine, cmdInfo, cr);
+ }
+
@Override
protected CommandThread createThread(CommandRunner cr)
throws ShellInvocationException {
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java 2009-05-04 16:54:44 UTC (rev 5409)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java 2009-05-05 14:12:11 UTC (rev 5410)
@@ -20,15 +20,28 @@
package org.jnode.shell.isolate;
+import java.util.Map;
+
import javax.isolate.Isolate;
import javax.isolate.Link;
import org.jnode.shell.CommandRunner;
+import org.jnode.vm.Unsafe;
import org.jnode.vm.isolate.ObjectLinkMessage;
+/**
+ * This is the class that the isolate invoker uses to launch the user's
+ * command in the new isolate.
+ *
+ * @author cr...@jn...
+ */
public class IsolateCommandLauncher {
/**
+ * The entry point that used to run the 'application' when the isolate is
+ * started. The actual command is then passed to us in a Link message
+ * in the form of a CommandRunner object.
+ *
* @param args
*/
public static void main(String[] args) {
@@ -37,8 +50,19 @@
try {
ObjectLinkMessage message = (ObjectLinkMessage) cl.receive();
cr = (CommandRunner) message.extract();
+ Map<String, String> env = cr.getEnv();
+ int envSize = (env == null) ? 0 : env.size();
+ byte[][] binEnv = new byte[envSize * 2][];
+ if (envSize > 0) {
+ int i = 0;
+ for (Map.Entry<String, String> entry : env.entrySet()) {
+ binEnv[i++] = entry.getKey().getBytes();
+ binEnv[i++] = entry.getValue().getBytes();
+ }
+ }
+ NativeProcessEnvironment.setIsolateInitialEnv(binEnv);
} catch (Exception e) {
- e.printStackTrace();
+ Unsafe.debugStackTrace(e.getMessage(), e);
return;
}
cr.run();
Modified: trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2009-05-04 16:54:44 UTC (rev 5409)
+++ trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java 2009-05-05 14:12:11 UTC (rev 5410)
@@ -50,6 +50,8 @@
/**
* This class implements the CommandThread API for running commands in a new isolates.
+ * It takes care of assembling the Stream bindings for the new isolate, creating it
+ * and passing it the CommandRunner that holds the command class and arguments.
*
* @author cr...@jn...
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|