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