CustomBaseImage: add custom base image loader
authorjihye424.kim <jihye424.kim@samsung.com>
Sun, 25 Oct 2015 01:16:56 +0000 (10:16 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Thu, 29 Oct 2015 02:43:03 +0000 (11:43 +0900)
- make custom bsae image list from base image xml file
- profile has standard and custom base image list
- priority: standard > custom

Change-Id: I11dad06371439da54bbc420dc916f80c7b5a9b84
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/platform/BaseImage.java
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/platform/ProfileList.java
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageLoader.java [new file with mode: 0644]
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageValue.java [new file with mode: 0644]
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageWorker.java [new file with mode: 0644]

index 6db6c0b..bc3f9f5 100644 (file)
@@ -32,11 +32,13 @@ package org.tizen.emulator.manager.platform;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 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.platform.baseimage.CustomBaseImageWorker;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
@@ -47,31 +49,50 @@ import org.tizen.emulator.manager.vms.VMProperty.Architecture;
 import org.tizen.emulator.manager.vms.option.IOption;
 
 public class BaseImage {
-       protected Platform platform;
+       public static BaseImage createCustomBaseImage(Platform platform, String path, String name) {
+               if (platform == null) {
+                       return null;
+               }
+
+               if (path == null || path.isEmpty()) {
+                       return null;
+               }
 
-       protected String path;
-       protected String pathName;
+               return new BaseImage(platform, path, name);
+       }
+
+       private Platform platform;
 
-       protected String id = "0"; //$NON-NLS-1$
-       protected String imageName;
-       protected String version;
-       protected String profile;
-       protected String extension;
-       protected String type;
-       protected Architecture cpu;
-       protected SKIN_SHAPE skinShape;
-       protected String binaryVersion;
+       private String path;
+       private String pathName;
 
-       protected boolean isStandard;
+       private String id;
+       private String imageName;
+       private String version;
+       private String profile;
+       private String extension;
+       private String type;
+       private Architecture cpu;
+       private SKIN_SHAPE skinShape;
+       private String binaryVersion;
+       private String description = "";
+       private boolean isDeleted = false;
 
+       private boolean isStandard;
+       private boolean isFilePathExist = true;
+
+       private CustomBaseImageWorker worker;
        private String information;
 
-       protected VMProperty defaultProperty;
-       protected ITemplate itemTemplate;
+       private VMProperty defaultProperty;
+       private ITemplate itemTemplate;
 
-       protected List<IOption> optionList;
+       private List<IOption> optionList;
        //private LaunchConfig launchTemplate; // TODO replace xDefaultOption.java
 
+       // for custom base image
+       private List<VMProperty> emulatorList = new ArrayList<VMProperty>();
+
        protected BaseImage() {
        }
 
@@ -97,17 +118,42 @@ public class BaseImage {
         * @throws IOException
         */
        public BaseImage(Platform platform, String path) {
-               if (platform == null) {
+               this(platform, path, null);
+       }
+
+       private BaseImage(Platform platform, String path, String name) {
+               if (platform == null || path == null) {
                        return;
                }
+
                this.platform = platform;
                isStandard = false;
 
                this.path = path;
-               if (path != null && !path.isEmpty()) {
-                       imageName = pathName = path.substring(path.lastIndexOf(File.separator) + 1);
+               if (!path.isEmpty()) {
+                       pathName = path.substring(path.lastIndexOf(File.separator) + 1);
                }
 
+               File file = new File(path);
+               if (!file.exists()) {
+                       setFilePathExist(false);
+               }
+
+               if (name != null) {
+                       imageName = name;
+               } else {
+                       imageName = pathName;
+               }
+
+               // check duplicate name
+//             int i = 1;
+//             String temp = imageName;
+//             while (HelperClass.checkDuplicateBaseImageName(temp) != null) {
+//                     temp = imageName + "(" + i + ")";
+//                     i++;
+//             }
+//             imageName = temp;
+
                settingProperty(platform);
                loadTemplate();
        }
@@ -125,14 +171,29 @@ public class BaseImage {
                return pathName;
        }
 
+       public void setPath(String path) {
+               this.path = path;
+               if (!path.isEmpty()) {
+                       pathName = path.substring(path.lastIndexOf(File.separator) + 1);
+               }
+       }
+
        public String getID() {
                return id;
        }
 
+       public void setID(String id) {
+               this.id = id;
+       }
+
        public String getName() {
                return imageName;
        }
 
+       public void setName(String name) {
+               imageName = name;
+       }
+
        public String getProfile() {
                return profile;
        }
@@ -164,6 +225,11 @@ public class BaseImage {
                return platform;
        }
 
+       public void setPlatform(Platform platform) {
+               this.platform = platform;
+               settingProperty(platform);
+       }
+
        public String getBinaryVersion() {
                return binaryVersion;
        }
@@ -191,6 +257,14 @@ public class BaseImage {
                return skinShape;
        }
 
+       public void setDescription(String message) {
+               this.description = message;
+       }
+
+       public String getDescription() {
+               return this.description;
+       }
+
        private void checkBaseImage() throws IOException {
                if (imageName == null) {
                        throw new IOException("Image name is null. This image can not add."); //$NON-NLS-1$
@@ -261,7 +335,7 @@ public class BaseImage {
                version = platform.getVersion();
                profile = platform.getProfile();
                type = "custom"; // TODO //$NON-NLS-1$
-               cpu     = findCpuTypeFromPath(); //$NON-NLS-1$
+               cpu     = findCpuTypeFromPath();
                skinShape = SKIN_SHAPE.NONE; // TODO
                binaryVersion = ""; //$NON-NLS-1$
                extension = platform.isChildPlatform()
@@ -276,6 +350,8 @@ public class BaseImage {
 
        private void settingImagePath(File path) throws IOException {
                for (File f : path.listFiles()) {
+                       // TODO: find first .x86 file.
+                       // if there are .x86 file more then two ??
                        if (f.isFile() && f.getName().endsWith(getCpu().toLowerCase())) {
                                this.path = f.getCanonicalPath();
                                this.pathName = f.getName();
@@ -286,7 +362,8 @@ public class BaseImage {
                }
        }
 
-       void setID(int id) {
+       // TODO: not used
+       public void setID(int id) {
                this.id = Integer.toString(id);
                //
                information = getName() + StringResources.NEW_LINE
@@ -313,6 +390,9 @@ public class BaseImage {
                }
        }
 
+       //
+       // for custom base image
+       //
        public boolean isStandard() {
                return isStandard;
        }
@@ -320,4 +400,48 @@ public class BaseImage {
        public void setStandard(boolean isStandard) {
                this.isStandard = isStandard;
        }
+
+       public boolean isFilePathExist() {
+               return isFilePathExist;
+       }
+
+       public void setFilePathExist(boolean isFilePathExist) {
+               this.isFilePathExist = isFilePathExist;
+       }
+
+       public List<VMProperty> getEmulatorList() {
+               return emulatorList;
+       }
+
+       public void setEmulatorList(List<VMProperty> emulatorList) {
+               this.emulatorList = emulatorList;
+       }
+
+       public void addEmulator(VMProperty prop) {
+               emulatorList.add(prop);
+       }
+
+       public void removeEmulator(VMProperty prop) {
+               emulatorList.remove(prop);
+       }
+
+       public boolean isEemulatorListEmpty() {
+               return emulatorList.isEmpty();
+       }
+
+       public boolean isDeleted() {
+               return isDeleted;
+       }
+
+       public void setDeleted(boolean isDeleted) {
+               this.isDeleted = isDeleted;
+       }
+
+       public CustomBaseImageWorker getWorker() {
+               return worker;
+       }
+
+       public void setWorker(CustomBaseImageWorker worker) {
+               this.worker = worker;
+       }
 }
index 62e823c..32391c7 100644 (file)
@@ -38,6 +38,7 @@ import java.util.List;
 import org.tizen.emulator.manager.devices.DeviceTemplate;
 import org.tizen.emulator.manager.devices.DeviceTemplateList;
 import org.tizen.emulator.manager.devices.DeviceTemplatePriority;
+import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageWorker;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
@@ -167,25 +168,38 @@ public class Profile {
 
        public void addEmulator(VMProperty vm) {
                //setting BaseImage
+               BaseImage image = null;
                if (vm.getPropertyValue().baseImage == null) {
                        if (vm.getImageType().equals(FSImageType.standard)) {
                                for (BaseImage b : imageList) {
-                                       if (vm.getBaseImagePath().equals(b.getPath())) {
-                                               vm.getPropertyValue().setBaseImage(b);
+                                       if (b.isStandard() && vm.getBaseImagePath().equals(b.getPath())) {
+                                               image = b;
                                                break;
                                        }
                                }
-                       } else {
-                               for (Platform p : platformList) {
-                                       if (vm.getImagePlatform().equals(p.getName())) {
-                                               vm.getPropertyValue().setBaseImage(
-                                                       new BaseImage(p, vm.getBaseImagePath()));
+                       } else { // custom base image
+                               for (BaseImage b : imageList) {
+                                       if (!b.isStandard() && vm.getBaseImageName().equals(b.getName())) {
+                                               image = b;
+                                               break;
+                                       }
+                               }
+
+                               if (image == null) {
+                                       for (Platform p : platformList) {
+                                               if (vm.getImagePlatform().equals(p.getName())) {
+                                                       image = CustomBaseImageWorker.createCustomBaseImage(p,
+                                                                                                                       vm.getBaseImagePath(),
+                                                                                                                       vm.getBaseImageName());
+                                               }
                                        }
                                }
                        }
                }
 
-               if (vm.getPropertyValue().baseImage != null) {
+               if (image != null) {
+                       vm.getPropertyValue().setBaseImage(image);
+                       image.addEmulator(vm);
                        vmList.add(vm);
                }
        }
@@ -233,6 +247,14 @@ public class Profile {
                }
        }
 
+       public void removeBaseImage(BaseImage base) {
+               if (base == null) {
+                       return;
+               }
+
+               imageList.remove(base);
+       }
+
        public List<BaseImage> getImageList() {
                return imageList;
        }
@@ -393,6 +415,19 @@ public class Profile {
                        BaseImage src = this.prop;
                        BaseImage target = ((ImagePair)o).prop;
 
+                       // 0. check standard  > custom
+                       if (target.isStandard()) {
+                               if (!src.isStandard()) {
+                                       return 1;
+                               }
+                       } else {
+                               if (src.isStandard()) {
+                                       return -1;
+                               } else {
+                                       return 1;
+                               }
+                       }
+
                        // 1. check version (descending order)
                        int order = target.getVersion().compareTo(src.getVersion());
                        if (order != 0) {
index c7616ac..3fbe85e 100644 (file)
@@ -39,6 +39,7 @@ import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.devices.DeviceTemplate;
 import org.tizen.emulator.manager.devices.DeviceTemplateList;
 import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageLoader;
 import org.tizen.emulator.manager.plugin.EMPlugin;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
 import org.tizen.emulator.manager.resources.FilePathResources;
@@ -121,14 +122,17 @@ public class ProfileList {
                        makePlatform(plugin);
                }
 
+               // add custom base image
+               makeCustomBaseImageList();
+
                // sorting base image and platform
                for (Profile profile : profileList) {
                        profile.sortBaseImageList();
                        profile.sortPlatformList();
                        // setting base image id and information
-                       for (BaseImage b : profile.getImageList()) {
-                               b.setID(imageID++);
-                       }
+//                     for (BaseImage b : profile.getImageList()) {
+//                             b.setID(imageID++);
+//                     }
                }
 
                // check base image version
@@ -186,7 +190,7 @@ public class ProfileList {
                return p;
        }
 
-       private static int imageID = 1;
+       //private static int imageID = 1;
        private static void makeBaesImageList(Profile profile, Platform platform, String platformPath) {
                if (platform == null || platformPath == null) {
                        return;
@@ -215,6 +219,23 @@ public class ProfileList {
                }
        }
 
+       /**
+        * calling this function after complete making profile and platform list
+        */
+       private static void makeCustomBaseImageList() {
+               BaseImage[] imageList = CustomBaseImageLoader.getCustomBsaeImageList(true);
+               if (imageList.length == 0) {
+                       return;
+               }
+
+               for (BaseImage image : imageList) {
+                       Profile profile = image.getPlatform().getProfileClass();
+                       if (profile != null) {
+                               profile.addBaseImage(image);
+                       }
+               }
+       }
+
        private static void settingVMPropertyListInternal() {
                EmulatorVMList vms = EmulatorVMList.getInstance();
                vms.refreshProperties();
diff --git a/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageLoader.java b/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageLoader.java
new file mode 100644 (file)
index 0000000..1821f5e
--- /dev/null
@@ -0,0 +1,339 @@
+/*
+ * 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 <sangho.p@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.platform.baseimage;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+import org.tizen.emulator.manager.baseimage.xml.BaseImageConfiguration;
+import org.tizen.emulator.manager.baseimage.xml.BaseImageType;
+import org.tizen.emulator.manager.baseimage.xml.ObjectFactory;
+import org.tizen.emulator.manager.logging.EMLogger;
+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.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.StringResources;
+
+public class CustomBaseImageLoader {
+       private static JAXBContext context = null;
+       private static File baseImageConfFile;
+
+       private static BaseImageConfiguration conf = null;
+       private static List<BaseImage> baseImageList = new ArrayList<BaseImage>();
+       private static String lastDirectory;
+
+       static {
+               try {
+                       context = JAXBContext.newInstance(BaseImageConfiguration.class);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().info(e.getMessage());
+               }
+
+               baseImageConfFile = new File(FilePathResources.getTizenSdkDataEmulatorPath()
+                               + File.separator
+                               + "custom-base-images.xml");
+       }
+
+       public static BaseImage[] getCustomBsaeImageList(boolean isRefresh) {
+               if (conf == null || isRefresh) {
+                       loadConfiguration();
+               }
+
+               return baseImageList.toArray(new BaseImage[baseImageList.size()]);
+       }
+
+       public static BaseImage findCustomBaseImage(String name) {
+               for (BaseImage image : baseImageList) {
+                       if (image.getName().equals(name)) {
+                               return image;
+                       }
+               }
+               return null;
+       }
+
+       public static String getLastDirectroy() {
+               if (lastDirectory == null || lastDirectory.isEmpty()) {
+                       lastDirectory = FilePathResources.getTizenSdkDataEmulatorPath();
+               }
+               return lastDirectory;
+       }
+
+       public static void setLastDirectory(String path) {
+               if (path == null || path.isEmpty()) {
+                       // TODO
+                       return;
+               }
+
+               File dir = new File(path);
+               if (!dir.isDirectory() || !dir.exists()) {
+                       // TODO
+                       return;
+               }
+
+               lastDirectory = path;
+               if (conf == null) {
+                       conf = new ObjectFactory().createBaseImageConfiguration();
+               }
+               conf.setLastDirectory(lastDirectory);
+
+               storeXML(conf);
+       }
+
+       public static boolean deleteBaseImageConfiguration(BaseImage image) {
+               if (conf == null) {
+                       return false;
+               }
+
+               if (image.isEemulatorListEmpty()) {
+                       baseImageList.remove(image);
+                       return CustomBaseImageLoader.saveBaseImageConfiguration();
+               } else {
+                       image.setDeleted(true);
+
+                       BaseImageType baseImageType = null;
+                       for (BaseImageType type : conf.getCustomBaseImage()) {
+                               if (type.getId().equals(image.getID())) {
+                                       baseImageType = type;
+                                       break;
+                               }
+                       }
+
+                       if (baseImageType == null) {
+                               return false;
+                       }
+                       baseImageType.setIsDeleted(image.isDeleted());
+
+                       return storeXML(conf);
+               }
+       }
+
+       public static boolean modfiyBaseImageConfiguration(BaseImage image) {
+               if (conf == null) {
+                       return false;
+               }
+
+               BaseImageType baseImageType = null;
+               for (BaseImageType type : conf.getCustomBaseImage()) {
+                       if (type.getId().equals(image.getID())) {
+                               baseImageType = type;
+                               break;
+                       }
+               }
+
+               if (baseImageType == null) {
+                       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());
+                       setLastDirectory(dir.getParentFile().getAbsolutePath());
+               }
+
+               baseImageType.setDescription(image.getDescription());
+               baseImageType.setIsDeleted(image.isDeleted());
+
+               return storeXML(conf);
+       }
+
+       public static boolean createBaseImageConfiguration(BaseImage image) {
+               ObjectFactory factory = new ObjectFactory();
+
+               if (conf == null) {
+                       conf = factory.createBaseImageConfiguration();
+               }
+
+               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());
+
+               conf.getCustomBaseImage().add(baseImageType);
+
+               File dir = new File(image.getPath());
+               setLastDirectory(dir.getParentFile().getAbsolutePath());
+
+               baseImageList.add(image);
+
+               return storeXML(conf);
+       }
+
+       public static boolean saveBaseImageConfiguration() {
+               ObjectFactory factory = new ObjectFactory();
+               conf = factory.createBaseImageConfiguration();
+
+               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());
+
+                       list.add(type);
+               }
+
+               return storeXML(conf);
+       }
+
+       private synchronized static void loadConfiguration() {
+               if (baseImageConfFile == null || !baseImageConfFile.exists()) {
+                       return;
+               }
+
+               baseImageList.clear();
+
+               conf = parseXML();
+               if (conf == null) {
+                       return;
+               }
+
+               for (BaseImageType baseImage : conf.getCustomBaseImage()) {
+                       Profile profile = ProfileList.getProfile(baseImage.getProfile());
+                       if (profile == null) {
+                               continue;
+                       }
+                       Platform platform = profile.getPlatformByName(baseImage.getPlatform());
+                       if (platform != null) {
+                               BaseImage image = BaseImage.createCustomBaseImage(platform, baseImage.getPath(),
+                                                                                               baseImage.getName());
+                               if (image == null) {
+                                       continue;
+                               }
+
+                               image.setDescription((baseImage.getDescription() == null
+                                                                       ? ""
+                                                                       : baseImage.getDescription()));
+                               image.setWorker(new CustomBaseImageWorker(image));
+                               baseImageList.add(image);
+                       }
+               }
+       }
+
+       private static BaseImageConfiguration parseXML() {
+               if (baseImageConfFile == null) {
+                       return null;
+               }
+
+
+               if (context == null) {
+                       EMLogger.getLogger().warning("Faile to load custom base image configuration (" //$NON-NLS-1$
+                                       + baseImageConfFile.getName() + ")"
+                                       + StringResources.NEW_LINE
+                                       + "Failed to make JAXBContext from BaseImageConfiguration class");
+                       return null;
+               }
+
+               JAXBElement<BaseImageConfiguration> element = null;
+
+               try {
+                       Unmarshaller unmarshaller = context.createUnmarshaller();
+                       element = unmarshaller.unmarshal(new StreamSource(baseImageConfFile),
+                                                                                       BaseImageConfiguration.class);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().warning("Failed to load custom base image configuration file ( " //$NON-NLS-1$
+                                                       + baseImageConfFile.getName() + ")"
+                                                       + StringResources.NEW_LINE + e.getMessage());
+                       return null;
+               }
+
+               return element.getValue();
+       }
+
+       private static boolean storeXML(BaseImageConfiguration conf) {
+               if (baseImageConfFile == null) {
+                       return false;
+               }
+
+               if (context == null) {
+                       EMLogger.getLogger().warning("Faile to save custom base image configuration (" //$NON-NLS-1$
+                                       + baseImageConfFile.getName() + ")"
+                                       + StringResources.NEW_LINE
+                                       + "Failed to make JAXBContext from BaseImageConfiguration class");
+                       return false;
+               }
+
+               FileOutputStream fos = null;
+               Marshaller marshaller;
+               try {
+                       marshaller = context.createMarshaller();
+                       marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
+                       marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+
+                       if (!baseImageConfFile.exists()) {
+                               baseImageConfFile.getParentFile().mkdirs();
+                       }
+
+                       fos = new FileOutputStream(baseImageConfFile);
+                       marshaller.marshal(conf, fos);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().warning("Failed to save custom base image configuration to file (" //$NON-NLS-1$
+                                       + baseImageConfFile.getName() + ")" + StringResources.NEW_LINE + e.getMessage());
+                       return false;
+               } catch (FileNotFoundException e) {
+                       EMLogger.getLogger().warning("Failed to save custom base image configuration to file (" //$NON-NLS-1$
+                                       + baseImageConfFile.getName() + ")" + StringResources.NEW_LINE + e.getMessage());
+                       return false;
+               } finally {
+                       if (fos != null) {
+                               try {
+                                       fos.close();
+                               } catch (IOException e) {
+                                       EMLogger.getLogger().warning("ERROR : " + e.getMessage()); //$NON-NLS-1$
+                               }
+                       }
+               }
+
+               return true;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageValue.java b/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageValue.java
new file mode 100644 (file)
index 0000000..99030c8
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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 <sangho.p@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.platform.baseimage;
+
+import org.tizen.emulator.manager.platform.BaseImage;
+import org.tizen.emulator.manager.platform.Platform;
+
+public class CustomBaseImageValue {
+       private String name = "";
+       private String profile = "";
+       private String platformName = "";
+       private Platform platform = null;
+       private String filePath = "";
+       private String description = "";
+       private boolean isAmendable = false;
+
+       public CustomBaseImageValue() {
+
+       }
+
+       public CustomBaseImageValue(BaseImage image) {
+               name = image.getName();
+               profile = image.getProfile();
+               platformName = image.getPlatformName();
+               platform = image.getPlatform();
+               filePath = image.getPath();
+               description = image.getDescription();
+               // emulator list is empty - you can modify base image properties
+               // emulator list is not empty - you can modify only description
+               setAmendable(image.isEemulatorListEmpty());
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getProfile() {
+               return profile;
+       }
+
+       public void setProfile(String profile) {
+               this.profile = profile;
+       }
+
+       public String getPlatformName() {
+               return platformName;
+       }
+
+       public void setPlatformName(String platformName) {
+               this.platformName = platformName;
+       }
+
+       public Platform getPlatform() {
+               return platform;
+       }
+
+       public void setPlatform(Platform platform) {
+               this.platform = platform;
+       }
+
+       public String getFilePath() {
+               return filePath;
+       }
+
+       public void setFilePath(String filePath) {
+               this.filePath = filePath;
+       }
+
+       public String getDescription() {
+               return description;
+       }
+
+       public void setDescription(String description) {
+               this.description = description;
+       }
+
+       public boolean isAmendable() {
+               return isAmendable;
+       }
+
+       public void setAmendable(boolean isAmendable) {
+               this.isAmendable = isAmendable;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageWorker.java b/src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageWorker.java
new file mode 100644 (file)
index 0000000..7e15722
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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 <sangho.p@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.platform.baseimage;
+
+import java.io.File;
+
+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;
+
+public class CustomBaseImageWorker {
+       private BaseImage image;
+
+       public CustomBaseImageWorker(BaseImage image) {
+               this.image = image;
+       }
+
+       // for old version custom base image
+       public static BaseImage createCustomBaseImage(Platform platform, String path, String name) {
+               BaseImage image = null;
+               image = BaseImage.createCustomBaseImage(platform, path, name);
+               if (image == null) {
+                       return null;
+               }
+
+               image.setID(image.getName());
+               image.setWorker(new CustomBaseImageWorker(image));
+
+               platform.getProfileClass().addBaseImage(image);
+               CustomBaseImageLoader.createBaseImageConfiguration(image);
+
+               return image;
+       }
+
+       public static BaseImage createCustomBaseImage(CustomBaseImageValue value) {
+               BaseImage image = null;
+               image = BaseImage.createCustomBaseImage(value.getPlatform(), value.getFilePath(), value.getName());
+               if (image == null) {
+                       return null;
+               }
+
+               image.setDescription(value.getDescription());
+               image.setID(value.getName());
+               image.setWorker(new CustomBaseImageWorker(image));
+
+               Profile profile = ProfileList.getProfile(value.getProfile());
+               profile.addBaseImage(image);
+               CustomBaseImageLoader.createBaseImageConfiguration(image);
+
+               return image;
+       }
+
+       public boolean modifyCustomBaseImage(CustomBaseImageValue value) {
+               image.setName(value.getName());
+               image.setPath(value.getFilePath());
+               image.setPlatform(value.getPlatform());
+               image.setDescription(value.getDescription());
+               return CustomBaseImageLoader.createBaseImageConfiguration(image);
+       }
+
+       public boolean deleteBaseImageConfiguration(boolean needDeleteFile) {
+               if (image.isEemulatorListEmpty()) {
+                       Profile profile = image.getPlatform().getProfileClass();
+                       profile.removeBaseImage(image);
+               }
+
+               boolean result = CustomBaseImageLoader.deleteBaseImageConfiguration(image);
+
+               if (result && needDeleteFile) {
+                       File file = new File(image.getPath());
+                       file.delete();
+                       for (BaseImage i : CustomBaseImageLoader.getCustomBsaeImageList(false)) {
+                               if (i .getPath().equals(file.getPath())) {
+                                       i .setFilePathExist(false);
+                               }
+                       }
+               }
+
+               return result;
+       }
+}