]>
Commit | Line | Data |
---|---|---|
b0282412 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | **/\r | |
0dc8c589 | 13 | package org.tianocore.migration;\r |
14 | \r | |
15 | import java.io.*;\r | |
16 | import java.util.*;\r | |
17 | \r | |
18 | import org.tianocore.*;\r | |
19 | import org.tianocore.SupportedArchitectures.Enum;\r | |
20 | import org.apache.xmlbeans.*;\r | |
21 | \r | |
22 | public class MsaWriter {\r | |
eee63a7b | 23 | MsaWriter(ModuleInfo moduleinfo) {\r |
0dc8c589 | 24 | mi = moduleinfo;\r |
0dc8c589 | 25 | }\r |
26 | \r | |
0dc8c589 | 27 | private ModuleInfo mi;\r |
0dc8c589 | 28 | \r |
29 | private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r | |
30 | \r | |
31 | private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r | |
32 | private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r | |
33 | private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r | |
34 | private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r | |
fb840aa8 | 35 | private GuidsDocument.Guids guids;\r |
36 | private ProtocolsDocument.Protocols protocols;\r | |
37 | private PPIsDocument.PPIs ppis;\r | |
0dc8c589 | 38 | private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r |
39 | private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r | |
40 | private ExternsDocument.Externs externs = msa.addNewExterns();\r | |
41 | \r | |
42 | private String Query (String requirement) throws Exception {\r | |
43 | String answer;\r | |
44 | BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r | |
45 | System.out.println(requirement);\r | |
46 | while ((answer = rd.readLine()).length() == 0) ;\r | |
47 | return answer;\r | |
48 | }\r | |
49 | \r | |
2be54d60 | 50 | private void addSourceFiles (String name) { // furthur modification needed\r |
51 | List<Enum> arch = new ArrayList<Enum>();\r | |
52 | FilenameDocument.Filename filename;\r | |
53 | filename = sourcefiles.addNewFilename();\r | |
54 | filename.setStringValue(name);\r | |
55 | \r | |
56 | if (name.contains("x64" + File.separator)) { // filename ???\r | |
57 | arch.add(SupportedArchitectures.X_64);\r | |
58 | System.out.println("x64" + File.separator);\r | |
59 | filename.setSupArchList(arch);\r | |
60 | } else if (name.contains("Ia32" + File.separator)) { // filename ???\r | |
61 | arch.add(SupportedArchitectures.IA_32);\r | |
62 | System.out.println("Ia32" + File.separator);\r | |
63 | filename.setSupArchList(arch);\r | |
64 | } else if (name.contains("Ipf" + File.separator)) { // filename ???\r | |
65 | arch.add(SupportedArchitectures.IPF);\r | |
66 | System.out.println("Ipf" + File.separator);\r | |
67 | filename.setSupArchList(arch);\r | |
68 | } else if (name.contains("Ebc" + File.separator)) { // filename ???\r | |
69 | arch.add(SupportedArchitectures.EBC);\r | |
70 | System.out.println("Ebc" + File.separator);\r | |
71 | filename.setSupArchList(arch);\r | |
72 | }\r | |
73 | }\r | |
74 | \r | |
0dc8c589 | 75 | private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r |
76 | Iterator<String> it;\r | |
77 | String temp;\r | |
78 | \r | |
79 | if (mi.modulename != null) {\r | |
80 | msaheader.setModuleName(mi.modulename);\r | |
81 | } else {\r | |
719cebfe | 82 | msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));\r |
0dc8c589 | 83 | }\r |
84 | if (mi.guidvalue != null) {\r | |
85 | msaheader.setGuidValue(mi.guidvalue);\r | |
86 | } else {\r | |
719cebfe | 87 | msaheader.setGuidValue(mi.guidvalue = Query("Guid Value Not Found! Please Input Guid Value"));\r |
0dc8c589 | 88 | }\r |
89 | if (mi.moduletype != null) {\r | |
9481cdac | 90 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r |
91 | /*\r | |
0dc8c589 | 92 | if (mi.moduletype.contains("PEI")) {\r |
93 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r | |
94 | } else {\r | |
95 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r | |
96 | }\r | |
9481cdac | 97 | */\r |
0dc8c589 | 98 | } else {\r |
719cebfe | 99 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r |
0dc8c589 | 100 | }\r |
fb840aa8 | 101 | \r |
0dc8c589 | 102 | msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r |
103 | msaheader.setVersion("1.0");\r | |
104 | msaheader.setAbstract("Component name for module " + mi.modulename);\r | |
90503bad | 105 | msaheader.setDescription("FIX ME!");\r |
0dc8c589 | 106 | msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r |
107 | " This software and associated documentation (if any) is furnished\n" +\r | |
108 | " under a license and may only be used or copied in accordance\n" +\r | |
109 | " with the terms of the license. Except as permitted by such\n" +\r | |
110 | " license, no part of this software or documentation may be\n" +\r | |
111 | " reproduced, stored in a retrieval system, or transmitted in any\n" +\r | |
112 | " form or by any means without the express written consent of\n" +\r | |
113 | " Intel Corporation.");\r | |
fb840aa8 | 114 | msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r |
0dc8c589 | 115 | \r |
116 | List<Enum> arch = new ArrayList<Enum>();\r | |
117 | arch.add(SupportedArchitectures.IA_32);\r | |
118 | arch.add(SupportedArchitectures.X_64);\r | |
119 | arch.add(SupportedArchitectures.IPF);\r | |
120 | arch.add(SupportedArchitectures.EBC);\r | |
121 | md.setSupportedArchitectures(arch);\r | |
122 | md.setBinaryModule(false);\r | |
123 | md.setOutputFileBasename(mi.modulename);\r | |
124 | \r | |
125 | pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r | |
126 | externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r | |
127 | externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r | |
128 | externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r | |
129 | \r | |
130 | it = mi.localmodulesources.iterator();\r | |
131 | while (it.hasNext()) {\r | |
2be54d60 | 132 | addSourceFiles(it.next());\r |
0dc8c589 | 133 | }\r |
fb840aa8 | 134 | if (!mi.protocol.isEmpty()) {\r |
135 | protocols = msa.addNewProtocols();\r | |
136 | it = mi.protocol.iterator();\r | |
137 | while (it.hasNext()) {\r | |
138 | if ((temp = it.next()) != null) {\r | |
139 | ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r | |
140 | pr.setProtocolCName(temp);\r | |
141 | pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
142 | }\r | |
0dc8c589 | 143 | }\r |
144 | }\r | |
fb840aa8 | 145 | if (!mi.ppi.isEmpty()) {\r |
146 | ppis = msa.addNewPPIs();\r | |
147 | it = mi.ppi.iterator();\r | |
148 | while (it.hasNext()) {\r | |
149 | if ((temp = it.next()) != null) {\r | |
150 | PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r | |
151 | pp.setPpiCName(temp);\r | |
152 | pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
153 | }\r | |
0dc8c589 | 154 | }\r |
155 | }\r | |
fb840aa8 | 156 | if (!mi.guid.isEmpty()) {\r |
157 | guids = msa.addNewGuids();\r | |
158 | it = mi.guid.iterator();\r | |
159 | while (it.hasNext()) {\r | |
160 | if ((temp = it.next()) != null) {\r | |
161 | GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r | |
162 | gcn.setGuidCName(temp);\r | |
163 | gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
164 | }\r | |
0dc8c589 | 165 | }\r |
166 | }\r | |
167 | it = mi.hashrequiredr9libs.iterator();\r | |
168 | while (it.hasNext()) {\r | |
169 | if ((temp = it.next()) != null && !temp.matches("%")) {\r | |
170 | LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r | |
171 | lc.setKeyword(temp);\r | |
172 | lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
173 | }\r | |
174 | }\r | |
175 | \r | |
176 | return msadoc;\r | |
177 | }\r | |
178 | \r | |
179 | public void flush() throws Exception {\r | |
180 | XmlOptions options = new XmlOptions();\r | |
181 | \r | |
182 | options.setCharacterEncoding("UTF-8");\r | |
183 | options.setSavePrettyPrint();\r | |
184 | options.setSavePrettyPrintIndent(2);\r | |
185 | options.setUseDefaultNamespace();\r | |
186 | \r | |
5f4eb6b6 | 187 | BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r |
0dc8c589 | 188 | fulfillMsadoc().save(bw, options);\r |
fed802b1 | 189 | //MsaTreeEditor.init(mi, ui, msadoc);\r |
0dc8c589 | 190 | bw.flush();\r |
191 | bw.close();\r | |
192 | }\r | |
6f55be9f | 193 | \r |
194 | private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {\r | |
195 | XmlOptions options = new XmlOptions();\r | |
196 | \r | |
197 | options.setCharacterEncoding("UTF-8");\r | |
198 | options.setSavePrettyPrint();\r | |
199 | options.setSavePrettyPrintIndent(2);\r | |
200 | options.setUseDefaultNamespace();\r | |
201 | \r | |
202 | BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r | |
203 | msadoc.save(bw, options);\r | |
204 | bw.flush();\r | |
205 | bw.close();\r | |
206 | }\r | |
207 | \r | |
208 | public static final void parse(String msafile) throws Exception {\r | |
209 | ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);\r | |
210 | flush("c:\\temp.msa", msadoc);\r | |
211 | }\r | |
0dc8c589 | 212 | }\r |