]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/MigrationTools/org/tianocore/migration/MsaOwner.java
fix .s comment
[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 /*
65 if (!libclassdefs.getLibraryClassList().contains(name)) {
66 LibraryClassDocument.LibraryClass classname;
67 classname = libclassdefs.addNewLibraryClass();
68 classname.setKeyword(name);
69 classname.setUsage(usage);
70 return true;
71 } else {
72 return false;
73 }
74 */
75 if (name == null) {
76 return false;
77 } else {
78 Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();
79 while (classit.hasNext()) {
80 if (classit.next().getKeyword().matches(name)) {
81 //MigrationTool.ui.println ("Warning: Duplicate LibraryClass");
82 return false;
83 }
84 }
85
86 LibraryClassDocument.LibraryClass classname;
87 classname = libclassdefs.addNewLibraryClass();
88 classname.setKeyword(name);
89 classname.setUsage(usage);
90 return true;
91
92 }
93 }
94
95 public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
96 if (guids == null) {
97 guids = msa.addNewGuids();
98 }
99
100 Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();
101 while (guidit.hasNext()) {
102 if (guidit.next().getGuidCName() == guidname) {
103 //MigrationTool.ui.println ("Warning: Duplicate Guid");
104 return false;
105 }
106 }
107
108 GuidsDocument.Guids.GuidCNames guid;
109 guid = guids.addNewGuidCNames();
110 guid.setGuidCName(guidname);
111 guid.setUsage(usage);
112 return true;
113 }
114
115
116 public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
117 if (ppis == null) {
118 ppis = msa.addNewPPIs();
119 }
120
121 Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
122 while (ppiit.hasNext()) {
123 if (ppiit.next().getPpiCName() == ppiname) {
124 //MigrationTool.ui.println ("Warning: Duplicate Ppi");
125 return false;
126 }
127 }
128
129 PPIsDocument.PPIs.Ppi ppi;
130 ppi = ppis.addNewPpi();
131 ppi.setPpiCName(ppiname);
132 ppi.setUsage(usage);
133 return true;
134 }
135
136 /*
137 private final boolean installProtocols () {
138 if (mapprotocols.isEmpty()) {
139 return false;
140 }
141 Set<String> setprotocols = mapprotocols.keySet();
142 ProtocolsDocument.Protocols.Protocol protocol;
143 Iterator<String> it = setprotocols.iterator();
144 while (it.hasNext()) {
145 protocol = protocols.addNewProtocol();
146 protocol.setProtocolCName(it.next());
147 protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));
148 }
149 return true;
150 }
151
152 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
153 if (mapprotocols.containsKey(protocol)) {
154 return false;
155 } else {
156 mapprotocols.put(protocol, usage);
157 return true;
158 }
159 }
160 */
161 public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
162 if (protocols == null) {
163 protocols = msa.addNewProtocols();
164 }
165
166 Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();
167 while (proit.hasNext()) {
168 if (proit.next().getProtocolCName() == proname) {
169 //MigrationTool.ui.println ("Warning: Duplicate Protocol");
170 return false;
171 }
172 }
173
174 ProtocolsDocument.Protocols.Protocol protocol;
175 protocol = protocols.addNewProtocol();
176 protocol.setProtocolCName(proname);
177 protocol.setUsage(usage);
178 return true;
179 }
180
181 /*
182 private final boolean installHashFilename () {
183 if (mapfilenames.isEmpty()) {
184 return false;
185 }
186 Set<String> setfilename = mapfilenames.keySet();
187 FilenameDocument.Filename filename;
188 List<Enum> arch = new ArrayList<Enum>();
189 Iterator<String> it = setfilename.iterator();
190 while (it.hasNext()) {
191 filename = sourcefiles.addNewFilename();
192 filename.setStringValue(it.next());
193 arch.add(mapfilenames.get(filename.getStringValue()));
194 filename.setSupArchList(arch);
195 }
196 return true;
197 }
198
199 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
200 if (mapfilenames.containsKey(filename)) {
201 return false;
202 } else {
203 mapfilenames.put(filename, arch);
204 return true;
205 }
206 }
207 */
208 public final boolean addSourceFile (String name, Enum en) {
209 Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();
210 while (fileit.hasNext()) {
211 if (fileit.next().getStringValue() == name) {
212 MigrationTool.ui.println ("Warning: Duplicate SourceFileName");
213 return false;
214 }
215 }
216
217 FilenameDocument.Filename filename;
218 List<Enum> arch = new ArrayList<Enum>();
219 filename = sourcefiles.addNewFilename();
220 filename.setStringValue(name);
221 arch.add(en);
222 filename.setSupArchList(arch);
223 return true;
224 }
225
226 // entry point todo
227
228 public final boolean setupExternSpecification () {
229 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
230 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
231 return true;
232 }
233
234 public final boolean addExternSpecification (String specification) {
235 if (externs.getSpecificationList().contains(specification)) {
236 return false;
237 } else {
238 externs.addSpecification(specification);
239 return true;
240 }
241 }
242
243 public final boolean setupPackageDependencies() {
244 Iterator<String> it;
245 //
246 // For now, simply add all package guids in the database.
247 //
248 it = MigrationTool.db.dumpAllPkgGuid();
249 while (it.hasNext()) {
250 packagedependencies.addNewPackage().setPackageGuid(it.next());
251 }
252 return true;
253 }
254
255 public final boolean addPackage (String guid) {
256 if (packagedependencies.getPackageList().contains(guid)) {
257 return false;
258 } else {
259 packagedependencies.addNewPackage().setPackageGuid(guid);
260 return true;
261 }
262 }
263
264 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
265 moduledefinitions.setBinaryModule(false);
266 moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
267 return true;
268 }
269 public final boolean addSupportedArchitectures (Enum arch) {
270 if (listarch.contains(arch)) {
271 return false;
272 } else {
273 listarch.add(arch);
274 return true;
275 }
276 }
277
278 public final boolean addSpecification (String specification) {
279 if (msaheader.getSpecification() == null) {
280 if (specification == null) {
281 msaheader.setSpecification(SPECIFICATION);
282 } else {
283 msaheader.setSpecification(specification);
284 }
285 return true;
286 } else {
287 MigrationTool.ui.println ("Warning: Duplicate Specification");
288 return false;
289 }
290 }
291
292 public final boolean addLicense (String licensecontent) {
293 if (msaheader.getLicense() == null) {
294 license = msaheader.addNewLicense();
295 if (licensecontent == null) {
296 license.setStringValue(LICENSE);
297 } else {
298 license.setStringValue(licensecontent);
299 }
300 return true;
301 } else {
302 MigrationTool.ui.println ("Warning: Duplicate License");
303 return false;
304 }
305 }
306
307 public final boolean addDescription (String description) {
308 if (msaheader.getDescription() == null) {
309 if (description == null) {
310 msaheader.setDescription(DESCRIPTION);
311 } else {
312 msaheader.setDescription(description);
313 }
314 return true;
315 } else {
316 MigrationTool.ui.println ("Warning: Duplicate Description");
317 return false;
318 }
319 }
320
321 public final boolean addAbstract (String abs) {
322 if (msaheader.getAbstract() == null) {
323 if (abs == null) {
324 msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
325 } else {
326 msaheader.setVersion(abs);
327 }
328 return true;
329 } else {
330 MigrationTool.ui.println ("Warning: Duplicate Abstract");
331 return false;
332 }
333 }
334
335 public final boolean addVersion (String version) {
336 if (msaheader.getVersion() == null) {
337 if (version == null) {
338 msaheader.setVersion(VERSION);
339 } else {
340 msaheader.setVersion(version);
341 }
342 return true;
343 } else {
344 MigrationTool.ui.println ("Warning: Duplicate Version");
345 return false;
346 }
347 }
348
349 public final boolean addCopyRight (String copyright) {
350 if (msaheader.getCopyright() == null) {
351 if (copyright == null) {
352 msaheader.setCopyright(COPYRIGHT);
353 } else {
354 msaheader.setCopyright(copyright);
355 }
356 return true;
357 } else {
358 MigrationTool.ui.println ("Warning: Duplicate CopyRight");
359 return false;
360 }
361 }
362
363 public final boolean addModuleType (String moduletype) {
364 if (msaheader.getModuleType() == null) {
365 msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
366 return true;
367 } else {
368 MigrationTool.ui.println ("Warning: Duplicate ModuleType");
369 return false;
370 }
371 }
372
373 public final boolean addGuidValue (String guidvalue) {
374 if (msaheader.getGuidValue() == null) {
375 msaheader.setGuidValue(guidvalue);
376 return true;
377 } else {
378 MigrationTool.ui.println ("Warning: Duplicate GuidValue");
379 return false;
380 }
381 }
382
383 public final boolean addModuleName (String modulename) {
384 if (msaheader.getModuleName() == null) {
385 msaheader.setModuleName(modulename);
386 return true;
387 } else {
388 MigrationTool.ui.println ("Warning: Duplicate ModuleName");
389 return false;
390 }
391 }
392 //-----------------------------msaheader-------------------------------------//
393
394 private final void fullfill () throws Exception {
395 addCopyRight(null);
396 addVersion(null);
397 addAbstract(null);
398 addDescription(null);
399 addLicense(null);
400 addSpecification(null);
401 }
402
403 public final void flush(String outputpath) throws Exception {
404 XmlOptions options = new XmlOptions();
405
406 options.setCharacterEncoding("UTF-8");
407 options.setSavePrettyPrint();
408 options.setSavePrettyPrintIndent(2);
409 options.setUseDefaultNamespace();
410
411 BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));
412 fullfill();
413 msadoc.save(bw, options);
414 bw.flush();
415 bw.close();
416 }
417
418 private final MsaOwner init () {
419 msa = msadoc.addNewModuleSurfaceArea();
420 msaheader = msa.addNewMsaHeader();
421 moduledefinitions = msa.addNewModuleDefinitions();
422 moduledefinitions.setSupportedArchitectures(listarch);
423
424 sourcefiles = msa.addNewSourceFiles();
425 packagedependencies = msa.addNewPackageDependencies();
426 libclassdefs = msa.addNewLibraryClassDefinitions();
427 externs = msa.addNewExterns();
428 return this;
429 }
430
431 public static final MsaOwner initNewMsaOwner() {
432 return new MsaOwner().init();
433 }
434 }