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
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import org
.apache
.xmlbeans
.XmlOptions
;
22 import org
.tianocore
.ExternsDocument
;
23 import org
.tianocore
.FilenameDocument
;
24 import org
.tianocore
.GuidsDocument
;
25 import org
.tianocore
.LibraryClassDefinitionsDocument
;
26 import org
.tianocore
.LibraryClassDocument
;
27 import org
.tianocore
.LicenseDocument
;
28 import org
.tianocore
.ModuleDefinitionsDocument
;
29 import org
.tianocore
.ModuleSurfaceAreaDocument
;
30 import org
.tianocore
.ModuleTypeDef
;
31 import org
.tianocore
.MsaHeaderDocument
;
32 import org
.tianocore
.PPIsDocument
;
33 import org
.tianocore
.PackageDependenciesDocument
;
34 import org
.tianocore
.ProtocolsDocument
;
35 import org
.tianocore
.SourceFilesDocument
;
36 import org
.tianocore
.SupportedArchitectures
;
37 import org
.tianocore
.UsageTypes
;
38 import org
.tianocore
.SupportedArchitectures
.Enum
;
40 public class MsaOwner
{
41 public static final String COPYRIGHT
= "Copyright (c) 2006, Intel Corporation";
43 public static final String VERSION
= "1.0";
45 public static final String ABSTRACT
= "Component name for module ";
47 public static final String DESCRIPTION
= "FIX ME!";
49 public static final String LICENSE
= "All rights reserved.\n"
50 + " This software and associated documentation (if any) is furnished\n"
51 + " under a license and may only be used or copied in accordance\n"
52 + " with the terms of the license. Except as permitted by such\n"
53 + " license, no part of this software or documentation may be\n"
54 + " reproduced, stored in a retrieval system, or transmitted in any\n"
55 + " form or by any means without the express written consent of\n"
56 + " Intel Corporation.";
58 public static final String SPECIFICATION
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
60 public static final Enum IA32
= SupportedArchitectures
.IA_32
;
62 public static final Enum X64
= SupportedArchitectures
.X_64
;
64 public static final Enum IPF
= SupportedArchitectures
.IPF
;
66 public static final Enum EBC
= SupportedArchitectures
.EBC
;
68 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
71 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
73 private MsaHeaderDocument
.MsaHeader msaheader
= null;
75 private LicenseDocument
.License license
= null;
77 private ModuleDefinitionsDocument
.ModuleDefinitions moduledefinitions
= null;
79 private SourceFilesDocument
.SourceFiles sourcefiles
= null; // found local
83 private GuidsDocument
.Guids guids
= null;
85 private ProtocolsDocument
.Protocols protocols
= null;
87 private PPIsDocument
.PPIs ppis
= null;
89 private PackageDependenciesDocument
.PackageDependencies packagedependencies
= null;
91 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= null;
93 private ExternsDocument
.Externs externs
= null;
95 private List
<Enum
> listarch
= new ArrayList
<Enum
>();
97 // private Map<String, Enum> mapfilenames = new HashMap<String, Enum>();
98 // //this need to be installed manually when msa is to be written
99 // private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String,
100 // UsageTypes.Enum>();
102 // -----------------------------msaheader-------------------------------------//
104 public final boolean addLibraryClass(String name
, UsageTypes
.Enum usage
) {
106 * if (!libclassdefs.getLibraryClassList().contains(name)) {
107 * LibraryClassDocument.LibraryClass classname; classname =
108 * libclassdefs.addNewLibraryClass(); classname.setKeyword(name);
109 * classname.setUsage(usage); return true; } else { return false; }
114 Iterator
<LibraryClassDocument
.LibraryClass
> classit
= libclassdefs
115 .getLibraryClassList().iterator();
116 while (classit
.hasNext()) {
117 if (classit
.next().getKeyword().matches(name
)) {
118 // MigrationTool.ui.println ("Warning: Duplicate
124 LibraryClassDocument
.LibraryClass classname
;
125 classname
= libclassdefs
.addNewLibraryClass();
126 classname
.setKeyword(name
);
127 classname
.setUsage(usage
);
133 public final boolean addGuid(String guidname
, UsageTypes
.Enum usage
) {
135 guids
= msa
.addNewGuids();
138 Iterator
<GuidsDocument
.Guids
.GuidCNames
> guidit
= guids
139 .getGuidCNamesList().iterator();
140 while (guidit
.hasNext()) {
141 if (guidit
.next().getGuidCName() == guidname
) {
142 // MigrationTool.ui.println ("Warning: Duplicate Guid");
147 GuidsDocument
.Guids
.GuidCNames guid
;
148 guid
= guids
.addNewGuidCNames();
149 guid
.setGuidCName(guidname
);
150 guid
.setUsage(usage
);
154 public final boolean addPpi(String ppiname
, UsageTypes
.Enum usage
) {
156 ppis
= msa
.addNewPPIs();
159 Iterator
<PPIsDocument
.PPIs
.Ppi
> ppiit
= ppis
.getPpiList().iterator();
160 while (ppiit
.hasNext()) {
161 if (ppiit
.next().getPpiCName() == ppiname
) {
162 // MigrationTool.ui.println ("Warning: Duplicate Ppi");
167 PPIsDocument
.PPIs
.Ppi ppi
;
168 ppi
= ppis
.addNewPpi();
169 ppi
.setPpiCName(ppiname
);
174 public final boolean addProtocol(String proname
, UsageTypes
.Enum usage
) {
175 if (protocols
== null) {
176 protocols
= msa
.addNewProtocols();
179 Iterator
<ProtocolsDocument
.Protocols
.Protocol
> proit
= protocols
180 .getProtocolList().iterator();
181 while (proit
.hasNext()) {
182 if (proit
.next().getProtocolCName() == proname
) {
183 // MigrationTool.ui.println ("Warning: Duplicate Protocol");
188 ProtocolsDocument
.Protocols
.Protocol protocol
;
189 protocol
= protocols
.addNewProtocol();
190 protocol
.setProtocolCName(proname
);
191 protocol
.setUsage(usage
);
195 public final boolean addSourceFile(String name
, Enum en
) {
196 Iterator
<FilenameDocument
.Filename
> fileit
= sourcefiles
197 .getFilenameList().iterator();
198 while (fileit
.hasNext()) {
199 if (fileit
.next().getStringValue() == name
) {
200 MigrationTool
.ui
.println("Warning: Duplicate SourceFileName");
205 FilenameDocument
.Filename filename
;
206 List
<Enum
> arch
= new ArrayList
<Enum
>();
207 filename
= sourcefiles
.addNewFilename();
208 filename
.setStringValue(name
);
210 filename
.setSupArchList(arch
);
216 public final boolean setupExternSpecification() {
217 addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
218 addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
222 public final boolean addExternSpecification(String specification
) {
223 if (externs
.getSpecificationList().contains(specification
)) {
226 externs
.addSpecification(specification
);
231 public final boolean setupPackageDependencies() {
234 // For now, simply add all package guids in the database.
236 it
= MigrationTool
.db
.dumpAllPkgGuid();
237 while (it
.hasNext()) {
238 packagedependencies
.addNewPackage().setPackageGuid(it
.next());
243 public final boolean addPackage(String guid
) {
244 if (packagedependencies
.getPackageList().contains(guid
)) {
247 packagedependencies
.addNewPackage().setPackageGuid(guid
);
252 public final boolean setupModuleDefinitions() { // ????????? give this job
254 moduledefinitions
.setBinaryModule(false);
255 moduledefinitions
.setOutputFileBasename(msaheader
.getModuleName());
259 public final boolean addSupportedArchitectures(Enum arch
) {
260 if (listarch
.contains(arch
)) {
268 public final boolean addSpecification(String specification
) {
269 if (msaheader
.getSpecification() == null) {
270 if (specification
== null) {
271 msaheader
.setSpecification(SPECIFICATION
);
273 msaheader
.setSpecification(specification
);
277 MigrationTool
.ui
.println("Warning: Duplicate Specification");
282 public final boolean addLicense(String licensecontent
) {
283 if (msaheader
.getLicense() == null) {
284 license
= msaheader
.addNewLicense();
285 if (licensecontent
== null) {
286 license
.setStringValue(LICENSE
);
288 license
.setStringValue(licensecontent
);
292 MigrationTool
.ui
.println("Warning: Duplicate License");
297 public final boolean addDescription(String description
) {
298 if (msaheader
.getDescription() == null) {
299 if (description
== null) {
300 msaheader
.setDescription(DESCRIPTION
);
302 msaheader
.setDescription(description
);
306 MigrationTool
.ui
.println("Warning: Duplicate Description");
311 public final boolean addAbstract(String abs
) {
312 if (msaheader
.getAbstract() == null) {
314 msaheader
.setAbstract(ABSTRACT
+ msaheader
.getModuleName());
316 msaheader
.setVersion(abs
);
320 MigrationTool
.ui
.println("Warning: Duplicate Abstract");
325 public final boolean addVersion(String version
) {
326 if (msaheader
.getVersion() == null) {
327 if (version
== null) {
328 msaheader
.setVersion(VERSION
);
330 msaheader
.setVersion(version
);
334 MigrationTool
.ui
.println("Warning: Duplicate Version");
339 public final boolean addCopyRight(String copyright
) {
340 if (msaheader
.getCopyright() == null) {
341 if (copyright
== null) {
342 msaheader
.setCopyright(COPYRIGHT
);
344 msaheader
.setCopyright(copyright
);
348 MigrationTool
.ui
.println("Warning: Duplicate CopyRight");
353 public final boolean addModuleType(String moduletype
) {
354 if (msaheader
.getModuleType() == null) {
355 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(moduletype
));
358 MigrationTool
.ui
.println("Warning: Duplicate ModuleType");
363 public final boolean addGuidValue(String guidvalue
) {
364 if (msaheader
.getGuidValue() == null) {
365 msaheader
.setGuidValue(guidvalue
);
368 MigrationTool
.ui
.println("Warning: Duplicate GuidValue");
373 public final boolean addModuleName(String modulename
) {
374 if (msaheader
.getModuleName() == null) {
375 msaheader
.setModuleName(modulename
);
378 MigrationTool
.ui
.println("Warning: Duplicate ModuleName");
383 // -----------------------------msaheader-------------------------------------//
385 private final void fullfill() throws Exception
{
389 addDescription(null);
391 addSpecification(null);
394 public final void flush(String outputpath
) throws Exception
{
395 XmlOptions options
= new XmlOptions();
397 options
.setCharacterEncoding("UTF-8");
398 options
.setSavePrettyPrint();
399 options
.setSavePrettyPrintIndent(2);
400 options
.setUseDefaultNamespace();
402 BufferedWriter bw
= new BufferedWriter(new FileWriter(outputpath
));
404 msadoc
.save(bw
, options
);
409 private final MsaOwner
init() {
410 msa
= msadoc
.addNewModuleSurfaceArea();
411 msaheader
= msa
.addNewMsaHeader();
412 moduledefinitions
= msa
.addNewModuleDefinitions();
413 moduledefinitions
.setSupportedArchitectures(listarch
);
415 sourcefiles
= msa
.addNewSourceFiles();
416 packagedependencies
= msa
.addNewPackageDependencies();
417 libclassdefs
= msa
.addNewLibraryClassDefinitions();
418 externs
= msa
.addNewExterns();
422 public static final MsaOwner
initNewMsaOwner() {
423 return new MsaOwner().init();