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