tap: arrange source codes
authorMunkyu Im <munkyu.im@samsung.com>
Mon, 4 Jan 2016 08:41:23 +0000 (17:41 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Wed, 6 Jan 2016 07:04:11 +0000 (16:04 +0900)
 - improve code readability a little bit.
 - adds non-externalize strings.
 - add externalize string for dialog message.

Change-Id: I4f29282cc287d5d96562cf4240881253937ee961
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
resource/strings/messages.properties
src/org/tizen/emulator/manager/tool/TapUtil.java

index 091ce66..916435c 100644 (file)
@@ -67,6 +67,8 @@ TapUtil.CreatedTapDevice.0=Tap device created :
 TapUtil.CreatedTapDevice.1=Do you want to see the guide for bridge network?
 TapUtil.CreateTapDevice.0=Creating tap device.
 TapUtil.CreateTapDevice.1=This will take minutes..
+TapUtil.CreateTapDeviceMacOSX.0=You need some configuration for bridge network.
+TapUtil.CreateTapDeviceMacOSX.1=Would you like to see a guide?
 TapUtil.FailedCreateTapDevice.0=Failed to create tap device.
 VMLauncher.ConfigError.0=Failed to launch config file
 VMLauncher.Error.0=Failed to launch.
index 780b178..7f7b80b 100644 (file)
@@ -353,7 +353,7 @@ public class TapUtil {
                                                        topKey + "\\" + subKey, value2); //$NON-NLS-1$
                                        if (compId != null && tapId != null) {
                                                if (compId.toLowerCase().startsWith("tap")) { //$NON-NLS-1$
-                                                       EMLogger.getLogger().info("tapId added: " + tapId);
+                                                       EMLogger.getLogger().info("tapId added: " + tapId); //$NON-NLS-1$
                                                        tapIdList.add(tapId);
                                                }
                                        }
@@ -467,7 +467,7 @@ public class TapUtil {
                                }
                        }
                }
-               EMLogger.getLogger().fine("Data in Registry " + path + ", " + value);
+               EMLogger.getLogger().fine("Data in Registry " + path + ", " + value); //$NON-NLS-1$ //$NON-NLS-2$
                if (resultArr == null) {
                        return new String[0];
                }
@@ -520,10 +520,10 @@ public class TapUtil {
                } else if (EmulatorManager.isMac()) {
                        String bridgeName = getBridgeNameForMac();
                        if (bridgeName.isEmpty()) {
-                               return "";
+                               return ""; //$NON-NLS-1$
                        }
                        List<String> cmd = Arrays.asList("/bin/sh", "-c", //$NON-NLS-1$ //$NON-NLS-2$
-                                       "ifconfig " + bridgeName + " | grep \"inet \" | awk '{print $4}'"); //$NON-NLS-1$
+                                       "ifconfig " + bridgeName + " | grep \"inet \" | awk '{print $4}'"); //$NON-NLS-1$ //$NON-NLS-2$
                        ProcessResult res = HelperClass.runProcess(cmd);
                        boolean isCommandSuccess = false;
                        if (res.isSuccess()) {
@@ -577,6 +577,7 @@ public class TapUtil {
                HKEY resultKey = null;
                String bridgeId = getBridgeId();
                if (bridgeId == null) {
+                       EMLogger.getLogger().warning("value is null"); //$NON-NLS-1$
                        return resultKey;
                }
 
@@ -608,9 +609,10 @@ public class TapUtil {
                return resultKey;
        }
 
-       private static void setWinbridgeNetwork(String interfaceClassID)
+       private static void setbridgeTcpipForWin(String interfaceClassID)
                        throws VMWorkerException {
                HKEY interfaceKey = getInterfaceTcpipKey(interfaceClassID);
+               EMLogger.getLogger().info("set bridge's IP"); //$NON-NLS-1$
                EMLogger.getLogger().info("interfaceID: " + interfaceClassID); //$NON-NLS-1$
                EMLogger.getLogger().info("bridgeID: " + getBridgeId()); //$NON-NLS-1$
                String interfaceName = getBridgeNameFromClassID(interfaceClassID);
@@ -622,61 +624,54 @@ public class TapUtil {
                ProcessResult res;
                if (interfaceKey != null) {
                        try {
-                               isDhcp = Advapi32Util.registryGetIntValue(interfaceKey,
-                                               "EnableDHCP");
+                               isDhcp = Advapi32Util.registryGetIntValue(interfaceKey, "EnableDHCP"); //$NON-NLS-1$
                                EMLogger.getLogger().info("DHCP: " + isDhcp); //$NON-NLS-1$
                                if (isDhcp == 0) {
                                        /* get original network interface's TCP/IP configuration */
-                                       String ips[] = registryGetStringArray(interfaceKey,
-                                                       "IPAddress"); //$NON-NLS-1$
+                                       String ips[] = registryGetStringArray(interfaceKey, "IPAddress"); //$NON-NLS-1$
                                        if (ips.length > 0) {
                                                ip = ips[0];
                                        }
-                                       EMLogger.getLogger().info("ip: " + ip);
-                                       String gateways[] = registryGetStringArray(interfaceKey,
-                                                       "DefaultGateway"); //$NON-NLS-1$
+                                       EMLogger.getLogger().info("ip: " + ip); //$NON-NLS-1$
+                                       String gateways[] = registryGetStringArray(interfaceKey, "DefaultGateway"); //$NON-NLS-1$
                                        if (gateways.length > 0) {
                                                gateway = gateways[0];
                                        }
-                                       EMLogger.getLogger().info("gateway: " + gateway);
-                                       String netmasks[] = registryGetStringArray(interfaceKey,
-                                                       "SubnetMask"); //$NON-NLS-1$
+                                       EMLogger.getLogger().info("gateway: " + gateway); //$NON-NLS-1$
+                                       String netmasks[] = registryGetStringArray(interfaceKey, "SubnetMask"); //$NON-NLS-1$
                                        if (netmasks.length > 0) {
                                                netmask = netmasks[0];
                                        }
-                                       EMLogger.getLogger().info("netmask: " + netmask);
+                                       EMLogger.getLogger().info("netmask: " + netmask); //$NON-NLS-1$
                                } else if (isDhcp == 1) {
                                        String dhcpIp = null;
                                        String dhcpGateway = null;
                                        String dhcpNetmask = null;
                                        dhcpIp = Advapi32Util.registryGetStringValue(interfaceKey, "DhcpIPAddress"); //$NON-NLS-1$
-                                       EMLogger.getLogger().info("DHCP ip: " + dhcpIp);
+                                       EMLogger.getLogger().info("DHCP ip: " + dhcpIp); //$NON-NLS-1$
 
-                                       String gateways[] = registryGetStringArray(interfaceKey,
-                                                       "DhcpDefaultGateway"); //$NON-NLS-1$
+                                       String gateways[] = registryGetStringArray(interfaceKey, "DhcpDefaultGateway"); //$NON-NLS-1$
                                        if (gateways.length > 0) {
                                                dhcpGateway = gateways[0];
                                        }
-                                       EMLogger.getLogger().info("DHCP gateway: " + dhcpGateway);
+                                       EMLogger.getLogger().info("DHCP gateway: " + dhcpGateway); //$NON-NLS-1$
                                        dhcpNetmask = Advapi32Util.registryGetStringValue(interfaceKey, "DhcpSubnetMask"); //$NON-NLS-1$
-                                       EMLogger.getLogger().info("DHCP netmask: " + dhcpNetmask);
+                                       EMLogger.getLogger().info("DHCP netmask: " + dhcpNetmask); //$NON-NLS-1$
 
                                        if ((dhcpIp != null && !dhcpIp.isEmpty())
                                                        && (dhcpNetmask != null && !dhcpNetmask.isEmpty())
                                                        && (dhcpGateway != null && !dhcpGateway.isEmpty())) {
-                                               EMLogger.getLogger().info("disable using DHCP");
-                                               cmd = Arrays.asList(NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                               EMLogger.getLogger().info("disable using DHCP"); //$NON-NLS-1$
+                                               cmd = Arrays.asList(NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                                                                                "\"" + "name=" + interfaceName + "\"", "source=static", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                                                "address=" + dhcpIp, "mask=" + dhcpNetmask, "gateway=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                                                                + dhcpGateway, "gwmetric=0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                res = HelperClass.runProcess(cmd);
                                                if (res.isSuccess() == false) {
-                                                       EMLogger.getLogger().warning(
-                                                                       "Failed to configure TCP/IP: "+ res.getResultMessage());
+                                                       EMLogger.getLogger().warning("Failed to configure TCP/IP: " + res.getResultMessage()); //$NON-NLS-1$
                                                }
-                                               EMLogger.getLogger().info("delete DHCP ip address");
-                                               cmd = Arrays
-                                                               .asList(NETSH, "interface", //$NON-NLS-1$ //$NON-NLS-2$
+                                               EMLogger.getLogger().info("delete DHCP ip address"); //$NON-NLS-1$
+                                               cmd = Arrays.asList(NETSH, "interface", //$NON-NLS-1$ //$NON-NLS-2$
                                                                                "ipv4", "delete", "address", interfaceName, "addr=" + dhcpIp, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                                                "gateway=all"); //$NON-NLS-1$
                                                res = HelperClass.runProcess(cmd);
@@ -685,65 +680,59 @@ public class TapUtil {
                                                }
                                        }
                                }
-                               String val = Advapi32Util.registryGetStringValue(interfaceKey,
-                                               "NameServer"); //$NON-NLS-1$
+                               String val = Advapi32Util.registryGetStringValue(interfaceKey, "NameServer"); //$NON-NLS-1$
                                String[] arr = val.split(","); //$NON-NLS-1$
                                if (arr.length > 0) {
                                        dns = arr[0];
                                }
-                               EMLogger.getLogger().info("NameServer: " + dns);
+                               EMLogger.getLogger().info("NameServer: " + dns); //$NON-NLS-1$
 
                                String bridgeName = getBridgeNameFromClassID(getBridgeId());
-                               EMLogger.getLogger().info("Bridge Name: " + bridgeName);
+                               EMLogger.getLogger().info("Bridge Name: " + bridgeName); //$NON-NLS-1$
                                /* set bridge network interface's TCP/IP configuration */
                                if (isDhcp == 0) {
                                        if (ip != null && !ip.isEmpty()) {
                                                interfaceName = getBridgeNameFromClassID(interfaceClassID);
-                                               EMLogger.getLogger().info("delete ip address");
-                                               cmd = Arrays
-                                                               .asList(NETSH, "interface", //$NON-NLS-1$ //$NON-NLS-2$
-                                                                               "ipv4", "delete", "address", interfaceName, "addr=" + ip, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                                                               "gateway=all"); //$NON-NLS-1$
+                                               EMLogger.getLogger().info("delete ip address"); //$NON-NLS-1$
+                                               cmd = Arrays.asList(NETSH, "interface", //$NON-NLS-1$ //$NON-NLS-2$
+                                                               "ipv4", "delete", "address", interfaceName, "addr=" + ip, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                               "gateway=all"); //$NON-NLS-1$
                                                res = HelperClass.runProcess(cmd);
                                                if (res.isSuccess() == false) {
-                                                       EMLogger.getLogger()
-                                                                       .warning(res.getResultMessage());
+                                                       EMLogger.getLogger().warning(res.getResultMessage());
                                                }
-                                               EMLogger.getLogger().info("set ip to bridge network");
+                                               EMLogger.getLogger().info("set ip to bridge network"); //$NON-NLS-1$
                                                if ((netmask != null && !netmask.isEmpty())
                                                                && (gateway != null && !gateway.isEmpty())) {
-                                                       cmd = Arrays
-                                                                       .asList(NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       cmd = Arrays.asList(NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                                                                                        "\"" + "name=" + bridgeName + "\"", "source=static", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                                                        "address=" + ip, "mask=" + netmask, "gateway=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                                                                                       + gateway, "gwmetric=0");
+                                                                                                       + gateway, "gwmetric=0"); //$NON-NLS-1$
                                                        res = HelperClass.runProcess(cmd);
                                                        if (res.isSuccess() == false) {
-                                                               EMLogger.getLogger().warning("Failed to configure TCP/IP: " + res.getResultMessage());
+                                                               EMLogger.getLogger().warning("Failed to configure TCP/IP: " + res.getResultMessage()); //$NON-NLS-1$
                                                        }
                                                }
                                        }
                                } else if (isDhcp == 1) {
                                        cmd = Arrays.asList(
-                                                       NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                                                        "\"" + "name=" + bridgeName + "\"", "dhcp"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                        res = HelperClass.runProcess(cmd);
                                        if (res.isSuccess() == false) {
-                                               EMLogger.getLogger().warning(
-                                                               "Failed to enable DHCP: " + res.getResultMessage());
+                                               EMLogger.getLogger().warning("Failed to enable DHCP: " + res.getResultMessage()); //$NON-NLS-1$
                                        }
                                } else {
-                                       EMLogger.getLogger().warning("isDhcp is wrong value: " + isDhcp);
+                                       EMLogger.getLogger().warning("isDhcp is wrong value: " + isDhcp); //$NON-NLS-1$
                                }
 
                                if (dns != null && !dns.isEmpty()) {
-                                       cmd = Arrays.asList(
-                                                       NETSH, "interface", "ipv4", "set", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                       cmd = Arrays.asList(NETSH, "interface", "ipv4", "set", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                                        "dnsservers", "\"" + "name=" + bridgeName + "\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                                       "static", dns, "primary"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       "static", dns, "primary"); //$NON-NLS-1$ //$NON-NLS-2$
                                        res = HelperClass.runProcess(cmd);
                                        if (res.isSuccess() == false) {
-                                               EMLogger.getLogger().warning("Failed to set DNS server: " + res.getResultMessage());
+                                               EMLogger.getLogger().warning("Failed to set DNS server: " + res.getResultMessage()); //$NON-NLS-1$
                                        }
                                }
                        } catch (Win32Exception e) {
@@ -752,7 +741,7 @@ public class TapUtil {
                                Advapi32Util.registryCloseKey(interfaceKey);
                        }
                } else {
-                       EMLogger.getLogger().warning("interface key is null");
+                       EMLogger.getLogger().warning("interface key is null"); //$NON-NLS-1$
                }
        }
 
@@ -774,9 +763,9 @@ public class TapUtil {
                                EMLogger.getLogger().warning(res.getResultMessage());
                        }
                } else {
-                       EMLogger.getLogger().warning("OS is not Windows!");
+                       EMLogger.getLogger().warning("OS is not Windows!"); //$NON-NLS-1$
                }
-               EMLogger.getLogger().info("bridgeId: " + bridgeId);
+               EMLogger.getLogger().info("bridgeId: " + bridgeId); //$NON-NLS-1$
                return bridgeId;
        }
 
@@ -826,10 +815,10 @@ public class TapUtil {
                } else if (EmulatorManager.isMac()) {
                        String bridgeName = getBridgeNameForMac();
                        if (bridgeName.isEmpty()) {
-                               return "";
+                               return ""; //$NON-NLS-1$
                        }
                        List<String> cmd = Arrays.asList("/bin/sh", "-c", //$NON-NLS-1$ //$NON-NLS-2$
-                                       "netstat -rn | grep " + bridgeName
+                                       "netstat -rn | grep " + bridgeName //$NON-NLS-1$
                                        + " | grep ^default | awk '{print $2}'"); //$NON-NLS-1$
                        ProcessResult res = HelperClass.runProcess(cmd);
                        boolean isCommandSuccess = false;
@@ -867,59 +856,55 @@ public class TapUtil {
                Display.getDefault().asyncExec(new Runnable() {
                        @Override
                        public void run() {
-                               int res = resultDialog
-                                               .openSelectionDialog(
-                                                               "You need some configuration for bridge network."
-                                                               + StringResources.NEW_LINE
-                                                               + "Would you like to see a guide?");
+                               int res = resultDialog.openSelectionDialog(Messages.getString("TapUtil.CreateTapDeviceMacOSX.0") //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + Messages.getString("TapUtil.CreateTapDeviceMacOSX.1")); //$NON-NLS-1$
                                if (res == SWT.OK) {
                                        // Show bridge guide dialog
                                        TapGuideDialogForMac.open();
                                }
                        }
                });
-
        }
 
        // return true if a guide for manual bridge is needed.
        private static boolean checkMacOSVersionForBridge() {
                String newLine = StringResources.NEW_LINE;
-               String command = "#!/bin/sh"
-                               + newLine + "do_version_check() {"
-                               + newLine + "   if [ \"$1\" == \"$2\" ]; then"
-                               + newLine + "      echo \"same\""
-                               + newLine + "      exit 0"
-                               + newLine + "   fi"
-                               + newLine + "   ver1front=`echo $1 | cut -d \".\" -f -1`"
-                               + newLine + "   ver1back=`echo $1 | cut -d \".\" -f 2-`"
-                               + newLine + "   ver2front=`echo $2 | cut -d \".\" -f -1`"
-                               + newLine + "   ver2back=`echo $2 | cut -d \".\" -f 2-`"
-                               + newLine + "   if [ \"$ver1front\" != \"$1\" ] || [ \"$ver2front\" != \"$2\" ]; then"
-                               + newLine + "      if [ \"$ver1front\" -gt \"$ver2front\" ]; then"
-                               + newLine + "         echo \"greater\""
-                               + newLine + "         exit 1"
-                               + newLine + "      fi"
-                               + newLine + "      if [ \"$ver1front\" -lt \"$ver2front\" ]; then"
-                               + newLine + "         echo \"lesser\""
-                               + newLine + "         exit -1"
-                               + newLine + "      fi"
-                               + newLine + "      if [ \"$ver1front\" == \"$1\" ] || [ -z \"$ver1back\" ]; then"
-                               + newLine + "         ver1back=0"
-                               + newLine + "      fi"
-                               + newLine + "      if [ \"$ver2front\" == \"$2\" ] || [ -z \"$ver2back\" ]; then"
-                               + newLine + "         ver2back = 0"
-                               + newLine + "      fi"
-                               + newLine + "      do_version_check \"$ver1back\" \"$ver2back\""
-                               + newLine + "   elif [ \"$1\" -gt \"$2\" ]; then"
-                               + newLine + "      echo \"greater\""
-                               + newLine + "      exit 1"
-                               + newLine + "   else"
-                               + newLine + "      echo \"lesser\""
-                               + newLine + "      exit -1"
-                               + newLine + "   fi"
-                               + newLine + "}"
-                               + newLine + "MAC_VER=\"`sw_vers | grep ProductVersion | awk '{print $2}'`\""
-                               + newLine + "do_version_check \"$MAC_VER\" \"10.9\"";
+               String command = "#!/bin/sh" //$NON-NLS-1$
+                               + newLine + "do_version_check() {" //$NON-NLS-1$
+                               + newLine + "   if [ \"$1\" == \"$2\" ]; then" //$NON-NLS-1$
+                               + newLine + "      echo \"same\"" //$NON-NLS-1$
+                               + newLine + "      exit 0" //$NON-NLS-1$
+                               + newLine + "   fi" //$NON-NLS-1$
+                               + newLine + "   ver1front=`echo $1 | cut -d \".\" -f -1`" //$NON-NLS-1$
+                               + newLine + "   ver1back=`echo $1 | cut -d \".\" -f 2-`" //$NON-NLS-1$
+                               + newLine + "   ver2front=`echo $2 | cut -d \".\" -f -1`" //$NON-NLS-1$
+                               + newLine + "   ver2back=`echo $2 | cut -d \".\" -f 2-`" //$NON-NLS-1$
+                               + newLine + "   if [ \"$ver1front\" != \"$1\" ] || [ \"$ver2front\" != \"$2\" ]; then" //$NON-NLS-1$
+                               + newLine + "      if [ \"$ver1front\" -gt \"$ver2front\" ]; then" //$NON-NLS-1$
+                               + newLine + "         echo \"greater\"" //$NON-NLS-1$
+                               + newLine + "         exit 1" //$NON-NLS-1$
+                               + newLine + "      fi" //$NON-NLS-1$
+                               + newLine + "      if [ \"$ver1front\" -lt \"$ver2front\" ]; then" //$NON-NLS-1$
+                               + newLine + "         echo \"lesser\"" //$NON-NLS-1$
+                               + newLine + "         exit -1" //$NON-NLS-1$
+                               + newLine + "      fi" //$NON-NLS-1$
+                               + newLine + "      if [ \"$ver1front\" == \"$1\" ] || [ -z \"$ver1back\" ]; then" //$NON-NLS-1$
+                               + newLine + "         ver1back=0" //$NON-NLS-1$
+                               + newLine + "      fi" //$NON-NLS-1$
+                               + newLine + "      if [ \"$ver2front\" == \"$2\" ] || [ -z \"$ver2back\" ]; then" //$NON-NLS-1$
+                               + newLine + "         ver2back = 0" //$NON-NLS-1$
+                               + newLine + "      fi" //$NON-NLS-1$
+                               + newLine + "      do_version_check \"$ver1back\" \"$ver2back\"" //$NON-NLS-1$
+                               + newLine + "   elif [ \"$1\" -gt \"$2\" ]; then" //$NON-NLS-1$
+                               + newLine + "      echo \"greater\"" //$NON-NLS-1$
+                               + newLine + "      exit 1" //$NON-NLS-1$
+                               + newLine + "   else" //$NON-NLS-1$
+                               + newLine + "      echo \"lesser\"" //$NON-NLS-1$
+                               + newLine + "      exit -1" //$NON-NLS-1$
+                               + newLine + "   fi" //$NON-NLS-1$
+                               + newLine + "}" //$NON-NLS-1$
+                               + newLine + "MAC_VER=\"`sw_vers | grep ProductVersion | awk '{print $2}'`\"" //$NON-NLS-1$
+                               + newLine + "do_version_check \"$MAC_VER\" \"10.9\""; //$NON-NLS-1$
 
                File tmpFile = createTmpFileWithContent(command);
 
@@ -927,10 +912,10 @@ public class TapUtil {
                        return true;
                }
 
-               List<String> cmd = Arrays.asList("/bin/sh", tmpFile.getAbsolutePath());
+               List<String> cmd = Arrays.asList("/bin/sh", tmpFile.getAbsolutePath()); //$NON-NLS-1$
                ProcessResult res = HelperClass.runProcess(cmd);
                if (!res.isSuccess()) {
-                       EMLogger.getLogger().info("Check os version for bridge fail : "
+                       EMLogger.getLogger().info("Check os version for bridge fail : " //$NON-NLS-1$
                                        + res.getResultMessage());
                        return true;
                }
@@ -948,40 +933,40 @@ public class TapUtil {
                        // Write script file.
                        // File is created once and removed when application exit
                        String newLine = StringResources.NEW_LINE;
-                       String command = ""
-                                       + "#!/bin/sh"
-                                       + newLine + "IF=\"\""
-                                       + newLine + "for x in `ifconfig | grep ^[a-zA-Z] | awk -F: '{print $1}'`;"
-                                       + newLine + "do"
-                                       + newLine + "   IF=`ifconfig $x | grep \"member: en0\"`"
-                                       + newLine + "   if [ \"x$IF\" != \"x\" ]; then"
-                                       + newLine + "      UP=`ifconfig $x | grep UP`"
-                                       + newLine + "      if [ \"x$UP\" != \"x\" ]; then"
-                                       + newLine + "         echo $x"
-                                       + newLine + "      fi"
-                                       + newLine + "   fi"
-                                       + newLine + "done";
+                       String command = "" //$NON-NLS-1$
+                                       + "#!/bin/sh" //$NON-NLS-1$
+                                       + newLine + "IF=\"\"" //$NON-NLS-1$
+                                       + newLine + "for x in `ifconfig | grep ^[a-zA-Z] | awk -F: '{print $1}'`;" //$NON-NLS-1$
+                                       + newLine + "do" //$NON-NLS-1$
+                                       + newLine + "   IF=`ifconfig $x | grep \"member: en0\"`" //$NON-NLS-1$
+                                       + newLine + "   if [ \"x$IF\" != \"x\" ]; then" //$NON-NLS-1$
+                                       + newLine + "      UP=`ifconfig $x | grep UP`" //$NON-NLS-1$
+                                       + newLine + "      if [ \"x$UP\" != \"x\" ]; then" //$NON-NLS-1$
+                                       + newLine + "         echo $x" //$NON-NLS-1$
+                                       + newLine + "      fi" //$NON-NLS-1$
+                                       + newLine + "   fi" //$NON-NLS-1$
+                                       + newLine + "done"; //$NON-NLS-1$
 
                        TMP_SCRIPT_FILE = createTmpFileWithContent(command);
                }
 
                if (TMP_SCRIPT_FILE == null || !TMP_SCRIPT_FILE.exists()) {
-                       return "";
+                       return ""; //$NON-NLS-1$
                }
 
                // Run script file.
-               List<String> cmd = Arrays.asList("/bin/sh", TMP_SCRIPT_FILE.getAbsolutePath());
+               List<String> cmd = Arrays.asList("/bin/sh", TMP_SCRIPT_FILE.getAbsolutePath()); //$NON-NLS-1$
                ProcessResult res = HelperClass.runProcess(cmd);
                if (!res.isSuccess()) {
-                       EMLogger.getLogger().info("Get bridge name fail : "
+                       EMLogger.getLogger().info("Get bridge name fail : " //$NON-NLS-1$
                                        + res.getResultMessage());
-                       return "";
+                       return ""; //$NON-NLS-1$
                }
 
                List<String> result = res.getStdOutMsg();
                if (result.size() < 1) {
-                       EMLogger.getLogger().info("No bridge name available..");
-                       return "";
+                       EMLogger.getLogger().info("No bridge name available.."); //$NON-NLS-1$
+                       return ""; //$NON-NLS-1$
                }
 
                return result.get(0);
@@ -992,7 +977,7 @@ public class TapUtil {
                BufferedWriter writer = null;
                File file = null;
                try {
-                       file = File.createTempFile("tap", ".sh");
+                       file = File.createTempFile("tap", ".sh"); //$NON-NLS-1$ //$NON-NLS-2$
                        file.deleteOnExit();
                        writer = new BufferedWriter(new FileWriter(file));
                        writer.append(content);
@@ -1246,7 +1231,7 @@ public class TapUtil {
                                        } else if (isDhcp == 1) {
                                                ipAddr = Advapi32Util.registryGetStringValue(key, "DhcpIPAddress"); //$NON-NLS-1$
                                        } else {
-                                               EMLogger.getLogger().warning("isDhcp is wrong value: " + isDhcp);
+                                               EMLogger.getLogger().warning("isDhcp is wrong value: " + isDhcp); //$NON-NLS-1$
                                        }
 
                                } catch (Win32Exception e) {
@@ -1265,7 +1250,7 @@ public class TapUtil {
                                return null;
                        }
                        List<String> cmd = Arrays.asList("/bin/sh", "-c", //$NON-NLS-1$ //$NON-NLS-2$
-                                       "ifconfig " + bridgeName + " | grep \"inet \" | awk '{print $2}'"); //$NON-NLS-1$
+                                       "ifconfig " + bridgeName + " | grep \"inet \" | awk '{print $2}'"); //$NON-NLS-1$ //$NON-NLS-2$
                        ProcessResult res = HelperClass.runProcess(cmd);
                        boolean isCommandSuccess = false;
                        if (res.isSuccess()) {
@@ -1451,7 +1436,6 @@ public class TapUtil {
                                Advapi32Util.registryCloseKey(regKey.getValue());
                        }
                }
-
                return null;
        }
 
@@ -1462,6 +1446,8 @@ public class TapUtil {
                final String ifName;
                final ComboViewItem comboViewItem; // for refresh combo-list
                final String platformVersion;
+               List<String> cmd;
+               ProcessResult res;
 
                public TapCreateWorker(String tapName, String ifName,
                                MessageDialog dialog, ComboViewItem comboViewItem, String platformVersion) {
@@ -1472,6 +1458,97 @@ public class TapUtil {
                        this.platformVersion = platformVersion;
                }
 
+               public String getCompatibleIDfromDeviceName(String deviceName) {
+                       EMLogger.getLogger().info("get CompatibleIDs from pci network device"); //$NON-NLS-1$
+                       cmd = Arrays.asList(getDevconPath(platformVersion), "find", "=net", "@pci*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                       res = HelperClass.runProcess(cmd);
+                       boolean isCommandSuccess = false;
+                       String CompatibleID = null;
+                       if (res.isSuccess()) {
+                               for (String str : res.getStdOutMsg()) {
+                                       if (str.endsWith(deviceName)) {
+                                               isCommandSuccess = true;
+                                               CompatibleID = str.split(":")[0].trim(); //$NON-NLS-1$
+                                               EMLogger.getLogger().info("CompatibleID: " + CompatibleID); //$NON-NLS-1$
+                                               return CompatibleID;
+                                       }
+                               }
+                       } else if (!res.isSuccess() || !isCommandSuccess) {
+                               EMLogger.getLogger().warning(res.getResultMessage());
+                       }
+                       return null;
+               }
+
+               public void createWinBridgeDevice() throws VMWorkerException {
+                       EMLogger.getLogger().info("create bridge"); //$NON-NLS-1$
+                       String windir = System.getenv("WINDIR"); //$NON-NLS-1$
+                       if (windir != null && !windir.isEmpty()) {
+                               windir = "c:\\windows"; //$NON-NLS-1$
+                       }
+                       cmd = Arrays.asList(getDevconPath(platformVersion), "install", //$NON-NLS-1$
+                                       windir + "\\inf\\netbrdgm.inf", //$NON-NLS-1$
+                                       "ms_bridgemp"); //$NON-NLS-1$
+                       res = HelperClass.runProcess(cmd);
+                       if (!res.isSuccess()) {
+                               throw new VMWorkerException(res.getResultMessage());
+                       }
+               }
+
+               public void bindToWinBridgeDevice(String compatibleId) throws VMWorkerException {
+                       EMLogger.getLogger().info("bind interface to bridge"); //$NON-NLS-1$
+                       cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion)
+                                       + File.separator + "bindbridge.exe", //$NON-NLS-1$
+                                       "ms_bridge", compatibleId, "bind"); //$NON-NLS-1$ //$NON-NLS-2$
+                       res = HelperClass.runProcess(cmd);
+                       if (!res.isSuccess()) {
+                               throw new VMWorkerException(res.getResultMessage());
+                       }
+               }
+
+               public void createWinTapDevice() throws VMWorkerException, InterruptedException {
+                       // Get tap list before create new tap.
+                       EMLogger.getLogger().info("Get tap list before create new tap."); //$NON-NLS-1$
+                       List<String> before = TapUtil.getTapList();
+
+                       // Create new tap
+                       EMLogger.getLogger().info("Create new tap."); //$NON-NLS-1$
+                       cmd = Arrays.asList(getDevconPath(platformVersion), "install", //$NON-NLS-1$
+                                       FilePathResources.getPlatformEmulatorBinPath(platformVersion) + File.separator
+                                                       + "OemWin2k.inf", "Tap0901"); //$NON-NLS-1$ //$NON-NLS-2$
+                       res = HelperClass.runProcess(cmd);
+                       if (!res.isSuccess()) {
+                               throw new VMWorkerException(res.getResultMessage());
+                       }
+                       //FIXME: to wait for re-naming tap name(work around)
+                       if (EmulatorManager.isWin8AndAbove()) {
+                               EMLogger.getLogger().info("wait for renaming tap name"); //$NON-NLS-1$
+                               Thread.sleep(WAIT_TIME);
+                       }
+                       // Get tap list and find new one.
+                       EMLogger.getLogger().info("Get tap list and find new one."); //$NON-NLS-1$
+                       List<String> after = TapUtil.getTapList();
+                       String newOne = null;
+                       for (String str : after) {
+                               if (!before.contains(str)) {
+                                       newOne = str;
+                                       break;
+                               }
+                       }
+
+                       if (newOne == null) {
+                               throw new VMWorkerException(
+                                               "Tap create fail. Cannot find new tap device."); //$NON-NLS-1$
+                       }
+                       // Rename new tap to tapX
+                       EMLogger.getLogger().info("Rename new tap to tapX."); //$NON-NLS-1$
+                       cmd = Arrays.asList(NETSH, "interface", "set", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                       "name=" + newOne, "newname=" + tapName); //$NON-NLS-1$ //$NON-NLS-2$
+                       res = HelperClass.runProcess(cmd);
+                       if (!res.isSuccess()) {
+                               throw new VMWorkerException(res.getResultMessage());
+                       }
+               }
+
                @Override
                public void run() {
                        // Create tap device
@@ -1483,98 +1560,14 @@ public class TapUtil {
                        ProcessResult res;
                        try {
                                if (!EmulatorManager.isWin8AndAbove()) {
-                                       EMLogger.getLogger().info(
-                                                       "get CompatibleIDs from pci network device"); //$NON-NLS-1$
-                                       cmd = Arrays.asList(getDevconPath(platformVersion), "find", "=net", //$NON-NLS-1$ //$NON-NLS-2$
-                                                       "@pci*"); //$NON-NLS-1$
-                                       res = HelperClass.runProcess(cmd);
-                                       boolean isCommandSuccess = false;
-                                       String CompatibleIDs = null;
-                                       if (res.isSuccess()) {
-                                               for (String str : res.getStdOutMsg()) {
-                                                       if (str.endsWith(ifName)) {
-                                                               isCommandSuccess = true;
-                                                               CompatibleIDs = str.split(":")[0].trim(); //$NON-NLS-1$
-                                                               EMLogger.getLogger().info(
-                                                                               "CompatibleIDs: " + CompatibleIDs); //$NON-NLS-1$
-                                                               break;
-                                                       }
-                                               }
-                                       } else if (!res.isSuccess() || !isCommandSuccess) {
-                                               EMLogger.getLogger().warning(res.getResultMessage());
-                                       }
-
+                                       String compatibleId = getCompatibleIDfromDeviceName(ifName);
                                        if (isWinBridgeExist() == false) {
-                                               // Create Bridge device and set IP
-                                               EMLogger.getLogger().info("create bridge"); //$NON-NLS-1$
-                                               cmd = Arrays
-                                                               .asList(getDevconPath(platformVersion),
-                                                                               "install", //$NON-NLS-1$
-                                                                               "c:\\windows\\inf\\netbrdgm.inf", //$NON-NLS-1$
-                                                                               "ms_bridgemp"); //$NON-NLS-1$
-                                               res = HelperClass.runProcess(cmd);
-                                               if (!res.isSuccess()) {
-                                                       throw new VMWorkerException(res.getResultMessage());
-                                               }
-
-                                               EMLogger.getLogger().info("bind interface to bridge"); //$NON-NLS-1$
-                                               cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion)
-                                                               + File.separator + "bindbridge.exe", //$NON-NLS-1$
-                                                               "ms_bridge", CompatibleIDs, "bind"); //$NON-NLS-1$ //$NON-NLS-2$
-                                               res = HelperClass.runProcess(cmd);
-                                               if (!res.isSuccess()) {
-                                                       throw new VMWorkerException(res.getResultMessage());
-                                               }
+                                               createWinBridgeDevice();
+                                               bindToWinBridgeDevice(compatibleId);
                                        }
-                                       EMLogger.getLogger().info("set bridge's IP"); //$NON-NLS-1$
-                                       setWinbridgeNetwork(getClassIDFromPnpInstanceID(CompatibleIDs));
+                                       setbridgeTcpipForWin(getClassIDFromPnpInstanceID(compatibleId));
                                }
-
-                               // Get tap list before create new tap.
-                               EMLogger.getLogger()
-                                               .info("Get tap list before create new tap."); //$NON-NLS-1$
-                               List<String> before = TapUtil.getTapList();
-
-                               // Create new tap
-                               EMLogger.getLogger().info("Create new tap."); //$NON-NLS-1$
-                               cmd = Arrays.asList(getDevconPath(platformVersion), "install", //$NON-NLS-1$
-                                               FilePathResources.getPlatformEmulatorBinPath(platformVersion) + File.separator
-                                                               + "OemWin2k.inf", "Tap0901"); //$NON-NLS-1$ //$NON-NLS-2$
-                               res = HelperClass.runProcess(cmd);
-
-                               if (!res.isSuccess()) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-                               //FIXME: to wait for re-naming tap name(work around)
-                               if (EmulatorManager.isWin8AndAbove()) {
-                                       EMLogger.getLogger().info("wait for renaming tap name");
-                                       Thread.sleep(WAIT_TIME);
-                               }
-                               // Get tap list and find new one.
-                               EMLogger.getLogger().info("Get tap list and find new one."); //$NON-NLS-1$
-                               List<String> after = TapUtil.getTapList();
-                               String newOne = null;
-                               for (String str : after) {
-                                       if (!before.contains(str)) {
-                                               newOne = str;
-                                               break;
-                                       }
-                               }
-
-                               if (newOne == null) {
-                                       throw new VMWorkerException(
-                                                       "Tap create fail. Cannot find new tap device."); //$NON-NLS-1$
-                               }
-
-                               // Rename new tap to tapX
-                               EMLogger.getLogger().info("Rename new tap to tapX."); //$NON-NLS-1$
-                               cmd = Arrays.asList(NETSH, "interface", "set", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "name=" + newOne, "newname=" + tapName); //$NON-NLS-1$ //$NON-NLS-2$
-                               res = HelperClass.runProcess(cmd);
-                               if (!res.isSuccess()) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
+                               createWinTapDevice();
                                // Check tap create in success.
                                EMLogger.getLogger().info("Check tap create in success."); //$NON-NLS-1$
                                boolean isTapExist = false;
@@ -1587,20 +1580,18 @@ public class TapUtil {
                                if (!EmulatorManager.isWin8AndAbove()) {
                                        EMLogger.getLogger().info("bind host network to bridge"); //$NON-NLS-1$
                                        String tapPnpInstanceID = getPnpInstanceIDFromName(tapName);
-
-                                       cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion)
-                                                       + File.separator + "bindbridge.exe", "ms_bridge", //$NON-NLS-1$ //$NON-NLS-2$
-                                                       tapPnpInstanceID, "bind"); //$NON-NLS-1$
-                                       res = HelperClass.runProcess(cmd);
-                                       if (!res.isSuccess()) {
-                                               throw new VMWorkerException(res.getResultMessage());
+                                       if (tapPnpInstanceID != null && !tapPnpInstanceID.isEmpty()) {
+                                               bindToWinBridgeDevice(tapPnpInstanceID);
+                                       } else {
+                                               EMLogger.getLogger().warning("tap ID is null or empty"); //$NON-NLS-1$
                                        }
                                        HKEY bridgeKey = getBridgeTcpipKey();
-                                       isDhcp = Advapi32Util.registryGetIntValue(bridgeKey, "EnableDHCP");
-                                       EMLogger.getLogger().info("bridge DHCP: " + isDhcp);
+                                       if (bridgeKey != null) {
+                                               isDhcp = Advapi32Util.registryGetIntValue(bridgeKey, "EnableDHCP"); //$NON-NLS-1$
+                                               EMLogger.getLogger().info("bridge DHCP: " + isDhcp); //$NON-NLS-1$
+                                       }
                                        if (isDhcp == 0) {
-                                               EMLogger.getLogger().info(
-                                                               "wait while finishing bridged network setting"); //$NON-NLS-1$
+                                               EMLogger.getLogger().info("wait while finishing bridged network setting"); //$NON-NLS-1$
                                                cmd = Arrays.asList(getCheckNetPath(), BRIDGE_OPTION); //$NON-NLS-1$
                                                res = HelperClass.runProcess(cmd);
                                                while (!res.getStdOutMsg().isEmpty()) {
@@ -1610,16 +1601,13 @@ public class TapUtil {
                                                                for (String str : res.getStdOutMsg()) {
                                                                        if (str.startsWith("IP Address:")) { //$NON-NLS-1$
                                                                                isCommandSuccess = true;
-                                                                               ipAddr = str.split("IP Address: ")[1] //$NON-NLS-1$
-                                                                                               .trim();
-                                                                               EMLogger.getLogger().info(
-                                                                                               "bridge IP address: " + ipAddr); //$NON-NLS-1$
+                                                                               ipAddr = str.split("IP Address: ")[1].trim(); //$NON-NLS-1$
+                                                                               EMLogger.getLogger().info("bridge IP address: " + ipAddr); //$NON-NLS-1$
                                                                                break;
                                                                        }
                                                                }
                                                        } else if (!res.isSuccess() || !isCommandSuccess) {
-                                                               EMLogger.getLogger().warning(
-                                                                               res.getResultMessage());
+                                                               EMLogger.getLogger().warning(res.getResultMessage());
                                                        }
                                                        if (ipAddr != null) {
                                                                break;
@@ -1633,29 +1621,25 @@ public class TapUtil {
                                                Display.getDefault().asyncExec(new Runnable() {
                                                        @Override
                                                        public void run() {
-                                                               messageDialog
-                                                                               .openInfoDialog(Messages.getString("TapUtil.CreatedTapDevice.0") //$NON-NLS-1$
-                                                                                               + tapName);
+                                                               messageDialog.openInfoDialog(Messages.getString("TapUtil.CreatedTapDevice.0") + tapName); //$NON-NLS-1$
                                                        }
                                                });
                                        }
-                               } else {
+                               } else { /* EmulatorManager.isWin8AndAbove() */
                                        final MessageDialog resultDialog = new MessageDialog();
                                        if (isTapExist) {
                                                Display.getDefault().asyncExec(new Runnable() {
                                                        @Override
                                                        public void run() {
-                                                               int res = resultDialog
-                                                                               .openSelectionDialog(Messages.getString("TapUtil.CreatedTapDevice.0") + tapName //$NON-NLS-1$
-                                                                                               + StringResources.NEW_LINE
-                                                                                               + Messages.getString("TapUtil.CreatedTapDevice.1")); //$NON-NLS-1$
+                                                               int res = resultDialog.openSelectionDialog(Messages
+                                                                               .getString("TapUtil.CreatedTapDevice.0") + tapName //$NON-NLS-1$
+                                                                               + StringResources.NEW_LINE + Messages.getString("TapUtil.CreatedTapDevice.1")); //$NON-NLS-1$
                                                                if (res == SWT.OK) {
                                                                        // Show bridge guide dialog
                                                                        TapGuideDialogForWin.open();
                                                                }
                                                        }
                                                });
-
                                        } else {
                                                throw new VMWorkerException("Tap is not exist : " + tapName);//$NON-NLS-1$
                                        }