Index: .classpath
===================================================================
RCS file: /cvsroot/jruby/jruby/.classpath,v
retrieving revision 1.25
diff -u -r1.25 .classpath
--- .classpath	26 Dec 2004 08:46:12 -0000	1.25
+++ .classpath	14 Apr 2006 01:25:00 -0000
@@ -6,5 +6,6 @@
 	<classpathentry kind="lib" path="lib/bsf.jar"/>
 	<classpathentry kind="lib" path="lib/junit.jar"/>
 	<classpathentry kind="lib" path="lib/ant.jar"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/tomcat"/>
 	<classpathentry kind="output" path="build/classes/jruby"/>
 </classpath>
Index: bin/jruby.bat
===================================================================
RCS file: /cvsroot/jruby/jruby/bin/jruby.bat,v
retrieving revision 1.12
diff -u -r1.12 jruby.bat
--- bin/jruby.bat	27 Mar 2006 16:07:45 -0000	1.12
+++ bin/jruby.bat	14 Apr 2006 01:25:00 -0000
@@ -53,11 +53,11 @@
 
 if not "%OS%" == "Windows_NT" goto noTitle
 rem set _STARTJAVA=start "JRuby" "%JAVA_HOME%\bin\java"
-set _STARTJAVA="%JAVA_HOME%\bin\java"
+set _STARTJAVA="%JAVA_HOME%\bin\javaw"
 goto gotTitle
 :noTitle
 rem set _STARTJAVA=start "%JAVA_HOME%\bin\java"
-set _STARTJAVA="%JAVA_HOME%\bin\java"
+set _STARTJAVA="%JAVA_HOME%\bin\javaw"
 :gotTitle
 
 set _RUNJAVA="%JAVA_HOME%\bin\java"
@@ -72,11 +72,11 @@
 set CLASSPATH=%CP%;%CLASSPATH%
 :doneCP
 
-rem echo Using JRUBY_BASE: %JRUBY_BASE%
-rem echo Using JRUBY_HOME: %JRUBY_HOME%
-rem echo Using CLASSPATH:  %CLASSPATH%
-rem echo Using JAVA_HOME:  %JAVA_HOME%
-rem echo Using Args:       %*
+echo Using JRUBY_BASE: %JRUBY_BASE%
+echo Using JRUBY_HOME: %JRUBY_HOME%
+echo Using CLASSPATH:  %CLASSPATH%
+echo Using JAVA_HOME:  %JAVA_HOME%
+echo Using Args:       %*
 
 rem ----- Execute The Requested Command ---------------------------------------
 
Index: src/org/jruby/IRuby.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/IRuby.java,v
retrieving revision 1.12
diff -u -r1.12 IRuby.java
--- src/org/jruby/IRuby.java	13 Apr 2006 03:41:36 -0000	1.12
+++ src/org/jruby/IRuby.java	14 Apr 2006 01:25:00 -0000
@@ -7,6 +7,7 @@
 import java.io.Reader;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 
 import org.jruby.ast.Node;
@@ -44,6 +45,12 @@
 
 	public IRubyObject eval(Node node);
 
+    public void setCustomEnvProperties(Map properties);
+    
+    public Map getCustomEnvProperties();
+    
+    public void init();
+    
 	public RubyClass getObject();
 
 	/** Returns the "true" instance from the instance pool.
Index: src/org/jruby/Ruby.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/Ruby.java,v
retrieving revision 1.115
diff -u -r1.115 Ruby.java
--- src/org/jruby/Ruby.java	13 Apr 2006 07:19:42 -0000	1.115
+++ src/org/jruby/Ruby.java	14 Apr 2006 01:25:01 -0000
@@ -44,6 +44,7 @@
 import java.io.StringReader;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 import java.util.Stack;
 
@@ -160,7 +161,6 @@
     	this.in = in;
     	this.out = out;
     	this.err = err;
-    	init();
     }
     
     /**
@@ -180,7 +180,10 @@
      * @return the JRuby runtime
      */
     public static IRuby getDefaultInstance() {
-        return new Ruby(System.in, System.out, System.err);
+        Ruby runtime = new Ruby(System.in, System.out, System.err);
+        runtime.init();
+        
+        return runtime;
     }
 
     /**
@@ -189,7 +192,16 @@
      * @return the JRuby runtime
      */
     public static IRuby newInstance(InputStream in, PrintStream out, PrintStream err) {
-        return new Ruby(in, out, err);
+        Ruby runtime = new Ruby(in, out, err);
+        runtime.init();
+        
+        return runtime;
+    }
+    
+    public static IRuby newInstanceNoInit(InputStream in, PrintStream out, PrintStream err) {
+    	Ruby runtime = new Ruby(in, out, err);
+    	
+    	return runtime;
     }
 
     /**
@@ -212,6 +224,17 @@
         	}
 		}
     }
+    
+    private Map customEnvProperties;
+    
+    public void setCustomEnvProperties(Map properties) {
+    	customEnvProperties = properties;
+    }
+    
+    public Map getCustomEnvProperties() {
+    	return customEnvProperties;
+    }
+    	
 
     public RubyClass getObject() {
     	return objectClass;
@@ -367,7 +390,7 @@
      *
      */
     // TODO: Figure out real dependencies between vars and reorder/refactor into better methods
-    private void init() {
+    public void init() {
         nilObject = new RubyNil(this);
         trueObject = new RubyBoolean(this, true);
         falseObject = new RubyBoolean(this, false);
Index: src/org/jruby/environment/OSEnvironment.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/environment/OSEnvironment.java,v
retrieving revision 1.1
diff -u -r1.1 OSEnvironment.java
--- src/org/jruby/environment/OSEnvironment.java	13 Apr 2006 03:58:39 -0000	1.1
+++ src/org/jruby/environment/OSEnvironment.java	14 Apr 2006 01:25:01 -0000
@@ -128,7 +128,9 @@
 		Map envs = new HashMap();
 		for (Iterator iter = entrySet.iterator(); iter.hasNext();) {
 			Map.Entry entry  = (Map.Entry) iter.next();
-            envs.put(runtime.newString((String)entry.getKey()),runtime.newString((String)entry.getValue()));
+			if (entry.getValue() != null) {
+				envs.put(runtime.newString((String)entry.getKey()),runtime.newString((String)entry.getValue()));
+			}
 		}
 		return envs;
 	}
Index: src/RailsCGIServlet.java
===================================================================
RCS file: src/RailsCGIServlet.java
diff -N src/RailsCGIServlet.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/RailsCGIServlet.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,136 @@
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.jruby.IRuby;
+import org.jruby.Ruby;
+import org.jruby.RubyGlobal;
+import org.jruby.environment.OSEnvironmentReaderFromRuntimeProperties;
+import org.jruby.internal.runtime.ValueAccessor;
+import org.jruby.runtime.IAccessor;
+import org.jruby.runtime.builtin.IRubyObject;
+
+public class RailsCGIServlet extends GenericServlet {
+	private IRuby runtime;
+	private ProxyInputStream fakeIn;
+	private ProxyOutputStream fakeOut;
+	private PrintStream fakePrintOut;
+	
+	private static class ProxyInputStream extends InputStream {
+		public InputStream currentStream;
+		
+		public int read() throws IOException {
+			return currentStream.read();
+		}
+	}
+	
+	private static class ProxyOutputStream extends OutputStream {
+		public OutputStream currentStream;
+
+		public void write(int b) throws IOException {
+			currentStream.write(b);
+		}
+	}
+
+	private static final String DISPATCH_CGI = "require \"C:/rails-1.0.0/config/environment\" unless defined?(RAILS_ROOT)\n"
+			+ "require \"dispatcher\"\n"
+			+ "ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)\n"
+			+ "Dispatcher.dispatch";
+
+	public void init(ServletConfig config) throws ServletException {
+		fakeIn = new ProxyInputStream();
+		fakeOut = new ProxyOutputStream();
+		fakePrintOut = new PrintStream(fakeOut);
+		
+		runtime = Ruby.newInstanceNoInit(fakeIn, fakePrintOut, System.err);
+
+		Map cgiEnv = new HashMap();
+
+		cgiEnv.put("REQUEST_METHOD", "GET");
+		cgiEnv.put("PATH_INFO", "/rails_info/properties");
+		cgiEnv.put("QUERY_STRING", "");
+		cgiEnv.put("REMOTE_HOST", "localhost");
+		cgiEnv.put("RAILS_ROOT", "C:/rails-1.0.0");
+		cgiEnv.put("JRUBY_HOME", "C:\\jrubywork\\jruby");
+
+		runtime.setCustomEnvProperties(cgiEnv);
+		System.setProperty("jruby.env.method",
+				OSEnvironmentReaderFromRuntimeProperties.class.getName());
+		System.setProperty("jruby.home", "C:\\jrubywork\\jruby");
+		System.setProperty("jruby.lib", "C:\\jrubywork\\jruby\\lib");
+		System.setProperty("jruby.base", "C:\\jrubywork\\jruby");
+		runtime.init();
+
+		IRubyObject argumentArray = runtime.newArray();
+		runtime.setVerbose(runtime.newBoolean(false));
+
+		defineGlobalVERBOSE(runtime);
+		runtime.getObject().setConstant("$VERBOSE", runtime.getNil());
+		runtime.defineGlobalConstant("ARGV", argumentArray);
+
+		defineGlobal(runtime, "$-p", false);
+		defineGlobal(runtime, "$-n", false);
+		defineGlobal(runtime, "$-a", false);
+		defineGlobal(runtime, "$-l", false);
+		runtime.getGlobalVariables().defineReadonly("$*",
+				new ValueAccessor(argumentArray));
+		// TODO this is a fake cause we have no real process number in Java
+		runtime.getGlobalVariables().defineReadonly("$$",
+				new ValueAccessor(runtime.newFixnum(runtime.hashCode())));
+		runtime.defineVariable(new RubyGlobal.StringGlobalVariable(runtime,
+				"$0", runtime
+						.newString("C:\\rails-1.0.0\\public\\dispatch.cgi")));
+		runtime.getLoadService().init(Collections.EMPTY_LIST);
+
+		super.init(config);
+	}
+
+	public void service(ServletRequest request, ServletResponse response)
+			throws ServletException, IOException {
+		fakeIn.currentStream = request.getInputStream();
+		fakeOut.currentStream = response.getOutputStream();
+		response.setContentType("text/html");
+
+		runtime.evalScript(DISPATCH_CGI);
+	}
+
+	private void defineGlobalVERBOSE(final IRuby runtime) {
+		// $VERBOSE can be true, false, or nil. Any non-false-nil value will get
+		// stored as true
+		runtime.getGlobalVariables().define("$VERBOSE", new IAccessor() {
+			public IRubyObject getValue() {
+				return runtime.getVerbose();
+			}
+
+			public IRubyObject setValue(IRubyObject newValue) {
+				if (newValue.isNil()) {
+					runtime.setVerbose(newValue);
+				} else {
+					runtime.setVerbose(runtime.newBoolean(newValue != runtime
+							.getFalse()));
+				}
+
+				return newValue;
+			}
+		});
+	}
+
+	private void defineGlobal(IRuby runtime, String name, boolean value) {
+		runtime.getGlobalVariables()
+				.defineReadonly(
+						name,
+						new ValueAccessor(value ? runtime.getTrue() : runtime
+								.getNil()));
+	}
+
+}
Index: src/org/jruby/environment/OSEnvironmentReaderFromRuntimeProperties.java
===================================================================
RCS file: src/org/jruby/environment/OSEnvironmentReaderFromRuntimeProperties.java
diff -N src/org/jruby/environment/OSEnvironmentReaderFromRuntimeProperties.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/jruby/environment/OSEnvironmentReaderFromRuntimeProperties.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,22 @@
+package org.jruby.environment;
+
+import java.util.Map;
+
+import org.jruby.IRuby;
+
+public class OSEnvironmentReaderFromRuntimeProperties extends Object implements
+		IOSEnvironmentReader {
+
+	public Map getVariables(IRuby runtime) {
+		return runtime.getCustomEnvProperties();
+	}
+
+	public boolean isAccessible(IRuby runtime) {
+		if (runtime.getCustomEnvProperties() != null) {
+			return true;
+		}
+		
+		return false;
+	}
+
+}




