git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1250 6f19259b...
[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
61 msaheader.setModuleName(mi.modulename = Query("ModuleName Not Found . Please Input ModuleName"));\r
62 }\r
63 if (mi.guidvalue != null) {\r
64 msaheader.setGuidValue(mi.guidvalue);\r
65 } else {\r
66 msaheader.setGuidValue(mi.guidvalue = Query("GuidValue Not Found . Please Input GuidValue"));\r
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
75 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("GuidValue Not Found . Please Input GuidValue")));\r
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
81 msaheader.setDescription("FIX ME!"); //???\r
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
106 it = mi.localmodulesources.iterator();\r
107 while (it.hasNext()) {\r
108 sourcefiles.addNewFilename().setStringValue(it.next());\r
109 }\r
fb840aa8 110 if (!mi.protocol.isEmpty()) {\r
111 protocols = msa.addNewProtocols();\r
112 it = mi.protocol.iterator();\r
113 while (it.hasNext()) {\r
114 if ((temp = it.next()) != null) {\r
115 ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
116 pr.setProtocolCName(temp);\r
117 pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
118 }\r
0dc8c589 119 }\r
120 }\r
fb840aa8 121 if (!mi.ppi.isEmpty()) {\r
122 ppis = msa.addNewPPIs();\r
123 it = mi.ppi.iterator();\r
124 while (it.hasNext()) {\r
125 if ((temp = it.next()) != null) {\r
126 PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
127 pp.setPpiCName(temp);\r
128 pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
129 }\r
0dc8c589 130 }\r
131 }\r
fb840aa8 132 if (!mi.guid.isEmpty()) {\r
133 guids = msa.addNewGuids();\r
134 it = mi.guid.iterator();\r
135 while (it.hasNext()) {\r
136 if ((temp = it.next()) != null) {\r
137 GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
138 gcn.setGuidCName(temp);\r
139 gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
140 }\r
0dc8c589 141 }\r
142 }\r
143 it = mi.hashrequiredr9libs.iterator();\r
144 while (it.hasNext()) {\r
145 if ((temp = it.next()) != null && !temp.matches("%")) {\r
146 LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
147 lc.setKeyword(temp);\r
148 lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
149 }\r
150 }\r
151 \r
152 return msadoc;\r
153 }\r
154 \r
155 public void flush() throws Exception {\r
156 XmlOptions options = new XmlOptions();\r
157\r
158 options.setCharacterEncoding("UTF-8");\r
159 options.setSavePrettyPrint();\r
160 options.setSavePrettyPrintIndent(2);\r
161 options.setUseDefaultNamespace();\r
162 \r
163 BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
164 fulfillMsadoc().save(bw, options);\r
165 bw.flush();\r
166 bw.close();\r
167 }\r
168}\r