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