0dc8c589 |
1 | package org.tianocore.migration;\r |
2 | \r |
3 | import java.io.*;\r |
4 | import java.util.*;\r |
5 | \r |
6 | import org.tianocore.*;\r |
7 | import org.tianocore.SupportedArchitectures.Enum;\r |
8 | import org.apache.xmlbeans.*;\r |
9 | \r |
10 | public class MsaWriter {\r |
11 | MsaWriter(String path, ModuleInfo moduleinfo, Database database) {\r |
12 | modulepath = path;\r |
13 | mi = moduleinfo;\r |
14 | db = database;\r |
15 | }\r |
16 | \r |
17 | private String modulepath;\r |
18 | private ModuleInfo mi;\r |
19 | private Database db;\r |
20 | \r |
21 | private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r |
22 | \r |
23 | private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r |
24 | private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r |
25 | private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r |
26 | private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r |
27 | private GuidsDocument.Guids guids = msa.addNewGuids();\r |
28 | private ProtocolsDocument.Protocols protocols = msa.addNewProtocols();\r |
29 | private PPIsDocument.PPIs ppis = msa.addNewPPIs();\r |
30 | private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r |
31 | private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r |
32 | private ExternsDocument.Externs externs = msa.addNewExterns();\r |
33 | \r |
34 | private String Query (String requirement) throws Exception {\r |
35 | String answer;\r |
36 | BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r |
37 | System.out.println(requirement);\r |
38 | while ((answer = rd.readLine()).length() == 0) ;\r |
39 | return answer;\r |
40 | }\r |
41 | \r |
42 | private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r |
43 | Iterator<String> it;\r |
44 | String temp;\r |
45 | \r |
46 | if (mi.modulename != null) {\r |
47 | msaheader.setModuleName(mi.modulename);\r |
48 | } else {\r |
49 | msaheader.setModuleName(mi.modulename = Query("ModuleName Not Found . Please Input ModuleName"));\r |
50 | }\r |
51 | if (mi.guidvalue != null) {\r |
52 | msaheader.setGuidValue(mi.guidvalue);\r |
53 | } else {\r |
54 | msaheader.setGuidValue(mi.guidvalue = Query("GuidValue Not Found . Please Input GuidValue"));\r |
55 | }\r |
56 | if (mi.moduletype != null) {\r |
57 | if (mi.moduletype.contains("PEI")) {\r |
58 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r |
59 | } else {\r |
60 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r |
61 | }\r |
62 | } else {\r |
63 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("GuidValue Not Found . Please Input GuidValue")));\r |
64 | }\r |
65 | msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r |
66 | msaheader.setVersion("1.0");\r |
67 | msaheader.setAbstract("Component name for module " + mi.modulename);\r |
68 | msaheader.setDescription("FIX ME!"); //???\r |
69 | msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r |
70 | " This software and associated documentation (if any) is furnished\n" +\r |
71 | " under a license and may only be used or copied in accordance\n" +\r |
72 | " with the terms of the license. Except as permitted by such\n" +\r |
73 | " license, no part of this software or documentation may be\n" +\r |
74 | " reproduced, stored in a retrieval system, or transmitted in any\n" +\r |
75 | " form or by any means without the express written consent of\n" +\r |
76 | " Intel Corporation.");\r |
77 | \r |
78 | List<Enum> arch = new ArrayList<Enum>();\r |
79 | arch.add(SupportedArchitectures.IA_32);\r |
80 | arch.add(SupportedArchitectures.X_64);\r |
81 | arch.add(SupportedArchitectures.IPF);\r |
82 | arch.add(SupportedArchitectures.EBC);\r |
83 | md.setSupportedArchitectures(arch);\r |
84 | md.setBinaryModule(false);\r |
85 | md.setOutputFileBasename(mi.modulename);\r |
86 | \r |
87 | pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r |
88 | externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r |
89 | externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r |
90 | externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r |
91 | \r |
92 | it = mi.localmodulesources.iterator();\r |
93 | while (it.hasNext()) {\r |
94 | sourcefiles.addNewFilename().setStringValue(it.next());\r |
95 | }\r |
96 | it = mi.protocol.iterator();\r |
97 | while (it.hasNext()) {\r |
98 | if ((temp = it.next()) != null) {\r |
99 | ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r |
100 | pr.setProtocolCName(temp);\r |
101 | pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r |
102 | }\r |
103 | }\r |
104 | it = mi.ppi.iterator();\r |
105 | while (it.hasNext()) {\r |
106 | if ((temp = it.next()) != null) {\r |
107 | PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r |
108 | pp.setPpiCName(temp);\r |
109 | pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r |
110 | }\r |
111 | }\r |
112 | it = mi.guid.iterator();\r |
113 | while (it.hasNext()) {\r |
114 | if ((temp = it.next()) != null) {\r |
115 | GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r |
116 | gcn.setGuidCName(temp);\r |
117 | gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r |
118 | }\r |
119 | }\r |
120 | it = mi.hashrequiredr9libs.iterator();\r |
121 | while (it.hasNext()) {\r |
122 | if ((temp = it.next()) != null && !temp.matches("%")) {\r |
123 | LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r |
124 | lc.setKeyword(temp);\r |
125 | lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r |
126 | }\r |
127 | }\r |
128 | \r |
129 | return msadoc;\r |
130 | }\r |
131 | \r |
132 | public void flush() throws Exception {\r |
133 | XmlOptions options = new XmlOptions();\r |
134 | \r |
135 | options.setCharacterEncoding("UTF-8");\r |
136 | options.setSavePrettyPrint();\r |
137 | options.setSavePrettyPrintIndent(2);\r |
138 | options.setUseDefaultNamespace();\r |
139 | \r |
140 | BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r |
141 | fulfillMsadoc().save(bw, options);\r |
142 | bw.flush();\r |
143 | bw.close();\r |
144 | }\r |
145 | }\r |