From: jihye424.kim Date: Tue, 12 May 2015 05:02:52 +0000 (+0900) Subject: Custom Base Image: modify custom base image for custom vm X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d97ac043349bed0d4c7779442eda5d57592ed80a;p=sdk%2Femulator%2Femulator-manager.git Custom Base Image: modify custom base image for custom vm - add isStandard variable to base image - add skin.shape property option to base image - add version information to custom vm (config.xml) Change-Id: I206168a424620ee4f4355c08f0d8a1bbc32dbc1a Signed-off-by: jihye424.kim --- diff --git a/common-project/src/org/tizen/emulator/manager/platform/BaseImage.java b/common-project/src/org/tizen/emulator/manager/platform/BaseImage.java index 169b72b..74cf2c8 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/BaseImage.java +++ b/common-project/src/org/tizen/emulator/manager/platform/BaseImage.java @@ -47,6 +47,7 @@ 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.EmulatorVMList; +import org.tizen.emulator.manager.vms.SKIN_SHAPE; import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.option.IOption; import org.tizen.emulator.manager.vms.option.LaunchConfig; @@ -64,8 +65,11 @@ public class BaseImage { protected String profile; protected String type; protected String cpu; + protected SKIN_SHAPE skinShape; protected String binaryVersion; + protected boolean isStandard; + private String information; protected String lastCreatedPropertyPath; @@ -90,6 +94,8 @@ public class BaseImage { public BaseImage(Platform platform, File path) throws IOException { this.platform = platform; + isStandard = true; + loadProperty(path); settingImagePath(path); initLastCreatedPropertyPath(); @@ -125,6 +131,20 @@ public class BaseImage { lastCreatedPropertyPath = sb.toString(); } + private void checkBaseImageName() throws IOException { + if (imageName == null) { + throw new IOException("Image name is null. This image can not add."); + } + // check duplicate name + for (BaseImage i : platform.getProfileClass().getImageList()) { + if (i.getName().equals(imageName)) { + throw new IOException( + "The same name of the base image already exist." + + "(name: " + imageName + ")"); + } + } + } + private void loadProperty(File path) throws IOException { File f = new File(path + File.separator + StringResources.IMAGE_INFO_FILENAME); FileInputStream inputStream = null; @@ -133,21 +153,15 @@ public class BaseImage { inputStream = new FileInputStream(f); Properties prop = new Properties(); prop.load(inputStream); - if (prop.get("[Meta]") != null) { - loadOldProperty(prop); - } else { - imageName = prop.getProperty(StringResources.IMAGE_NAME); -// imageName = prop.getProperty(StringResources.IMAGE_NAME).toLowerCase(); - if (imageName == null) { - throw new IOException("Image name is null. This image can not add."); - } - version = prop.getProperty(StringResources.IMAGE_VERSION, "2.4"); - profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MobileProfile).toLowerCase(); - type = prop.getProperty(StringResources.IMAGE_TYPE, "default"); - cpu = prop.getProperty(StringResources.TARGET_CPU, "x86"); - cpu = cpu.toLowerCase(); - binaryVersion = prop.getProperty(StringResources.BINARY_VERSION, "1.0.0"); - } + imageName = prop.getProperty(StringResources.IMAGE_NAME); + checkBaseImageName(); + version = prop.getProperty(StringResources.IMAGE_VERSION, "2.4"); + profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MobileProfile).toLowerCase(); + type = prop.getProperty(StringResources.IMAGE_TYPE, "default"); + cpu = prop.getProperty(StringResources.TARGET_CPU, "x86"); + cpu = cpu.toLowerCase(); + skinShape = SKIN_SHAPE.find(prop.getProperty(StringResources.SKIN_SHAPE, "square")); + binaryVersion = prop.getProperty(StringResources.BINARY_VERSION, "1.0.0"); } else { throw new IOException(StringResources.IMAGE_INFO_FILENAME + " file does not exist."); } @@ -163,22 +177,6 @@ public class BaseImage { } } - private void loadOldProperty(Properties prop) throws IOException { -// imageName = prop.getProperty(StringResources.IMAGE_NAME).toLowerCase(); - imageName = prop.getProperty(StringResources.IMAGE_NAME); - if (imageName == null) { - throw new IOException("Image name is null. This image can not add."); - } - version = platform.getName(); - profile = prop.getProperty(StringResources.PRODUCT_OLD_DOMAIN, PlatformStringResources.MobileProfile).toLowerCase(); - if (profile.equals(PlatformStringResources.OldMobileProfile)) { - profile = PlatformStringResources.MobileProfile; - } - type = prop.getProperty(StringResources.IMAGE_TYPE, "default"); - cpu = prop.getProperty(StringResources.TARGET_CPU, "x86"); - cpu = cpu.toLowerCase(); - } - private void settingImagePath(File path) throws IOException { for (File f : path.listFiles()) { if (f.isFile() && f.getName().endsWith(cpu.toLowerCase())) { @@ -355,4 +353,12 @@ public class BaseImage { defaultProperty = vmList.parseXML(propertyFile); } } + + public boolean isStandard() { + return isStandard; + } + + public void setStandard(boolean isStandard) { + this.isStandard = isStandard; + } } diff --git a/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java b/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java index 829dfa5..4f86c5e 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java +++ b/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java @@ -40,6 +40,7 @@ import org.tizen.emulator.manager.resources.FilePathResources; import org.tizen.emulator.manager.resources.StringResources; import org.tizen.emulator.manager.ui.detail.item.OptionType; import org.tizen.emulator.manager.vms.EmulatorVMList; +import org.tizen.emulator.manager.vms.SKIN_SHAPE; 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; @@ -51,20 +52,35 @@ public class CustomBaseImage extends BaseImage { public static ObjectFactory factory = new ObjectFactory(); - public CustomBaseImage(Platform platform, String name, String cpu, String profile) throws IOException { + public CustomBaseImage(Platform platform, String path) throws IOException { + if (platform == null) { + throw new IOException("Failed to create custom base image " + + StringResources.NEW_LINE + "because platform is null."); + } this.platform = platform; + isStandard = false; + + this.path = path; + if (path != null && !path.isEmpty()) { + imageName = pathName = path.substring(path.lastIndexOf(File.separator)); + } + + settingProperty(platform); - this.imageName = name; - this.cpu = cpu; - // TODO - this.profile = profile; - this.version = "0"; - this.binaryVersion = ""; initLastCreatedPropertyPath(); loadProperty(); createTemplate(); } + private void settingProperty(Platform platform) { + version = platform.getVersion(); + profile = platform.getProfile(); + type = "custom"; // TODO + cpu = "x86"; + skinShape = SKIN_SHAPE.NONE; // TODO + binaryVersion = ""; + } + protected void initLastCreatedPropertyPath() { StringBuilder sb = new StringBuilder(); sb.append(FilePathResources.getTizenVmsPath()).append(File.separator) diff --git a/common-project/src/org/tizen/emulator/manager/platform/CustomPlatform.java b/common-project/src/org/tizen/emulator/manager/platform/CustomPlatform.java index 6fa0f70..8790233 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/CustomPlatform.java +++ b/common-project/src/org/tizen/emulator/manager/platform/CustomPlatform.java @@ -41,7 +41,7 @@ public class CustomPlatform extends Platform { this.platformPath = ""; //this.version = name; try { - imageList.add(new CustomBaseImage(this, "x86", "x86", profile)); + imageList.add(new CustomBaseImage(this, "")); // TODO this.profile = imageList.get(0).getProfile(); diff --git a/common-project/src/org/tizen/emulator/manager/platform/Platform.java b/common-project/src/org/tizen/emulator/manager/platform/Platform.java index 6141129..3169c6b 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/Platform.java +++ b/common-project/src/org/tizen/emulator/manager/platform/Platform.java @@ -88,7 +88,7 @@ public class Platform { this.profileClass = profile; this.profile = profile.getName(); this.version = version; - this.platformName = profile + "-" + version; + this.platformName = this.profile + "-" + version; this.platformPath = path; loadSkins(); @@ -138,14 +138,14 @@ public class Platform { if(defaultImages.exists() && defaultImages.isDirectory()) { for (File f : defaultImages.listFiles()) { if (!f.getName().equals("default")) { // skip default directory - makeBaseImage(f); + //makeBaseImage(f); } } } if (oldImages.exists() && oldImages.isDirectory()) { for (File f : oldImages.listFiles()) { - makeBaseImage(f); + //makeBaseImage(f); } } @@ -355,4 +355,12 @@ public class Platform { public void setPlugin(EMPlugin plugin) { this.plugin = plugin; } + + public Profile getProfileClass() { + return profileClass; + } + + public void setProfileClass(Profile profileClass) { + this.profileClass = profileClass; + } } diff --git a/common-project/src/org/tizen/emulator/manager/platform/Profile.java b/common-project/src/org/tizen/emulator/manager/platform/Profile.java index a32e7d9..4f9752e 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/Profile.java +++ b/common-project/src/org/tizen/emulator/manager/platform/Profile.java @@ -30,9 +30,11 @@ package org.tizen.emulator.manager.platform; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.VMProperty.FSImageType; @@ -81,7 +83,6 @@ public class Profile { } public void addEmulator(VMProperty vm) { - vmList.add(vm); //setting BaseImage if (vm.getPropertyValue().baseImage == null) { if (vm.getImageType().equals(FSImageType.standard)) { @@ -93,9 +94,23 @@ public class Profile { } } else { // TODO: create custom base image - vm.getPropertyValue().baseImage = new BaseImage(); + for (Platform p : platformList) { + if (vm.getImagePlatform().equals(p.getName())) { + try { + vm.getPropertyValue().baseImage + = new CustomBaseImage(p, + vm.getBaseImagePath()); + } catch (IOException e) { + EMLogger.getLogger().warning(e.getMessage()); + } + } + } } } + + if (vm.getPropertyValue().baseImage != null) { + vmList.add(vm); + } } public void removeEmulator(VMProperty vm) { diff --git a/common-project/src/org/tizen/emulator/manager/platform/ProfileList.java b/common-project/src/org/tizen/emulator/manager/platform/ProfileList.java index acfc2fc..676664c 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/ProfileList.java +++ b/common-project/src/org/tizen/emulator/manager/platform/ProfileList.java @@ -77,8 +77,13 @@ public class ProfileList { for (File profile : platform.listFiles()) { if (profile.isDirectory() && isProfileDir(profile)) { Profile p = ProfileList.makeProfile(profile.getName()); + String version = platform.getName(); + // delete 'tizen' string from platform directory name + if (version.contains("tizen-")) { + version = version.substring(version.lastIndexOf("-") + 1); + } Platform pl = ProfileList.makePlatform (p, // profile - platform.getName(), // version + version, // version profile.getAbsolutePath()); // platform path ProfileList.makeBaesImageList(p, pl, profile.getAbsolutePath()); } diff --git a/common-project/src/org/tizen/emulator/manager/vms/SKIN_SHAPE.java b/common-project/src/org/tizen/emulator/manager/vms/SKIN_SHAPE.java new file mode 100644 index 0000000..6b3f844 --- /dev/null +++ b/common-project/src/org/tizen/emulator/manager/vms/SKIN_SHAPE.java @@ -0,0 +1,55 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.vms; + +public enum SKIN_SHAPE { + NONE(""), SQUARE("square"), CIRCLE("circle"); + String shape; + + SKIN_SHAPE(String shape) { + this.shape = shape; + } + + @Override + public String toString() { + return shape; + } + + public static SKIN_SHAPE find(String shape) { + for (SKIN_SHAPE s : SKIN_SHAPE.values()) { + if (shape.equals(s.toString())) { + return s; + } + } + // TODO: return null or default value + return SQUARE; + } +} diff --git a/common-project/src/org/tizen/emulator/manager/vms/VMProperty.java b/common-project/src/org/tizen/emulator/manager/vms/VMProperty.java index 1981c46..7eab7cd 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/VMProperty.java +++ b/common-project/src/org/tizen/emulator/manager/vms/VMProperty.java @@ -163,6 +163,15 @@ public class VMProperty { return configuration.getBaseInformation().getDiskImage().getBase(); } + public String getBaseImagePath() { + if (configuration == null + || configuration.getBaseInformation() == null + || configuration.getBaseInformation().getDiskImage() == null) { + return ""; + } + + return configuration.getBaseInformation().getDiskImage().getBaseDiskImage().getValue(); + } public String getChildImagePath() { if(configuration == null || configuration.getBaseInformation() == null || configuration.getBaseInformation().getDiskImage() == null) { @@ -201,25 +210,13 @@ public class VMProperty { } public String getImagePlatform() { - if (getImageType() == FSImageType.custom) { - return FSImageType.custom.toString(); - } else { - String version = getImageVersion(); - String profile = getImageProfile(); - if (version == null) { - return null; - } - - if (version.contains("tizen")) { - return version; - } else { - if (profile == null) { - return version; - } - - return profile + "-" + version; - } + String version = getImageVersion(); + String profile = getImageProfile(); + if (version == null || profile == null) { + return null; } + + return profile + "-" + version; } public EmulatorConfiguration getConfiguration() {