VM-create: change setting device-template.
authorminkee.lee <minkee.lee@samsung.com>
Wed, 11 Nov 2015 02:30:44 +0000 (11:30 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Wed, 11 Nov 2015 02:30:44 +0000 (11:30 +0900)
When template's value (SubDevice) is copied to VMProperty (VMOption),
value should be exist in item-list.
If value is not exist in item-list, it is not copied.

Change-Id: I616c5607203df8d8bbf2462f3de3a30264649f61
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
src/org/tizen/emulator/manager/platform/BaseImage.java
src/org/tizen/emulator/manager/plugin/EMPlugin.java
src/org/tizen/emulator/manager/template/renewal/TemplateLoader.java
src/org/tizen/emulator/manager/template/renewal/VmItem.java
src/org/tizen/emulator/manager/vms/VMPropertyValue.java
src/org/tizen/emulator/manager/vms/option/ConnectivityOption.java
src/org/tizen/emulator/manager/vms/option/LaunchConfig.java
xsd/x86-standard-template-v2.xml

index 54e99a5..c2a548c 100644 (file)
@@ -44,6 +44,7 @@ import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.template.ITemplate;
+import org.tizen.emulator.manager.template.renewal.VmItem;
 import org.tizen.emulator.manager.template.renewal.VmTemplate;
 import org.tizen.emulator.manager.template.renewal.VmTemplateUtil;
 import org.tizen.emulator.manager.ui.renewal.dialoghandler.VMModifyHandler;
@@ -108,6 +109,9 @@ public class BaseImage {
        // for custom base image
        private List<VMProperty> emulatorList = new ArrayList<VMProperty>();
 
+       // It contains available item list (experimental checked, os version checked,,,)
+       private List<VmItem> vmItemList = null;
+
        protected BaseImage() {
        }
 
@@ -536,12 +540,22 @@ public class BaseImage {
                        EMLogger.getLogger().info("Use CommonOptionFactory.");
                }
 
-               VmTemplate template = platform.findTemplate(imageName);
-               if (template == null) {
-                       EMLogger.getLogger().warning("No template found");
-                       return;
+               optionList = f.makeOptionList(getVmItemList());
+       }
+
+
+       public List<VmItem> getVmItemList() {
+               if (vmItemList == null) {
+                       VmTemplate template = platform.findTemplate(imageName);
+                       if (template == null) {
+                               EMLogger.getLogger().warning("No template found");
+                               vmItemList = new ArrayList<VmItem>();
+                       }
+                       vmItemList = VmTemplateUtil.getAvailableItemList(template);
                }
-               optionList = f.makeOptionList(VmTemplateUtil.getAvailableItemList(template));
+
+               return vmItemList;
+
        }
 
        @Override
index a63ec11..4f92367 100644 (file)
@@ -72,11 +72,11 @@ public class EMPlugin {
        }
 
        private String platformName;
-       private String platformPath;
-       private File pluginJar;
-       private Attributes attr;
+       private final String platformPath;
+       private final File pluginJar;
+       private final Attributes attr;
        private URLClassLoader loader;
-       private ArrayList<ExtensionItem> exItemList
+       private final ArrayList<ExtensionItem> exItemList
                = new ArrayList<ExtensionItem>();
        private EMPlugin parentPlugin;
 
@@ -118,8 +118,8 @@ public class EMPlugin {
                        if (item != null) {
                                exItemList.add(item);
                        } else {
-                               EMLogger.getLogger().info("This plugin does not have " + ex //$NON-NLS-1$
-                                               + " extension point."); //$NON-NLS-1$
+                               EMLogger.getLogger().info(platform.getName() + "'s plugin does not have " + ex //$NON-NLS-1$
+                                               + " extension point. "); //$NON-NLS-1$
                        }
                }
                return true;
index f1d3cd2..7f4c9a4 100644 (file)
@@ -73,9 +73,11 @@ public class TemplateLoader {
                        if (f.getName().contains(PlatformStringResources.TEMPLATE)) { // ui template file for detail view
                                VmTemplate vmTemplate = loadTemplate(f);
                                if (!checkTemplate(vmTemplate)) {
+                                       EMLogger.getLogger().info(f.getName() + " is not valid for "+ platform.getName());
                                        continue;
                                }
 
+                               EMLogger.getLogger().info(f.getName() + " is loaded for "+ platform.getName());
                                platform.getTemplateList().add(vmTemplate);
 
                                // setting default item list
@@ -99,7 +101,7 @@ public class TemplateLoader {
 
                // check default template
                if (platform.getDefaultTemplate() == null) {
-                       EMLogger.getLogger().info("No default template found..");
+                       EMLogger.getLogger().info("No default template found for " + platform.getName());
                        loadBaseTemplate(platform);
                }
 
@@ -112,7 +114,7 @@ public class TemplateLoader {
                        return;
                }
                platform.setDefaultTemplate(vmTemplate);
-               EMLogger.getLogger().info("Load template from " + f.getAbsolutePath());
+               EMLogger.getLogger().info(platform.getName() + " load template from " + f.getAbsolutePath());
        }
 
        private static boolean checkTemplate(VmTemplate template) {
index 221a866..c4f051a 100644 (file)
@@ -65,6 +65,11 @@ public class VmItem {
                return str;
        }
 
+       @Override
+       public String toString() {
+               return toString("");
+       }
+
        // following getter must not be changed.
        public String getName() {
                return name;
index 75298dd..8fa1cf3 100644 (file)
@@ -43,6 +43,8 @@ import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.platform.BaseImage;
 import org.tizen.emulator.manager.platform.Skin;
 import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.template.renewal.VmItem;
+import org.tizen.emulator.manager.ui.renewal.item.ItemName;
 import org.tizen.emulator.manager.vms.xml.OptionType;
 
 
@@ -395,32 +397,55 @@ public class VMPropertyValue implements Cloneable {
                this.cpu = value.getCpuCount();
                this.ramSize = value.getRamSize();
 
-               // TODO: device -> connectivity, camera
-               for (SubDevice subDevice : value.getAdditionalDevices()) {
-                       for (VMOption option : advancedVMOptionList) {
-                               if (option.getName().equals(subDevice.getName())) {
-                                       settionOption(subDevice, option);
-                               }
+
+               // find device-template sub item.
+               List<VmItem> deviceTemplateItems = null;
+               for (VmItem vmItem : baseImage.getVmItemList()) {
+                       if (vmItem.getName().equals(ItemName.DEVICE_TEMPLATE)) {
+                               deviceTemplateItems = vmItem.getSubItems();
                        }
                }
+               if (deviceTemplateItems == null) {
+                       // if device-template sub items not exist..?
+                       deviceTemplateItems = baseImage.getVmItemList();
+               }
+
+               // Set addtional VMOptions
+               // TODO:  camera
+               for (SubDevice subDevice : value.getAdditionalDevices()) {
+                       setAdditionalOptions(deviceTemplateItems, subDevice);
+               }
        }
 
-       private void settionOption(SubDevice device, VMOption option) {
-               // setting sensor, connectivity
-               for (SubDeviceItem item : device.getItems()) {
-                       for(VMSubOption type : option.getSubOptionList()) {
-                               if (item.getId().equals(type.getName())) {
-                                       if (item.isSupport()) {
-                                               type.setValue("on");
-                                       } else {
-                                               type.setValue("off");
+
+       private void setAdditionalOptions(List<VmItem> deviceTemplateItems,
+                       SubDevice device) {
+               // Set subOptions
+               //  if SubDevice is exist in item-template(VmItem list).
+               //  (and if SubDeviceItem is in VmItem's sub-item list)
+
+               for (VmItem vmItem : deviceTemplateItems) {
+
+                       // if SubDevice is in VmItem list
+                       if (vmItem.getName().equals(device.getName())) {
+                               String name = device.getName();
+                               for (SubDeviceItem subItem : device.getItems()) {
+                                       for (VmItem subVmItem : vmItem.getSubItems()) {
+
+                                               // if subDeviceItem is in VmItem's sub-item list
+                                               if (subVmItem.getName().equals(subItem.getId())) {
+                                                       setAdvancedOptionSub(name, subItem.getId(),
+                                                                       subItem.isSupport() ? "on" : "off");
+                                               }
+                                               break;
                                        }
-                                       break;
                                }
+                               break;
                        }
                }
        }
 
+
        // for plug-in -> will be deleted
        @ Deprecated
        public OptionType getAdvancedOption(String optionName) {
index 88e77bf..eb32d7a 100644 (file)
@@ -40,7 +40,9 @@ public class ConnectivityOption extends Option {
                // for nfc
                if (checkOn(property.getPropertyValue().getAdvancedOptionSubValue(
                                ItemName.CONNECTIVITY, ItemName.NFC))) {
-                       config.addQemuOption("-device", "virtio-maru-nfc-pci"); //$NON-NLS-1$ //$NON-NLS-2$
+                       String nfcOption = isGreaterThanOrEqualTo(property.getImageVersion(), "3.0") ?
+                                       "virtio-maru-nfc-pci" : "virtio-nfc-pci";
+                       config.addQemuOption("-device", nfcOption); //$NON-NLS-1$ //$NON-NLS-2$
                }
        }
 }
index 9bbe6ea..d23c4e6 100644 (file)
@@ -157,7 +157,8 @@ public class LaunchConfig {
                        bw.newLine();
                        String comment = null;
                        String var = null;
-                       for (OPTION_KEY key : OPTION_KEY.values()) {
+                       for (OPTION_KEY optionKey : OPTION_KEY.values()) {
+                               String key = optionKey.toString();
                                if ( (comment = varComment.get(key)) != null) {
                                        bw.write(comment);
                                        bw.newLine();
index 7370ac1..a1b4c41 100644 (file)
                                <item name="nfc" title="NFC" type="checkbox" />
                                <option name="numColumn">2</option>
                        </item>
-                       <item name="camera" title="Camera" type="checkLabel">
-                               <item name="rear" title="Rear" type="checkbox" />
-<!--                           <item name="front" title="Front" type="checkbox" /> -->
-                               <option name="numColumn">2</option>
-                       </item>
                        <item name="camera" title="Camera" type="label" >
 <!--                                   <item type="combo" name="frontType" title="Front"/> -->
 <!--                                   <item type="file" name="frontImage" title="(image)"/> -->
                        <option name="v1.1_v2.0">v1.1 &amp; v2.0</option>
                        <option name="supportOS">mac</option>
                </item>
-               <item name="viewer" title="Viewer" type="label" >
-                       <item name="type" title="Type" type="combo">
-                               <option name="list">Native, Web</option>
-                               <option name="experimental">true</option>
-                               <option name="defaultOnCreate">Native</option>
-                       </item>
+               <item name="viewer" title="Viewer" type="combo" >
+                       <option name="list">Native, Web</option>
+                       <option name="experimental">true</option>
+                       <option name="defaultOnCreate">Native</option>
+               </item>
+               <item name="displayMode" title="Display Mode" type="combo" >
+                       <option name="list">Native, Web</option>
+                       <option name="experimental">true</option>
+                       <option name="defaultOnCreate">Native</option>
                </item>
        </itemGroup>