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