1 package org
.tianocore
.migration
;
6 import org
.tianocore
.*;
7 import org
.tianocore
.SupportedArchitectures
.Enum
;
8 import org
.apache
.xmlbeans
.*;
10 public class MsaWriter
{
11 MsaWriter(String path
, ModuleInfo moduleinfo
, Database database
) {
17 private String modulepath
;
18 private ModuleInfo mi
;
21 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
23 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= msadoc
.addNewModuleSurfaceArea();
24 private MsaHeaderDocument
.MsaHeader msaheader
= msa
.addNewMsaHeader();
25 private ModuleDefinitionsDocument
.ModuleDefinitions md
= msa
.addNewModuleDefinitions();
26 private SourceFilesDocument
.SourceFiles sourcefiles
= msa
.addNewSourceFiles(); //found local .h files are not written
27 private GuidsDocument
.Guids guids
= msa
.addNewGuids();
28 private ProtocolsDocument
.Protocols protocols
= msa
.addNewProtocols();
29 private PPIsDocument
.PPIs ppis
= msa
.addNewPPIs();
30 private PackageDependenciesDocument
.PackageDependencies pd
= msa
.addNewPackageDependencies();
31 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= msa
.addNewLibraryClassDefinitions();
32 private ExternsDocument
.Externs externs
= msa
.addNewExterns();
34 private String
Query (String requirement
) throws Exception
{
36 BufferedReader rd
= new BufferedReader(new InputStreamReader(System
.in
));
37 System
.out
.println(requirement
);
38 while ((answer
= rd
.readLine()).length() == 0) ;
42 private ModuleSurfaceAreaDocument
fulfillMsadoc() throws Exception
{
46 if (mi
.modulename
!= null) {
47 msaheader
.setModuleName(mi
.modulename
);
49 msaheader
.setModuleName(mi
.modulename
= Query("ModuleName Not Found . Please Input ModuleName"));
51 if (mi
.guidvalue
!= null) {
52 msaheader
.setGuidValue(mi
.guidvalue
);
54 msaheader
.setGuidValue(mi
.guidvalue
= Query("GuidValue Not Found . Please Input GuidValue"));
56 if (mi
.moduletype
!= null) {
57 if (mi
.moduletype
.contains("PEI")) {
58 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("PEIM"));
60 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("DXE_DRIVER"));
63 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(mi
.moduletype
= Query("GuidValue Not Found . Please Input GuidValue")));
65 msaheader
.setCopyright("Copyright (c) 2006, Intel Corporation");
66 msaheader
.setVersion("1.0");
67 msaheader
.setAbstract("Component name for module " + mi
.modulename
);
68 msaheader
.setDescription("FIX ME!"); //???
69 msaheader
.addNewLicense().setStringValue("All rights reserved.\n" +
70 " This software and associated documentation (if any) is furnished\n" +
71 " under a license and may only be used or copied in accordance\n" +
72 " with the terms of the license. Except as permitted by such\n" +
73 " license, no part of this software or documentation may be\n" +
74 " reproduced, stored in a retrieval system, or transmitted in any\n" +
75 " form or by any means without the express written consent of\n" +
76 " Intel Corporation.");
78 List
<Enum
> arch
= new ArrayList
<Enum
>();
79 arch
.add(SupportedArchitectures
.IA_32
);
80 arch
.add(SupportedArchitectures
.X_64
);
81 arch
.add(SupportedArchitectures
.IPF
);
82 arch
.add(SupportedArchitectures
.EBC
);
83 md
.setSupportedArchitectures(arch
);
84 md
.setBinaryModule(false);
85 md
.setOutputFileBasename(mi
.modulename
);
87 pd
.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
88 externs
.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
89 externs
.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
90 externs
.addNewExtern().setModuleEntryPoint(mi
.entrypoint
);
92 it
= mi
.localmodulesources
.iterator();
93 while (it
.hasNext()) {
94 sourcefiles
.addNewFilename().setStringValue(it
.next());
96 it
= mi
.protocol
.iterator();
97 while (it
.hasNext()) {
98 if ((temp
= it
.next()) != null) {
99 ProtocolsDocument
.Protocols
.Protocol pr
= protocols
.addNewProtocol();
100 pr
.setProtocolCName(temp
);
101 pr
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
104 it
= mi
.ppi
.iterator();
105 while (it
.hasNext()) {
106 if ((temp
= it
.next()) != null) {
107 PPIsDocument
.PPIs
.Ppi pp
= ppis
.addNewPpi();
108 pp
.setPpiCName(temp
);
109 pp
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
112 it
= mi
.guid
.iterator();
113 while (it
.hasNext()) {
114 if ((temp
= it
.next()) != null) {
115 GuidsDocument
.Guids
.GuidCNames gcn
= guids
.addNewGuidCNames();
116 gcn
.setGuidCName(temp
);
117 gcn
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
120 it
= mi
.hashrequiredr9libs
.iterator();
121 while (it
.hasNext()) {
122 if ((temp
= it
.next()) != null && !temp
.matches("%")) {
123 LibraryClassDocument
.LibraryClass lc
= libclassdefs
.addNewLibraryClass();
125 lc
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
132 public void flush() throws Exception
{
133 XmlOptions options
= new XmlOptions();
135 options
.setCharacterEncoding("UTF-8");
136 options
.setSavePrettyPrint();
137 options
.setSavePrettyPrintIndent(2);
138 options
.setUseDefaultNamespace();
140 BufferedWriter bw
= new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "result" + File
.separator
+ mi
.modulename
+ ".msa"));
141 fulfillMsadoc().save(bw
, options
);