base-image: Added x86_64 image handling.
authorminkee.lee <minkee.lee@samsung.com>
Thu, 30 Jul 2015 10:22:27 +0000 (19:22 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 31 Jul 2015 08:18:53 +0000 (17:18 +0900)
- Image file's extention is added : ".i368", ".x86_64"
- ".x86" and ".i386" is for 32bit image. (".x86" is legacy)
- ".x86_64" for 64bit image.
- Above three extention type is supported for custom image.

Change-Id: I21f544aaf9b631ac83dd7b7b893868471065d07d
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
src/org/tizen/emulator/manager/console/ConsoleProcessor.java
src/org/tizen/emulator/manager/platform/BaseImage.java
src/org/tizen/emulator/manager/resources/FilePathResources.java
src/org/tizen/emulator/manager/ui/MenuHandling.java
src/org/tizen/emulator/manager/ui/detail/item/property/BaseImageViewItem.java
src/org/tizen/emulator/manager/ui/detail/item/template/loader/CustomPropertyTemplateLoader.java [new file with mode: 0644]
src/org/tizen/emulator/manager/vms/Creator.java
src/org/tizen/emulator/manager/vms/VMProperty.java
src/org/tizen/emulator/manager/vms/option/CommonOption.java

index 95de9fa..c7bef73 100644 (file)
@@ -83,21 +83,21 @@ public class ConsoleProcessor {
                                prop.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue());
                        str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "Child Disk Image", //$NON-NLS-1$ //$NON-NLS-2$
                                        prop.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue());
-       
+
                        str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "Resolution", //$NON-NLS-1$ //$NON-NLS-2$
                                        (prop.getConfiguration().getDevice().getDisplay().getResolution().getWidth()
                                        + "x" + prop.getConfiguration().getDevice().getDisplay().getResolution().getHeight())); //$NON-NLS-1$
-                       
+
                        str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "DPI", //$NON-NLS-1$ //$NON-NLS-2$
                                        prop.getConfiguration().getDevice().getDisplay().getDensity().getValue());
                        str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "Skin Path", //$NON-NLS-1$ //$NON-NLS-2$
                                        prop.getConfiguration().getDevice().getDisplay().getSkinPath().getPath());
-       
+
                        if (prop.getConfiguration().getDevice().getTouch() != null) {
                                str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "Max Touch Point", //$NON-NLS-1$ //$NON-NLS-2$
                                                prop.getConfiguration().getDevice().getTouch().getMaxTouchPoint());
                        }
-       
+
                        str+= String.format("\t%-17s : %s" + StringResources.NEW_LINE, "RAM Size", //$NON-NLS-1$ //$NON-NLS-2$
                                        prop.getConfiguration().getDevice().getRAM().getSize().getValue());
 
@@ -140,7 +140,7 @@ public class ConsoleProcessor {
                        // error
                        message.add(Messages.getString("ConsoleProcessor.VMList.0")); //$NON-NLS-1$
                } else {
-                       
+
                        if (!isDetail) {
                                for (VMProperty prop : properties) {
                                        message.add(prop.getName());
@@ -357,7 +357,7 @@ public class ConsoleProcessor {
 
                try {
                        if (f.isDirectory()) {
-                               path = path + File.separator + "emulimg-" + name + "." + prop.getArch().toString(); //$NON-NLS-1$ //$NON-NLS-2$
+                               path = path + File.separator + "emulimg-" + name + "." + prop.getArchInternal().toString(); //$NON-NLS-1$ //$NON-NLS-2$
                        }
                        prop.getWorker().createNewBaseImage(prop, path);
                } catch (VMWorkerException e) {
index f586281..f142adc 100644 (file)
@@ -36,11 +36,12 @@ import java.util.List;
 import java.util.Properties;
 import java.util.logging.Level;
 
-
 import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.vms.SKIN_SHAPE;
 import org.tizen.emulator.manager.vms.VMProperty;
+import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 import org.tizen.emulator.manager.vms.option.IOption;
 import org.tizen.emulator.manager.vms.xml.template.ItemList;
 
@@ -55,7 +56,7 @@ public class BaseImage {
        protected String version;
        protected String profile;
        protected String type;
-       protected String cpu;
+       protected Architecture cpu;
        protected SKIN_SHAPE skinShape;
        protected String binaryVersion;
 
@@ -139,6 +140,13 @@ public class BaseImage {
        }
 
        public String getCpu() {
+               if (cpu == null) {
+                       return "";
+               }
+               return cpu.toString();
+       }
+
+       public Architecture getCpuType() {
                return cpu;
        }
 
@@ -218,8 +226,8 @@ public class BaseImage {
                                version = prop.getProperty(StringResources.IMAGE_VERSION, "2.4"); //$NON-NLS-1$
                                profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MOBILE_PROFILE).toLowerCase();
                                type = prop.getProperty(StringResources.IMAGE_TYPE, "default"); //$NON-NLS-1$
-                               cpu     = prop.getProperty(StringResources.TARGET_CPU, "x86"); //$NON-NLS-1$
-                               cpu = cpu.toLowerCase();
+                               String cpuValue = prop.getProperty(StringResources.TARGET_CPU, "i386"); //$NON-NLS-1$
+                               cpu = Architecture.getType(cpuValue);
                                skinShape = SKIN_SHAPE.find(prop.getProperty(StringResources.SKIN_SHAPE, "square")); //$NON-NLS-1$
                                binaryVersion = prop.getProperty(StringResources.BINARY_VERSION, "1.0.0"); //$NON-NLS-1$
                                checkBaseImage();
@@ -246,14 +254,19 @@ public class BaseImage {
                version = platform.getVersion();
                profile = platform.getProfile();
                type = "custom"; // TODO //$NON-NLS-1$
-               cpu     = "x86"; //$NON-NLS-1$
+               cpu     = findCpuTypeFromPath(); //$NON-NLS-1$
                skinShape = SKIN_SHAPE.NONE; // TODO
                binaryVersion = ""; //$NON-NLS-1$
        }
 
+       private Architecture findCpuTypeFromPath() {
+               String ext = FilePathResources.getFileExtention(this.path);
+               return Architecture.getType(ext);
+       }
+
        private void settingImagePath(File path) throws IOException {
                for (File f : path.listFiles()) {
-                       if (f.isFile() && f.getName().endsWith(cpu.toLowerCase())) {
+                       if (f.isFile() && f.getName().endsWith(getCpu().toLowerCase())) {
                                this.path = f.getCanonicalPath();
                                this.pathName = f.getName();
                        }
index d05f457..0f4803b 100644 (file)
@@ -466,4 +466,14 @@ public class FilePathResources {
        public static String getTizenSdkDataPath() {
                return tizensdkdataPath;
        }
+
+       public static String getFileExtention(String path) {
+               if (path != null) {
+                       String arr[] = path.split("\\.");
+                       if (arr.length > 1) {
+                               return arr[arr.length-1];
+                       }
+               }
+               return "";
+       }
 }
index 5b3ea0f..690d80f 100644 (file)
@@ -43,7 +43,7 @@ import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.helper.VMWorkerException;
 
 public class MenuHandling {
-       private Shell shell;
+       private final Shell shell;
 
        public MenuHandling() {
                this.shell = MainDialog.getShell();
@@ -114,8 +114,8 @@ public class MenuHandling {
 
                FileDialog fd = new FileDialog(shell, SWT.SAVE);
                fd.setText(Messages.getString("MenuHandling.ExportDiglogTitle.0")); //$NON-NLS-1$
-               String[] filter = {"*."+ property.getArch().toString()}; //$NON-NLS-1$
-               String[] filterName = {"Image Files(*." + property.getArch().toString() + ")"}; //$NON-NLS-1$ //$NON-NLS-2$
+               String[] filter = {"*."+ property.getArchInternal().toString()}; //$NON-NLS-1$
+               String[] filterName = {"Image Files(*." + property.getArchInternal().toString() + ")"}; //$NON-NLS-1$ //$NON-NLS-2$
                fd.setFilterExtensions(filter);
                fd.setFilterNames(filterName);
                fd.setFileName("emulimg-" + property.getName()); //$NON-NLS-1$
index d167667..e4727a9 100644 (file)
@@ -63,6 +63,7 @@ import org.tizen.emulator.manager.ui.dialog.MessageDialog;
 import org.tizen.emulator.manager.ui.widgets.ImageCombo;
 import org.tizen.emulator.manager.ui.widgets.ImageLabel;
 import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 import org.tizen.emulator.manager.vms.VMPropertyValue;
 import org.tizen.emulator.manager.vms.helper.HelperClass;
 import org.tizen.emulator.manager.vms.xml.template.Item;
@@ -80,7 +81,7 @@ public class BaseImageViewItem extends ComboViewItem {
        // For base image combo
        private boolean isSelected;
        private BaseImage currentBaseImage = null;
-       private List<BaseImage> baseImageList = new ArrayList<BaseImage>();
+       private final List<BaseImage> baseImageList = new ArrayList<BaseImage>();
        // Remember custom image list while emulator manager life-cycle.
        //private static List<BaseImage> customBaseImageList = new ArrayList<BaseImage>();
 
@@ -204,8 +205,16 @@ public class BaseImageViewItem extends ComboViewItem {
                                        fd.setText(String.format(Messages.getString("BaseImageViewItem.CustomDialogTitle.0"))); //$NON-NLS-1$
                                        String[] filter = null;
                                        String[] filterName = null;
-                                       filter = new String[] { "*.x86" }; //$NON-NLS-1$
-                                       filterName = new String[] { "Disk Image Files(*.x86)" }; //$NON-NLS-1$
+                                       filter = new String[] {
+                                                       "*." + Architecture.i386.toString(),
+                                                       "*." + Architecture.x86_64.toString(),
+                                                       "*." + Architecture.x86.toString()
+                                                       };
+                                       filterName = new String[] {
+                                                       "i386 Disk Image Files (*." + Architecture.i386.toString() + ")",
+                                                       "x86_64 Disk Image Files (*." + Architecture.x86_64.toString() + ")",
+                                                       "Legacy i386 Disk Image Files (*." + Architecture.x86.toString() + ")"
+                                                       };
                                        fd.setFilterExtensions(filter);
                                        fd.setFilterNames(filterName);
                                }
diff --git a/src/org/tizen/emulator/manager/ui/detail/item/template/loader/CustomPropertyTemplateLoader.java b/src/org/tizen/emulator/manager/ui/detail/item/template/loader/CustomPropertyTemplateLoader.java
new file mode 100644 (file)
index 0000000..6530af5
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.template.loader;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.tizen.emulator.manager.ui.detail.item.OptionType;
+import org.tizen.emulator.manager.vms.xml.template.DeviceList;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.ItemList;
+import org.tizen.emulator.manager.vms.xml.template.ObjectFactory;
+import org.tizen.emulator.manager.vms.xml.template.Option;
+import org.tizen.emulator.manager.vms.xml.template.PropertyList;
+
+public class CustomPropertyTemplateLoader {
+       public static ObjectFactory factory = new ObjectFactory();
+
+       public static ItemList makeCustomPropertyTemplate(List<ItemList> templateList) {
+               if (templateList.size() == 0) {
+                       return null;
+
+               } else if (templateList.size() == 1) {
+                       ItemList template = cloneTemplate(templateList.get(0));
+                       template.setImage(null);
+                       return template;
+
+               } else { // Make union set
+                       ItemList base = cloneTemplate(templateList.get(0));
+                       for (int i=1 ; i < templateList.size() ; i++) {
+                               addToBase(base,templateList.get(i));
+                       }
+                       return base;
+               }
+       }
+
+       private static void addToBase(ItemList base, ItemList newOne) {
+               // Property list add
+               PropertyList newPropertyList = newOne.getPropertyList();
+               PropertyList basePropertyList = base.getPropertyList();
+               if (newPropertyList != null) {
+                       if (basePropertyList == null) {
+                               basePropertyList = factory.createPropertyList();
+                               base.setPropertyList(basePropertyList);
+                       }
+                       for (Item newItem : newPropertyList.getItem()) {
+                               boolean itemExistInBase = false;
+                               for (Item baseItem : basePropertyList.getItem()) {
+                                       if (baseItem.getName().equals(newItem.getName())) {
+                                               itemExistInBase = true;
+                                               joinItem(baseItem, newItem);
+                                       }
+                               }
+                               if (!itemExistInBase) {
+                                       basePropertyList.getItem().add(cloneItem(newItem));
+                               }
+                       }
+               }
+
+               // Device list add
+               DeviceList newDeviceList = newOne.getDeviceList();
+               DeviceList baseDeviceList = base.getDeviceList();
+               if (newDeviceList != null) {
+                       if (baseDeviceList == null) {
+                               baseDeviceList = factory.createDeviceList();
+                               base.setDeviceList(baseDeviceList);
+                       }
+                       for (Item newItem : newDeviceList.getItem()) {
+                               boolean itemExistInBase = false;
+                               for (Item baseItem : baseDeviceList.getItem()) {
+                                       if (baseItem.getName().equals(newItem.getName())) {
+                                               itemExistInBase = true;
+                                               joinItem(baseItem, newItem);
+                                       }
+                               }
+                               if (!itemExistInBase) {
+                                       baseDeviceList.getItem().add(cloneItem(newItem));
+                               }
+                       }
+               }
+       }
+
+       private static void joinItem(Item baseItem, Item newItem) {
+               // join sub items
+               for (Item newSub : newItem.getItem()) {
+                       boolean itemExistInBase = false;
+                       for (Item baseSub : baseItem.getItem()) {
+                               if (baseSub.getName().equals(newSub.getName())) {
+                                       itemExistInBase = true;
+                                       joinItem(baseSub, newSub);
+                               }
+                       }
+                       if (!itemExistInBase) {
+                               baseItem.getItem().add(cloneItem(newSub));
+                       }
+               }
+               // join options
+               for (Option newOption : newItem.getOption()) {
+                       boolean optionExistInBase = false;
+                       for (Option baseOption : baseItem.getOption()) {
+                               if (baseOption.getName().equals(newOption.getName())) {
+                                       optionExistInBase = true;
+                                       if (isListOption(baseOption, newOption)) {
+                                               joinOption(baseOption, newOption);
+                                       }
+                               }
+                       }
+
+                       if (!optionExistInBase) {
+                               baseItem.getOption().add(cloneOption(newOption));
+                       }
+               }
+
+       }
+
+       private static void joinOption(Option baseOption, Option newOption) {
+               baseOption.setValue(joinCommaString(baseOption.getValue(), newOption.getValue()));
+       }
+
+       private static String joinCommaString(String base, String newOne) {
+               List<String> optionList = new ArrayList<String>();
+               if (base != null) {
+                       String[] split = base.split(","); //$NON-NLS-1$
+                       for (String str : split) {
+                               optionList.add(str.trim());
+                       }
+               }
+               if (newOne != null) {
+                       String[] split = newOne.split(","); //$NON-NLS-1$
+                       for (String str : split) {
+                               optionList.add(str.trim());
+                       }
+               }
+
+               if (optionList.size() > 0) {
+                       Set<String> optionSet = new HashSet<String>();
+                       optionSet.addAll(optionList);
+                       optionList.clear();
+                       optionList.addAll(optionSet);
+//                     Collections.sort(optionList);
+                       StringBuilder sb = new StringBuilder();
+
+                       for (int i=0 ; i<optionList.size() ; i++) {
+                               sb.append(optionList.get(i));
+                               if (i < optionList.size()-1) {
+                                       sb.append(","); //$NON-NLS-1$
+                               }
+                       }
+
+                       return sb.toString();
+               }
+
+               return null;
+       }
+
+       private static ItemList cloneTemplate(ItemList template) {
+               ItemList newTemplate = factory.createItemList();
+               newTemplate.setProfile(template.getProfile());
+               newTemplate.setImage(template.getImage());
+
+               // clone property list
+               PropertyList propertyList = template.getPropertyList();
+               if (propertyList != null) {
+                       PropertyList newPropertyList = factory.createPropertyList();
+                       newTemplate.setPropertyList(newPropertyList);
+
+                       for (Item item : propertyList.getItem()) {
+                               newPropertyList.getItem().add(cloneItem(item));
+                       }
+               }
+
+               // clone device list.
+               DeviceList deviceList = template.getDeviceList();
+               if (deviceList != null) {
+                       DeviceList newDeviceList = factory.createDeviceList();
+                       newTemplate.setDeviceList(newDeviceList);
+
+                       for (Item item : deviceList.getItem()) {
+                               newDeviceList.getItem().add(cloneItem(item));
+                       }
+               }
+
+               return newTemplate;
+       }
+
+       private static Item cloneItem(Item item) {
+               Item newItem = factory.createItem();
+               newItem.setType(item.getType());
+               newItem.setName(item.getName());
+               newItem.setTitle(item.getTitle());
+
+               for (Option option : item.getOption()) {
+                       newItem.getOption().add(cloneOption(option));
+               }
+
+               for (Item subItem : item.getItem()) {
+                       newItem.getItem().add(cloneItem(subItem));
+               }
+
+               return newItem;
+       }
+
+       private static Option cloneOption(Option option) {
+               Option newOption = factory.createOption();
+               newOption.setName(option.getName());
+               newOption.setValue(option.getValue());
+               return newOption;
+       }
+
+       private static boolean isListOption(Option baseOption, Option newOption) {
+               if (baseOption.getName().equals(OptionType.COMBO_LIST.getName())
+                               && newOption.getName().equals(OptionType.COMBO_LIST.getName())) {
+                       return true;
+               }
+
+               return false;
+       }
+}
index 327dc79..552a36a 100644 (file)
@@ -67,7 +67,7 @@ public class Creator {
 
                this.folder = new File(FilePathResources.getVirtualTargetPath(newVM.vmsName));
        }
-       
+
        public VMProperty createInternal() throws VMWorkerException {
                // lock.acquire
                WorkerLock.acquire();
@@ -156,7 +156,7 @@ public class Creator {
                                }
                        }
                        folder.delete();
-               }       
+               }
        }
 
        private String customPath = null;
index b34748a..51f7286 100644 (file)
@@ -169,9 +169,15 @@ public class VMProperty {
                                || configuration.getBaseInformation() == null) {
                        return null;
                }
+               return Architecture.getDisplayType(configuration.getBaseInformation().getArchitecture());
+       }
 
-               return Architecture.x86.toString().equals(configuration.getBaseInformation().getArchitecture()) ?
-                               Architecture.x86 : Architecture.ARM;
+       public Architecture getArchInternal() {
+               if(configuration == null
+                               || configuration.getBaseInformation() == null) {
+                       return null;
+               }
+               return Architecture.getType(configuration.getBaseInformation().getArchitecture());
        }
 
        public FSImageType getImageType() {
@@ -291,7 +297,7 @@ public class VMProperty {
        }
 
        public enum Architecture {
-               x86("x86"), ARM("arm"); //$NON-NLS-1$ //$NON-NLS-2$
+               x86("x86"), i386("i386"), x86_64("x86_64"), ARM("arm"); //$NON-NLS-1$ //$NON-NLS-2$
 
                private String arch;
 
@@ -303,6 +309,29 @@ public class VMProperty {
                public String toString() {
                        return arch;
                }
+
+               public static Architecture getDisplayType(String arch) {
+                       if (arch.equals(x86.arch) || arch.equals(i386.arch)) {
+                               return i386; // for legacy image (.x86)
+
+                       } else {
+                               for (Architecture type : Architecture.values()) {
+                                       if (arch.equals(type.arch)) {
+                                               return type;
+                                       }
+                               }
+                       }
+                       return i386;
+               }
+
+               public static Architecture getType(String arch) {
+                       for (Architecture type : Architecture.values()) {
+                               if (arch.equals(type.arch)) {
+                                       return type;
+                               }
+                       }
+                       return i386;
+               }
        };
 
        public enum FSImageType {
index 89c4469..27a5951 100644 (file)
@@ -73,7 +73,7 @@ public class CommonOption extends Option {
 
                // kernel image
                config.addVariableWithSpace(OPTION_KEY.VAR_KERNEL, FilePathResources.getEmulatorKernelPath(emulatorPath)
-                               + File.separator + "bzImage." + property.getArch().toString()); //$NON-NLS-1$
+                               + File.separator + "bzImage." + property.getArchInternal().toString()); //$NON-NLS-1$
                config.addQemuOption("-kernel", varForm(OPTION_KEY.VAR_KERNEL)); //$NON-NLS-1$
 
                // kernel