]>
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 | |
90 | if (mi.moduletype.contains("PEI")) {\r | |
91 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r | |
92 | } else {\r | |
93 | msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r | |
94 | }\r | |
95 | } else {\r | |
719cebfe | 96 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r |
0dc8c589 | 97 | }\r |
fb840aa8 | 98 | \r |
0dc8c589 | 99 | msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r |
100 | msaheader.setVersion("1.0");\r | |
101 | msaheader.setAbstract("Component name for module " + mi.modulename);\r | |
90503bad | 102 | msaheader.setDescription("FIX ME!");\r |
0dc8c589 | 103 | msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r |
104 | " This software and associated documentation (if any) is furnished\n" +\r | |
105 | " under a license and may only be used or copied in accordance\n" +\r | |
106 | " with the terms of the license. Except as permitted by such\n" +\r | |
107 | " license, no part of this software or documentation may be\n" +\r | |
108 | " reproduced, stored in a retrieval system, or transmitted in any\n" +\r | |
109 | " form or by any means without the express written consent of\n" +\r | |
110 | " Intel Corporation.");\r | |
fb840aa8 | 111 | msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r |
0dc8c589 | 112 | \r |
113 | List<Enum> arch = new ArrayList<Enum>();\r | |
114 | arch.add(SupportedArchitectures.IA_32);\r | |
115 | arch.add(SupportedArchitectures.X_64);\r | |
116 | arch.add(SupportedArchitectures.IPF);\r | |
117 | arch.add(SupportedArchitectures.EBC);\r | |
118 | md.setSupportedArchitectures(arch);\r | |
119 | md.setBinaryModule(false);\r | |
120 | md.setOutputFileBasename(mi.modulename);\r | |
121 | \r | |
122 | pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r | |
123 | externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r | |
124 | externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r | |
125 | externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r | |
126 | \r | |
127 | it = mi.localmodulesources.iterator();\r | |
128 | while (it.hasNext()) {\r | |
2be54d60 | 129 | addSourceFiles(it.next());\r |
0dc8c589 | 130 | }\r |
fb840aa8 | 131 | if (!mi.protocol.isEmpty()) {\r |
132 | protocols = msa.addNewProtocols();\r | |
133 | it = mi.protocol.iterator();\r | |
134 | while (it.hasNext()) {\r | |
135 | if ((temp = it.next()) != null) {\r | |
136 | ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r | |
137 | pr.setProtocolCName(temp);\r | |
138 | pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
139 | }\r | |
0dc8c589 | 140 | }\r |
141 | }\r | |
fb840aa8 | 142 | if (!mi.ppi.isEmpty()) {\r |
143 | ppis = msa.addNewPPIs();\r | |
144 | it = mi.ppi.iterator();\r | |
145 | while (it.hasNext()) {\r | |
146 | if ((temp = it.next()) != null) {\r | |
147 | PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r | |
148 | pp.setPpiCName(temp);\r | |
149 | pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
150 | }\r | |
0dc8c589 | 151 | }\r |
152 | }\r | |
fb840aa8 | 153 | if (!mi.guid.isEmpty()) {\r |
154 | guids = msa.addNewGuids();\r | |
155 | it = mi.guid.iterator();\r | |
156 | while (it.hasNext()) {\r | |
157 | if ((temp = it.next()) != null) {\r | |
158 | GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r | |
159 | gcn.setGuidCName(temp);\r | |
160 | gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
161 | }\r | |
0dc8c589 | 162 | }\r |
163 | }\r | |
164 | it = mi.hashrequiredr9libs.iterator();\r | |
165 | while (it.hasNext()) {\r | |
166 | if ((temp = it.next()) != null && !temp.matches("%")) {\r | |
167 | LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r | |
168 | lc.setKeyword(temp);\r | |
169 | lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r | |
170 | }\r | |
171 | }\r | |
172 | \r | |
173 | return msadoc;\r | |
174 | }\r | |
175 | \r | |
176 | public void flush() throws Exception {\r | |
177 | XmlOptions options = new XmlOptions();\r | |
178 | \r | |
179 | options.setCharacterEncoding("UTF-8");\r | |
180 | options.setSavePrettyPrint();\r | |
181 | options.setSavePrettyPrintIndent(2);\r | |
182 | options.setUseDefaultNamespace();\r | |
183 | \r | |
eee63a7b | 184 | BufferedWriter bw = new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r |
0dc8c589 | 185 | fulfillMsadoc().save(bw, options);\r |
fed802b1 | 186 | //MsaTreeEditor.init(mi, ui, msadoc);\r |
0dc8c589 | 187 | bw.flush();\r |
188 | bw.close();\r | |
189 | }\r | |
190 | }\r |