Option: Modified proxy, drive option.
authorminkee.lee <minkee.lee@samsung.com>
Fri, 22 May 2015 08:45:29 +0000 (17:45 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 26 May 2015 07:55:04 +0000 (16:55 +0900)
- Host proxy option is changed to set on emulator launch time.
  (Launch config file's variable is overrided at launch time)
- Added double quotation mark at drive option.

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

index fb22607..65d6a84 100644 (file)
@@ -49,6 +49,8 @@ import org.tizen.emulator.manager.vms.helper.VMLauncherException;
 import org.tizen.emulator.manager.vms.helper.VMLogUtil;
 import org.tizen.emulator.manager.vms.helper.VMWorkerException;
 import org.tizen.emulator.manager.vms.option.LaunchConfig;
+import org.tizen.emulator.manager.vms.option.NetProxyOption;
+import org.tizen.emulator.manager.vms.option.Option;
 
 public class VMLauncher {
 
@@ -113,7 +115,8 @@ public class VMLauncher {
                }
 
                List<String> cmd = new ArrayList<String>();
-               String emulatorCmd = binaryPath + " --conf " + configPath;
+               String emulatorCmd = binaryPath + " --conf " + configPath
+                               + getProxyArgument(property);
                if (EmulatorManager.isWin()) {
                        cmd.add("cmd");
                        cmd.add("/c");
@@ -121,16 +124,32 @@ public class VMLauncher {
                        cmd.add("/bin/sh");
                        cmd.add("-c");
                }
+               // Add log redirection to command.
+               cmd.add(emulatorCmd + getLogRedirectCmd(property.getName()));
+
                System.out.println("Launch command : " + emulatorCmd);
                EMLogger.getLogger().log(Level.INFO, "Starting Emulator Command : ");
                EMLogger.getLogger().log(Level.INFO, emulatorCmd);
-               // Add log redirection to command.
-               cmd.add(emulatorCmd + " > " + VMLogUtil.getEmulatorLogPath(property.getName()) + " 2>&1");
 
                return cmd;
 
        }
 
+       private static String getProxyArgument(VMProperty property) {
+               String hostProxy = NetProxyOption.getHostProxyCmd(property);
+               if (hostProxy.isEmpty()) {
+                       return "";
+
+               } else {
+                       return " --" + Option.VAR_NETWORK_PROXY
+                                       + " \"" + hostProxy + "\"";
+               }
+       }
+
+       private static String getLogRedirectCmd(String vmName) {
+               return " > " + VMLogUtil.getEmulatorLogPath(vmName) + " 2>&1";
+       }
+
        private static void checkDiskImage(VMProperty property)
                        throws VMLauncherException {
                // check disk image
index 2ee69d1..dc96096 100644 (file)
@@ -35,14 +35,14 @@ public class BaseImageOption extends Option {
        @Override
        public void getLaunchArgument(LaunchConfig config, VMProperty property) {
 
-               config.addVariable(VAR_DRIVE, "file="
+               config.addVariable(VAR_DRIVE, "\"file="
                                + property.getConfiguration().getBaseInformation()
                                                .getDiskImage().getCurrentDiskImage().getValue()
-                               + ",if=virtio,index=1,cache.no-flush=on");
-               config.addVariable(VAR_SWAP, "file="
+                               + ",if=virtio,index=1,cache.no-flush=on\"");
+               config.addVariable(VAR_SWAP, "\"file="
                                + property.getConfiguration().getBaseInformation()
                                                .getDiskImage().getSwapDiskImage().getValue()
-                               + ",if=virtio,index=2");
+                               + ",if=virtio,index=2\"");
 
                config.addQemuOption("-drive", varForm(VAR_DRIVE) + ",id=drive");
                config.addQemuOption("-drive", varForm(VAR_SWAP) + ",id=swap");
index a2dcb7a..8b5c988 100644 (file)
@@ -51,6 +51,7 @@ public class LaunchConfig {
        List<String> qemuOptions = new ArrayList<String>();
        List<String> kernelOptions = new ArrayList<String>();
        Map<String, String> variables = new HashMap<String, String>();
+       Map<String, String> varComment = new HashMap<String, String>();
 
        public static String DEFAULT_VALUE = "[[VARIABLES]]";
        public static String SKIN_OPTIONS = "[[SKIN_OPTIONS]]";
@@ -60,6 +61,13 @@ public class LaunchConfig {
                variables.put(key, value);
        }
 
+       public void addVariable(String key, String value, String comment) {
+               if (comment != null && !comment.isEmpty()) {
+                       varComment.put(key, comment);
+               }
+               addVariable(key, value);
+       }
+
        public void addQemuOption(String option) {
                qemuOptions.add(option);
        }
@@ -115,7 +123,12 @@ public class LaunchConfig {
                        // Write variables
                        bw.write(DEFAULT_VALUE);
                        bw.newLine();
+                       String comment = null;
                        for (String str : variables.keySet()) {
+                               if ( (comment = varComment.get(str)) != null) {
+                                       bw.write(comment);
+                                       bw.newLine();
+                               }
                                bw.write(str + "=" + variables.get(str));
                                bw.newLine();
                        }
index 4213130..bbb2ec7 100644 (file)
@@ -46,47 +46,75 @@ import org.tizen.emulator.manager.vms.helper.VMWorkerException;
 
 public class NetProxyOption extends Option {
 
-       @Override
-       public void getLaunchArgument(LaunchConfig config, VMProperty property)
-                       throws VMWorkerException {
-               String proxyArgument = getProxy(property);
-               if (!proxyArgument.isEmpty()) {
-                       config.addVariable(VAR_NETWORK_PROXY, proxyArgument);
-                       config.addKernelOption(varForm(VAR_NETWORK_PROXY));
+       public static String hostProxy = "";
+       public static final String PROXY_COMMENT = "# network_proxy : use host's proxy configuration \n"
+                       + "# (only if VM's proxy option is set as using host proxy)";
+       static {
+               try {
+                       hostProxy = getHostProxy();
+               } catch (VMWorkerException e) {
+                       EMLogger.getLogger().info("Failed to get host proxy :" + e.getMessage());
                }
        }
 
-       private String getProxy(VMProperty property) throws VMWorkerException {
-               String proxyConfig = "";
+       public static String getHostProxyCmd(VMProperty property) {
                String proxyMode = property.getPropertyValue()
                                .getAdvancedOptionSubValue(ItemName.NET_PROXY,
                                                NetProxyViewItem.ITEM_PROXY_MODE);
                if (proxyMode.equals(NetProxyViewItem.MODE_AUTO)) {
-                       proxyConfig = getHostProxy(property.getPropertyValue().version);
-
-               } else if (proxyMode.equals(NetProxyViewItem.MODE_MANUAL)) {
-                       proxyConfig = "http_proxy="
-                                       + property.getPropertyValue().getAdvancedOptionSubValue(
-                                                       ItemName.NET_PROXY,
-                                                       NetProxyViewItem.ITEM_HTTP_PROXY)
-                                       + " https_proxy="
-                                       + property.getPropertyValue().getAdvancedOptionSubValue(
-                                                       ItemName.NET_PROXY,
-                                                       NetProxyViewItem.ITEM_HTTPS_PROXY)
-                                       + " ftp_proxy="
-                                       + property.getPropertyValue()
-                                                       .getAdvancedOptionSubValue(ItemName.NET_PROXY,
-                                                                       NetProxyViewItem.ITEM_FTP_PROXY)
-                                       + " socks_proxy="
-                                       + property.getPropertyValue().getAdvancedOptionSubValue(
-                                                       ItemName.NET_PROXY,
-                                                       NetProxyViewItem.ITEM_SOCKS_PROXY);
+                       return hostProxy;
+               }
+
+               return "";
+       }
+
+       @Override
+       public void getLaunchArgument(LaunchConfig config, VMProperty property)
+                       throws VMWorkerException {
+               String proxyMode = property.getPropertyValue()
+                               .getAdvancedOptionSubValue(ItemName.NET_PROXY,
+                                               NetProxyViewItem.ITEM_PROXY_MODE);
+
+               String comment = null;
+               String proxyConfig;
+               if (NetProxyViewItem.MODE_AUTO.equals(proxyMode)) {
+                       comment = PROXY_COMMENT;
+                       proxyConfig = "";
+
+               } else if (NetProxyViewItem.MODE_MANUAL.equals(proxyMode)) {
+                       proxyConfig = getManualProxy(property);
+
+               } else { // Proxy is not used
+                       proxyConfig = null;
                }
-               return proxyConfig;
+
+               if (proxyConfig != null) {
+                       config.addVariable(VAR_NETWORK_PROXY, "\"" + proxyConfig + "\"", comment);
+                       config.addKernelOption(varForm(VAR_NETWORK_PROXY));
+               }
+       }
+
+       private String getManualProxy(VMProperty property) {
+               return "http_proxy="
+                               + property.getPropertyValue().getAdvancedOptionSubValue(
+                                               ItemName.NET_PROXY,
+                                               NetProxyViewItem.ITEM_HTTP_PROXY)
+                               + " https_proxy="
+                               + property.getPropertyValue().getAdvancedOptionSubValue(
+                                               ItemName.NET_PROXY,
+                                               NetProxyViewItem.ITEM_HTTPS_PROXY)
+                               + " ftp_proxy="
+                               + property.getPropertyValue()
+                                               .getAdvancedOptionSubValue(ItemName.NET_PROXY,
+                                                               NetProxyViewItem.ITEM_FTP_PROXY)
+                               + " socks_proxy="
+                               + property.getPropertyValue().getAdvancedOptionSubValue(
+                                               ItemName.NET_PROXY,
+                                               NetProxyViewItem.ITEM_SOCKS_PROXY);
 
        }
 
-       private String getHostProxy(String platformVersion) throws VMWorkerException {
+       public static String getHostProxy() throws VMWorkerException {
                String result = null;
                String proxyCommand = "check-net";
                if (EmulatorManager.isWin()) {