base image: add architecture type for custom base image
authorjihye424.kim <jihye424.kim@samsung.com>
Fri, 6 Nov 2015 10:42:05 +0000 (19:42 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Fri, 6 Nov 2015 10:42:05 +0000 (19:42 +0900)
- choose 32bit or 64bit kernel

Change-Id: If147695addbe07248ca506ef4835543cef21733a
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/platform/BaseImage.java
src/org/tizen/emulator/manager/platform/Platform.java
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageLoader.java
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageValue.java
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageWorker.java
src/org/tizen/emulator/manager/vms/VMProperty.java

index fa47ee3..60ab05a 100644 (file)
@@ -42,7 +42,6 @@ import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageWorker;
 import org.tizen.emulator.manager.plugin.EMPlugin;
 import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
-import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.template.ITemplate;
 import org.tizen.emulator.manager.ui.renewal.dialog.ItemListUtil;
@@ -87,13 +86,15 @@ public class BaseImage {
        private SKIN_SHAPE skinShape;
        private String binaryVersion;
        private String description = "";
-       private boolean isDeleted = false;
 
        private boolean isStandard;
+       private boolean isDeleted = false;
        private boolean isFilePathExist = true;
 
+       // for create, delete, modify custom base image
        private CustomBaseImageWorker worker;
-       private String information;
+       // detail information (for cli)
+       private String information = "";
 
        private VMProperty defaultProperty;
        private ITemplate itemTemplate;
@@ -101,8 +102,6 @@ public class BaseImage {
        protected List<ModifyDialogItem> defaultItemList;
        protected List<ModifyDialogItem> advancedItemList;
 
-
-
        protected List<IOption> optionList;
        //private LaunchConfig launchTemplate; // TODO replace xDefaultOption.java
 
@@ -224,6 +223,10 @@ public class BaseImage {
                return version;
        }
 
+       public void setCpuType(Architecture type) {
+               cpu = type;
+       }
+
        public String getCpu() {
                if (cpu == null) {
                        return "";
@@ -364,7 +367,6 @@ public class BaseImage {
                version = platform.getVersion();
                profile = platform.getProfile();
                type = "custom"; // TODO //$NON-NLS-1$
-               cpu     = findCpuTypeFromPath();
                skinShape = SKIN_SHAPE.NONE; // TODO
                binaryVersion = ""; //$NON-NLS-1$
                extension = platform.isChildPlatform()
@@ -372,11 +374,6 @@ public class BaseImage {
                                : "";
        }
 
-       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()) {
                        // TODO: find first .x86 file.
index 0c08e50..84bb603 100644 (file)
@@ -45,6 +45,7 @@ import org.tizen.emulator.manager.template.renewal.TemplateLoader;
 import org.tizen.emulator.manager.vms.RESOLUTION;
 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.xml.template.v2.ItemList;
 
 public class Platform {
@@ -67,6 +68,7 @@ public class Platform {
                }
                return null;
        }
+
        // platform name = profile + version = profile-version
        private String platformName = null;
        private String platformPath = null;
@@ -93,6 +95,8 @@ public class Platform {
        // for custom base image
        private ITemplate customItemTemplate;
 
+       private List<Architecture> archList = new ArrayList<Architecture>();
+
        private Platform(Profile profile, EMPlugin plugin) {
                initializePlatform(profile, plugin);
        }
@@ -316,4 +320,38 @@ public class Platform {
                }
                return defaultTemplate;
        }
+
+       /**
+        * support kernel architecture list (32bit or 64bit kernel)
+        * @return
+        */
+       public List<Architecture> getArchitectureList() {
+               if (archList.isEmpty()) {
+                       makeArchitectureList();
+               }
+               return archList;
+       }
+
+       public Architecture findArchitecture(int bit) {
+               for (Architecture arch : archList) {
+                       if (arch.getBit() == bit) {
+                               return arch;
+                       }
+               }
+               return null;
+       }
+
+       private void makeArchitectureList() {
+               String kernelPath = FilePathResources.getEmulatorKernelPath(FilePathResources.getPlatformEmulatorPath(version));
+               File kernelDir = new File(kernelPath);
+               if (!kernelDir.isDirectory() || !kernelDir.exists()) {
+                       archList.add(Architecture.x86);
+                       return;
+               }
+
+               for (File f : kernelDir.listFiles()) {
+                       String ext = FilePathResources.getFileExtention(f.getPath());
+                       archList.add(Architecture.getType(ext));
+               }
+       }
 }
index 43655e4..ee49968 100644 (file)
@@ -199,8 +199,10 @@ public class Profile {
 
                if (image != null) {
                        vm.getPropertyValue().setBaseImage(image);
-                       image.addEmulator(vm);
                        vmList.add(vm);
+                       if (!name.equals(StringResources.TOTAL_PROFILE)) {
+                               image.addEmulator(vm);
+                       }
                }
        }
 
index a4fa576..c4479a4 100644 (file)
@@ -54,6 +54,7 @@ import org.tizen.emulator.manager.platform.Profile;
 import org.tizen.emulator.manager.platform.ProfileList;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 
 public class CustomBaseImageLoader {
        private static JAXBContext context = null;
@@ -165,20 +166,14 @@ public class CustomBaseImageLoader {
                        return false;
                }
 
-               baseImageType.setId(image.getID());
-               baseImageType.setName(image.getName());
-               baseImageType.setProfile(image.getProfile());
-               baseImageType.setPlatform(image.getPlatformName());
                if (!baseImageType.getPath().equals(image.getPath())) {
-                       baseImageType.setPath(image.getPath());
                        File dir = new File(image.getPath());
                        if (dir.exists()) {
                                setLastDirectory(dir.getParentFile().getAbsolutePath());
                        }
                }
 
-               baseImageType.setDescription(image.getDescription());
-               baseImageType.setIsDeleted(image.isDeleted());
+               settingConfiguration(image, baseImageType);
 
                return storeXML(conf);
        }
@@ -191,12 +186,7 @@ public class CustomBaseImageLoader {
                }
 
                BaseImageType baseImageType = factory.createBaseImageType();
-               baseImageType.setId(image.getID());
-               baseImageType.setName(image.getName());
-               baseImageType.setProfile(image.getProfile());
-               baseImageType.setPlatform(image.getPlatformName());
-               baseImageType.setPath(image.getPath());
-               baseImageType.setDescription(image.getDescription());
+               settingConfiguration(image, baseImageType);
 
                conf.getCustomBaseImage().add(baseImageType);
 
@@ -215,12 +205,7 @@ public class CustomBaseImageLoader {
                ArrayList<BaseImageType> list = (ArrayList<BaseImageType>) conf.getCustomBaseImage();
                for (BaseImage image : baseImageList) {
                        BaseImageType type = factory.createBaseImageType();
-                       type.setId(image.getID());
-                       type.setName(image.getName());
-                       type.setProfile(image.getProfile());
-                       type.setPlatform(image.getPlatformName());
-                       type.setPath(image.getPath());
-                       type.setDescription(image.getDescription());
+                       settingConfiguration(image, type);
 
                        list.add(type);
                }
@@ -228,6 +213,18 @@ public class CustomBaseImageLoader {
                return storeXML(conf);
        }
 
+       private static void settingConfiguration(BaseImage image, BaseImageType type) {
+               type.setId(image.getID());
+               type.setName(image.getName());
+               type.setProfile(image.getProfile());
+               type.setPlatform(image.getPlatformName());
+               type.setCpu(image.getCpu());
+               type.setSkinShape(image.getSkinShape().toString());
+               type.setPath(image.getPath());
+               type.setDescription(image.getDescription());
+               type.setIsDeleted(image.isDeleted());
+       }
+
        private synchronized static void loadConfiguration() {
                if (baseImageConfFile == null || !baseImageConfFile.exists()) {
                        return;
@@ -254,6 +251,7 @@ public class CustomBaseImageLoader {
                                }
 
                                image.setID(baseImage.getId());
+                               image.setCpuType(Architecture.getType(baseImage.getCpu()));
                                image.setDescription((baseImage.getDescription() == null
                                                                        ? ""
                                                                        : baseImage.getDescription()));
index 99030c8..83a8cae 100644 (file)
@@ -32,12 +32,16 @@ package org.tizen.emulator.manager.platform.baseimage;
 
 import org.tizen.emulator.manager.platform.BaseImage;
 import org.tizen.emulator.manager.platform.Platform;
+import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 
 public class CustomBaseImageValue {
+       // name == id
        private String name = "";
        private String profile = "";
        private String platformName = "";
        private Platform platform = null;
+       // default value is i386
+       private Architecture cpu = Architecture.i386;
        private String filePath = "";
        private String description = "";
        private boolean isAmendable = false;
@@ -51,6 +55,7 @@ public class CustomBaseImageValue {
                profile = image.getProfile();
                platformName = image.getPlatformName();
                platform = image.getPlatform();
+               cpu = image.getCpuType();
                filePath = image.getPath();
                description = image.getDescription();
                // emulator list is empty - you can modify base image properties
@@ -90,6 +95,14 @@ public class CustomBaseImageValue {
                this.platform = platform;
        }
 
+       public Architecture getCpu() {
+               return cpu;
+       }
+
+       public void setCpu(Architecture cpu) {
+               this.cpu = cpu;
+       }
+
        public String getFilePath() {
                return filePath;
        }
index eccd3f9..88191ff 100644 (file)
@@ -36,6 +36,7 @@ import org.tizen.emulator.manager.platform.BaseImage;
 import org.tizen.emulator.manager.platform.Platform;
 import org.tizen.emulator.manager.platform.Profile;
 import org.tizen.emulator.manager.platform.ProfileList;
+import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 
 public class CustomBaseImageWorker {
        private BaseImage image;
@@ -53,6 +54,7 @@ public class CustomBaseImageWorker {
                }
 
                image.setID(image.getName());
+               image.setCpuType(Architecture.findCpuTypeFromPath(path));
                image.setWorker(new CustomBaseImageWorker(image));
 
                platform.getProfileClass().addBaseImage(image);
@@ -68,8 +70,9 @@ public class CustomBaseImageWorker {
                        return null;
                }
 
-               image.setDescription(value.getDescription());
                image.setID(value.getName());
+               image.setCpuType(value.getCpu());
+               image.setDescription(value.getDescription());
                image.setWorker(new CustomBaseImageWorker(image));
 
                Profile profile = ProfileList.getProfile(value.getProfile());
@@ -83,6 +86,7 @@ public class CustomBaseImageWorker {
                image.setName(value.getName());
                image.setPath(value.getFilePath());
                image.setPlatform(value.getPlatform());
+               image.setCpuType(value.getCpu());
                image.setDescription(value.getDescription());
                return CustomBaseImageLoader.modfiyBaseImageConfiguration(image);
        }
index 1da0826..3d7dea5 100644 (file)
@@ -36,6 +36,7 @@ import org.tizen.emulator.manager.platform.BaseImage;
 import org.tizen.emulator.manager.plugin.EMPlugin;
 import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
+import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.vms.helper.VMLogUtil;
 import org.tizen.emulator.manager.vms.xml.EmulatorConfiguration;
 import org.tizen.emulator.manager.vms.xml.ObjectFactory;
@@ -325,12 +326,14 @@ public class VMProperty {
        }
 
        public enum Architecture {
-               x86("x86"), i386("i386"), x86_64("x86_64"); //$NON-NLS-1$ //$NON-NLS-2$
+               x86("x86", 32), i386("i386", 32), x86_64("x86_64", 64); //$NON-NLS-1$ //$NON-NLS-2$
 
                private String name;
+               private int bit;
 
-               Architecture(String arch) {
+               Architecture(String arch, int bit) {
                        this.name = arch;
+                       this.bit = bit;
                }
 
                @Override
@@ -338,6 +341,15 @@ public class VMProperty {
                        return name;
                }
 
+               public int getBit(){
+                       return bit;
+               }
+
+               public static Architecture findCpuTypeFromPath(String path) {
+                       String ext = FilePathResources.getFileExtention(path);
+                       return Architecture.getType(ext);
+               }
+
                public static boolean isSupported(String extension) {
                        for (Architecture arch : Architecture.values()) {
                                if (arch.name.equals(extension.toLowerCase())) {