Add License Head to all files
[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
39 private GuidsDocument.Guids guids = msa.addNewGuids();\r
40 private ProtocolsDocument.Protocols protocols = msa.addNewProtocols();\r
41 private PPIsDocument.PPIs ppis = msa.addNewPPIs();\r
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
77 msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
78 msaheader.setVersion("1.0");\r
79 msaheader.setAbstract("Component name for module " + mi.modulename);\r
80 msaheader.setDescription("FIX ME!"); //???\r
81 msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
82 " This software and associated documentation (if any) is furnished\n" +\r
83 " under a license and may only be used or copied in accordance\n" +\r
84 " with the terms of the license. Except as permitted by such\n" +\r
85 " license, no part of this software or documentation may be\n" +\r
86 " reproduced, stored in a retrieval system, or transmitted in any\n" +\r
87 " form or by any means without the express written consent of\n" +\r
88 " Intel Corporation.");\r
89 \r
90 List<Enum> arch = new ArrayList<Enum>();\r
91 arch.add(SupportedArchitectures.IA_32);\r
92 arch.add(SupportedArchitectures.X_64);\r
93 arch.add(SupportedArchitectures.IPF);\r
94 arch.add(SupportedArchitectures.EBC);\r
95 md.setSupportedArchitectures(arch);\r
96 md.setBinaryModule(false);\r
97 md.setOutputFileBasename(mi.modulename);\r
98 \r
99 pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
100 externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
101 externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
102 externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
103 \r
104 it = mi.localmodulesources.iterator();\r
105 while (it.hasNext()) {\r
106 sourcefiles.addNewFilename().setStringValue(it.next());\r
107 }\r
108 it = mi.protocol.iterator();\r
109 while (it.hasNext()) {\r
110 if ((temp = it.next()) != null) {\r
111 ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
112 pr.setProtocolCName(temp);\r
113 pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
114 }\r
115 }\r
116 it = mi.ppi.iterator();\r
117 while (it.hasNext()) {\r
118 if ((temp = it.next()) != null) {\r
119 PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
120 pp.setPpiCName(temp);\r
121 pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
122 }\r
123 }\r
124 it = mi.guid.iterator();\r
125 while (it.hasNext()) {\r
126 if ((temp = it.next()) != null) {\r
127 GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
128 gcn.setGuidCName(temp);\r
129 gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
130 }\r
131 }\r
132 it = mi.hashrequiredr9libs.iterator();\r
133 while (it.hasNext()) {\r
134 if ((temp = it.next()) != null && !temp.matches("%")) {\r
135 LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
136 lc.setKeyword(temp);\r
137 lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
138 }\r
139 }\r
140 \r
141 return msadoc;\r
142 }\r
143 \r
144 public void flush() throws Exception {\r
145 XmlOptions options = new XmlOptions();\r
146\r
147 options.setCharacterEncoding("UTF-8");\r
148 options.setSavePrettyPrint();\r
149 options.setSavePrettyPrintIndent(2);\r
150 options.setUseDefaultNamespace();\r
151 \r
152 BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
153 fulfillMsadoc().save(bw, options);\r
154 bw.flush();\r
155 bw.close();\r
156 }\r
157}\r