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
;
18 import org
.tianocore
.*;
19 import org
.tianocore
.SupportedArchitectures
.Enum
;
20 import org
.apache
.xmlbeans
.*;
22 public class MsaWriter
{
23 MsaWriter(String path
, ModuleInfo moduleinfo
, Database database
) {
29 private String modulepath
;
30 private ModuleInfo mi
;
33 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
35 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= msadoc
.addNewModuleSurfaceArea();
36 private MsaHeaderDocument
.MsaHeader msaheader
= msa
.addNewMsaHeader();
37 private ModuleDefinitionsDocument
.ModuleDefinitions md
= msa
.addNewModuleDefinitions();
38 private SourceFilesDocument
.SourceFiles sourcefiles
= msa
.addNewSourceFiles(); //found local .h files are not written
39 private GuidsDocument
.Guids guids
= msa
.addNewGuids();
40 private ProtocolsDocument
.Protocols protocols
= msa
.addNewProtocols();
41 private PPIsDocument
.PPIs ppis
= msa
.addNewPPIs();
42 private PackageDependenciesDocument
.PackageDependencies pd
= msa
.addNewPackageDependencies();
43 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= msa
.addNewLibraryClassDefinitions();
44 private ExternsDocument
.Externs externs
= msa
.addNewExterns();
46 private String
Query (String requirement
) throws Exception
{
48 BufferedReader rd
= new BufferedReader(new InputStreamReader(System
.in
));
49 System
.out
.println(requirement
);
50 while ((answer
= rd
.readLine()).length() == 0) ;
54 private ModuleSurfaceAreaDocument
fulfillMsadoc() throws Exception
{
58 if (mi
.modulename
!= null) {
59 msaheader
.setModuleName(mi
.modulename
);
61 msaheader
.setModuleName(mi
.modulename
= Query("ModuleName Not Found . Please Input ModuleName"));
63 if (mi
.guidvalue
!= null) {
64 msaheader
.setGuidValue(mi
.guidvalue
);
66 msaheader
.setGuidValue(mi
.guidvalue
= Query("GuidValue Not Found . Please Input GuidValue"));
68 if (mi
.moduletype
!= null) {
69 if (mi
.moduletype
.contains("PEI")) {
70 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("PEIM"));
72 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("DXE_DRIVER"));
75 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(mi
.moduletype
= Query("GuidValue Not Found . Please Input GuidValue")));
77 msaheader
.setCopyright("Copyright (c) 2006, Intel Corporation");
78 msaheader
.setVersion("1.0");
79 msaheader
.setAbstract("Component name for module " + mi
.modulename
);
80 msaheader
.setDescription("FIX ME!"); //???
81 msaheader
.addNewLicense().setStringValue("All rights reserved.\n" +
82 " This software and associated documentation (if any) is furnished\n" +
83 " under a license and may only be used or copied in accordance\n" +
84 " with the terms of the license. Except as permitted by such\n" +
85 " license, no part of this software or documentation may be\n" +
86 " reproduced, stored in a retrieval system, or transmitted in any\n" +
87 " form or by any means without the express written consent of\n" +
88 " Intel Corporation.");
90 List
<Enum
> arch
= new ArrayList
<Enum
>();
91 arch
.add(SupportedArchitectures
.IA_32
);
92 arch
.add(SupportedArchitectures
.X_64
);
93 arch
.add(SupportedArchitectures
.IPF
);
94 arch
.add(SupportedArchitectures
.EBC
);
95 md
.setSupportedArchitectures(arch
);
96 md
.setBinaryModule(false);
97 md
.setOutputFileBasename(mi
.modulename
);
99 pd
.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
100 externs
.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
101 externs
.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
102 externs
.addNewExtern().setModuleEntryPoint(mi
.entrypoint
);
104 it
= mi
.localmodulesources
.iterator();
105 while (it
.hasNext()) {
106 sourcefiles
.addNewFilename().setStringValue(it
.next());
108 it
= mi
.protocol
.iterator();
109 while (it
.hasNext()) {
110 if ((temp
= it
.next()) != null) {
111 ProtocolsDocument
.Protocols
.Protocol pr
= protocols
.addNewProtocol();
112 pr
.setProtocolCName(temp
);
113 pr
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
116 it
= mi
.ppi
.iterator();
117 while (it
.hasNext()) {
118 if ((temp
= it
.next()) != null) {
119 PPIsDocument
.PPIs
.Ppi pp
= ppis
.addNewPpi();
120 pp
.setPpiCName(temp
);
121 pp
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
124 it
= mi
.guid
.iterator();
125 while (it
.hasNext()) {
126 if ((temp
= it
.next()) != null) {
127 GuidsDocument
.Guids
.GuidCNames gcn
= guids
.addNewGuidCNames();
128 gcn
.setGuidCName(temp
);
129 gcn
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
132 it
= mi
.hashrequiredr9libs
.iterator();
133 while (it
.hasNext()) {
134 if ((temp
= it
.next()) != null && !temp
.matches("%")) {
135 LibraryClassDocument
.LibraryClass lc
= libclassdefs
.addNewLibraryClass();
137 lc
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
144 public void flush() throws Exception
{
145 XmlOptions options
= new XmlOptions();
147 options
.setCharacterEncoding("UTF-8");
148 options
.setSavePrettyPrint();
149 options
.setSavePrettyPrintIndent(2);
150 options
.setUseDefaultNamespace();
152 BufferedWriter bw
= new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "result" + File
.separator
+ mi
.modulename
+ ".msa"));
153 fulfillMsadoc().save(bw
, options
);