]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/MsaOwner.java
Add Package-Guid Map.
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / MsaOwner.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.BufferedWriter;
16 import java.io.FileWriter;
17 import java.util.*;
18
19 import org.apache.xmlbeans.XmlOptions;
20 import org.tianocore.*;
21 import org.tianocore.SupportedArchitectures.Enum;
22
23 public class MsaOwner {
24 public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";
25 public static final String VERSION = "1.0";
26 public static final String ABSTRACT = "Component name for module ";
27 public static final String DESCRIPTION = "FIX ME!";
28 public static final String LICENSE = "All rights reserved.\n" +
29 " This software and associated documentation (if any) is furnished\n" +
30 " under a license and may only be used or copied in accordance\n" +
31 " with the terms of the license. Except as permitted by such\n" +
32 " license, no part of this software or documentation may be\n" +
33 " reproduced, stored in a retrieval system, or transmitted in any\n" +
34 " form or by any means without the express written consent of\n" +
35 " Intel Corporation.";
36 public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
37
38 public static final Enum IA32 = SupportedArchitectures.IA_32;
39 public static final Enum X64 = SupportedArchitectures.X_64;
40 public static final Enum IPF = SupportedArchitectures.IPF;
41 public static final Enum EBC = SupportedArchitectures.EBC;
42
43 private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
44
45 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
46 private MsaHeaderDocument.MsaHeader msaheader = null;
47 private LicenseDocument.License license = null;
48 private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
49 private SourceFilesDocument.SourceFiles sourcefiles = null; //found local .h files are not written
50 private GuidsDocument.Guids guids = null;
51 private ProtocolsDocument.Protocols protocols = null;
52 private PPIsDocument.PPIs ppis = null;
53 private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
54 private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
55 private ExternsDocument.Externs externs = null;
56
57 private List<Enum> listarch = new ArrayList<Enum>();
58 //private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written
59 //private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();
60
61 //-----------------------------msaheader-------------------------------------//
62
63 public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {
64 Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();
65 while (classit.hasNext()) {
66 if (classit.next().getKeyword() == name) {
67 MigrationTool.ui.println ("Warning: Duplicate LibraryClass");
68 return false;
69 }
70 }
71
72 LibraryClassDocument.LibraryClass classname;
73 classname = libclassdefs.addNewLibraryClass();
74 classname.setKeyword(name);
75 classname.setUsage(usage);
76 return true;
77 }
78
79 public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
80 if (guids == null) {
81 guids = msa.addNewGuids();
82 }
83
84 Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();
85 while (guidit.hasNext()) {
86 if (guidit.next().getGuidCName() == guidname) {
87 MigrationTool.ui.println ("Warning: Duplicate Guid");
88 return false;
89 }
90 }
91
92 GuidsDocument.Guids.GuidCNames guid;
93 guid = guids.addNewGuidCNames();
94 guid.setGuidCName(guidname);
95 guid.setUsage(usage);
96 return true;
97 }
98
99
100 public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
101 if (ppis == null) {
102 ppis = msa.addNewPPIs();
103 }
104
105 Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
106 while (ppiit.hasNext()) {
107 if (ppiit.next().getPpiCName() == ppiname) {
108 MigrationTool.ui.println ("Warning: Duplicate Ppi");
109 return false;
110 }
111 }
112
113 PPIsDocument.PPIs.Ppi ppi;
114 ppi = ppis.addNewPpi();
115 ppi.setPpiCName(ppiname);
116 ppi.setUsage(usage);
117 return true;
118 }
119
120 /*
121 private final boolean installProtocols () {
122 if (mapprotocols.isEmpty()) {
123 return false;
124 }
125 Set<String> setprotocols = mapprotocols.keySet();
126 ProtocolsDocument.Protocols.Protocol protocol;
127 Iterator<String> it = setprotocols.iterator();
128 while (it.hasNext()) {
129 protocol = protocols.addNewProtocol();
130 protocol.setProtocolCName(it.next());
131 protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));
132 }
133 return true;
134 }
135
136 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
137 if (mapprotocols.containsKey(protocol)) {
138 return false;
139 } else {
140 mapprotocols.put(protocol, usage);
141 return true;
142 }
143 }
144 */
145 public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
146 if (protocols == null) {
147 protocols = msa.addNewProtocols();
148 }
149
150 Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();
151 while (proit.hasNext()) {
152 if (proit.next().getProtocolCName() == proname) {
153 MigrationTool.ui.println ("Warning: Duplicate Protocol");
154 return false;
155 }
156 }
157
158 ProtocolsDocument.Protocols.Protocol protocol;
159 protocol = protocols.addNewProtocol();
160 protocol.setProtocolCName(proname);
161 protocol.setUsage(usage);
162 return true;
163 }
164
165 /*
166 private final boolean installHashFilename () {
167 if (mapfilenames.isEmpty()) {
168 return false;
169 }
170 Set<String> setfilename = mapfilenames.keySet();
171 FilenameDocument.Filename filename;
172 List<Enum> arch = new ArrayList<Enum>();
173 Iterator<String> it = setfilename.iterator();
174 while (it.hasNext()) {
175 filename = sourcefiles.addNewFilename();
176 filename.setStringValue(it.next());
177 arch.add(mapfilenames.get(filename.getStringValue()));
178 filename.setSupArchList(arch);
179 }
180 return true;
181 }
182
183 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
184 if (mapfilenames.containsKey(filename)) {
185 return false;
186 } else {
187 mapfilenames.put(filename, arch);
188 return true;
189 }
190 }
191 */
192 public final boolean addSourceFile (String name, Enum en) {
193 Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();
194 while (fileit.hasNext()) {
195 if (fileit.next().getStringValue() == name) {
196 MigrationTool.ui.println ("Warning: Duplicate SourceFileName");
197 return false;
198 }
199 }
200
201 FilenameDocument.Filename filename;
202 List<Enum> arch = new ArrayList<Enum>();
203 filename = sourcefiles.addNewFilename();
204 filename.setStringValue(name);
205 arch.add(en);
206 filename.setSupArchList(arch);
207 return true;
208 }
209
210 // entry point todo
211
212 public final boolean setupExternSpecification () {
213 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
214 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
215 return true;
216 }
217
218 public final boolean addExternSpecification (String specification) {
219 if (externs.getSpecificationList().contains(specification)) {
220 return false;
221 } else {
222 externs.addSpecification(specification);
223 return true;
224 }
225 }
226
227 public final boolean setupPackageDependencies() {
228 Iterator<String> it;
229 //
230 // For now, simply add all package guids in the database.
231 //
232 it = MigrationTool.db.dumpAllPkgGuid();
233 while (it.hasNext()) {
234 packagedependencies.addNewPackage().setPackageGuid(it.next());
235 }
236 return true;
237 }
238
239 public final boolean addPackage (String guid) {
240 if (packagedependencies.getPackageList().contains(guid)) {
241 return false;
242 } else {
243 packagedependencies.addNewPackage().setPackageGuid(guid);
244 return true;
245 }
246 }
247
248 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
249 moduledefinitions.setBinaryModule(false);
250 moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
251 return true;
252 }
253 public final boolean addSupportedArchitectures (Enum arch) {
254 if (listarch.contains(arch)) {
255 return false;
256 } else {
257 listarch.add(arch);
258 return true;
259 }
260 }
261
262 public final boolean addSpecification (String specification) {
263 if (msaheader.getSpecification() == null) {
264 if (specification == null) {
265 msaheader.setSpecification(SPECIFICATION);
266 } else {
267 msaheader.setSpecification(specification);
268 }
269 return true;
270 } else {
271 MigrationTool.ui.println ("Warning: Duplicate Specification");
272 return false;
273 }
274 }
275
276 public final boolean addLicense (String licensecontent) {
277 if (msaheader.getLicense() == null) {
278 license = msaheader.addNewLicense();
279 if (licensecontent == null) {
280 license.setStringValue(LICENSE);
281 } else {
282 license.setStringValue(licensecontent);
283 }
284 return true;
285 } else {
286 MigrationTool.ui.println ("Warning: Duplicate License");
287 return false;
288 }
289 }
290
291 public final boolean addDescription (String description) {
292 if (msaheader.getDescription() == null) {
293 if (description == null) {
294 msaheader.setDescription(DESCRIPTION);
295 } else {
296 msaheader.setDescription(description);
297 }
298 return true;
299 } else {
300 MigrationTool.ui.println ("Warning: Duplicate Description");
301 return false;
302 }
303 }
304
305 public final boolean addAbstract (String abs) {
306 if (msaheader.getAbstract() == null) {
307 if (abs == null) {
308 msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
309 } else {
310 msaheader.setVersion(abs);
311 }
312 return true;
313 } else {
314 MigrationTool.ui.println ("Warning: Duplicate Abstract");
315 return false;
316 }
317 }
318
319 public final boolean addVersion (String version) {
320 if (msaheader.getVersion() == null) {
321 if (version == null) {
322 msaheader.setVersion(VERSION);
323 } else {
324 msaheader.setVersion(version);
325 }
326 return true;
327 } else {
328 MigrationTool.ui.println ("Warning: Duplicate Version");
329 return false;
330 }
331 }
332
333 public final boolean addCopyRight (String copyright) {
334 if (msaheader.getCopyright() == null) {
335 if (copyright == null) {
336 msaheader.setCopyright(COPYRIGHT);
337 } else {
338 msaheader.setCopyright(copyright);
339 }
340 return true;
341 } else {
342 MigrationTool.ui.println ("Warning: Duplicate CopyRight");
343 return false;
344 }
345 }
346
347 public final boolean addModuleType (String moduletype) {
348 if (msaheader.getModuleType() == null) {
349 msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
350 return true;
351 } else {
352 MigrationTool.ui.println ("Warning: Duplicate ModuleType");
353 return false;
354 }
355 }
356
357 public final boolean addGuidValue (String guidvalue) {
358 if (msaheader.getGuidValue() == null) {
359 msaheader.setGuidValue(guidvalue);
360 return true;
361 } else {
362 MigrationTool.ui.println ("Warning: Duplicate GuidValue");
363 return false;
364 }
365 }
366
367 public final boolean addModuleName (String modulename) {
368 if (msaheader.getModuleName() == null) {
369 msaheader.setModuleName(modulename);
370 return true;
371 } else {
372 MigrationTool.ui.println ("Warning: Duplicate ModuleName");
373 return false;
374 }
375 }
376 //-----------------------------msaheader-------------------------------------//
377
378 public final void flush(String outputpath) throws Exception {
379 XmlOptions options = new XmlOptions();
380
381 options.setCharacterEncoding("UTF-8");
382 options.setSavePrettyPrint();
383 options.setSavePrettyPrintIndent(2);
384 options.setUseDefaultNamespace();
385
386 BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));
387 msadoc.save(bw, options);
388 bw.flush();
389 bw.close();
390 }
391
392 private final MsaOwner init () {
393 msa = msadoc.addNewModuleSurfaceArea();
394 msaheader = msa.addNewMsaHeader();
395 moduledefinitions = msa.addNewModuleDefinitions();
396 moduledefinitions.setSupportedArchitectures(listarch);
397
398 sourcefiles = msa.addNewSourceFiles();
399 packagedependencies = msa.addNewPackageDependencies();
400 libclassdefs = msa.addNewLibraryClassDefinitions();
401 externs = msa.addNewExterns();
402 return this;
403 }
404
405 public static final MsaOwner initNewMsaOwner() {
406 return new MsaOwner().init();
407 }
408 }