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