

Index: admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java
===================================================================
RCS file: /cvs/glassfish/admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java,v
retrieving revision 1.4
diff -u -b -r1.4 AgentManager.java
--- admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java	22 Oct 2006 19:57:30 -0000	1.4
+++ admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java	10 Nov 2006 00:03:51 -0000
@@ -127,6 +127,11 @@
             }
         }
     }
+    @Override
+    public String getNativeName()
+    {
+        return "appservAgent";
+    }
     
     public void createNodeAgent() throws AgentException 
     {   
Index: admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java,v
retrieving revision 1.5
diff -u -b -r1.5 EEInstancesManager.java
--- admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java	22 Oct 2006 19:57:31 -0000	1.5
+++ admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java	10 Nov 2006 00:03:53 -0000
@@ -83,6 +83,12 @@
         setMessages(messages);
     }
 
+    @Override
+    public String getNativeName()
+    {
+        return "appserv";
+    }
+
     protected InstanceConfig getInstanceConfig() {
         return (InstanceConfig)getConfig();
     }
Index: admin-ee/templates/ee80/startserv.tomcat.bat.template
===================================================================
RCS file: /cvs/glassfish/admin-ee/templates/ee80/startserv.tomcat.bat.template,v
retrieving revision 1.1.1.1
diff -u -b -r1.1.1.1 startserv.tomcat.bat.template
--- admin-ee/templates/ee80/startserv.tomcat.bat.template	8 Aug 2006 19:48:40 -0000	1.1.1.1
+++ admin-ee/templates/ee80/startserv.tomcat.bat.template	10 Nov 2006 00:03:55 -0000
@@ -1,73 +1,81 @@
 @echo off
-if "%OS%" == "Windows_NT" setlocal
+setlocal
 
-rem Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
-rem Use is subject to license terms.
-
-rem Sun ONE App Server startup scripts
-rem
-rem Environment Variable Prequisites
-rem
-rem   JAVA_HOME       Must point at your Java Development Kit installation.
-
-rem Get standard environment variables
-
-set PRG=%0
+if "%1"=="help" goto help
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Required Environment ---------------------------
+rem ---------------------------------------------------------------------------
 set ASENV_CONF_LOCATION=%%%CONFIG_HOME%%%
+call "%ASENV_CONF_LOCATION%/asenv.bat"
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Check JAVA_HOME  --------------------------------------
+rem ---------------------------------------------------------------------------
+if "%JAVA_HOME%"=="" set JAVA_HOME=%AS_JAVA%
+if exist "%JAVA_HOME%\bin\java.exe" goto gotJava
+echo JAVA_HOME (%JAVA_HOME%) is not pointing at a valid JDK installation.
+goto end
+:gotJava
 
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Domain-Specific Environment  ----------------------
+rem ---------------------------------------------------------------------------
 set SERVER_NAME=%%%SERVER_NAME%%%
 set DOMAIN_NAME=%%%DOMAIN_NAME%%%
+set INSTANCE_ROOT=%~dp0..
 
-if exist "%ASENV_CONF_LOCATION%\asenv.bat" goto gotCmdPath
-rem %0 must have been found by DOS using the %PATH% so we assume that asenv.bat
-rem will also be found in the %PATH%
-call asenv.bat
-goto doneSetenv
-:gotCmdPath
-call "%ASENV_CONF_LOCATION%\asenv.bat"
-:doneSetenv
-
-set INSTANCE_ROOT=%%%INSTANCE_ROOT%%%
-
-set JAVA_HOME=%AS_JAVA%
-rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJavaHome
-echo The JAVA_HOME environment variable is not defined
-echo This environment variable is needed to run this program
+rem ---------------------------------------------------------------------------
+rem ------------------  Process Args                      ---------------------
+rem ---------------------------------------------------------------------------
+set CLI=
+if not "%1"=="cli" goto NOT_CLI
+shift /1
+set CLI=cli
+:NOT_CLI
+
+rem check for "native" remove and remember it
+set NATIVE=
+if  not "%1"=="native" goto NOT_NATIVE
+shift /1
+set NATIVE=native
+
+rem Don't allow "native" arg when running directly from the commandline, because
+rem we have no access to stdin
+if not "%CLI%"=="cli" goto NATIVE_NOT_ALLOWED
+
+:NOT_NATIVE
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Set  Environment for Readability  ---------------------
+rem ---------------------------------------------------------------------------
+set CLASSNAME=com.sun.enterprise.admin.servermgmt.launch.ASLauncher
+set JAVA="%JAVA_HOME%\bin\java.exe" 
+set CP="%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\admin-cli.jar"
+set D01=-Dcom.sun.aas.installRoot="%AS_INSTALL%" 
+set D02=-Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  
+set D03=-Dcom.sun.aas.instanceName="%SERVER_NAME%"
+if "%CLI%"=="cli" set D04=-Dcaller=cli
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Start    ------------------------------------------------
+rem ---------------------------------------------------------------------------
+
+set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin
+if  not "%NATIVE%"=="native" goto JAVA_LAUNCH
+
+"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%"  "\"%~df0\" %CLI% display %1 %2 %3 %4" 
+exit
+
+:JAVA_LAUNCH
+%JAVA% %JAVA_DEBUGXX% -cp %CP% %D01% %D02% %D03% %D04% %CLASSNAME% start %1 %2 %3 %4 %5 %6 %7 %8
+rem if ERRORLEVEL 1 goto error 
 goto end
-:gotJavaHome
-
-
-rem Get command line arguments and save them
-rem set CMD_LINE_ARGS=
-rem :setArgs
-rem if ""%1""=="""" goto doneSetArgs
-rem set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
-rem shift
-rem goto setArgs
-rem :doneSetArgs
-
-set PATH=%AS_NSS%;%AS_INSTALL%\lib;%AS_INSTALL%\bin;%PATH%
 
-cd %INSTANCE_ROOT%\config
-
-rem add in native launcher functionality
-if NOT "%1" == "native" GOTO JAVALAUNCHER
-	SHIFT;
-	rem set PATH=%AS_JAVA%%AS_NATIVE_LAUNCHER_LIB_PREFIX%;%PATH%
-	"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%" "\"%INSTANCE_ROOT%/bin/startserv.bat\" display %*"
-    exit
-
-:JAVALAUNCHER
-
-
-rem Launch the S1AS server using s1as-start target 
-rem "%JAVA_HOME%\bin\java" -classpath "%AS_INSTALL%\lib";"%AS_INSTALL%\lib\commons-launcher.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_ANT_LIB%\ant.jar";"%AS_ANT_LIB%\optional.jar";"%AS_INSTALL%\lib\endorsed\xercesImpl.jar";"%AS_INSTALL%\lib\endorsed\xalan.jar" -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%" -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" LauncherBootstrap  s1as-server -DJAVA_HOME="%JAVA_HOME%"   -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" start %*
-
-rem set hold flag
-set HOLD_FLAG=return
-
-rem executing launcher
-"%JAVA_HOME%\bin\java" -cp "%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\javaee.jar" -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" -DJAVA_HOME="%JAVA_HOME%" -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager -Dcom.sun.aas.launcherReturn="%HOLD_FLAG%" -Dcom.sun.aas.processName="as9-server" -Dcom.sun.aas.processLauncher="SE" -Dcom.sun.aas.promptForIdentity="true" com.sun.enterprise.tools.launcher.ProcessLauncher start %*
+:help
+echo startserv [verbose] [debug]
+goto end
 
+:NATIVE_NOT_ALLOWED
+echo Can not start in native mode from the commandline
 :end
+endlocal
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java,v
retrieving revision 1.6
diff -u -b -r1.6 InstancesManager.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java	22 Oct 2006 19:57:30 -0000	1.6
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java	10 Nov 2006 00:03:56 -0000
@@ -114,4 +114,6 @@
      * to take effect, false otherwise.
      */
     boolean isRestartNeeded() throws InstanceException;
+
+    public String getNativeName();
 }
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java,v
retrieving revision 1.2
diff -u -b -r1.2 ASLauncher.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java	18 Oct 2006 22:36:02 -0000	1.2
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java	10 Nov 2006 00:03:58 -0000
@@ -42,6 +42,7 @@
 import java.io.BufferedWriter;
 import java.io.PushbackInputStream;
 import java.lang.InterruptedException;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
@@ -69,6 +70,7 @@
 import com.sun.enterprise.util.ASenvPropertyReader;
 import com.sun.enterprise.util.SystemPropertyConstants;
 import com.sun.enterprise.util.ProcessExecutor;
+import com.sun.enterprise.util.io.ProcessStreamDrainer;
 import com.sun.enterprise.util.i18n.StringManager;
 import com.sun.enterprise.config.ConfigContext;
 import com.sun.enterprise.config.ConfigException;
@@ -89,7 +91,7 @@
 import com.sun.enterprise.config.serverbeans.ServerHelper;
 import com.sun.enterprise.config.serverbeans.NodeAgentHelper;
 import com.sun.enterprise.config.serverbeans.ClusterHelper;
-//import com.sun.enterprise.cli.framework.CliUtil;
+import com.sun.enterprise.util.natives.NativeUtils;
 import com.sun.enterprise.security.store.IdentityManager;
 import com.sun.enterprise.admin.util.JvmOptionsHelper;
 
@@ -148,7 +150,7 @@
     private static final String SCRIPT_PATH_SYSTEM_PROPERTY = "com.sun.aas.scriptpath";
     
     static       int    returnValue = 1;
-    private String[]    securityInfo;   // username & passwords if neccessary...
+    String[]    securityInfo;   // username & passwords if neccessary...
     
     // WBN the level is here as a constant so that it can be changed to INFO or better
     // when actively debugging in order to see the messages easily.  Always return to FINE
@@ -162,9 +164,9 @@
     public static void main(String[] args) {
         try {
             ASLauncher pl=new ASLauncher();
-            pl.preProcess();    // figure out relocatable stuff
-            pl.getSecurityFromUser();
-            pl.process(args, pl.securityInfo);
+            pl.preProcess(args, new Properties());    // figure out relocatable stuff
+            pl.getSecurityFromUser(args);
+            Process process = pl.process(args, pl.securityInfo);
         }
         catch(Exception e) {
             e.printStackTrace();
@@ -207,6 +209,61 @@
         // start processing
         pl.process(args);
     }
+    /**
+     * WBN Oct 2006 -- The startserv script has been made relocatable.  But we have to be backward
+     * compatible.  So look for the new args and preprocess them...
+     * Adding this allows us to remove lots of unchanging stuff from the script.
+     */
+    public void preProcess(String[] args, Properties extraProps) throws ASLauncherException
+    {
+        boolean nativeLauncher = false;
+        boolean verbose = false;
+
+        readASEnv();
+        
+        for(String arg : args)
+        {
+            if("display".equalsIgnoreCase(arg))
+                nativeLauncher = true;
+
+            if("verbose".equalsIgnoreCase(arg))
+                verbose = true;
+        }
+        
+        // Set system props needed by launcher
+        // first add all the ones that were passed in from a caller...
+        
+        Enumeration keys = extraProps.propertyNames();
+        
+        while(keys.hasMoreElements())
+        {
+            String key = (String)keys.nextElement();
+            String value = extraProps.getProperty(key);
+            System.setProperty(key, value);
+        }
+        
+
+        // set props but only if NOT in extraProps already!
+        setInstanceRoot(extraProps);
+
+        if(extraProps.getProperty(LaunchConstants.JAVA_HOME_PROP) == null)
+                System.setProperty(LaunchConstants.JAVA_HOME_PROP, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
+        if(extraProps.getProperty(LaunchConstants.LOG_MGR_PROP) == null)
+            System.setProperty(LaunchConstants.LOG_MGR_PROP, LaunchConstants.LOG_MGR_VALUE);
+        if(extraProps.getProperty(LaunchConstants.ENV_FACTORY_PROP) == null)
+            System.setProperty(LaunchConstants.ENV_FACTORY_PROP, LaunchConstants.ENV_FACTORY_VALUE);
+        if(extraProps.getProperty(LaunchConstants.PROCESS_NAME_PROP) == null)
+            System.setProperty(LaunchConstants.PROCESS_NAME_PROP, "as9-server");
+        if( extraProps.getProperty(LaunchConstants.LAUNCHER_RETURN_PROP) == null)
+        {
+            if(verbose && nativeLauncher)
+                System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_HOLD_VALUE);
+            else
+                System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_RETURN_VALUE);
+        }
+        // TODO set it to hold in an else????
+        
+    }
     
     
     /**
@@ -219,7 +276,8 @@
         process(args, null);
     }
 
-    public void process(String[] args, String[] SecurityInfo) {
+    public Process process(String[] args, String[] SecurityInfo) {
+        Process process = null;
         try {
             returnValue=1;
             securityInfo = SecurityInfo;
@@ -228,7 +286,6 @@
                 System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
             // store args for later use (e.g. debug, verbose)
             setArgs(args);
-            readASEnv();
 
             // look for Debug system property
             if (System.getProperty("Debug") != null) {
@@ -259,10 +316,12 @@
             
             // execute command that was build and pass in action
             if (bDebug) System.out.println("ASLauncher Executing command ..");
-            executeCommand(command, passArg);
             
             // if no exception, should have executed properly or logged errors
             returnValue=0;
+            
+            process = executeCommand(command, passArg);
+            
         } catch (ConfigException ce) {
             // try to log but the log main not be set up properly if domain.xml had a problem
             getLogger().log(Level.SEVERE, "launcher.config_exception", ce);
@@ -272,6 +331,7 @@
             getLogger().log(Level.SEVERE, "enterprise.launcher_exception_startup",e);
             e.printStackTrace();
         }
+        return process;
     }
     
     
@@ -280,7 +340,7 @@
      * @param cmd - command to execute
      * @param action - action to take, should be start or stop.  defaults to "start"
      */
-    public void executeCommand(Command command, String action) throws IOException {
+    public Process executeCommand(Command command, String action) throws IOException {
         
         String[] cmd=null;
         
@@ -355,9 +415,11 @@
                 System.out.print(cmd[ii] + sxDelim);
             }
             System.out.print("ENDOFCOMMAND" + sxDelim);
-            
+            // we can't return a Process because we are being CALLED by the external process.
+            // only ASNativeLauncher will have a handle to the native process that called us
+            return null;
         } else { // all other execution paths
-            executeBackgroundCommand(command, isVerboseEnabled(), action);
+            return executeBackgroundCommand(command, isVerboseEnabled(), action);
         }
         
     }
@@ -369,7 +431,7 @@
     }
     
     
-    public void executeBackgroundCommand(Command command, boolean verbose, String action) throws IOException {
+    public Process executeBackgroundCommand(Command command, boolean verbose, String action) throws IOException {
         
         // execute the command as a runtime.exec and immediately return,
         // return will not pertain to the the executed process
@@ -442,11 +504,13 @@
             
             // must sleep for a couple of seconds, so if there is a jvm startup error, the parent process
             // is around to catch and report it when the process in executed in verbose mode.
-            // WBN  ?????? It doesn't appear that we need this ????
-            try {
-                Thread.currentThread().sleep(SLEEP_TIME_FOR_PROCESS_START);
-            } catch (InterruptedException ie) {}
+            // WBN  ?????? It doesn't appear that we need this ????  Verbose mode was handled in the "if"
+            // above...
+            //try {
+                //Thread.currentThread().sleep(SLEEP_TIME_FOR_PROCESS_START);
+            //} catch (InterruptedException ie) {}
         }
+        return process;
     }
     
     private void sendInputToProcessInput(InputStream in, Process subProcess) {
@@ -1792,7 +1856,7 @@
     }
 
     
-    private void writeSecurityInfoToProcess(Process p)
+    void writeSecurityInfoToProcess(Process p)
     {
         if(securityInfo == null) // impossible!
             return;
@@ -1846,44 +1910,62 @@
         }
     }
         
-    /**
-     * WBN Oct 2006 -- The startserv script has been made relocatable.  But we have to be backward
-     * compatible.  So look for the new args and preprocess them...
-     */
-    private void preProcess() throws ASLauncherException
+    
+    private void getSecurityFromUser(String[] args) throws IOException 
+    {
+        // HACK-O-RAMA
+        // yet another hack for backward compatibility!
+        // CLI will gather up passwords and send them in as an arg...
+        if(System.getProperty("caller", "not-cli").equals("cli"))
+            return;
+        
+        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+        securityInfo = new String[3];
+        NativeUtils nativeUtils = new NativeUtils(); 
+        System.out.print("admin username:");
+        securityInfo[0] = reader.readLine();
+        securityInfo[1] = nativeUtils.getPassword("admin password: ");
+        securityInfo[2] = nativeUtils.getPassword("master password: ");
+        
+        System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
+    }
+
+    private void setInstanceRoot(Properties callerProps)  throws ASLauncherException
     {
-        // THIS ONLY WORKS FOR DOMAINS!!! (because of instance-name/domain-name issues)
-        String  scriptPath = System.getProperty(SCRIPT_PATH_SYSTEM_PROPERTY);
+        String irpTag = SystemPropertyConstants.INSTANCE_ROOT_PROPERTY; // too ugly to type!
+        String irp = callerProps.getProperty(irpTag);
         
-        if(scriptPath == null)
-            return; // old script
+        if(irp != null)
+            System.setProperty(irpTag, irp);
 
-        String  installRoot = System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY);
         
+        // if the user is running a script stand-alone the instance-root may be
+        // something like "./startserv".  We need to convert it to a real path
         
-        DASLauncherInfo info = new DASLauncherInfo(DASLauncherInfo.SCRIPT_PATH + scriptPath, DASLauncherInfo.INSTALL_DIR + installRoot);
-        info.validate();
+        irp = System.getProperty(irpTag);
 
-        // all sorts of directories have benn checked for -- everything is A-OK!
-        // So now set the sys-props that this overly-flexible code is looking for...
-        System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, info.domainDir.getPath());
-        System.setProperty(SystemPropertyConstants.SERVER_NAME, "server"); 
-        System.setProperty("domain.name", info.domainName);
+        if(irp == null || irp.length() <= 0 )
+        {
+            // if we are being called from stand-alone java or a script -- they need to
+            // do a -DirpTag=...
+            // if we are called from PEInstancesManager, it has been set.  If it isn't
+            // set let's fail right now!
+            throw new ASLauncherException("Missing System Property: " + irpTag);
     }
     
-    private void getSecurityFromUser() throws IOException 
+		File f = new File(irp);
+		try
     {
-        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
-        securityInfo = new String[3];
+			irp = f.getCanonicalPath();
+		}
+		catch(Exception e)
+		{
+			irp = f.getAbsolutePath();
+		}
     
-        System.out.println("admin username:");
-        securityInfo[0] = reader.readLine();
-        System.out.println("admin password:");
-        securityInfo[1] = reader.readLine();
-        System.out.println("master password:");
-        securityInfo[2] = reader.readLine();
-        System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
+        System.setProperty(irpTag, irp);
     }
+
     // END END END END ENDEND -- this is here for grepping to the end of this gigantic class!!
     
     //**************************************************************************
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java,v
retrieving revision 1.1
diff -u -b -r1.1 ASLauncherException.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java	18 Oct 2006 05:29:53 -0000	1.1
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java	10 Nov 2006 00:04:00 -0000
@@ -32,4 +32,9 @@
     {
         super(msg);
     }
+
+    public ASLauncherException(Throwable t)
+    {
+        super(t);
+    }
 }
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java,v
retrieving revision 1.7
diff -u -b -r1.7 PEInstancesManager.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java	23 Oct 2006 03:36:08 -0000	1.7
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java	10 Nov 2006 00:04:04 -0000
@@ -25,16 +25,19 @@
 
 import com.sun.enterprise.admin.event.AdminEventResult;
 import com.sun.enterprise.admin.event.ShutdownEvent;
+import com.sun.enterprise.admin.servermgmt.launch.ASLauncherException;
+import com.sun.enterprise.admin.servermgmt.launch.ASNativeLauncher;
 import com.sun.enterprise.admin.servermgmt.launch.LaunchConstants;
+import java.io.*;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.ArrayList;
-import java.io.File;
 import java.lang.reflect.Method;
 
 import com.sun.enterprise.util.ProcessExecutor;
 import com.sun.enterprise.util.SystemPropertyConstants;
 import com.sun.enterprise.util.io.FileUtils;
+import com.sun.enterprise.util.io.ProcessStreamDrainer;
 import com.sun.enterprise.util.i18n.StringManager;
 import com.sun.enterprise.admin.servermgmt.InstancesManager;
 import com.sun.enterprise.admin.servermgmt.InstanceException;
@@ -60,20 +63,6 @@
     private static final StringManager _strMgr =
         StringManager.getManager(PEInstancesManager.class);
 
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    private static final boolean temporaryFlagStartservScriptReady = false;
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-
     private final           RepositoryConfig    _config;
     private                 Properties          systemPropsCopy;
     private                 String[]            securityInfo;
@@ -89,6 +78,11 @@
         _config = config;
     }
 
+    public String getNativeName()
+    {
+        return "appservDAS";
+    }
+
     protected RepositoryConfig getConfig()
     {
         return _config;
@@ -129,20 +123,20 @@
         
         nativeLauncher = Boolean.getBoolean(SystemPropertyConstants.NATIVE_LAUNCHER);
         
-        // WBN TEMPORARILY TURN OFF NEW CODE BY DEFAULT
-        String s = System.getenv("NEW_LAUNCHER");
+        // WBN TURN OFF OLD CODE BY DEFAULT
+        String s = System.getenv("OLD_LAUNCHER");
 
-        if(s == null || !s.equals("true"))
+        if(s != null && s.equals("true"))
             return startInstanceUsingScript(commandLineArgs);
-        else
-        {
             try
             {
                 saveSystemProps();
                 
+            //
                 if(nativeLauncher)
                     return startInstanceUsingScript(commandLineArgs);
                 else
+             //
                     return startInstanceAllJava(commandLineArgs);
             }
             finally
@@ -150,7 +144,6 @@
                 restoreSystemProps();
             }
         }
-    }
 
     public Process startInstance(String[] interativeOptions, String[] commandLineArgs)
         throws InstanceException
@@ -213,43 +206,45 @@
             if(isTrue((Boolean)getConfig().get(DomainConfig.K_DEBUG)))
                 debug = true;
 
-            setSystemProps();
             setSecurity();
             ArrayList<String> args = new ArrayList<String>();
-            
             args.add("start");
 
             if(nativeLauncher)
                 args.add("display");
+
             if ( debug ) 
                 args.add("debug");
+            
             if ( verbose ) 
                 args.add("verbose");
             
             String[] launcherArgs = args.toArray(new String[args.size()]);
             
-            /* I can't get this to work yet...
+            System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
+                getConfig().getRepositoryRoot() + File.separator +
+                getConfig().getRepositoryName());
+        
             if(nativeLauncher)
             {
-                ProcessBuilder pb = new ProcessBuilder(
-                    "C:/ee/lib/appservLauncher.exe",
-                    "C:/ee/lib/appserv.exe",
-                    System.getProperty("domain.name"),
-                    "\"C:/ee/domains/domain1/bin/startserv.bat\"",
-                    "cli",
-                    "display",
-                    "debug"
-                );
-                
-                process = pb.start();
+                ASNativeLauncher launcher = new ASNativeLauncher(this);
+                launcher.preProcess(launcherArgs, envProps);
+                try
+                {
+                    process = launcher.launch(launcherArgs, securityInfo);
+                }
+                catch(ASLauncherException e)
+                {
+                    throw new InstanceException(e);
+                }
             }
             else
-             **/
             {
                 ASLauncher launcher = new ASLauncher();
-                launcher.process(launcherArgs, securityInfo);
+                launcher.preProcess(launcherArgs, envProps);
+                process = launcher.process(launcherArgs, securityInfo);
             }
-            if(!verbose)
+            if(!verbose || nativeLauncher)
             {
                 waitUntilStarting(null);
                 waitUntilStarted();
@@ -295,7 +290,6 @@
         alCmd.add(script.getAbsolutePath());
 
         // WBN - we need to distinguish CLI calls from commandline calls
-        if(temporaryFlagStartservScriptReady)
             alCmd.add("cli");
 
         //
@@ -793,42 +787,6 @@
         return Boolean.TRUE.equals(b);
     }
 
-    protected void setSystemProps()
-    {
-        // Set system props needed by launcher
-        // first add all the ones that were passed in from a caller...
-        
-        Enumeration keys = envProps.propertyNames();
-        
-        while(keys.hasMoreElements())
-        {
-            String key = (String)keys.nextElement();
-            String value = envProps.getProperty(key);
-            System.setProperty(key, value);
-        }
-        
-        // set props but only if NOT in envProps already!
-        
-        if(envProps.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY) == null)
-            System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
-                    getConfig().getRepositoryRoot() + File.separator +
-                    getConfig().getRepositoryName());
-
-
-        if(envProps.getProperty(LaunchConstants.JAVA_HOME_PROP) == null)
-                System.setProperty(LaunchConstants.JAVA_HOME_PROP, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
-        
-        if(envProps.getProperty(LaunchConstants.LOG_MGR_PROP) == null)
-            System.setProperty(LaunchConstants.LOG_MGR_PROP, LaunchConstants.LOG_MGR_VALUE);
-        if(envProps.getProperty(LaunchConstants.ENV_FACTORY_PROP) == null)
-            System.setProperty(LaunchConstants.ENV_FACTORY_PROP, LaunchConstants.ENV_FACTORY_VALUE);
-        if(envProps.getProperty(LaunchConstants.PROCESS_NAME_PROP) == null)
-            System.setProperty(LaunchConstants.PROCESS_NAME_PROP, "as9-server");
-
-        if( envProps.getProperty(LaunchConstants.LAUNCHER_RETURN_PROP) == null && !(verbose && nativeLauncher) )
-            System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_RETURN_VALUE);
-    }
-    
     private boolean ok(String s)
     {
         return s != null && s.length() > 0;
Index: admin/templates/pe80/startserv.tomcat.bat.template
===================================================================
RCS file: /cvs/glassfish/admin/templates/pe80/startserv.tomcat.bat.template,v
retrieving revision 1.4
diff -u -b -r1.4 startserv.tomcat.bat.template
--- admin/templates/pe80/startserv.tomcat.bat.template	12 Nov 2005 01:45:34 -0000	1.4
+++ admin/templates/pe80/startserv.tomcat.bat.template	10 Nov 2006 00:04:05 -0000
@@ -1,75 +1,81 @@
 @echo off
-if "%OS%" == "Windows_NT" setlocal
+setlocal
+
+if "%1"=="help" goto help
 rem ---------------------------------------------------------------------------
-rem Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
-rem Use is subject to license terms.
-rem
-rem Sun ONE App Server startup scripts
-rem
-rem Environment Variable Prequisites
-rem
-rem   JAVA_HOME       Must point at your Java Development Kit installation.
-rem
-rem $Id: startserv.tomcat.bat.template,v 1.4 2005/11/12 01:45:34 km105526 Exp $
+rem ------------------  Set Required Environment ---------------------------
 rem ---------------------------------------------------------------------------
-rem
-
-rem Get standard environment variables
-
-set PRG=%0
 set ASENV_CONF_LOCATION=%%%CONFIG_HOME%%%
+call "%ASENV_CONF_LOCATION%/asenv.bat"
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Check JAVA_HOME  --------------------------------------
+rem ---------------------------------------------------------------------------
+if "%JAVA_HOME%"=="" set JAVA_HOME=%AS_JAVA%
+if exist "%JAVA_HOME%\bin\java.exe" goto gotJava
+echo JAVA_HOME (%JAVA_HOME%) is not pointing at a valid JDK installation.
+goto end
+:gotJava
 
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Domain-Specific Environment  ----------------------
+rem ---------------------------------------------------------------------------
 set SERVER_NAME=%%%SERVER_NAME%%%
 set DOMAIN_NAME=%%%DOMAIN_NAME%%%
+set INSTANCE_ROOT=%~dp0..
 
-if exist "%ASENV_CONF_LOCATION%\asenv.bat" goto gotCmdPath
-rem %0 must have been found by DOS using the %PATH% so we assume that asenv.bat
-rem will also be found in the %PATH%
-call asenv.bat
-goto doneSetenv
-:gotCmdPath
-call "%ASENV_CONF_LOCATION%\asenv.bat"
-:doneSetenv
-
-set INSTANCE_ROOT=%%%INSTANCE_ROOT%%%
-
-set JAVA_HOME=%AS_JAVA%
-rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJavaHome
-echo The JAVA_HOME environment variable is not defined
-echo This environment variable is needed to run this program
-goto end
-:gotJavaHome
-
+rem ---------------------------------------------------------------------------
+rem ------------------  Process Args                      ---------------------
+rem ---------------------------------------------------------------------------
+set CLI=
+if not "%1"=="cli" goto NOT_CLI
+shift /1
+set CLI=cli
+:NOT_CLI
+
+rem check for "native" remove and remember it
+set NATIVE=
+if  not "%1"=="native" goto NOT_NATIVE
+shift /1
+set NATIVE=native
+
+rem Don't allow "native" arg when running directly from the commandline, because
+rem we have no access to stdin
+if not "%CLI%"=="cli" goto NATIVE_NOT_ALLOWED
 
-rem Get command line arguments and save them
-rem set CMD_LINE_ARGS=
-rem :setArgs
-rem if ""%1""=="""" goto doneSetArgs
-rem set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
-rem shift
-rem goto setArgs
-rem :doneSetArgs
+:NOT_NATIVE
 
-set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin;%PATH%
+rem ---------------------------------------------------------------------------
+rem ------------------  Set  Environment for Readability  ---------------------
+rem ---------------------------------------------------------------------------
+set CLASSNAME=com.sun.enterprise.admin.servermgmt.launch.ASLauncher
+set JAVA="%JAVA_HOME%\bin\java.exe" 
+set CP="%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\admin-cli.jar"
+set D01=-Dcom.sun.aas.installRoot="%AS_INSTALL%" 
+set D02=-Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  
+set D03=-Dcom.sun.aas.instanceName="%SERVER_NAME%"
+if "%CLI%"=="cli" set D04=-Dcaller=cli
 
-cd "%INSTANCE_ROOT%\config"
+rem ---------------------------------------------------------------------------
+rem ------------------  Start    ------------------------------------------------
+rem ---------------------------------------------------------------------------
 
-rem add in native launcher functionality
-if NOT "%1" == "native" GOTO JAVALAUNCHER
-	SHIFT;
-	rem set PATH=%AS_JAVA%%AS_NATIVE_LAUNCHER_LIB_PREFIX%;%PATH%
-	"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appserv.exe %DOMAIN_NAME%"  "\"%INSTANCE_ROOT%/bin/startserv.bat\" display %*"
-    exit
+set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin
+if  not "%NATIVE%"=="native" goto JAVA_LAUNCH
 
-:JAVALAUNCHER
+"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%"  "\"%~df0\" %CLI% display %1 %2 %3 %4" 
+exit
 
-rem Launch the S1AS server using s1as-start target 
-rem "%JAVA_HOME%\bin\java" -classpath "%AS_INSTALL%\lib";"%AS_INSTALL%\lib\commons-launcher.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_ANT_LIB%\ant.jar";"%AS_ANT_LIB%\optional.jar";"%AS_INSTALL%\lib\endorsed\xercesImpl.jar";"%AS_INSTALL%\lib\endorsed\xalan.jar" -Dcom.sun.aas.antLib="%AS_ANT_LIB%" -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%" -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" LauncherBootstrap  s1as-server -DJAVA_HOME="%JAVA_HOME%"   -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" start %*
+:JAVA_LAUNCH
+%JAVA% %JAVA_DEBUGXX% -cp %CP% %D01% %D02% %D03% %D04% %CLASSNAME% start %1 %2 %3 %4 %5 %6 %7 %8
+rem if ERRORLEVEL 1 goto error 
+goto end
 
-rem set hold flag
-set HOLD_FLAG=return
+:help
+echo startserv [verbose] [debug]
+goto end
 
-rem executing launcher
-"%JAVA_HOME%\bin\java" -cp "%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\javaee.jar" -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" -DJAVA_HOME="%JAVA_HOME%" -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager -Dcom.sun.aas.launcherReturn="%HOLD_FLAG%" -Dcom.sun.aas.processName="as9-server" -Dcom.sun.aas.processLauncher="SE" -Dcom.sun.aas.promptForIdentity="true" com.sun.enterprise.tools.launcher.ProcessLauncher start %*
+:NATIVE_NOT_ALLOWED
+echo Can not start in native mode from the commandline
 :end
+endlocal
Index: appserv-commons/build.xml
===================================================================
RCS file: /cvs/glassfish/appserv-commons/build.xml,v
retrieving revision 1.36
diff -u -b -r1.36 build.xml
--- appserv-commons/build.xml	9 Sep 2006 16:40:24 -0000	1.36
+++ appserv-commons/build.xml	10 Nov 2006 00:04:07 -0000
@@ -102,6 +102,21 @@
         <rmic base="${component.classes.dir}" iiop="yes" debug="${javac.debug}">
             <include name="com/sun/enterprise/util/UniqueValueGeneratorBackendImpl.class"/>
         </rmic>
+        
+        <antcall target="do.javah"/>
+
+    </target>
+
+    <!--  Calling javah utitility to create C header file -->
+    <target name="do.javah"
+            depends="tools.init.platform">
+        <echo message="Generating JNI headers for NativeUtils"/>
+        <exec executable="${JAVAH}">
+            <arg line="-classpath ${component.classes.dir}"/>
+            <arg line="-d ${component.classes.dir}"/>
+            <arg line="-force"/>
+            <arg line="com.sun.enterprise.util.natives.NativeUtils"/>
+        </exec>
     </target>
 
     <!-- assemble -->
@@ -318,4 +333,38 @@
     </java>
     <delete file="${output.dtd}"/>
   </target>
-</project>
+
+  <target name="tools.init">
+      <condition property="windows">
+          <os family="windows" />
+      </condition>
+      <condition property="unix">
+          <os family="unix" />
+      </condition>
+      <condition property="solaris">
+          <os name="SunOS"/>
+      </condition>
+      <condition property="linux">
+          <os name="Linux"/>
+      </condition>
+      <condition property="mac">
+          <os name="Mac OS X"/>
+      </condition>
+</target>
+  <target name="tools.init.windows" if="windows">
+    <property name="JAVAH" value="${java.home}/../bin/javah.exe"/>
+    <property name="MAKE" value="gmake"/>
+</target>
+<target name="tools.init.unix" if="unix" unless="mac">
+    <property name="JAVAH" value="${java.home}/../bin/javah"/>
+    <property name="MAKE" value="gmake"/>
+</target>
+    <target name="tools.init.mac" if="mac">
+    <property name="JAVAH" value="${java.home}/bin/javah"/>
+    <property name="MAKE" value="make"/>
+</target>
+<target name="tools.init.platform" 
+    depends="tools.init, tools.init.windows, tools.init.unix, tools.init.mac">
+</target>
+
+  </project>
Index: appserv-native/src/cpp/cli/CliUtilImpl.cpp
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/CliUtilImpl.cpp,v
retrieving revision 1.2
diff -u -b -r1.2 CliUtilImpl.cpp
--- appserv-native/src/cpp/cli/CliUtilImpl.cpp	25 Dec 2005 17:52:05 -0000	1.2
+++ appserv-native/src/cpp/cli/CliUtilImpl.cpp	10 Nov 2006 00:04:11 -0000
@@ -34,6 +34,7 @@
 #define getpassphrase getpass
 #endif
 #include "com_sun_enterprise_cli_framework_CliUtil.h"
+#include "com_sun_enterprise_util_natives_NativeUtils.h"
 //C++ include
 #include <string>
 #include <vector>
@@ -185,4 +186,12 @@
     return retArr;
 }
     
-  
+/*
+ * Class:     com_sun_enterprise_util_natives_NativeUtils
+ * Method:    getPasswordNative
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_sun_enterprise_util_natives_NativeUtils_getPasswordNative(JNIEnv *env, jobject obj)
+{
+    return Java_com_sun_enterprise_cli_framework_CliUtil_getPassword(env, obj);
+}
\ No newline at end of file
Index: appserv-native/src/cpp/cli/Makefile
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/Makefile,v
retrieving revision 1.2
diff -u -b -r1.2 Makefile
--- appserv-native/src/cpp/cli/Makefile	25 Dec 2005 17:52:05 -0000	1.2
+++ appserv-native/src/cpp/cli/Makefile	10 Nov 2006 00:04:12 -0000
@@ -43,6 +43,7 @@
 DLL_OBJS=CliUtilImpl
 
 LOCAL_INC += -I$(GLASSFISH_MAVEN)/../admin-cli/framework/build
+LOCAL_INC += -I$(GLASSFISH_MAVEN)/../appserv-commons/build
 LOCAL_INC += $(JNI_INCLUDES)
 
 #LOCAL_LIB += pam
Index: appserv-native/src/cpp/cli/libcliutil.spec
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/libcliutil.spec,v
retrieving revision 1.2
diff -u -b -r1.2 libcliutil.spec
--- appserv-native/src/cpp/cli/libcliutil.spec	26 Sep 2005 22:02:28 -0000	1.2
+++ appserv-native/src/cpp/cli/libcliutil.spec	10 Nov 2006 00:04:14 -0000
@@ -9,4 +9,10 @@
 end
 
 
+function        Java_com_sun_enterprise_util_natives_NativeUtils_getPasswordNative
+arch            all
+version         SUNWprivate
+end
+
+
 
Index: admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java
===================================================================
RCS file: /cvs/glassfish/admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java,v
retrieving revision 1.4
diff -u -b -r1.4 AgentManager.java
--- admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java	22 Oct 2006 19:57:30 -0000	1.4
+++ admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/AgentManager.java	10 Nov 2006 00:26:42 -0000
@@ -127,6 +127,11 @@
             }
         }
     }
+    @Override
+    public String getNativeName()
+    {
+        return "appservAgent";
+    }
     
     public void createNodeAgent() throws AgentException 
     {   
Index: admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java,v
retrieving revision 1.5
diff -u -b -r1.5 EEInstancesManager.java
--- admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java	22 Oct 2006 19:57:31 -0000	1.5
+++ admin-ee/servermgmt/src/java/com/sun/enterprise/ee/admin/servermgmt/EEInstancesManager.java	10 Nov 2006 00:26:44 -0000
@@ -83,6 +83,12 @@
         setMessages(messages);
     }
 
+    @Override
+    public String getNativeName()
+    {
+        return "appserv";
+    }
+
     protected InstanceConfig getInstanceConfig() {
         return (InstanceConfig)getConfig();
     }
Index: admin-ee/templates/ee80/startserv.tomcat.bat.template
===================================================================
RCS file: /cvs/glassfish/admin-ee/templates/ee80/startserv.tomcat.bat.template,v
retrieving revision 1.1.1.1
diff -u -b -r1.1.1.1 startserv.tomcat.bat.template
--- admin-ee/templates/ee80/startserv.tomcat.bat.template	8 Aug 2006 19:48:40 -0000	1.1.1.1
+++ admin-ee/templates/ee80/startserv.tomcat.bat.template	10 Nov 2006 00:26:46 -0000
@@ -1,73 +1,81 @@
 @echo off
-if "%OS%" == "Windows_NT" setlocal
+setlocal
 
-rem Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
-rem Use is subject to license terms.
-
-rem Sun ONE App Server startup scripts
-rem
-rem Environment Variable Prequisites
-rem
-rem   JAVA_HOME       Must point at your Java Development Kit installation.
-
-rem Get standard environment variables
-
-set PRG=%0
+if "%1"=="help" goto help
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Required Environment ---------------------------
+rem ---------------------------------------------------------------------------
 set ASENV_CONF_LOCATION=%%%CONFIG_HOME%%%
+call "%ASENV_CONF_LOCATION%/asenv.bat"
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Check JAVA_HOME  --------------------------------------
+rem ---------------------------------------------------------------------------
+if "%JAVA_HOME%"=="" set JAVA_HOME=%AS_JAVA%
+if exist "%JAVA_HOME%\bin\java.exe" goto gotJava
+echo JAVA_HOME (%JAVA_HOME%) is not pointing at a valid JDK installation.
+goto end
+:gotJava
 
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Domain-Specific Environment  ----------------------
+rem ---------------------------------------------------------------------------
 set SERVER_NAME=%%%SERVER_NAME%%%
 set DOMAIN_NAME=%%%DOMAIN_NAME%%%
+set INSTANCE_ROOT=%~dp0..
 
-if exist "%ASENV_CONF_LOCATION%\asenv.bat" goto gotCmdPath
-rem %0 must have been found by DOS using the %PATH% so we assume that asenv.bat
-rem will also be found in the %PATH%
-call asenv.bat
-goto doneSetenv
-:gotCmdPath
-call "%ASENV_CONF_LOCATION%\asenv.bat"
-:doneSetenv
-
-set INSTANCE_ROOT=%%%INSTANCE_ROOT%%%
-
-set JAVA_HOME=%AS_JAVA%
-rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJavaHome
-echo The JAVA_HOME environment variable is not defined
-echo This environment variable is needed to run this program
+rem ---------------------------------------------------------------------------
+rem ------------------  Process Args                      ---------------------
+rem ---------------------------------------------------------------------------
+set CLI=
+if not "%1"=="cli" goto NOT_CLI
+shift /1
+set CLI=cli
+:NOT_CLI
+
+rem check for "native" remove and remember it
+set NATIVE=
+if  not "%1"=="native" goto NOT_NATIVE
+shift /1
+set NATIVE=native
+
+rem Don't allow "native" arg when running directly from the commandline, because
+rem we have no access to stdin
+if not "%CLI%"=="cli" goto NATIVE_NOT_ALLOWED
+
+:NOT_NATIVE
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Set  Environment for Readability  ---------------------
+rem ---------------------------------------------------------------------------
+set CLASSNAME=com.sun.enterprise.admin.servermgmt.launch.ASLauncher
+set JAVA="%JAVA_HOME%\bin\java.exe" 
+set CP="%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\admin-cli.jar"
+set D01=-Dcom.sun.aas.installRoot="%AS_INSTALL%" 
+set D02=-Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  
+set D03=-Dcom.sun.aas.instanceName="%SERVER_NAME%"
+if "%CLI%"=="cli" set D04=-Dcaller=cli
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Start    ------------------------------------------------
+rem ---------------------------------------------------------------------------
+
+set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin
+if  not "%NATIVE%"=="native" goto JAVA_LAUNCH
+
+"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%"  "\"%~df0\" %CLI% display %1 %2 %3 %4" 
+exit
+
+:JAVA_LAUNCH
+%JAVA% %JAVA_DEBUGXX% -cp %CP% %D01% %D02% %D03% %D04% %CLASSNAME% start %1 %2 %3 %4 %5 %6 %7 %8
+rem if ERRORLEVEL 1 goto error 
 goto end
-:gotJavaHome
-
-
-rem Get command line arguments and save them
-rem set CMD_LINE_ARGS=
-rem :setArgs
-rem if ""%1""=="""" goto doneSetArgs
-rem set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
-rem shift
-rem goto setArgs
-rem :doneSetArgs
-
-set PATH=%AS_NSS%;%AS_INSTALL%\lib;%AS_INSTALL%\bin;%PATH%
 
-cd %INSTANCE_ROOT%\config
-
-rem add in native launcher functionality
-if NOT "%1" == "native" GOTO JAVALAUNCHER
-	SHIFT;
-	rem set PATH=%AS_JAVA%%AS_NATIVE_LAUNCHER_LIB_PREFIX%;%PATH%
-	"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%" "\"%INSTANCE_ROOT%/bin/startserv.bat\" display %*"
-    exit
-
-:JAVALAUNCHER
-
-
-rem Launch the S1AS server using s1as-start target 
-rem "%JAVA_HOME%\bin\java" -classpath "%AS_INSTALL%\lib";"%AS_INSTALL%\lib\commons-launcher.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_ANT_LIB%\ant.jar";"%AS_ANT_LIB%\optional.jar";"%AS_INSTALL%\lib\endorsed\xercesImpl.jar";"%AS_INSTALL%\lib\endorsed\xalan.jar" -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%" -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" LauncherBootstrap  s1as-server -DJAVA_HOME="%JAVA_HOME%"   -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" start %*
-
-rem set hold flag
-set HOLD_FLAG=return
-
-rem executing launcher
-"%JAVA_HOME%\bin\java" -cp "%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\javaee.jar" -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" -DJAVA_HOME="%JAVA_HOME%" -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager -Dcom.sun.aas.launcherReturn="%HOLD_FLAG%" -Dcom.sun.aas.processName="as9-server" -Dcom.sun.aas.processLauncher="SE" -Dcom.sun.aas.promptForIdentity="true" com.sun.enterprise.tools.launcher.ProcessLauncher start %*
+:help
+echo startserv [verbose] [debug]
+goto end
 
+:NATIVE_NOT_ALLOWED
+echo Can not start in native mode from the commandline
 :end
+endlocal
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java,v
retrieving revision 1.6
diff -u -b -r1.6 InstancesManager.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java	22 Oct 2006 19:57:30 -0000	1.6
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/InstancesManager.java	10 Nov 2006 00:26:48 -0000
@@ -114,4 +114,6 @@
      * to take effect, false otherwise.
      */
     boolean isRestartNeeded() throws InstanceException;
+
+    public String getNativeName();
 }
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java,v
retrieving revision 1.2
diff -u -b -r1.2 ASLauncher.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java	18 Oct 2006 22:36:02 -0000	1.2
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncher.java	10 Nov 2006 00:26:50 -0000
@@ -42,6 +42,7 @@
 import java.io.BufferedWriter;
 import java.io.PushbackInputStream;
 import java.lang.InterruptedException;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
@@ -89,7 +90,7 @@
 import com.sun.enterprise.config.serverbeans.ServerHelper;
 import com.sun.enterprise.config.serverbeans.NodeAgentHelper;
 import com.sun.enterprise.config.serverbeans.ClusterHelper;
-//import com.sun.enterprise.cli.framework.CliUtil;
+import com.sun.enterprise.util.natives.NativeUtils;
 import com.sun.enterprise.security.store.IdentityManager;
 import com.sun.enterprise.admin.util.JvmOptionsHelper;
 
@@ -148,7 +149,7 @@
     private static final String SCRIPT_PATH_SYSTEM_PROPERTY = "com.sun.aas.scriptpath";
     
     static       int    returnValue = 1;
-    private String[]    securityInfo;   // username & passwords if neccessary...
+    String[]    securityInfo;   // username & passwords if neccessary...
     
     // WBN the level is here as a constant so that it can be changed to INFO or better
     // when actively debugging in order to see the messages easily.  Always return to FINE
@@ -162,9 +163,9 @@
     public static void main(String[] args) {
         try {
             ASLauncher pl=new ASLauncher();
-            pl.preProcess();    // figure out relocatable stuff
-            pl.getSecurityFromUser();
-            pl.process(args, pl.securityInfo);
+            pl.preProcess(args, new Properties());    // figure out relocatable stuff
+            pl.getSecurityFromUser(args);
+            Process process = pl.process(args, pl.securityInfo);
         }
         catch(Exception e) {
             e.printStackTrace();
@@ -207,6 +208,61 @@
         // start processing
         pl.process(args);
     }
+    /**
+     * WBN Oct 2006 -- The startserv script has been made relocatable.  But we have to be backward
+     * compatible.  So look for the new args and preprocess them...
+     * Adding this allows us to remove lots of unchanging stuff from the script.
+     */
+    public void preProcess(String[] args, Properties extraProps) throws ASLauncherException
+    {
+        boolean nativeLauncher = false;
+        boolean verbose = false;
+
+        readASEnv();
+        
+        for(String arg : args)
+        {
+            if("display".equalsIgnoreCase(arg))
+                nativeLauncher = true;
+
+            if("verbose".equalsIgnoreCase(arg))
+                verbose = true;
+        }
+        
+        // Set system props needed by launcher
+        // first add all the ones that were passed in from a caller...
+        
+        Enumeration keys = extraProps.propertyNames();
+        
+        while(keys.hasMoreElements())
+        {
+            String key = (String)keys.nextElement();
+            String value = extraProps.getProperty(key);
+            System.setProperty(key, value);
+        }
+        
+
+        // set props but only if NOT in extraProps already!
+        setInstanceRoot(extraProps);
+
+        if(extraProps.getProperty(LaunchConstants.JAVA_HOME_PROP) == null)
+                System.setProperty(LaunchConstants.JAVA_HOME_PROP, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
+        if(extraProps.getProperty(LaunchConstants.LOG_MGR_PROP) == null)
+            System.setProperty(LaunchConstants.LOG_MGR_PROP, LaunchConstants.LOG_MGR_VALUE);
+        if(extraProps.getProperty(LaunchConstants.ENV_FACTORY_PROP) == null)
+            System.setProperty(LaunchConstants.ENV_FACTORY_PROP, LaunchConstants.ENV_FACTORY_VALUE);
+        if(extraProps.getProperty(LaunchConstants.PROCESS_NAME_PROP) == null)
+            System.setProperty(LaunchConstants.PROCESS_NAME_PROP, "as9-server");
+        if( extraProps.getProperty(LaunchConstants.LAUNCHER_RETURN_PROP) == null)
+        {
+            if(verbose && nativeLauncher)
+                System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_HOLD_VALUE);
+            else
+                System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_RETURN_VALUE);
+        }
+        // TODO set it to hold in an else????
+        
+    }
     
     
     /**
@@ -219,7 +275,8 @@
         process(args, null);
     }
 
-    public void process(String[] args, String[] SecurityInfo) {
+    public Process process(String[] args, String[] SecurityInfo) {
+        Process process = null;
         try {
             returnValue=1;
             securityInfo = SecurityInfo;
@@ -228,7 +285,6 @@
                 System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
             // store args for later use (e.g. debug, verbose)
             setArgs(args);
-            readASEnv();
 
             // look for Debug system property
             if (System.getProperty("Debug") != null) {
@@ -259,10 +315,12 @@
             
             // execute command that was build and pass in action
             if (bDebug) System.out.println("ASLauncher Executing command ..");
-            executeCommand(command, passArg);
             
             // if no exception, should have executed properly or logged errors
             returnValue=0;
+            
+            process = executeCommand(command, passArg);
+            
         } catch (ConfigException ce) {
             // try to log but the log main not be set up properly if domain.xml had a problem
             getLogger().log(Level.SEVERE, "launcher.config_exception", ce);
@@ -272,6 +330,7 @@
             getLogger().log(Level.SEVERE, "enterprise.launcher_exception_startup",e);
             e.printStackTrace();
         }
+        return process;
     }
     
     
@@ -280,7 +339,7 @@
      * @param cmd - command to execute
      * @param action - action to take, should be start or stop.  defaults to "start"
      */
-    public void executeCommand(Command command, String action) throws IOException {
+    public Process executeCommand(Command command, String action) throws IOException {
         
         String[] cmd=null;
         
@@ -355,9 +414,11 @@
                 System.out.print(cmd[ii] + sxDelim);
             }
             System.out.print("ENDOFCOMMAND" + sxDelim);
-            
+            // we can't return a Process because we are being CALLED by the external process.
+            // only ASNativeLauncher will have a handle to the native process that called us
+            return null;
         } else { // all other execution paths
-            executeBackgroundCommand(command, isVerboseEnabled(), action);
+            return executeBackgroundCommand(command, isVerboseEnabled(), action);
         }
         
     }
@@ -369,7 +430,7 @@
     }
     
     
-    public void executeBackgroundCommand(Command command, boolean verbose, String action) throws IOException {
+    public Process executeBackgroundCommand(Command command, boolean verbose, String action) throws IOException {
         
         // execute the command as a runtime.exec and immediately return,
         // return will not pertain to the the executed process
@@ -442,11 +503,13 @@
             
             // must sleep for a couple of seconds, so if there is a jvm startup error, the parent process
             // is around to catch and report it when the process in executed in verbose mode.
-            // WBN  ?????? It doesn't appear that we need this ????
-            try {
-                Thread.currentThread().sleep(SLEEP_TIME_FOR_PROCESS_START);
-            } catch (InterruptedException ie) {}
+            // WBN  ?????? It doesn't appear that we need this ????  Verbose mode was handled in the "if"
+            // above...
+            //try {
+                //Thread.currentThread().sleep(SLEEP_TIME_FOR_PROCESS_START);
+            //} catch (InterruptedException ie) {}
         }
+        return process;
     }
     
     private void sendInputToProcessInput(InputStream in, Process subProcess) {
@@ -1792,7 +1855,7 @@
     }
 
     
-    private void writeSecurityInfoToProcess(Process p)
+    void writeSecurityInfoToProcess(Process p)
     {
         if(securityInfo == null) // impossible!
             return;
@@ -1846,44 +1909,62 @@
         }
     }
         
-    /**
-     * WBN Oct 2006 -- The startserv script has been made relocatable.  But we have to be backward
-     * compatible.  So look for the new args and preprocess them...
-     */
-    private void preProcess() throws ASLauncherException
+    
+    private void getSecurityFromUser(String[] args) throws IOException 
+    {
+        // HACK-O-RAMA
+        // yet another hack for backward compatibility!
+        // CLI will gather up passwords and send them in as an arg...
+        if(System.getProperty("caller", "not-cli").equals("cli"))
+            return;
+        
+        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+        securityInfo = new String[3];
+        NativeUtils nativeUtils = new NativeUtils(); 
+        System.out.print("admin username:");
+        securityInfo[0] = reader.readLine();
+        securityInfo[1] = nativeUtils.getPassword("admin password: ");
+        securityInfo[2] = nativeUtils.getPassword("master password: ");
+        
+        System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
+    }
+
+    private void setInstanceRoot(Properties callerProps)  throws ASLauncherException
     {
-        // THIS ONLY WORKS FOR DOMAINS!!! (because of instance-name/domain-name issues)
-        String  scriptPath = System.getProperty(SCRIPT_PATH_SYSTEM_PROPERTY);
+        String irpTag = SystemPropertyConstants.INSTANCE_ROOT_PROPERTY; // too ugly to type!
+        String irp = callerProps.getProperty(irpTag);
         
-        if(scriptPath == null)
-            return; // old script
+        if(irp != null)
+            System.setProperty(irpTag, irp);
 
-        String  installRoot = System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY);
         
+        // if the user is running a script stand-alone the instance-root may be
+        // something like "./startserv".  We need to convert it to a real path
         
-        DASLauncherInfo info = new DASLauncherInfo(DASLauncherInfo.SCRIPT_PATH + scriptPath, DASLauncherInfo.INSTALL_DIR + installRoot);
-        info.validate();
+        irp = System.getProperty(irpTag);
 
-        // all sorts of directories have benn checked for -- everything is A-OK!
-        // So now set the sys-props that this overly-flexible code is looking for...
-        System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, info.domainDir.getPath());
-        System.setProperty(SystemPropertyConstants.SERVER_NAME, "server"); 
-        System.setProperty("domain.name", info.domainName);
+        if(irp == null || irp.length() <= 0 )
+        {
+            // if we are being called from stand-alone java or a script -- they need to
+            // do a -DirpTag=...
+            // if we are called from PEInstancesManager, it has been set.  If it isn't
+            // set let's fail right now!
+            throw new ASLauncherException("Missing System Property: " + irpTag);
     }
     
-    private void getSecurityFromUser() throws IOException 
+		File f = new File(irp);
+		try
     {
-        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
-        securityInfo = new String[3];
+			irp = f.getCanonicalPath();
+		}
+		catch(Exception e)
+		{
+			irp = f.getAbsolutePath();
+		}
     
-        System.out.println("admin username:");
-        securityInfo[0] = reader.readLine();
-        System.out.println("admin password:");
-        securityInfo[1] = reader.readLine();
-        System.out.println("master password:");
-        securityInfo[2] = reader.readLine();
-        System.setProperty(PROPMPT_FOR_IDENTITY_SYSTEM_PROPERTY, "true");
+        System.setProperty(irpTag, irp);
     }
+
     // END END END END ENDEND -- this is here for grepping to the end of this gigantic class!!
     
     //**************************************************************************
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java,v
retrieving revision 1.1
diff -u -b -r1.1 ASLauncherException.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java	18 Oct 2006 05:29:53 -0000	1.1
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/launch/ASLauncherException.java	10 Nov 2006 00:26:52 -0000
@@ -32,4 +32,9 @@
     {
         super(msg);
     }
+
+    public ASLauncherException(Throwable t)
+    {
+        super(t);
+    }
 }
Index: admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java
===================================================================
RCS file: /cvs/glassfish/admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java,v
retrieving revision 1.7
diff -u -b -r1.7 PEInstancesManager.java
--- admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java	23 Oct 2006 03:36:08 -0000	1.7
+++ admin/servermgmt/src/java/com/sun/enterprise/admin/servermgmt/pe/PEInstancesManager.java	10 Nov 2006 00:26:56 -0000
@@ -25,11 +25,13 @@
 
 import com.sun.enterprise.admin.event.AdminEventResult;
 import com.sun.enterprise.admin.event.ShutdownEvent;
+import com.sun.enterprise.admin.servermgmt.launch.ASLauncherException;
+import com.sun.enterprise.admin.servermgmt.launch.ASNativeLauncher;
 import com.sun.enterprise.admin.servermgmt.launch.LaunchConstants;
+import java.io.*;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.ArrayList;
-import java.io.File;
 import java.lang.reflect.Method;
 
 import com.sun.enterprise.util.ProcessExecutor;
@@ -60,20 +62,6 @@
     private static final StringManager _strMgr =
         StringManager.getManager(PEInstancesManager.class);
 
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    private static final boolean temporaryFlagStartservScriptReady = false;
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-    // TEMPORARY UNTIL STARTSERV GETS CHECKED IN!!!
-
     private final           RepositoryConfig    _config;
     private                 Properties          systemPropsCopy;
     private                 String[]            securityInfo;
@@ -89,6 +77,11 @@
         _config = config;
     }
 
+    public String getNativeName()
+    {
+        return "appservDAS";
+    }
+
     protected RepositoryConfig getConfig()
     {
         return _config;
@@ -129,20 +122,20 @@
         
         nativeLauncher = Boolean.getBoolean(SystemPropertyConstants.NATIVE_LAUNCHER);
         
-        // WBN TEMPORARILY TURN OFF NEW CODE BY DEFAULT
-        String s = System.getenv("NEW_LAUNCHER");
+        // WBN TURN OFF OLD CODE BY DEFAULT
+        String s = System.getenv("OLD_LAUNCHER");
 
-        if(s == null || !s.equals("true"))
+        if(s != null && s.equals("true"))
             return startInstanceUsingScript(commandLineArgs);
-        else
-        {
             try
             {
                 saveSystemProps();
                 
+            //
                 if(nativeLauncher)
                     return startInstanceUsingScript(commandLineArgs);
                 else
+             //
                     return startInstanceAllJava(commandLineArgs);
             }
             finally
@@ -150,7 +143,6 @@
                 restoreSystemProps();
             }
         }
-    }
 
     public Process startInstance(String[] interativeOptions, String[] commandLineArgs)
         throws InstanceException
@@ -213,43 +205,45 @@
             if(isTrue((Boolean)getConfig().get(DomainConfig.K_DEBUG)))
                 debug = true;
 
-            setSystemProps();
             setSecurity();
             ArrayList<String> args = new ArrayList<String>();
-            
             args.add("start");
 
             if(nativeLauncher)
                 args.add("display");
+
             if ( debug ) 
                 args.add("debug");
+            
             if ( verbose ) 
                 args.add("verbose");
             
             String[] launcherArgs = args.toArray(new String[args.size()]);
             
-            /* I can't get this to work yet...
+            System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
+                getConfig().getRepositoryRoot() + File.separator +
+                getConfig().getRepositoryName());
+        
             if(nativeLauncher)
             {
-                ProcessBuilder pb = new ProcessBuilder(
-                    "C:/ee/lib/appservLauncher.exe",
-                    "C:/ee/lib/appserv.exe",
-                    System.getProperty("domain.name"),
-                    "\"C:/ee/domains/domain1/bin/startserv.bat\"",
-                    "cli",
-                    "display",
-                    "debug"
-                );
-                
-                process = pb.start();
+                ASNativeLauncher launcher = new ASNativeLauncher(this);
+                launcher.preProcess(launcherArgs, envProps);
+                try
+                {
+                    process = launcher.launch(launcherArgs, securityInfo);
+                }
+                catch(ASLauncherException e)
+                {
+                    throw new InstanceException(e);
+                }
             }
             else
-             **/
             {
                 ASLauncher launcher = new ASLauncher();
-                launcher.process(launcherArgs, securityInfo);
+                launcher.preProcess(launcherArgs, envProps);
+                process = launcher.process(launcherArgs, securityInfo);
             }
-            if(!verbose)
+            if(!verbose || nativeLauncher)
             {
                 waitUntilStarting(null);
                 waitUntilStarted();
@@ -295,7 +289,6 @@
         alCmd.add(script.getAbsolutePath());
 
         // WBN - we need to distinguish CLI calls from commandline calls
-        if(temporaryFlagStartservScriptReady)
             alCmd.add("cli");
 
         //
@@ -793,42 +786,6 @@
         return Boolean.TRUE.equals(b);
     }
 
-    protected void setSystemProps()
-    {
-        // Set system props needed by launcher
-        // first add all the ones that were passed in from a caller...
-        
-        Enumeration keys = envProps.propertyNames();
-        
-        while(keys.hasMoreElements())
-        {
-            String key = (String)keys.nextElement();
-            String value = envProps.getProperty(key);
-            System.setProperty(key, value);
-        }
-        
-        // set props but only if NOT in envProps already!
-        
-        if(envProps.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY) == null)
-            System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
-                    getConfig().getRepositoryRoot() + File.separator +
-                    getConfig().getRepositoryName());
-
-
-        if(envProps.getProperty(LaunchConstants.JAVA_HOME_PROP) == null)
-                System.setProperty(LaunchConstants.JAVA_HOME_PROP, System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
-        
-        if(envProps.getProperty(LaunchConstants.LOG_MGR_PROP) == null)
-            System.setProperty(LaunchConstants.LOG_MGR_PROP, LaunchConstants.LOG_MGR_VALUE);
-        if(envProps.getProperty(LaunchConstants.ENV_FACTORY_PROP) == null)
-            System.setProperty(LaunchConstants.ENV_FACTORY_PROP, LaunchConstants.ENV_FACTORY_VALUE);
-        if(envProps.getProperty(LaunchConstants.PROCESS_NAME_PROP) == null)
-            System.setProperty(LaunchConstants.PROCESS_NAME_PROP, "as9-server");
-
-        if( envProps.getProperty(LaunchConstants.LAUNCHER_RETURN_PROP) == null && !(verbose && nativeLauncher) )
-            System.setProperty(LaunchConstants.LAUNCHER_RETURN_PROP, LaunchConstants.LAUNCHER_RETURN_RETURN_VALUE);
-    }
-    
     private boolean ok(String s)
     {
         return s != null && s.length() > 0;
Index: admin/templates/pe80/startserv.tomcat.bat.template
===================================================================
RCS file: /cvs/glassfish/admin/templates/pe80/startserv.tomcat.bat.template,v
retrieving revision 1.4
diff -u -b -r1.4 startserv.tomcat.bat.template
--- admin/templates/pe80/startserv.tomcat.bat.template	12 Nov 2005 01:45:34 -0000	1.4
+++ admin/templates/pe80/startserv.tomcat.bat.template	10 Nov 2006 00:26:57 -0000
@@ -1,75 +1,81 @@
 @echo off
-if "%OS%" == "Windows_NT" setlocal
+setlocal
+
+if "%1"=="help" goto help
 rem ---------------------------------------------------------------------------
-rem Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
-rem Use is subject to license terms.
-rem
-rem Sun ONE App Server startup scripts
-rem
-rem Environment Variable Prequisites
-rem
-rem   JAVA_HOME       Must point at your Java Development Kit installation.
-rem
-rem $Id: startserv.tomcat.bat.template,v 1.4 2005/11/12 01:45:34 km105526 Exp $
+rem ------------------  Set Required Environment ---------------------------
 rem ---------------------------------------------------------------------------
-rem
-
-rem Get standard environment variables
-
-set PRG=%0
 set ASENV_CONF_LOCATION=%%%CONFIG_HOME%%%
+call "%ASENV_CONF_LOCATION%/asenv.bat"
+
+rem ---------------------------------------------------------------------------
+rem ------------------  Check JAVA_HOME  --------------------------------------
+rem ---------------------------------------------------------------------------
+if "%JAVA_HOME%"=="" set JAVA_HOME=%AS_JAVA%
+if exist "%JAVA_HOME%\bin\java.exe" goto gotJava
+echo JAVA_HOME (%JAVA_HOME%) is not pointing at a valid JDK installation.
+goto end
+:gotJava
 
+rem ---------------------------------------------------------------------------
+rem ------------------  Set Domain-Specific Environment  ----------------------
+rem ---------------------------------------------------------------------------
 set SERVER_NAME=%%%SERVER_NAME%%%
 set DOMAIN_NAME=%%%DOMAIN_NAME%%%
+set INSTANCE_ROOT=%~dp0..
 
-if exist "%ASENV_CONF_LOCATION%\asenv.bat" goto gotCmdPath
-rem %0 must have been found by DOS using the %PATH% so we assume that asenv.bat
-rem will also be found in the %PATH%
-call asenv.bat
-goto doneSetenv
-:gotCmdPath
-call "%ASENV_CONF_LOCATION%\asenv.bat"
-:doneSetenv
-
-set INSTANCE_ROOT=%%%INSTANCE_ROOT%%%
-
-set JAVA_HOME=%AS_JAVA%
-rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJavaHome
-echo The JAVA_HOME environment variable is not defined
-echo This environment variable is needed to run this program
-goto end
-:gotJavaHome
-
+rem ---------------------------------------------------------------------------
+rem ------------------  Process Args                      ---------------------
+rem ---------------------------------------------------------------------------
+set CLI=
+if not "%1"=="cli" goto NOT_CLI
+shift /1
+set CLI=cli
+:NOT_CLI
+
+rem check for "native" remove and remember it
+set NATIVE=
+if  not "%1"=="native" goto NOT_NATIVE
+shift /1
+set NATIVE=native
+
+rem Don't allow "native" arg when running directly from the commandline, because
+rem we have no access to stdin
+if not "%CLI%"=="cli" goto NATIVE_NOT_ALLOWED
 
-rem Get command line arguments and save them
-rem set CMD_LINE_ARGS=
-rem :setArgs
-rem if ""%1""=="""" goto doneSetArgs
-rem set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
-rem shift
-rem goto setArgs
-rem :doneSetArgs
+:NOT_NATIVE
 
-set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin;%PATH%
+rem ---------------------------------------------------------------------------
+rem ------------------  Set  Environment for Readability  ---------------------
+rem ---------------------------------------------------------------------------
+set CLASSNAME=com.sun.enterprise.admin.servermgmt.launch.ASLauncher
+set JAVA="%JAVA_HOME%\bin\java.exe" 
+set CP="%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\admin-cli.jar"
+set D01=-Dcom.sun.aas.installRoot="%AS_INSTALL%" 
+set D02=-Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  
+set D03=-Dcom.sun.aas.instanceName="%SERVER_NAME%"
+if "%CLI%"=="cli" set D04=-Dcaller=cli
 
-cd "%INSTANCE_ROOT%\config"
+rem ---------------------------------------------------------------------------
+rem ------------------  Start    ------------------------------------------------
+rem ---------------------------------------------------------------------------
 
-rem add in native launcher functionality
-if NOT "%1" == "native" GOTO JAVALAUNCHER
-	SHIFT;
-	rem set PATH=%AS_JAVA%%AS_NATIVE_LAUNCHER_LIB_PREFIX%;%PATH%
-	"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appserv.exe %DOMAIN_NAME%"  "\"%INSTANCE_ROOT%/bin/startserv.bat\" display %*"
-    exit
+set PATH=%AS_INSTALL%\lib;%AS_INSTALL%\bin
+if  not "%NATIVE%"=="native" goto JAVA_LAUNCH
 
-:JAVALAUNCHER
+"%AS_INSTALL%/lib/appservLauncher.exe" "%AS_INSTALL%/lib/appservDAS.exe %DOMAIN_NAME%"  "\"%~df0\" %CLI% display %1 %2 %3 %4" 
+exit
 
-rem Launch the S1AS server using s1as-start target 
-rem "%JAVA_HOME%\bin\java" -classpath "%AS_INSTALL%\lib";"%AS_INSTALL%\lib\commons-launcher.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\appserv-rt.jar";"%AS_ANT_LIB%\ant.jar";"%AS_ANT_LIB%\optional.jar";"%AS_INSTALL%\lib\endorsed\xercesImpl.jar";"%AS_INSTALL%\lib\endorsed\xalan.jar" -Dcom.sun.aas.antLib="%AS_ANT_LIB%" -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%" -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" LauncherBootstrap  s1as-server -DJAVA_HOME="%JAVA_HOME%"   -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" start %*
+:JAVA_LAUNCH
+%JAVA% %JAVA_DEBUGXX% -cp %CP% %D01% %D02% %D03% %D04% %CLASSNAME% start %1 %2 %3 %4 %5 %6 %7 %8
+rem if ERRORLEVEL 1 goto error 
+goto end
 
-rem set hold flag
-set HOLD_FLAG=return
+:help
+echo startserv [verbose] [debug]
+goto end
 
-rem executing launcher
-"%JAVA_HOME%\bin\java" -cp "%AS_INSTALL%\lib\appserv-rt.jar";"%AS_INSTALL%\lib\appserv-admin.jar";"%AS_INSTALL%\lib\javaee.jar" -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.instanceRoot="%INSTANCE_ROOT%"  -Dcom.sun.aas.configRoot="%ASENV_CONF_LOCATION%" -DJAVA_HOME="%JAVA_HOME%" -Dcom.sun.aas.instanceName="%SERVER_NAME%" -Ddomain.name="%DOMAIN_NAME%" -DCATALINA_OPTS="%CATALINA_OPTS%" -Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager -Dcom.sun.aas.launcherReturn="%HOLD_FLAG%" -Dcom.sun.aas.processName="as9-server" -Dcom.sun.aas.processLauncher="SE" -Dcom.sun.aas.promptForIdentity="true" com.sun.enterprise.tools.launcher.ProcessLauncher start %*
+:NATIVE_NOT_ALLOWED
+echo Can not start in native mode from the commandline
 :end
+endlocal
Index: appserv-commons/build.xml
===================================================================
RCS file: /cvs/glassfish/appserv-commons/build.xml,v
retrieving revision 1.36
diff -u -b -r1.36 build.xml
--- appserv-commons/build.xml	9 Sep 2006 16:40:24 -0000	1.36
+++ appserv-commons/build.xml	10 Nov 2006 00:26:59 -0000
@@ -102,6 +102,21 @@
         <rmic base="${component.classes.dir}" iiop="yes" debug="${javac.debug}">
             <include name="com/sun/enterprise/util/UniqueValueGeneratorBackendImpl.class"/>
         </rmic>
+        
+        <antcall target="do.javah"/>
+
+    </target>
+
+    <!--  Calling javah utitility to create C header file -->
+    <target name="do.javah"
+            depends="tools.init.platform">
+        <echo message="Generating JNI headers for NativeUtils"/>
+        <exec executable="${JAVAH}">
+            <arg line="-classpath ${component.classes.dir}"/>
+            <arg line="-d ${component.classes.dir}"/>
+            <arg line="-force"/>
+            <arg line="com.sun.enterprise.util.natives.NativeUtils"/>
+        </exec>
     </target>
 
     <!-- assemble -->
@@ -318,4 +333,38 @@
     </java>
     <delete file="${output.dtd}"/>
   </target>
-</project>
+
+  <target name="tools.init">
+      <condition property="windows">
+          <os family="windows" />
+      </condition>
+      <condition property="unix">
+          <os family="unix" />
+      </condition>
+      <condition property="solaris">
+          <os name="SunOS"/>
+      </condition>
+      <condition property="linux">
+          <os name="Linux"/>
+      </condition>
+      <condition property="mac">
+          <os name="Mac OS X"/>
+      </condition>
+</target>
+  <target name="tools.init.windows" if="windows">
+    <property name="JAVAH" value="${java.home}/../bin/javah.exe"/>
+    <property name="MAKE" value="gmake"/>
+</target>
+<target name="tools.init.unix" if="unix" unless="mac">
+    <property name="JAVAH" value="${java.home}/../bin/javah"/>
+    <property name="MAKE" value="gmake"/>
+</target>
+    <target name="tools.init.mac" if="mac">
+    <property name="JAVAH" value="${java.home}/bin/javah"/>
+    <property name="MAKE" value="make"/>
+</target>
+<target name="tools.init.platform" 
+    depends="tools.init, tools.init.windows, tools.init.unix, tools.init.mac">
+</target>
+
+  </project>
Index: appserv-native/src/cpp/cli/CliUtilImpl.cpp
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/CliUtilImpl.cpp,v
retrieving revision 1.2
diff -u -b -r1.2 CliUtilImpl.cpp
--- appserv-native/src/cpp/cli/CliUtilImpl.cpp	25 Dec 2005 17:52:05 -0000	1.2
+++ appserv-native/src/cpp/cli/CliUtilImpl.cpp	10 Nov 2006 00:27:02 -0000
@@ -34,6 +34,7 @@
 #define getpassphrase getpass
 #endif
 #include "com_sun_enterprise_cli_framework_CliUtil.h"
+#include "com_sun_enterprise_util_natives_NativeUtils.h"
 //C++ include
 #include <string>
 #include <vector>
@@ -185,4 +186,12 @@
     return retArr;
 }
     
-  
+/*
+ * Class:     com_sun_enterprise_util_natives_NativeUtils
+ * Method:    getPasswordNative
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_sun_enterprise_util_natives_NativeUtils_getPasswordNative(JNIEnv *env, jobject obj)
+{
+    return Java_com_sun_enterprise_cli_framework_CliUtil_getPassword(env, obj);
+}
\ No newline at end of file
Index: appserv-native/src/cpp/cli/Makefile
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/Makefile,v
retrieving revision 1.2
diff -u -b -r1.2 Makefile
--- appserv-native/src/cpp/cli/Makefile	25 Dec 2005 17:52:05 -0000	1.2
+++ appserv-native/src/cpp/cli/Makefile	10 Nov 2006 00:27:03 -0000
@@ -43,6 +43,7 @@
 DLL_OBJS=CliUtilImpl
 
 LOCAL_INC += -I$(GLASSFISH_MAVEN)/../admin-cli/framework/build
+LOCAL_INC += -I$(GLASSFISH_MAVEN)/../appserv-commons/build
 LOCAL_INC += $(JNI_INCLUDES)
 
 #LOCAL_LIB += pam
Index: appserv-native/src/cpp/cli/libcliutil.spec
===================================================================
RCS file: /cvs/glassfish/appserv-native/src/cpp/cli/libcliutil.spec,v
retrieving revision 1.2
diff -u -b -r1.2 libcliutil.spec
--- appserv-native/src/cpp/cli/libcliutil.spec	26 Sep 2005 22:02:28 -0000	1.2
+++ appserv-native/src/cpp/cli/libcliutil.spec	10 Nov 2006 00:27:05 -0000
@@ -9,4 +9,10 @@
 end
 
 
+function        Java_com_sun_enterprise_util_natives_NativeUtils_getPasswordNative
+arch            all
+version         SUNWprivate
+end
+
+
 
