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
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.
13 package org
.tianocore
.migration
;
15 import java
.io
.BufferedWriter
;
16 import java
.io
.FileWriter
;
19 import org
.apache
.xmlbeans
.XmlOptions
;
20 import org
.tianocore
.*;
21 import org
.tianocore
.SupportedArchitectures
.Enum
;
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";
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
;
43 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
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;
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>();
61 //-----------------------------msaheader-------------------------------------//
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");
72 LibraryClassDocument
.LibraryClass classname
;
73 classname
= libclassdefs
.addNewLibraryClass();
74 classname
.setKeyword(name
);
75 classname
.setUsage(usage
);
79 public final boolean addGuid (String guidname
, UsageTypes
.Enum usage
) {
81 guids
= msa
.addNewGuids();
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");
92 GuidsDocument
.Guids
.GuidCNames guid
;
93 guid
= guids
.addNewGuidCNames();
94 guid
.setGuidCName(guidname
);
100 public final boolean addPpi (String ppiname
, UsageTypes
.Enum usage
) {
102 ppis
= msa
.addNewPPIs();
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");
113 PPIsDocument
.PPIs
.Ppi ppi
;
114 ppi
= ppis
.addNewPpi();
115 ppi
.setPpiCName(ppiname
);
121 private final boolean installProtocols () {
122 if (mapprotocols.isEmpty()) {
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()));
136 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
137 if (mapprotocols.containsKey(protocol)) {
140 mapprotocols.put(protocol, usage);
145 public final boolean addProtocol (String proname
, UsageTypes
.Enum usage
) {
146 if (protocols
== null) {
147 protocols
= msa
.addNewProtocols();
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");
158 ProtocolsDocument
.Protocols
.Protocol protocol
;
159 protocol
= protocols
.addNewProtocol();
160 protocol
.setProtocolCName(proname
);
161 protocol
.setUsage(usage
);
166 private final boolean installHashFilename () {
167 if (mapfilenames.isEmpty()) {
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);
183 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
184 if (mapfilenames.containsKey(filename)) {
187 mapfilenames.put(filename, arch);
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");
201 FilenameDocument
.Filename filename
;
202 List
<Enum
> arch
= new ArrayList
<Enum
>();
203 filename
= sourcefiles
.addNewFilename();
204 filename
.setStringValue(name
);
206 filename
.setSupArchList(arch
);
212 public final boolean setupExternSpecification () {
213 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
214 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
218 public final boolean addExternSpecification (String specification
) {
219 if (externs
.getSpecificationList().contains(specification
)) {
222 externs
.addSpecification(specification
);
227 public final boolean setupPackageDependencies() {
230 // For now, simply add all package guids in the database.
232 it
= MigrationTool
.db
.dumpAllPkgGuid();
233 while (it
.hasNext()) {
234 packagedependencies
.addNewPackage().setPackageGuid(it
.next());
239 public final boolean addPackage (String guid
) {
240 if (packagedependencies
.getPackageList().contains(guid
)) {
243 packagedependencies
.addNewPackage().setPackageGuid(guid
);
248 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
249 moduledefinitions
.setBinaryModule(false);
250 moduledefinitions
.setOutputFileBasename(msaheader
.getModuleName());
253 public final boolean addSupportedArchitectures (Enum arch
) {
254 if (listarch
.contains(arch
)) {
262 public final boolean addSpecification (String specification
) {
263 if (msaheader
.getSpecification() == null) {
264 if (specification
== null) {
265 msaheader
.setSpecification(SPECIFICATION
);
267 msaheader
.setSpecification(specification
);
271 MigrationTool
.ui
.println ("Warning: Duplicate Specification");
276 public final boolean addLicense (String licensecontent
) {
277 if (msaheader
.getLicense() == null) {
278 license
= msaheader
.addNewLicense();
279 if (licensecontent
== null) {
280 license
.setStringValue(LICENSE
);
282 license
.setStringValue(licensecontent
);
286 MigrationTool
.ui
.println ("Warning: Duplicate License");
291 public final boolean addDescription (String description
) {
292 if (msaheader
.getDescription() == null) {
293 if (description
== null) {
294 msaheader
.setDescription(DESCRIPTION
);
296 msaheader
.setDescription(description
);
300 MigrationTool
.ui
.println ("Warning: Duplicate Description");
305 public final boolean addAbstract (String abs
) {
306 if (msaheader
.getAbstract() == null) {
308 msaheader
.setAbstract(ABSTRACT
+ msaheader
.getModuleName());
310 msaheader
.setVersion(abs
);
314 MigrationTool
.ui
.println ("Warning: Duplicate Abstract");
319 public final boolean addVersion (String version
) {
320 if (msaheader
.getVersion() == null) {
321 if (version
== null) {
322 msaheader
.setVersion(VERSION
);
324 msaheader
.setVersion(version
);
328 MigrationTool
.ui
.println ("Warning: Duplicate Version");
333 public final boolean addCopyRight (String copyright
) {
334 if (msaheader
.getCopyright() == null) {
335 if (copyright
== null) {
336 msaheader
.setCopyright(COPYRIGHT
);
338 msaheader
.setCopyright(copyright
);
342 MigrationTool
.ui
.println ("Warning: Duplicate CopyRight");
347 public final boolean addModuleType (String moduletype
) {
348 if (msaheader
.getModuleType() == null) {
349 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(moduletype
));
352 MigrationTool
.ui
.println ("Warning: Duplicate ModuleType");
357 public final boolean addGuidValue (String guidvalue
) {
358 if (msaheader
.getGuidValue() == null) {
359 msaheader
.setGuidValue(guidvalue
);
362 MigrationTool
.ui
.println ("Warning: Duplicate GuidValue");
367 public final boolean addModuleName (String modulename
) {
368 if (msaheader
.getModuleName() == null) {
369 msaheader
.setModuleName(modulename
);
372 MigrationTool
.ui
.println ("Warning: Duplicate ModuleName");
376 //-----------------------------msaheader-------------------------------------//
378 public final void flush(String outputpath
) throws Exception
{
379 XmlOptions options
= new XmlOptions();
381 options
.setCharacterEncoding("UTF-8");
382 options
.setSavePrettyPrint();
383 options
.setSavePrettyPrintIndent(2);
384 options
.setUseDefaultNamespace();
386 BufferedWriter bw
= new BufferedWriter(new FileWriter(outputpath
));
387 msadoc
.save(bw
, options
);
392 private final MsaOwner
init () {
393 msa
= msadoc
.addNewModuleSurfaceArea();
394 msaheader
= msa
.addNewMsaHeader();
395 moduledefinitions
= msa
.addNewModuleDefinitions();
396 moduledefinitions
.setSupportedArchitectures(listarch
);
398 sourcefiles
= msa
.addNewSourceFiles();
399 packagedependencies
= msa
.addNewPackageDependencies();
400 libclassdefs
= msa
.addNewLibraryClassDefinitions();
401 externs
= msa
.addNewExterns();
405 public static final MsaOwner
initNewMsaOwner() {
406 return new MsaOwner().init();