]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
\t 2 \ \ \ \
[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 mi.guidvalue = UUID.randomUUID().toString();
86 MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!");
87 }
88 msaheader.setGuidValue(mi.guidvalue);
89 if (mi.moduletype != null) {
90 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));
91 /*
92 if (mi.moduletype.contains("PEI")) {
93 msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));
94 } else {
95 msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));
96 }
97 */
98 } else {
99 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));
100 }
101
102 msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");
103 msaheader.setVersion("1.0");
104 msaheader.setAbstract("Component name for module " + mi.modulename);
105 msaheader.setDescription("FIX ME!");
106 msaheader.addNewLicense().setStringValue("All rights reserved.\n" +
107 " This software and associated documentation (if any) is furnished\n" +
108 " under a license and may only be used or copied in accordance\n" +
109 " with the terms of the license. Except as permitted by such\n" +
110 " license, no part of this software or documentation may be\n" +
111 " reproduced, stored in a retrieval system, or transmitted in any\n" +
112 " form or by any means without the express written consent of\n" +
113 " Intel Corporation.");
114 msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
115
116 List<Enum> arch = new ArrayList<Enum>();
117 arch.add(SupportedArchitectures.IA_32);
118 arch.add(SupportedArchitectures.X_64);
119 arch.add(SupportedArchitectures.IPF);
120 arch.add(SupportedArchitectures.EBC);
121 md.setSupportedArchitectures(arch);
122 md.setBinaryModule(false);
123 md.setOutputFileBasename(mi.modulename);
124
125 pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
126 externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
127 externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
128 externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
129
130 it = mi.localmodulesources.iterator();
131 while (it.hasNext()) {
132 addSourceFiles(it.next());
133 }
134 if (!mi.protocol.isEmpty()) {
135 protocols = msa.addNewProtocols();
136 it = mi.protocol.iterator();
137 while (it.hasNext()) {
138 if ((temp = it.next()) != null) {
139 ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();
140 pr.setProtocolCName(temp);
141 pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
142 }
143 }
144 }
145 if (!mi.ppi.isEmpty()) {
146 ppis = msa.addNewPPIs();
147 it = mi.ppi.iterator();
148 while (it.hasNext()) {
149 if ((temp = it.next()) != null) {
150 PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();
151 pp.setPpiCName(temp);
152 pp.setUsage(UsageTypes.ALWAYS_CONSUMED);
153 }
154 }
155 }
156 if (!mi.guid.isEmpty()) {
157 guids = msa.addNewGuids();
158 it = mi.guid.iterator();
159 while (it.hasNext()) {
160 if ((temp = it.next()) != null) {
161 GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();
162 gcn.setGuidCName(temp);
163 gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
164 }
165 }
166 }
167 it = mi.hashrequiredr9libs.iterator();
168 while (it.hasNext()) {
169 if ((temp = it.next()) != null && !temp.matches("%")) {
170 LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();
171 lc.setKeyword(temp);
172 lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
173 }
174 }
175
176 return msadoc;
177 }
178
179 public void flush() throws Exception {
180 XmlOptions options = new XmlOptions();
181
182 options.setCharacterEncoding("UTF-8");
183 options.setSavePrettyPrint();
184 options.setSavePrettyPrintIndent(2);
185 options.setUseDefaultNamespace();
186
187 BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
188 fulfillMsadoc().save(bw, options);
189 //MsaTreeEditor.init(mi, ui, msadoc);
190 bw.flush();
191 bw.close();
192 }
193
194 private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {
195 XmlOptions options = new XmlOptions();
196
197 options.setCharacterEncoding("UTF-8");
198 options.setSavePrettyPrint();
199 options.setSavePrettyPrintIndent(2);
200 options.setUseDefaultNamespace();
201
202 BufferedWriter bw = new BufferedWriter(new FileWriter(path));
203 msadoc.save(bw, options);
204 bw.flush();
205 bw.close();
206 }
207
208 public static final void parse(String msafile) throws Exception {
209 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);
210 flush("c:\\temp.msa", msadoc);
211 }
212 }