]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Fixed the Indentifier type issue.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
index b15e5d28d8ddebdba0920722c9d3cc5670fa5459..d8dfb279ba59f2228a4fce57ceb13b79fb57ad91 100644 (file)
@@ -62,6 +62,7 @@ import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
 import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
+import org.tianocore.frameworkwizard.workspace.Workspace;\r
 \r
 /**\r
  This class processes fpd file contents such as add remove xml elements. \r
@@ -115,8 +116,8 @@ public class FpdFileContents {
               if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {\r
                   continue;\r
               }\r
-              String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() +\r
-               " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());\r
+              String ModuleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() +\r
+               " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());\r
               List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();\r
               ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();\r
               while (lpi.hasNext()) {\r
@@ -358,6 +359,9 @@ public class FpdFileContents {
                 if (!cursor.isText()) {\r
                     break;\r
                 }\r
+                if (cursor.getObject() == null) {\r
+                    break;\r
+                }\r
                 String s = cursor.getTextValue();\r
                 if (s.matches(regExpNewLineAndSpaces)) {\r
                     continue;\r
@@ -371,22 +375,24 @@ public class FpdFileContents {
             cursor.pop();\r
             cursor.removeXml();\r
             if (getFrameworkModulesCount() == 0) {\r
-                cursor.toParent();\r
-                cursor.removeXml();\r
+                cursor.dispose();\r
+                removeElement(getfpdFrameworkModules());\r
+                fpdFrameworkModules = null;\r
+                return;\r
             }\r
         }\r
         cursor.dispose();\r
     }\r
     \r
-    public boolean adjustPcd (int seqModuleSa) throws Exception {\r
+    public boolean adjustPcd (int seqModuleSa, Vector<String> vExceptions) throws Exception {\r
         boolean dataModified = false;\r
         ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);\r
         int pcdCount = getPcdDataCount(seqModuleSa);\r
         String[][] saaModuleSaPcd = new String[pcdCount][7];\r
         getPcdData(seqModuleSa, saaModuleSaPcd);\r
-        String mg = moduleSa.getModuleGuid();\r
+        String mg = moduleSa.getModuleGuid().toLowerCase();\r
         String mv = moduleSa.getModuleVersion();\r
-        String pg = moduleSa.getPackageGuid();\r
+        String pg = moduleSa.getPackageGuid().toLowerCase();\r
         String pv = moduleSa.getPackageVersion();\r
         String arch = listToString(moduleSa.getSupArchList());\r
         //\r
@@ -397,6 +403,10 @@ public class FpdFileContents {
         String[][] saaLib = new String[libCount][5];\r
         getLibraryInstances(moduleKey, saaLib);\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
+        if (mi == null) {\r
+            vExceptions.add("Module " + mg + " does NOT exist in workspace.");\r
+            throw new Exception ("Module does NOT exist in workspace.");\r
+        }\r
         Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();\r
         //\r
         // create vector for module & library instance MIs.\r
@@ -405,14 +415,19 @@ public class FpdFileContents {
         for (int j = 0; j < saaLib.length; ++j) {\r
             String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];\r
             ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);\r
-            vMi.add(libMi);\r
+            if (libMi != null) {\r
+                vMi.add(libMi);\r
+            }\r
         }\r
         \r
     nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {\r
 \r
                 for (int j = 0; j < vMi.size(); ++j) {\r
                     ModuleIdentification nextMi = vMi.get(j);\r
-                    if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) {\r
+                    if (nextMi == null) {\r
+                        continue;\r
+                    }\r
+                    if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], arch, nextMi)) {\r
                         continue nextPcd;\r
                     }\r
                 }\r
@@ -435,11 +450,18 @@ public class FpdFileContents {
                     ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());\r
                     if (al != null) {\r
                         for (int j = 0; j < al.size(); ++j) {\r
-                            if (al.get(j).contains(moduleKey)) {\r
+                            if (al.get(j).startsWith(moduleKey)) {\r
                                 continue msaPcdIter;\r
                             }\r
                         }\r
                     }\r
+                    // Check sup arch conformance for the new PCD\r
+                    if (msaPcd.getSupArchList() != null) {\r
+                       String newPcdArch = msaPcd.getSupArchList().toString();\r
+                       if (!newPcdArch.toLowerCase().contains(arch.toLowerCase())) {\r
+                               continue;\r
+                       }\r
+                    }\r
                     \r
                     PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));\r
                     PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
@@ -447,8 +469,13 @@ public class FpdFileContents {
                         //\r
                         // ToDo Error \r
                         //\r
-                        throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "\r
-                                                  + mi.getName());\r
+                        String errorMessage = "No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "\r
+                        + mi.getName();\r
+                        if (i != 0) {\r
+                            errorMessage += " Library Instance " + vMi.get(i).getName(); \r
+                        }\r
+                        vExceptions.add(errorMessage);\r
+                        throw new PcdDeclNotFound(errorMessage);\r
                     }\r
                     //\r
                     // AddItem to ModuleSA PcdBuildDefinitions\r
@@ -457,7 +484,7 @@ public class FpdFileContents {
                                                                         : msaPcd.getDefaultValue();\r
 \r
                     genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),\r
-                               msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);\r
+                               msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd);\r
                     dataModified = true;\r
                  }\r
 \r
@@ -475,7 +502,7 @@ public class FpdFileContents {
         String[] s = moduleInfo.split(" ");\r
         for(int i = 0; i < al.size(); ++i){\r
             String consumer = al.get(i);\r
-            if (consumer.contains(s[0]) && consumer.contains(s[2])){\r
+            if (consumer.contains(s[0].toLowerCase()) && consumer.contains(s[2].toLowerCase())){\r
                 String[] consumerPart = consumer.split(" ");\r
                 if (!consumerPart[4].equals(s[4])) {\r
                     continue;\r
@@ -573,12 +600,21 @@ public class FpdFileContents {
                     //\r
                     // change item type while not updating dynPcdData????\r
                     //\r
-                    pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
-                    if(pcdData.getDatumType().equals("VOID*")) {\r
+                    if (itemType != null) {\r
+                        pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
+                    }\r
+                    \r
+                    if(pcdData.getDatumType().equals("VOID*") && maxSize != null) {\r
                         pcdData.setMaxDatumSize(new Integer(maxSize));\r
                     }\r
-                    pcdData.setValue(value);\r
-                    defaultPcdValue.put(cName + " " + tsGuid, value);\r
+                    //\r
+                    // if value input is null, keep old value untouched.\r
+                    //\r
+                    if (value != null) {\r
+                        pcdData.setValue(value);\r
+                        defaultPcdValue.put(cName + " " + tsGuid, value);\r
+                    }\r
+                    \r
                     break;\r
                 }\r
             }\r
@@ -593,54 +629,49 @@ public class FpdFileContents {
      * @param sa Results: HelpText, Original item type.\r
      * @return\r
      */\r
-    public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{\r
-        try {\r
-           \r
-            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);\r
-            if (msa.getPcdCoded() == null) {\r
-                return false;\r
+    public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa, Vector<String> validPcdTypes) throws Exception{\r
+       \r
+        ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile\r
+                                                                                                                        .getModuleXmlObject(mi);\r
+        if (msa.getPcdCoded() == null) {\r
+            return false;\r
+        }\r
+\r
+        PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
+        //\r
+        // First look through MSA pcd entries.\r
+        //\r
+        List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
+        ListIterator li = l.listIterator();\r
+        while (li.hasNext()) {\r
+            PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();\r
+            if (!msaPcd.getCName().equals(cName)) {\r
+                continue;\r
             }\r
-            \r
-            Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
-            m.put("ModuleSurfaceArea", msa);\r
-            SurfaceAreaQuery.setDoc(m);\r
-            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
-            //\r
-            // First look through MSA pcd entries.\r
-            //\r
-            List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
-            ListIterator li = l.listIterator();\r
-            while(li.hasNext()) {\r
-                PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
-                if (!msaPcd.getCName().equals(cName)) {\r
-                    continue;\r
-                }\r
-                if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {\r
-                    continue;\r
-                }\r
-                PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
-                if (spdPcd == null) {\r
-                    //\r
-                    // ToDo Error \r
-                    //\r
-                    throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());\r
-                }\r
+            if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {\r
+                continue;\r
+            }\r
+            PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
+            if (spdPcd == null || spdPcd.getValidUsage() == null) {\r
                 //\r
-                // Get Pcd help text and original item type.\r
+                // ToDo Error \r
                 //\r
-                sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();\r
-                sa[1] = msaPcd.getPcdItemType()+"";\r
-                sa[2] = msa.getModuleDefinitions().getBinaryModule()+"";\r
-                return true;\r
+                throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());\r
             }\r
-            \r
-            \r
-        }\r
-        catch (Exception e){\r
-            e.printStackTrace();\r
-            throw e;\r
+            //\r
+            // Get Pcd help text and original item type.\r
+            //\r
+            sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();\r
+            sa[1] = msaPcd.getPcdItemType() + "";\r
+            sa[2] = msa.getModuleDefinitions().getBinaryModule() + "";\r
+            ListIterator iter = spdPcd.getValidUsage().listIterator();\r
+            while (iter.hasNext()) {\r
+                String usage = iter.next().toString();\r
+                validPcdTypes.add(usage);\r
+            }\r
+            return true;\r
         }\r
-        \r
+\r
         return false;\r
     }\r
     \r
@@ -662,7 +693,7 @@ public class FpdFileContents {
         \r
         int pcdSourceCount = 0;\r
         for (int i = 0; i < vMi.size(); ++i) {\r
-            if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) {\r
+            if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, null, vMi.get(i))) {\r
                 pcdSourceCount++;\r
             }\r
         }\r
@@ -806,7 +837,7 @@ public class FpdFileContents {
         XmlCursor cursor = instance.newCursor();\r
         try{\r
             String comment = "Pkg: " + pn + " Mod: " + mn \r
-                + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
+                + " Path: " + libMi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);\r
             cursor.insertComment(comment);\r
         }\r
         catch (Exception e){\r
@@ -1137,46 +1168,45 @@ public class FpdFileContents {
     public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {\r
         //ToDo add Arch filter\r
         \r
-        try {\r
-            if (moduleSa == null) {\r
-                moduleSa = genModuleSA(mi, arch);\r
-            }\r
-            \r
-            ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);\r
-            if (msa.getPcdCoded() == null) {\r
-                return;\r
-            }\r
-            \r
-            Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
-            m.put("ModuleSurfaceArea", msa);\r
-            SurfaceAreaQuery.setDoc(m);\r
-            PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
-            //\r
-            // Implementing InitializePlatformPcdBuildDefinitions\r
-            //\r
-            List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
-            ListIterator li = l.listIterator();\r
-            while(li.hasNext()) {\r
-                PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
-                PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
-                if (spdPcd == null) {\r
-                    //\r
-                    // ToDo Error \r
-                    //\r
-                    throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());\r
-                }\r
+        if (moduleSa == null) {\r
+            moduleSa = genModuleSA(mi, arch);\r
+        }\r
+\r
+        ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile\r
+                                                                                                                        .getModuleXmlObject(mi);\r
+        if (msa.getPcdCoded() == null) {\r
+            return;\r
+        }\r
+\r
+        PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);\r
+        //\r
+        // Implementing InitializePlatformPcdBuildDefinitions\r
+        //\r
+        List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
+        ListIterator li = l.listIterator();\r
+        while (li.hasNext()) {\r
+            PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();\r
+            if (msaPcd.getSupArchList() != null) {\r
+               if (!msaPcd.getSupArchList().toString().toLowerCase().contains(arch.toLowerCase())) {\r
+                       continue;\r
+               }\r
+            }\r
+            PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
+            if (spdPcd == null) {\r
                 //\r
-                // AddItem to ModuleSA PcdBuildDefinitions\r
+                // ToDo Error \r
                 //\r
-                String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();\r
-                \r
-                genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);\r
+                throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + "\n used by Module "\r
+                                          + mi.getName() + " or its Library Instances.");\r
             }\r
-            \r
-        }\r
-        catch (Exception e){\r
-            \r
-            throw e; \r
+            //\r
+            // AddItem to ModuleSA PcdBuildDefinitions\r
+            //\r
+            String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();\r
+\r
+            genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType()\r
+                                                                                                    .toString(),\r
+                       spdPcd.getDatumType() + "", defaultVal, moduleSa, spdPcd);\r
         }\r
         \r
     }\r
@@ -1215,7 +1245,7 @@ public class FpdFileContents {
         XmlCursor cursor = msa.newCursor();\r
         try{\r
             String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "\r
-                            + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
+                            + mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);\r
             cursor.insertComment(comment);\r
         }\r
         catch(Exception e){\r
@@ -1237,7 +1267,25 @@ public class FpdFileContents {
         return msa;\r
     }\r
     \r
-    private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) \r
+    private String chooseDefaultPcdType (List validPcdTypes) {\r
+        String choosedType = "";\r
+        if (validPcdTypes.contains("FIXED_AT_BUILD")) {\r
+            choosedType = "FIXED_AT_BUILD";\r
+        }\r
+        else if (validPcdTypes.contains("DYNAMIC")) {\r
+            choosedType = "DYNAMIC";\r
+        }\r
+        else if (validPcdTypes.contains("PATCHABLE_IN_MODULE")) {\r
+            choosedType = "PATCHABLE_IN_MODULE";\r
+        }\r
+        else if (validPcdTypes.contains("DYNAMIC_EX")) {\r
+            choosedType = "DYNAMIC_EX";\r
+        }\r
+        return choosedType;\r
+    }\r
+    \r
+    private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, \r
+                             ModuleSADocument.ModuleSA moduleSa, PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd) \r
     throws PcdItemTypeConflictException, PcdValueMalFormed{\r
         if (moduleSa.getPcdBuildDefinition() == null){\r
             moduleSa.addNewPcdBuildDefinition();\r
@@ -1261,12 +1309,43 @@ public class FpdFileContents {
                 return;\r
             }\r
         }\r
+        // if pcd type from MSA file is Dynamic\r
+        // we must choose one default type from SPD file for it.\r
+        //\r
+        List validPcdTypes = spdPcd.getValidUsage();\r
         //\r
         // Using existing Pcd type, if this pcd already exists in other ModuleSA\r
         //\r
         if (pcdConsumer.size() > 0) {\r
+            //\r
+            // platform should only contain one type for each pcd.\r
+            //\r
+            String existingItemType = itemType (pcdConsumer.get(0));\r
+            for (int i = 1; i < pcdConsumer.size(); ++i) {\r
+                if (!existingItemType.equals(itemType(pcdConsumer.get(i)))) {\r
+                    throw new PcdItemTypeConflictException (cName, pcdConsumer.get(0), pcdConsumer.get(i));\r
+                }\r
+            }\r
             \r
-            itemType = itemType (pcdConsumer.get(0));\r
+            if (itemType.equals("DYNAMIC")) {\r
+                if (!validPcdTypes.contains(existingItemType)) {\r
+                    throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0));\r
+                }\r
+                itemType = existingItemType;\r
+            }\r
+            else {\r
+                if (!itemType.equals(existingItemType)) {\r
+                    throw new PcdItemTypeConflictException(cName, pcdConsumer.get(0));\r
+                }\r
+            }\r
+        }\r
+        //\r
+        // if this is the first occurence of this pcd. \r
+        //\r
+        else {\r
+            if (itemType.equals("DYNAMIC")) {\r
+                itemType = chooseDefaultPcdType (validPcdTypes);\r
+            }\r
         }\r
         String listValue = moduleInfo + " " + itemType;\r
         pcdConsumer.add(listValue);\r
@@ -1279,7 +1358,7 @@ public class FpdFileContents {
         fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
         fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));\r
         \r
-        if (defaultVal != null){\r
+        if (defaultVal != null && defaultVal.length() > 0){\r
             fpdPcd.setValue(defaultVal);\r
         }\r
         else {\r
@@ -1290,7 +1369,7 @@ public class FpdFileContents {
                 fpdPcd.setValue("FALSE");\r
             }\r
             if (dataType.equals("VOID*")) {\r
-                fpdPcd.setValue("");\r
+                fpdPcd.setValue("L\"\"");\r
             }\r
         }\r
         //\r
@@ -1441,7 +1520,7 @@ public class FpdFileContents {
             saa[i][1] = dynPcd.getToken().toString();\r
             saa[i][2] = dynPcd.getTokenSpaceGuidCName();\r
             saa[i][3] = dynPcd.getMaxDatumSize()+"";\r
-            saa[i][4] = dynPcd.getDatumType().toString();\r
+            saa[i][4] = dynPcd.getDatumType()+"";\r
             \r
             ++i;\r
         }\r
@@ -1517,7 +1596,10 @@ public class FpdFileContents {
                 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
                     \r
                     if (getDynamicPcdBuildDataCount() == 1) {\r
-                        cursor.toParent();\r
+                        cursor.dispose();\r
+                        removeElement(o);\r
+                        fpdDynPcdBuildDefs = null;\r
+                        return;\r
                     }\r
                     cursor.removeXml();\r
                     cursor.dispose();\r
@@ -1534,6 +1616,8 @@ public class FpdFileContents {
     public int getDynamicPcdSkuInfoCount(int i){\r
         if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null \r
                         || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {\r
+            removeElement(getfpdDynPcdBuildDefs());\r
+            fpdDynPcdBuildDefs = null;\r
             return 0;\r
         }\r
         \r
@@ -1661,9 +1745,10 @@ public class FpdFileContents {
                 return;\r
             }\r
             else {\r
-                QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r
-                cursor.toChild(qSkuInfo);\r
-                cursor.removeXml();\r
+               pcdData.getSkuInfoList().clear();\r
+//                QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r
+//                cursor.toChild(qSkuInfo);\r
+//                cursor.removeXml();\r
             }\r
         }\r
         cursor.dispose();\r
@@ -1702,9 +1787,11 @@ public class FpdFileContents {
     \r
     public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
                                                  String hiiDefault, String vpdOffset, String value, int i){\r
-//        if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
-//            return;\r
-//        }\r
+        if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
+            removeElement(getfpdDynPcdBuildDefs());\r
+            fpdDynPcdBuildDefs = null;\r
+            return;\r
+        }\r
         \r
         XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
         if (cursor.toFirstChild()) {\r
@@ -1741,15 +1828,15 @@ public class FpdFileContents {
         return fpdBuildOpts;\r
     }\r
     \r
-    public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {\r
+    public void genBuildOptionsUserExtensions(String fvName, String userId, String id, 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
+        userExts.setUserID(userId);\r
+        userExts.setIdentifier(id);\r
         XmlCursor cursor = userExts.newCursor();\r
         cursor.toEndToken();\r
         \r
@@ -1758,7 +1845,7 @@ public class FpdFileContents {
         cursor.toNextToken();\r
         \r
         cursor.beginElement(elementInfFileName);\r
-        cursor.insertChars(fvName + ".inf");\r
+        cursor.insertChars(outputFileName);\r
         cursor.toNextToken();\r
         \r
         cursor.beginElement(elementIncludeModules);\r
@@ -1780,15 +1867,19 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
-    public int getUserExtsIncModCount (String fvName) {\r
+    public int getUserExtsIncModCount (String fvName, String userId, int id) {\r
         if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
             return -1;\r
         }\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
+            if (!ues.getUserID().equals(userId)) {\r
+                continue;\r
+            }\r
+            if (ues.getIdentifier() == null || ues.getIdentifier() != new Integer(id).toString()) {\r
                 continue;\r
             }\r
             XmlCursor cursor = ues.newCursor();\r
@@ -1810,14 +1901,15 @@ public class FpdFileContents {
         return -1;\r
     }\r
     \r
-    public void getUserExtsIncMods(String fvName, String[][] saa) {\r
+    public void getUserExtsIncMods(String fvName, String userId, int id, String[][] saa) {\r
         if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
             return;\r
         }\r
-        \r
+\r
         XmlCursor cursor = getfpdBuildOpts().newCursor();\r
         QName elementUserExts = new QName (xmlNs, "UserExtensions");\r
         QName attribUserId = new QName ("UserID");\r
+        QName attribId = new QName ("Identifier");\r
         QName elementFvName = new QName (xmlNs, "FvName");\r
         QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
         QName attribModuleGuid = new QName("ModuleGuid");\r
@@ -1829,7 +1921,7 @@ public class FpdFileContents {
         if (cursor.toChild(elementUserExts)) {\r
             do {\r
                 cursor.push();\r
-                if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {\r
+                if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {\r
                     cursor.toChild(elementFvName);\r
                     String elementName = cursor.getTextValue();\r
                     if (elementName.equals(fvName)) {\r
@@ -1876,15 +1968,18 @@ public class FpdFileContents {
         \r
     }\r
     \r
-    public void removeBuildOptionsUserExtensions (String fvName) {\r
+    public void removeBuildOptionsUserExtensions (String fvName, String userId, int id) {\r
         if (getfpdBuildOpts().getUserExtensionsList() == null) {\r
             return;\r
         }\r
-        \r
+\r
         ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
         while (li.hasNext()) {\r
             UserExtensionsDocument.UserExtensions ues = li.next();\r
-            if (!ues.getUserID().equals("IMAGES")) {\r
+            if (!ues.getUserID().equals(userId)) {\r
+                continue;\r
+            }\r
+            if (ues.getIdentifier()== null || ues.getIdentifier() != new Integer(id).toString()) {\r
                 continue;\r
             }\r
             XmlCursor cursor = ues.newCursor();\r
@@ -1915,13 +2010,13 @@ public class FpdFileContents {
         return false;\r
     }\r
     \r
-    public boolean moduleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {\r
+    public boolean moduleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {\r
         boolean inList = false;\r
-        if (getUserExtsIncModCount(fvName) > 0) {\r
-            \r
+        if (getUserExtsIncModCount(fvName, userId, id) > 0) {\r
             XmlCursor cursor = getfpdBuildOpts().newCursor();\r
             QName elementUserExts = new QName (xmlNs, "UserExtensions");\r
             QName attribUserId = new QName ("UserID");\r
+            QName attribId = new QName ("Identifier");\r
             QName elementFvName = new QName (xmlNs, "FvName");\r
             QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
             QName attribModuleGuid = new QName("ModuleGuid");\r
@@ -1933,7 +2028,7 @@ public class FpdFileContents {
             if (cursor.toChild(elementUserExts)) {\r
                 do {\r
                     cursor.push();\r
-                    if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {\r
+                    if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {\r
                         cursor.toChild(elementFvName);\r
                         String elementName = cursor.getTextValue();\r
                         if (elementName.equals(fvName)) {\r
@@ -1976,12 +2071,21 @@ public class FpdFileContents {
         return inList;\r
     }\r
     \r
-    public void removeModuleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {\r
-        if (getUserExtsIncModCount(fvName) > 0) {\r
-            \r
+    public void removeModuleInBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {\r
+        //\r
+        // if there is only one module before remove operation, the whole user extension should be removed.\r
+        //\r
+        int moduleAmount = getUserExtsIncModCount(fvName, userId, id);\r
+        if (moduleAmount == 1) {\r
+            removeBuildOptionsUserExtensions(fvName, userId, id);\r
+            return;\r
+        }\r
+        \r
+        if (moduleAmount > 1) {\r
             XmlCursor cursor = getfpdBuildOpts().newCursor();\r
             QName elementUserExts = new QName (xmlNs, "UserExtensions");\r
             QName attribUserId = new QName ("UserID");\r
+            QName attribId = new QName ("Identifier");\r
             QName elementFvName = new QName (xmlNs, "FvName");\r
             QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
             QName attribModuleGuid = new QName("ModuleGuid");\r
@@ -1993,7 +2097,7 @@ public class FpdFileContents {
             if (cursor.toChild(elementUserExts)) {\r
                 do {\r
                     cursor.push();\r
-                    if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {\r
+                    if (cursor.getAttributeText(attribUserId).equals(userId) && cursor.getAttributeText(attribId).equals(id+"")) {\r
                         cursor.toChild(elementFvName);\r
                         String elementName = cursor.getTextValue();\r
                         if (elementName.equals(fvName)) {\r
@@ -2034,6 +2138,49 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public void addModuleIntoBuildOptionsUserExtensions (String fvName, String userId, int id, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {\r
+        if (moduleInBuildOptionsUserExtensions (fvName, userId, id, moduleGuid, moduleVersion, packageGuid, packageVersion, arch)) {\r
+            return;\r
+        }\r
+\r
+        ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();\r
+        QName elementIncludeModules = new QName(xmlNs, "IncludeModules");\r
+        QName elementModule = new QName(xmlNs, "Module");\r
+        while (li.hasNext()) {\r
+            UserExtensionsDocument.UserExtensions ues = li.next();\r
+            if (!ues.getUserID().equals(userId)) {\r
+                continue;\r
+            }\r
+            if (ues.getIdentifier() == null || ues.getIdentifier() != new Integer(id).toString()) {\r
+                continue;\r
+            }\r
+            XmlCursor cursor = ues.newCursor();\r
+            cursor.toFirstChild();\r
+            String elementName = cursor.getTextValue();\r
+            if (elementName.equals(fvName)) {\r
+                cursor.toNextSibling(elementIncludeModules);\r
+                cursor.toLastChild();\r
+                cursor.toEndToken();\r
+                cursor.toNextToken();\r
+                cursor.beginElement(elementModule);\r
+                cursor.insertAttributeWithValue("ModuleGuid", moduleGuid);\r
+                if (!moduleVersion.equals("null") && moduleVersion.length() != 0) {\r
+                    cursor.insertAttributeWithValue("ModuleVersion", moduleVersion);\r
+                }\r
+                cursor.insertAttributeWithValue("PackageGuid", packageGuid);\r
+                if (!packageVersion.equals("null") && packageVersion.length() != 0) {\r
+                    cursor.insertAttributeWithValue("PackageVersion", packageVersion);\r
+                }\r
+                \r
+                cursor.insertAttributeWithValue("Arch", arch);\r
+                cursor.dispose();\r
+                return;\r
+            }\r
+            cursor.dispose();\r
+        }\r
+        \r
+    }\r
+    \r
     public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r
         UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
         if (udats == null) {\r
@@ -2266,10 +2413,8 @@ public class FpdFileContents {
     }\r
     \r
     public void updateBuildOptionsFfsSectionsType(int i, String type) {\r
-        BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r
-        if (type != null) {\r
-            ffs.addNewSections().setEncapsulationType(type);\r
-        }\r
+        BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
+        ffs.getSections().setEncapsulationType(type);\r
     }\r
     \r
     public void genBuildOptionsFfsAttribute(int i, String name, String value) {\r
@@ -2369,7 +2514,9 @@ public class FpdFileContents {
         if (sections == null){\r
             sections = ffs.addNewSections();\r
         }\r
-        sections.addNewSections().setEncapsulationType(encapType);\r
+        BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections();\r
+        sections2.setEncapsulationType(encapType);\r
+        sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32"));\r
     }\r
     \r
     public void removeBuildOptionsFfsSectionsSections(int i, int j) {\r
@@ -2495,9 +2642,9 @@ public class FpdFileContents {
             ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();\r
             while(li.hasNext()) {\r
                 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();\r
-                if (section.isSetSectionType()) {\r
-                    al.add(section.getSectionType().toString());\r
-                }\r
+//                if (section.isSetSectionType()) {\r
+                    al.add(section.getSectionType()+"");\r
+//                }\r
                 \r
             }\r
         }\r
@@ -2546,7 +2693,7 @@ public class FpdFileContents {
                 if (ffs.getSections().getSectionList() != null){\r
                     ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();\r
                     while (li.hasNext()) {\r
-                        firstLevelSection.add(li.next().getSectionType().toString());\r
+                        firstLevelSection.add(li.next().getSectionType()+"");\r
                     }\r
                 }\r
                 if (ffs.getSections().getSectionsList() != null) {\r
@@ -3214,32 +3361,31 @@ public class FpdFileContents {
      * @param name\r
      * @param value\r
      */\r
-    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {\r
+    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value, String newName) {\r
         boolean fvImageExists = false;\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
+        if (getfpdFlash().getFvImages() != null) {\r
+\r
+            List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+            if (l != null) {\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
+                    fvImageExists = true;\r
+                    setFvImagesFvImageNameValue(fi, name, value, newName);\r
+                }\r
             }\r
-            fvImageExists = true;\r
-            setFvImagesFvImageNameValue (fi, name, value, null);\r
         }\r
-        \r
+\r
         if (!fvImageExists) {\r
             HashMap<String, String> map = new HashMap<String, String>();\r
             map.put(name, value);\r
-            genFvImagesFvImage(new String[]{fvName}, type, map);\r
+            genFvImagesFvImage(new String[] { fvName }, type, map);\r
         }\r
     }\r
     \r
@@ -3295,7 +3441,7 @@ public class FpdFileContents {
             FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();\r
             nv.setName(name);\r
             nv.setValue(value);\r
-            if (newName != null) {\r
+            if (newName != null && !newName.equals(name)) {\r
                 nv.setName(newName);\r
             }\r
             return;\r
@@ -3307,7 +3453,7 @@ public class FpdFileContents {
                 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
+                    if (newName != null && !newName.equals(name)) {\r
                         nv.setName(newName);\r
                     }\r
                     cursor.dispose();\r
@@ -3319,7 +3465,7 @@ public class FpdFileContents {
         FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();\r
         nv.setName(name);\r
         nv.setValue(value);\r
-        if (newName != null) {\r
+        if (newName != null && !newName.equals(name)) {\r
             nv.setName(newName);\r
         }\r
         cursor.dispose();\r
@@ -3566,9 +3712,36 @@ class PcdItemTypeConflictException extends Exception {
     private static final long serialVersionUID = 1L;\r
     private String details = null;\r
     \r
-    PcdItemTypeConflictException(String pcdName, String info){\r
+    PcdItemTypeConflictException (String pcdName, String info) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(info);\r
-        details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();\r
+        if (mi != null) {\r
+            details = pcdName + " ItemType Conflicts with " + mi.getName() + "\n in Pkg " + mi.getPackageId().getName();    \r
+        }\r
+        else {\r
+            details = pcdName + " ItemType Conflicts with \n" + info;\r
+        }\r
+    }\r
+    \r
+    PcdItemTypeConflictException (String pcdName, String info1, String info2) {\r
+        ModuleIdentification mi1 = WorkspaceProfile.getModuleId(info1);\r
+        ModuleIdentification mi2 = WorkspaceProfile.getModuleId(info2);\r
+        String moduleInfo1 = "";\r
+        String moduleInfo2 = "";\r
+        if (mi1 != null) {\r
+            moduleInfo1 = mi1.getName() + " in Pkg " + mi1.getPackageId().getName();\r
+        }\r
+        else {\r
+            moduleInfo1 = info1;\r
+        }\r
+        \r
+        if (mi2 != null) {\r
+            moduleInfo2 = mi2.getName() + " in Pkg " + mi2.getPackageId().getName();\r
+        }\r
+        else {\r
+            moduleInfo2 = info2;\r
+        }\r
+        \r
+        details = pcdName + " ItemType Conflicts in \n" + moduleInfo1 + "\n and " + moduleInfo2;\r
     }\r
     \r
     public String getMessage() {\r