]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
a. Enhanced toolchain setting UI for ModuleSa build options and global build options.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
index 0897ac030beef0b583a77c230e0b55606975d60d..9e2f955599a4130847bee90aac003e4b48a78ad6 100644 (file)
@@ -746,11 +746,15 @@ public class FpdFileContents {
     }\r
     \r
     public String getFvBinding(String moduleKey){\r
-        ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);\r
-        if (msa == null || msa.getModuleSaBuildOptions() == null) {\r
+        ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
+        return getFvBinding (moduleSa);\r
+    }\r
+    \r
+    public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {\r
             return null;\r
         }\r
-        return msa.getModuleSaBuildOptions().getFvBinding();\r
+        return moduleSa.getModuleSaBuildOptions().getFvBinding();\r
     }\r
     \r
     public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {\r
@@ -776,6 +780,23 @@ public class FpdFileContents {
         setFvBinding (moduleSa, fvBinding);\r
     }\r
     \r
+    private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {\r
+        if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {\r
+            return -1;\r
+        }\r
+        \r
+        String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();\r
+        String[] fvNamesArray = fvNameList.split(" ");\r
+        int occursAt = -1;\r
+        for (int i = 0; i < fvNamesArray.length; ++i) {\r
+            if (fvNamesArray[i].equals(fvName)) {\r
+                occursAt = i;\r
+                break;\r
+            }\r
+        }\r
+        return occursAt;\r
+    }\r
+    \r
     public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {\r
         if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {\r
             return;\r
@@ -821,6 +842,37 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public void appendFvBindingAll (String fvName) {\r
+        if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
+            removeElement(getfpdFrameworkModules());\r
+            fpdFrameworkModules = null;\r
+            return;\r
+        }\r
+        \r
+        Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();\r
+        while (li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = li.next();\r
+            appendFvBinding (moduleSa, fvName); \r
+        }\r
+    }\r
+    \r
+    public void appendFvBindingFor (String oldFvName, String newFvName) {\r
+        if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){\r
+            removeElement(getfpdFrameworkModules());\r
+            fpdFrameworkModules = null;\r
+            return;\r
+        }\r
+        \r
+        Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();\r
+        while (li.hasNext()) {\r
+            ModuleSADocument.ModuleSA moduleSa = li.next();\r
+            String fvBinding = getFvBinding (moduleSa);\r
+            if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {\r
+                appendFvBinding (moduleSa, newFvName); \r
+            }\r
+        }\r
+    }\r
+    \r
     public void appendFvBinding (String moduleKey, String fvName) {\r
         ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
         appendFvBinding (moduleSa, fvName);\r
@@ -936,7 +988,9 @@ public class FpdFileContents {
             \r
             if (opt.getSupArchList() != null){\r
                 saa[i][4] = listToString(opt.getSupArchList());\r
-\r
+            }\r
+            else {\r
+                saa[i][4] = "";\r
             }\r
             \r
             saa[i][5] = opt.getStringValue();\r
@@ -1147,7 +1201,7 @@ public class FpdFileContents {
                 fpdPcd.setValue("0");\r
             }\r
             if (dataType.equals("BOOLEAN")){\r
-                fpdPcd.setValue("false");\r
+                fpdPcd.setValue("FALSE");\r
             }\r
             if (dataType.equals("VOID*")) {\r
                 fpdPcd.setValue("");\r
@@ -1602,23 +1656,28 @@ public class FpdFileContents {
     }\r
     \r
     public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {\r
+        QName elementFvName = new QName (xmlNs, "FvName");\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        QName elementInfFileName = new QName(xmlNs, "InfFileName");\r
+        QName elementModule = new QName(xmlNs, "Module");\r
+        \r
         UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();\r
         userExts.setUserID("IMAGES");\r
         userExts.setIdentifier(new BigInteger("1"));\r
         XmlCursor cursor = userExts.newCursor();\r
         cursor.toEndToken();\r
         \r
-        cursor.beginElement("FvName");\r
+        cursor.beginElement(elementFvName);\r
         cursor.insertChars(fvName);\r
         cursor.toNextToken();\r
         \r
-        cursor.beginElement("InfFileName");\r
+        cursor.beginElement(elementInfFileName);\r
         cursor.insertChars(fvName + ".inf");\r
         cursor.toNextToken();\r
         \r
-        cursor.beginElement("IncludeModules");\r
+        cursor.beginElement(elementIncludeModules);\r
         for (int i = 0; i < includeModules.size(); ++i) {\r
-            cursor.beginElement("Module");\r
+            cursor.beginElement(elementModule);\r
             cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);\r
             cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]);\r
             cursor.toEndToken();\r
@@ -1632,6 +1691,7 @@ public class FpdFileContents {
             return -1;\r
         }\r
         ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
         while (li.hasNext()) {\r
             UserExtensionsDocument.UserExtensions ues = li.next();\r
             if (!ues.getUserID().equals("IMAGES")) {\r
@@ -1641,7 +1701,7 @@ public class FpdFileContents {
             cursor.toFirstChild();\r
             String elementName = cursor.getTextValue();\r
             if (elementName.equals(fvName)) {\r
-                cursor.toNextSibling(new QName("", "IncludeModules"));\r
+                cursor.toNextSibling(elementIncludeModules);\r
                 if (cursor.toFirstChild()) {\r
                     int i = 1;\r
                     for (i = 1; cursor.toNextSibling(); ++i);\r
@@ -1660,6 +1720,45 @@ public class FpdFileContents {
         if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
             return;\r
         }\r
+        \r
+        XmlCursor cursor = getfpdBuildOpts().newCursor();\r
+        QName elementUserExts = new QName (xmlNs, "UserExtensions");\r
+        QName attribUserId = new QName ("UserID");\r
+        QName elementFvName = new QName (xmlNs, "FvName");\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        QName attribModuleGuid = new QName("ModuleGuid");\r
+        QName attribBaseName = new QName("BaseName");\r
+        \r
+        if (cursor.toChild(elementUserExts)) {\r
+            do {\r
+                cursor.push();\r
+                if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {\r
+                    cursor.toChild(elementFvName);\r
+                    String elementName = cursor.getTextValue();\r
+                    if (elementName.equals(fvName)) {\r
+                        cursor.toNextSibling(elementIncludeModules);\r
+                        if (cursor.toFirstChild()) {\r
+                            int i = 0;\r
+                            do {\r
+                                saa[i][0] = cursor.getAttributeText(attribModuleGuid);\r
+                                saa[i][1] = cursor.getAttributeText(attribBaseName);\r
+                                ++i;\r
+                            }while (cursor.toNextSibling());\r
+                        }\r
+                        break;\r
+                    }\r
+                }\r
+                cursor.pop();\r
+            }while (cursor.toNextSibling(elementUserExts));\r
+        }\r
+        cursor.dispose();\r
+        \r
+    }\r
+    \r
+    public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {\r
+        if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
+            return;\r
+        }\r
         ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
         while (li.hasNext()) {\r
             UserExtensionsDocument.UserExtensions ues = li.next();\r
@@ -1669,18 +1768,8 @@ public class FpdFileContents {
             XmlCursor cursor = ues.newCursor();\r
             cursor.toFirstChild();\r
             String elementName = cursor.getTextValue();\r
-            if (elementName.equals(fvName)) {\r
-                cursor.toNextSibling(new QName("", "IncludeModules"));\r
-                if (cursor.toFirstChild()) {\r
-                    int i = 0;\r
-                    do {\r
-                        saa[i][0] = cursor.getAttributeText(new QName("ModuleGuid"));\r
-                        saa[i][1] = cursor.getAttributeText(new QName("BaseName"));\r
-                        ++i;\r
-                    }while (cursor.toNextSibling());\r
-                }\r
-                cursor.dispose();\r
-                return;\r
+            if (elementName.equals(oldFvName)) {\r
+                cursor.setTextValue(newFvName);\r
             }\r
             cursor.dispose();\r
         }\r
@@ -2501,6 +2590,43 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {\r
+        FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
+        if (fis == null || fis.getFvImageList() == null) {\r
+            return;\r
+        }\r
+        \r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            if (fi.getType().toString().equals("ImageName")) {\r
+                vImageNames.addAll(fi.getFvImageNamesList());\r
+                return;\r
+            }\r
+        }\r
+    }\r
+    \r
+    public void AddFvImageFvImageNames (String[] fvNames) {\r
+        FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
+        if (fis == null || fis.getFvImageList() == null) {\r
+            genFvImagesFvImage (fvNames, "ImageName", null);\r
+            return;\r
+        }\r
+        \r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            if (fi.getType().toString().equals("ImageName")) {\r
+                for (int i = 0; i < fvNames.length; ++i) {\r
+                    fi.addFvImageNames(fvNames[i]);\r
+                }\r
+                return;\r
+            }\r
+        }\r
+        genFvImagesFvImage (fvNames, "ImageName", null);\r
+        \r
+    }\r
+    \r
     public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
       \r
         FvImagesDocument.FvImages fis = null;\r
@@ -2560,6 +2686,52 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
+    /**\r
+     * @param oldFvName\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
+    public void updateFvImageNameAll (String oldFvName, String newFvName) {\r
+        if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
+            return;\r
+        }\r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            updateFvImageNamesInFvImage (fi, oldFvName, newFvName);\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * @param fi\r
+     * @param oldFvName The FV Name to be replaced.\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
+    public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {\r
+        QName qFvImageNames = new QName(xmlNs, "FvImageNames");\r
+        XmlCursor cursor = fi.newCursor();\r
+        \r
+        if (cursor.toChild(qFvImageNames)) {\r
+            do {\r
+                if (cursor.getTextValue().equals(oldFvName)){\r
+                    if (newFvName != null) {\r
+                        cursor.setTextValue(newFvName);\r
+                    }\r
+                    else {\r
+                        if (fi.getFvImageNamesList().size() == 1) {\r
+                            removeElement(fi);\r
+                            break;\r
+                        }\r
+                        else {\r
+                            cursor.removeXml();\r
+                        }\r
+                    }\r
+                }\r
+            }while (cursor.toNextSibling(qFvImageNames));\r
+        }\r
+        \r
+        cursor.dispose();\r
+    }\r
+    \r
     public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
            \r
         XmlObject o = getfpdFlash().getFvImages();\r
@@ -2600,18 +2772,50 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
-    public int getFvImagesFvImageCount() {\r
+    public int getFvImagesFvImageCount(String type) {\r
         \r
         if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
             return 0;\r
         }\r
-        return getfpdFlash().getFvImages().getFvImageList().size();\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        int i = 0;\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            \r
+            ++i;\r
+        }\r
+        \r
+        return i;\r
     }\r
     \r
-    /**Only Get Fv image setting - name and type.\r
+    public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();\r
+        if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
+            return vFvImage;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (fi.getFvImageNamesList().contains(fvName)) {\r
+                vFvImage.add(fi);\r
+            }\r
+        }\r
+        \r
+        return vFvImage;\r
+    }\r
+    /**\r
      * @param saa\r
+     * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.\r
      */\r
-    public void getFvImagesFvImages(String[][] saa) {\r
+    public void getFvImagesFvImages(String[][] saa, String type) {\r
     \r
         if (getfpdFlash().getFvImages() == null) {\r
             return;\r
@@ -2624,6 +2828,9 @@ public class FpdFileContents {
         int i = 0;\r
         while(li.hasNext()) {\r
             FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
             //\r
             // get FvImageNames array, space separated\r
             //\r
@@ -2642,6 +2849,108 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    /**Add name-value pair to FvImage element with type.\r
+     * @param fvName FV name to add name-value pair.\r
+     * @param type FvImage attribute.\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (!fi.getFvImageNamesList().contains(fvName)) {\r
+                continue;\r
+            }\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+    }\r
+    \r
+    /**Add to all FvImage elements with type, the name-value pair.\r
+     * @param type\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedFvImageNameValue (String type, String name, String value) {\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+    }\r
+    \r
+    /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.\r
+     * @param fi\r
+     * @param name\r
+     * @param value\r
+     * @param newName\r
+     */\r
+    public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {\r
+        if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+            return;\r
+        }\r
+        \r
+        XmlCursor cursor = fi.getFvImageOptions().newCursor();\r
+        if (cursor.toFirstChild()) {\r
+            do {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();\r
+                if (nv.getName().equals(name)) {\r
+                    nv.setValue(value);\r
+                    if (newName != null) {\r
+                        nv.setName(newName);\r
+                    }\r
+                    cursor.dispose();\r
+                    return;\r
+                }\r
+            }while (cursor.toNextSibling());\r
+        }\r
+        \r
+        FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();\r
+        nv.setName(name);\r
+        nv.setValue(value);\r
+        if (newName != null) {\r
+            nv.setName(newName);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");\r
+        for (int i = 0; i < vFvImage.size(); ++i) {\r
+            FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);\r
+            if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+                continue;\r
+            }\r
+\r
+            ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()\r
+                                                                                            .getNameValueList()\r
+                                                                                            .listIterator();\r
+            while (li.hasNext()) {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
+                m.put(nv.getName(), nv.getValue());\r
+            }\r
+        }\r
+    }\r
     /**Get FvImage Options for FvImage i\r
      * @param i the ith FvImage\r
      */\r