VM-launch: change the use of API for VM launch.
authorminkee.lee <minkee.lee@samsung.com>
Thu, 1 Oct 2015 05:33:18 +0000 (14:33 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Thu, 1 Oct 2015 06:02:49 +0000 (15:02 +0900)
- Current code occurs error at some JVM version. (1.7.0_13)

   cmd.add("cmd");
   cmd.add("/c");
   cmd.add("\"" + binaryPath + "\" --conf \"" configPath + "\"");
   new ProcessBuilder(cmd) ...
   (According to following release note, I guess problem is qouted binathPath.
    - http://www.oracle.com/technetwork/java/javase/6u45-relnotes-1932876.html)

- So I changed like followings
   cmd.add(binaryPath);
   cmd.add("--conf");
   cmd.add(configPath);
   ...

Change-Id: I7b21067d92066511f281c59fd760300e2595a269
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
src/org/tizen/emulator/manager/vms/VMLauncher.java

index 7627a3f..7f914d4 100644 (file)
@@ -116,40 +116,32 @@ public class VMLauncher {
                }
 
                List<String> cmd = new ArrayList<String>();
-               String emulatorCmd = "\"" + binaryPath + "\" --conf \"" + configPath + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                               + getProxyArgument(property);
-               if (EmulatorManager.isWin()) {
-                       cmd.add("cmd"); //$NON-NLS-1$
-                       cmd.add("/c"); //$NON-NLS-1$
-               } else {
-                       cmd.add("/bin/sh"); //$NON-NLS-1$
-                       cmd.add("-c"); //$NON-NLS-1$
+
+               // set executable and config file
+               cmd.add(binaryPath);
+               cmd.add("--conf");
+               cmd.add(configPath);
+
+               // set proxy argument
+               String hostProxy = NetProxyOption.getHostProxyCmd(property);
+               if (!hostProxy.isEmpty()) {
+                       cmd.add("--" + OPTION_KEY.VAR_NETWORK_PROXY.toString());
+                       cmd.add(hostProxy);
                }
-               // Add log redirection to command.
-               cmd.add(emulatorCmd + getLogRedirectCmd(property.getName()));
 
-               System.out.println("Launch command : " + emulatorCmd); //$NON-NLS-1$
-               EMLogger.getLogger().log(Level.INFO, "Starting Emulator Command : "); //$NON-NLS-1$
-               EMLogger.getLogger().log(Level.INFO, emulatorCmd);
 
-               return cmd;
 
-       }
+               String commandLineCmd = "\"" + binaryPath + "\" --conf \"" + configPath + "\""
+                               + (hostProxy.isEmpty() ? "" : " --" + OPTION_KEY.VAR_NETWORK_PROXY.toString()
+                                               + " \"" + hostProxy + "\"");
+               System.out.println("Launch command : " + commandLineCmd); //$NON-NLS-1$
+               EMLogger.getLogger().log(Level.INFO, "Starting Emulator Command : "); //$NON-NLS-1$
+               EMLogger.getLogger().log(Level.INFO, commandLineCmd);
 
-       private static String getProxyArgument(VMProperty property) throws VMLauncherException {
-               String hostProxy = NetProxyOption.getHostProxyCmd(property);
-               if (hostProxy.isEmpty()) {
-                       return ""; //$NON-NLS-1$
+               return cmd;
 
-               } else {
-                       return " --" + OPTION_KEY.VAR_NETWORK_PROXY.toString() //$NON-NLS-1$
-                                       + " \"" + hostProxy + "\""; //$NON-NLS-1$ //$NON-NLS-2$
-               }
        }
 
-       private static String getLogRedirectCmd(String vmName) {
-               return " > \"" + VMLogUtil.getEmulatorLogPath(vmName) + "\" 2>&1"; //$NON-NLS-1$ //$NON-NLS-2$
-       }
 
        private static void checkDiskImage(VMProperty property)
                        throws VMLauncherException {
@@ -180,6 +172,12 @@ public class VMLauncher {
        public static Process launch(String vmName, String emulatorPath,
                        List<String> cmd, String binPath) {
                ProcessBuilder pb = new ProcessBuilder(cmd);
+               EMLogger.getLogger().log(Level.INFO, "Command list for ProcessBuilder");
+               EMLogger.getLogger().log(Level.INFO, cmd.toString());
+
+               // redirect stdout, stderr to log file
+               pb.redirectErrorStream(true);
+               pb.redirectOutput(new File(VMLogUtil.getEmulatorLogPath(vmName)));
 
                // Make backup log.
                VMLogUtil.makeVMBackupLog(vmName);