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
) {
65 if (!libclassdefs.getLibraryClassList().contains(name)) {
66 LibraryClassDocument.LibraryClass classname;
67 classname = libclassdefs.addNewLibraryClass();
68 classname.setKeyword(name);
69 classname.setUsage(usage);
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");
86 LibraryClassDocument
.LibraryClass classname
;
87 classname
= libclassdefs
.addNewLibraryClass();
88 classname
.setKeyword(name
);
89 classname
.setUsage(usage
);
95 public final boolean addGuid (String guidname
, UsageTypes
.Enum usage
) {
97 guids
= msa
.addNewGuids();
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");
108 GuidsDocument
.Guids
.GuidCNames guid
;
109 guid
= guids
.addNewGuidCNames();
110 guid
.setGuidCName(guidname
);
111 guid
.setUsage(usage
);
116 public final boolean addPpi (String ppiname
, UsageTypes
.Enum usage
) {
118 ppis
= msa
.addNewPPIs();
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");
129 PPIsDocument
.PPIs
.Ppi ppi
;
130 ppi
= ppis
.addNewPpi();
131 ppi
.setPpiCName(ppiname
);
137 private final boolean installProtocols () {
138 if (mapprotocols.isEmpty()) {
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()));
152 public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {
153 if (mapprotocols.containsKey(protocol)) {
156 mapprotocols.put(protocol, usage);
161 public final boolean addProtocol (String proname
, UsageTypes
.Enum usage
) {
162 if (protocols
== null) {
163 protocols
= msa
.addNewProtocols();
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");
174 ProtocolsDocument
.Protocols
.Protocol protocol
;
175 protocol
= protocols
.addNewProtocol();
176 protocol
.setProtocolCName(proname
);
177 protocol
.setUsage(usage
);
182 private final boolean installHashFilename () {
183 if (mapfilenames.isEmpty()) {
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);
199 public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?
200 if (mapfilenames.containsKey(filename)) {
203 mapfilenames.put(filename, arch);
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");
217 FilenameDocument
.Filename filename
;
218 List
<Enum
> arch
= new ArrayList
<Enum
>();
219 filename
= sourcefiles
.addNewFilename();
220 filename
.setStringValue(name
);
222 filename
.setSupArchList(arch
);
228 public final boolean setupExternSpecification () {
229 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
230 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
234 public final boolean addExternSpecification (String specification
) {
235 if (externs
.getSpecificationList().contains(specification
)) {
238 externs
.addSpecification(specification
);
243 public final boolean setupPackageDependencies() {
246 // For now, simply add all package guids in the database.
248 it
= MigrationTool
.db
.dumpAllPkgGuid();
249 while (it
.hasNext()) {
250 packagedependencies
.addNewPackage().setPackageGuid(it
.next());
255 public final boolean addPackage (String guid
) {
256 if (packagedependencies
.getPackageList().contains(guid
)) {
259 packagedependencies
.addNewPackage().setPackageGuid(guid
);
264 public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
265 moduledefinitions
.setBinaryModule(false);
266 moduledefinitions
.setOutputFileBasename(msaheader
.getModuleName());
269 public final boolean addSupportedArchitectures (Enum arch
) {
270 if (listarch
.contains(arch
)) {
278 public final boolean addSpecification (String specification
) {
279 if (msaheader
.getSpecification() == null) {
280 if (specification
== null) {
281 msaheader
.setSpecification(SPECIFICATION
);
283 msaheader
.setSpecification(specification
);
287 MigrationTool
.ui
.println ("Warning: Duplicate Specification");
292 public final boolean addLicense (String licensecontent
) {
293 if (msaheader
.getLicense() == null) {
294 license
= msaheader
.addNewLicense();
295 if (licensecontent
== null) {
296 license
.setStringValue(LICENSE
);
298 license
.setStringValue(licensecontent
);
302 MigrationTool
.ui
.println ("Warning: Duplicate License");
307 public final boolean addDescription (String description
) {
308 if (msaheader
.getDescription() == null) {
309 if (description
== null) {
310 msaheader
.setDescription(DESCRIPTION
);
312 msaheader
.setDescription(description
);
316 MigrationTool
.ui
.println ("Warning: Duplicate Description");
321 public final boolean addAbstract (String abs
) {
322 if (msaheader
.getAbstract() == null) {
324 msaheader
.setAbstract(ABSTRACT
+ msaheader
.getModuleName());
326 msaheader
.setVersion(abs
);
330 MigrationTool
.ui
.println ("Warning: Duplicate Abstract");
335 public final boolean addVersion (String version
) {
336 if (msaheader
.getVersion() == null) {
337 if (version
== null) {
338 msaheader
.setVersion(VERSION
);
340 msaheader
.setVersion(version
);
344 MigrationTool
.ui
.println ("Warning: Duplicate Version");
349 public final boolean addCopyRight (String copyright
) {
350 if (msaheader
.getCopyright() == null) {
351 if (copyright
== null) {
352 msaheader
.setCopyright(COPYRIGHT
);
354 msaheader
.setCopyright(copyright
);
358 MigrationTool
.ui
.println ("Warning: Duplicate CopyRight");
363 public final boolean addModuleType (String moduletype
) {
364 if (msaheader
.getModuleType() == null) {
365 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(moduletype
));
368 MigrationTool
.ui
.println ("Warning: Duplicate ModuleType");
373 public final boolean addGuidValue (String guidvalue
) {
374 if (msaheader
.getGuidValue() == null) {
375 msaheader
.setGuidValue(guidvalue
);
378 MigrationTool
.ui
.println ("Warning: Duplicate GuidValue");
383 public final boolean addModuleName (String modulename
) {
384 if (msaheader
.getModuleName() == null) {
385 msaheader
.setModuleName(modulename
);
388 MigrationTool
.ui
.println ("Warning: Duplicate ModuleName");
392 //-----------------------------msaheader-------------------------------------//
394 private final void fullfill () throws Exception
{
398 addDescription(null);
400 addSpecification(null);
403 public final void flush(String outputpath
) throws Exception
{
404 XmlOptions options
= new XmlOptions();
406 options
.setCharacterEncoding("UTF-8");
407 options
.setSavePrettyPrint();
408 options
.setSavePrettyPrintIndent(2);
409 options
.setUseDefaultNamespace();
411 BufferedWriter bw
= new BufferedWriter(new FileWriter(outputpath
));
413 msadoc
.save(bw
, options
);
418 private final MsaOwner
init () {
419 msa
= msadoc
.addNewModuleSurfaceArea();
420 msaheader
= msa
.addNewMsaHeader();
421 moduledefinitions
= msa
.addNewModuleDefinitions();
422 moduledefinitions
.setSupportedArchitectures(listarch
);
424 sourcefiles
= msa
.addNewSourceFiles();
425 packagedependencies
= msa
.addNewPackageDependencies();
426 libclassdefs
= msa
.addNewLibraryClassDefinitions();
427 externs
= msa
.addNewExterns();
431 public static final MsaOwner
initNewMsaOwner() {
432 return new MsaOwner().init();