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
, UI u
) {
30 private String modulepath
;
31 private ModuleInfo mi
;
35 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
37 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= msadoc
.addNewModuleSurfaceArea();
38 private MsaHeaderDocument
.MsaHeader msaheader
= msa
.addNewMsaHeader();
39 private ModuleDefinitionsDocument
.ModuleDefinitions md
= msa
.addNewModuleDefinitions();
40 private SourceFilesDocument
.SourceFiles sourcefiles
= msa
.addNewSourceFiles(); //found local .h files are not written
41 private GuidsDocument
.Guids guids
;
42 private ProtocolsDocument
.Protocols protocols
;
43 private PPIsDocument
.PPIs ppis
;
44 private PackageDependenciesDocument
.PackageDependencies pd
= msa
.addNewPackageDependencies();
45 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= msa
.addNewLibraryClassDefinitions();
46 private ExternsDocument
.Externs externs
= msa
.addNewExterns();
48 private String
Query (String requirement
) throws Exception
{
50 BufferedReader rd
= new BufferedReader(new InputStreamReader(System
.in
));
51 System
.out
.println(requirement
);
52 while ((answer
= rd
.readLine()).length() == 0) ;
56 private void addSourceFiles (String name
) { // furthur modification needed
57 List
<Enum
> arch
= new ArrayList
<Enum
>();
58 FilenameDocument
.Filename filename
;
59 filename
= sourcefiles
.addNewFilename();
60 filename
.setStringValue(name
);
62 if (name
.contains("x64" + File
.separator
)) { // filename ???
63 arch
.add(SupportedArchitectures
.X_64
);
64 System
.out
.println("x64" + File
.separator
);
65 filename
.setSupArchList(arch
);
66 } else if (name
.contains("Ia32" + File
.separator
)) { // filename ???
67 arch
.add(SupportedArchitectures
.IA_32
);
68 System
.out
.println("Ia32" + File
.separator
);
69 filename
.setSupArchList(arch
);
70 } else if (name
.contains("Ipf" + File
.separator
)) { // filename ???
71 arch
.add(SupportedArchitectures
.IPF
);
72 System
.out
.println("Ipf" + File
.separator
);
73 filename
.setSupArchList(arch
);
74 } else if (name
.contains("Ebc" + File
.separator
)) { // filename ???
75 arch
.add(SupportedArchitectures
.EBC
);
76 System
.out
.println("Ebc" + File
.separator
);
77 filename
.setSupArchList(arch
);
81 private ModuleSurfaceAreaDocument
fulfillMsadoc() throws Exception
{
85 if (mi
.modulename
!= null) {
86 msaheader
.setModuleName(mi
.modulename
);
88 msaheader
.setModuleName(mi
.modulename
= Query("Module Name Not Found! Please Input ModuleName"));
90 if (mi
.guidvalue
!= null) {
91 msaheader
.setGuidValue(mi
.guidvalue
);
93 msaheader
.setGuidValue(mi
.guidvalue
= Query("Guid Value Not Found! Please Input Guid Value"));
95 if (mi
.moduletype
!= null) {
96 if (mi
.moduletype
.contains("PEI")) {
97 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("PEIM"));
99 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString("DXE_DRIVER"));
102 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(mi
.moduletype
= Query("Guid Value Not Found! Please Input Guid Value")));
105 msaheader
.setCopyright("Copyright (c) 2006, Intel Corporation");
106 msaheader
.setVersion("1.0");
107 msaheader
.setAbstract("Component name for module " + mi
.modulename
);
108 msaheader
.setDescription("FIX ME!");
109 msaheader
.addNewLicense().setStringValue("All rights reserved.\n" +
110 " This software and associated documentation (if any) is furnished\n" +
111 " under a license and may only be used or copied in accordance\n" +
112 " with the terms of the license. Except as permitted by such\n" +
113 " license, no part of this software or documentation may be\n" +
114 " reproduced, stored in a retrieval system, or transmitted in any\n" +
115 " form or by any means without the express written consent of\n" +
116 " Intel Corporation.");
117 msaheader
.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
119 List
<Enum
> arch
= new ArrayList
<Enum
>();
120 arch
.add(SupportedArchitectures
.IA_32
);
121 arch
.add(SupportedArchitectures
.X_64
);
122 arch
.add(SupportedArchitectures
.IPF
);
123 arch
.add(SupportedArchitectures
.EBC
);
124 md
.setSupportedArchitectures(arch
);
125 md
.setBinaryModule(false);
126 md
.setOutputFileBasename(mi
.modulename
);
128 pd
.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
129 externs
.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
130 externs
.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
131 externs
.addNewExtern().setModuleEntryPoint(mi
.entrypoint
);
133 it
= mi
.localmodulesources
.iterator();
134 while (it
.hasNext()) {
135 addSourceFiles(it
.next());
137 if (!mi
.protocol
.isEmpty()) {
138 protocols
= msa
.addNewProtocols();
139 it
= mi
.protocol
.iterator();
140 while (it
.hasNext()) {
141 if ((temp
= it
.next()) != null) {
142 ProtocolsDocument
.Protocols
.Protocol pr
= protocols
.addNewProtocol();
143 pr
.setProtocolCName(temp
);
144 pr
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
148 if (!mi
.ppi
.isEmpty()) {
149 ppis
= msa
.addNewPPIs();
150 it
= mi
.ppi
.iterator();
151 while (it
.hasNext()) {
152 if ((temp
= it
.next()) != null) {
153 PPIsDocument
.PPIs
.Ppi pp
= ppis
.addNewPpi();
154 pp
.setPpiCName(temp
);
155 pp
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
159 if (!mi
.guid
.isEmpty()) {
160 guids
= msa
.addNewGuids();
161 it
= mi
.guid
.iterator();
162 while (it
.hasNext()) {
163 if ((temp
= it
.next()) != null) {
164 GuidsDocument
.Guids
.GuidCNames gcn
= guids
.addNewGuidCNames();
165 gcn
.setGuidCName(temp
);
166 gcn
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
170 it
= mi
.hashrequiredr9libs
.iterator();
171 while (it
.hasNext()) {
172 if ((temp
= it
.next()) != null && !temp
.matches("%")) {
173 LibraryClassDocument
.LibraryClass lc
= libclassdefs
.addNewLibraryClass();
175 lc
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
182 public void flush() throws Exception
{
183 XmlOptions options
= new XmlOptions();
185 options
.setCharacterEncoding("UTF-8");
186 options
.setSavePrettyPrint();
187 options
.setSavePrettyPrintIndent(2);
188 options
.setUseDefaultNamespace();
190 BufferedWriter bw
= new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "result" + File
.separator
+ mi
.modulename
+ ".msa"));
191 fulfillMsadoc().save(bw
, options
);
192 //MsaTreeEditor.init(mi, ui, msadoc);