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