]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
re
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / MsaWriter.java
index 25d959f67a2560a8b88a2d21fc4f94faf4b4f987..2da3c98a23d79a659aba97d1ea90cea90e8854ab 100644 (file)
@@ -19,129 +19,166 @@ import org.tianocore.*;
 import org.tianocore.SupportedArchitectures.Enum;\r
 import org.apache.xmlbeans.*;\r
 \r
-public class MsaWriter {\r
-       MsaWriter(String path, ModuleInfo moduleinfo, Database database) {\r
-               modulepath = path;\r
+public class MsaWriter implements MsaOwner {\r
+       MsaWriter(ModuleInfo moduleinfo) {\r
                mi = moduleinfo;\r
-               db = database;\r
-       }\r
-\r
-       private String modulepath;\r
-       private ModuleInfo mi;\r
-       private Database db;\r
-       \r
-       private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
-       \r
-       private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
-       private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
-       private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
-       private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles();  //found local .h files are not written\r
-       private GuidsDocument.Guids guids = msa.addNewGuids();\r
-       private ProtocolsDocument.Protocols protocols = msa.addNewProtocols();\r
-       private PPIsDocument.PPIs ppis = msa.addNewPPIs();\r
-       private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
-       private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
-       private ExternsDocument.Externs externs = msa.addNewExterns();\r
-       \r
-       private String Query (String requirement) throws Exception {\r
-               String answer;\r
-               BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
-               System.out.println(requirement);\r
-               while ((answer = rd.readLine()).length() == 0) ;\r
-               return answer;\r
+               //msadoc = mi.msadoc;\r
        }\r
        \r
-       private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
-               Iterator<String> it;\r
-               String temp;\r
-               \r
-               if (mi.modulename != null) {\r
-                       msaheader.setModuleName(mi.modulename);\r
-               } else {\r
-                       msaheader.setModuleName(mi.modulename = Query("ModuleName Not Found . Please Input ModuleName"));\r
-               }\r
-               if (mi.guidvalue != null) {\r
-                       msaheader.setGuidValue(mi.guidvalue);\r
-               } else {\r
-                       msaheader.setGuidValue(mi.guidvalue = Query("GuidValue Not Found . Please Input GuidValue"));\r
-               }\r
-               if (mi.moduletype != null) {\r
-                       if (mi.moduletype.contains("PEI")) {\r
-                               msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r
-                       } else {\r
-                               msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r
-                       }\r
-               } else {\r
-                       msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("GuidValue Not Found . Please Input GuidValue")));\r
-               }\r
-               msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
-               msaheader.setVersion("1.0");\r
-               msaheader.setAbstract("Component name for module " + mi.modulename);\r
-               msaheader.setDescription("FIX ME!");                                                    //???\r
-               msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
-                               "      This software and associated documentation (if any) is furnished\n" +\r
-                               "      under a license and may only be used or copied in accordance\n" +\r
-                               "      with the terms of the license. Except as permitted by such\n" +\r
-                               "      license, no part of this software or documentation may be\n" +\r
-                               "      reproduced, stored in a retrieval system, or transmitted in any\n" +\r
-                               "      form or by any means without the express written consent of\n" +\r
-                               "      Intel Corporation.");\r
-               \r
-               List<Enum> arch = new ArrayList<Enum>();\r
-               arch.add(SupportedArchitectures.IA_32);\r
-               arch.add(SupportedArchitectures.X_64);\r
-               arch.add(SupportedArchitectures.IPF);\r
-               arch.add(SupportedArchitectures.EBC);\r
-               md.setSupportedArchitectures(arch);\r
-               md.setBinaryModule(false);\r
-               md.setOutputFileBasename(mi.modulename);\r
-               \r
-               pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
-               externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
-               externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
-               externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
-               \r
-               it = mi.localmodulesources.iterator();\r
-               while (it.hasNext()) {\r
-                       sourcefiles.addNewFilename().setStringValue(it.next());\r
-               }\r
-               it = mi.protocol.iterator();\r
-               while (it.hasNext()) {\r
-                       if ((temp = it.next()) != null) {\r
-                               ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
-                               pr.setProtocolCName(temp);\r
-                               pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
-                       }\r
-               }\r
-               it = mi.ppi.iterator();\r
-               while (it.hasNext()) {\r
-                       if ((temp = it.next()) != null) {\r
-                               PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
-                               pp.setPpiCName(temp);\r
-                               pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
-                       }\r
-               }\r
-               it = mi.guid.iterator();\r
-               while (it.hasNext()) {\r
-                       if ((temp = it.next()) != null) {\r
-                               GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
-                               gcn.setGuidCName(temp);\r
-                               gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
-                       }\r
-               }\r
-               it = mi.hashrequiredr9libs.iterator();\r
-               while (it.hasNext()) {\r
-                       if ((temp = it.next()) != null && !temp.matches("%")) {\r
-                               LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
-                               lc.setKeyword(temp);\r
-                               lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
-                       }\r
-               }\r
-               \r
-               return msadoc;\r
-       }\r
-       \r
-       public void flush() throws Exception {\r
+    private ModuleInfo mi;\r
+    private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
+    \r
+    private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
+    private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
+    private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
+    private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles();    //found local .h files are not written\r
+    private GuidsDocument.Guids guids;\r
+    private ProtocolsDocument.Protocols protocols;\r
+    private PPIsDocument.PPIs ppis;\r
+    private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
+    private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
+    private ExternsDocument.Externs externs = msa.addNewExterns();\r
+    \r
+    private String Query (String requirement) throws Exception {\r
+        String answer;\r
+        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
+        System.out.println(requirement);\r
+        while ((answer = rd.readLine()).length() == 0) ;\r
+        return answer;\r
+    }\r
+    \r
+    private void addSourceFiles (String name) {                        // furthur modification needed\r
+        List<Enum> arch = new ArrayList<Enum>();\r
+        FilenameDocument.Filename filename;\r
+        filename = sourcefiles.addNewFilename();\r
+        filename.setStringValue(name);\r
+        \r
+        if (name.contains("x64" + File.separator)) {                // filename ???\r
+            arch.add(SupportedArchitectures.X_64);\r
+            System.out.println("x64" + File.separator);\r
+            filename.setSupArchList(arch);\r
+        } else if (name.contains("Ia32" + File.separator)) {        // filename ???\r
+            arch.add(SupportedArchitectures.IA_32);\r
+            System.out.println("Ia32" + File.separator);\r
+            filename.setSupArchList(arch);\r
+        } else if (name.contains("Ipf" + File.separator)) {            // filename ???\r
+            arch.add(SupportedArchitectures.IPF);\r
+            System.out.println("Ipf" + File.separator);\r
+            filename.setSupArchList(arch);\r
+        } else if (name.contains("Ebc" + File.separator)) {            // filename ???\r
+            arch.add(SupportedArchitectures.EBC);\r
+            System.out.println("Ebc" + File.separator);\r
+            filename.setSupArchList(arch);\r
+        }\r
+    }\r
+    \r
+    private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
+        Iterator<String> it;\r
+        String temp;\r
+        \r
+        if (mi.modulename != null) {\r
+            msaheader.setModuleName(mi.modulename);\r
+        } else {\r
+            msaheader.setModuleName(mi.modulename = Query("Module Name Not Found!  Please Input ModuleName"));\r
+        }\r
+        if (mi.guidvalue == null) {\r
+          mi.guidvalue = UUID.randomUUID().toString();\r
+          MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!"); \r
+        } \r
+        msaheader.setGuidValue(mi.guidvalue);\r
+        if (mi.moduletype != null) {\r
+            msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r
+        } else {\r
+            msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found!  Please Input Guid Value")));\r
+        }\r
+\r
+        msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
+        msaheader.setVersion("1.0");\r
+        msaheader.setAbstract("Component name for module " + mi.modulename);\r
+        msaheader.setDescription("FIX ME!");\r
+        msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
+                "      This software and associated documentation (if any) is furnished\n" +\r
+                "      under a license and may only be used or copied in accordance\n" +\r
+                "      with the terms of the license. Except as permitted by such\n" +\r
+                "      license, no part of this software or documentation may be\n" +\r
+                "      reproduced, stored in a retrieval system, or transmitted in any\n" +\r
+                "      form or by any means without the express written consent of\n" +\r
+                "      Intel Corporation.");\r
+        msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052");\r
+        \r
+        List<Enum> arch = new ArrayList<Enum>();\r
+        arch.add(SupportedArchitectures.IA_32);\r
+        arch.add(SupportedArchitectures.X_64);\r
+        arch.add(SupportedArchitectures.IPF);\r
+        arch.add(SupportedArchitectures.EBC);\r
+        md.setSupportedArchitectures(arch);\r
+        md.setBinaryModule(false);\r
+        md.setOutputFileBasename(mi.modulename);\r
+        \r
+        pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
+        pd.addNewPackage().setPackageGuid("68169ab0-d41b-4009-9060-292c253ac43d");\r
+        externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
+        externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
+        if (mi.entrypoint != null) {\r
+          externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
+          org.tianocore.ModuleTypeDef.Enum moduleType = msaheader.getModuleType();\r
+          if (moduleType == ModuleTypeDef.PEIM) {\r
+              mi.hashrequiredr9libs.add("PeimEntryPoint");\r
+          } else {\r
+              mi.hashrequiredr9libs.add("UefiDriverEntryPoint");\r
+          }\r
+        }\r
+       \r
+        it = mi.localmodulesources.iterator();\r
+        while (it.hasNext()) {\r
+            addSourceFiles(it.next());\r
+        }\r
+        if (!mi.protocol.isEmpty()) {\r
+            protocols = msa.addNewProtocols();\r
+            it = mi.protocol.iterator();\r
+            while (it.hasNext()) {\r
+                if ((temp = it.next()) != null) {\r
+                    ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
+                    pr.setProtocolCName(temp);\r
+                    pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+                }\r
+            }\r
+        }\r
+        if (!mi.ppi.isEmpty()) {\r
+            ppis = msa.addNewPPIs();\r
+            it = mi.ppi.iterator();\r
+            while (it.hasNext()) {\r
+                if ((temp = it.next()) != null) {\r
+                    PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
+                    pp.setPpiCName(temp);\r
+                    pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+                }\r
+            }\r
+        }\r
+        if (!mi.guid.isEmpty()) {\r
+            guids = msa.addNewGuids();\r
+            it = mi.guid.iterator();\r
+            while (it.hasNext()) {\r
+                if ((temp = it.next()) != null) {\r
+                    GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
+                    gcn.setGuidCName(temp);\r
+                    gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+                }\r
+            }\r
+        }\r
+        it = mi.hashrequiredr9libs.iterator();\r
+        while (it.hasNext()) {\r
+            if ((temp = it.next()) != null && !temp.matches("%") && !temp.matches("n/a")) {\r
+                LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
+                lc.setKeyword(temp);\r
+                lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+            }\r
+        }\r
+        \r
+        return msadoc;\r
+    }\r
+    \r
+    public void flush() throws Exception {\r
         XmlOptions options = new XmlOptions();\r
 \r
         options.setCharacterEncoding("UTF-8");\r
@@ -149,9 +186,37 @@ public class MsaWriter {
         options.setSavePrettyPrintIndent(2);\r
         options.setUseDefaultNamespace();\r
         \r
-               BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
-               fulfillMsadoc().save(bw, options);\r
-               bw.flush();\r
-               bw.close();\r
+        BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
+        fulfillMsadoc().save(bw, options);\r
+        //MsaTreeEditor.init(mi, ui, msadoc);\r
+        bw.flush();\r
+        bw.close();\r
+    }\r
+\r
+    private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
+        XmlOptions options = new XmlOptions();\r
+\r
+        options.setCharacterEncoding("UTF-8");\r
+        options.setSavePrettyPrint();\r
+        options.setSavePrettyPrintIndent(2);\r
+        options.setUseDefaultNamespace();\r
+\r
+        BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r
+        msadoc.save(bw, options);\r
+        bw.flush();\r
+        bw.close();\r
+    }\r
+    \r
+    //---------------------------MsaOwner---------------------------------//\r
+       \r
+       public void addSourceFiles(String filename, int arch) {\r
+               \r
        }\r
+\r
+    //---------------------------MsaOwner---------------------------------//\r
+    \r
+    public static final void parse(String msafile) throws Exception {\r
+        ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);\r
+        flush("c:\\temp.msa", msadoc);\r
+    }\r
 }\r