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(ModuleInfo moduleinfo
) {
27 private ModuleInfo mi
;
28 private ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
30 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= msadoc
.addNewModuleSurfaceArea();
31 private MsaHeaderDocument
.MsaHeader msaheader
= msa
.addNewMsaHeader();
32 private ModuleDefinitionsDocument
.ModuleDefinitions md
= msa
.addNewModuleDefinitions();
33 private SourceFilesDocument
.SourceFiles sourcefiles
= msa
.addNewSourceFiles(); //found local .h files are not written
34 private GuidsDocument
.Guids guids
;
35 private ProtocolsDocument
.Protocols protocols
;
36 private PPIsDocument
.PPIs ppis
;
37 private PackageDependenciesDocument
.PackageDependencies pd
= msa
.addNewPackageDependencies();
38 private LibraryClassDefinitionsDocument
.LibraryClassDefinitions libclassdefs
= msa
.addNewLibraryClassDefinitions();
39 private ExternsDocument
.Externs externs
= msa
.addNewExterns();
41 private String
Query (String requirement
) throws Exception
{
43 BufferedReader rd
= new BufferedReader(new InputStreamReader(System
.in
));
44 System
.out
.println(requirement
);
45 while ((answer
= rd
.readLine()).length() == 0) ;
49 private void addSourceFiles (String name
) { // furthur modification needed
50 List
<Enum
> arch
= new ArrayList
<Enum
>();
51 FilenameDocument
.Filename filename
;
52 filename
= sourcefiles
.addNewFilename();
53 filename
.setStringValue(name
);
55 if (name
.contains("x64" + File
.separator
)) { // filename ???
56 arch
.add(SupportedArchitectures
.X_64
);
57 System
.out
.println("x64" + File
.separator
);
58 filename
.setSupArchList(arch
);
59 } else if (name
.contains("Ia32" + File
.separator
)) { // filename ???
60 arch
.add(SupportedArchitectures
.IA_32
);
61 System
.out
.println("Ia32" + File
.separator
);
62 filename
.setSupArchList(arch
);
63 } else if (name
.contains("Ipf" + File
.separator
)) { // filename ???
64 arch
.add(SupportedArchitectures
.IPF
);
65 System
.out
.println("Ipf" + File
.separator
);
66 filename
.setSupArchList(arch
);
67 } else if (name
.contains("Ebc" + File
.separator
)) { // filename ???
68 arch
.add(SupportedArchitectures
.EBC
);
69 System
.out
.println("Ebc" + File
.separator
);
70 filename
.setSupArchList(arch
);
74 private ModuleSurfaceAreaDocument
fulfillMsadoc() throws Exception
{
78 if (mi
.modulename
!= null) {
79 msaheader
.setModuleName(mi
.modulename
);
81 msaheader
.setModuleName(mi
.modulename
= Query("Module Name Not Found! Please Input ModuleName"));
83 if (mi
.guidvalue
== null) {
84 mi
.guidvalue
= UUID
.randomUUID().toString();
85 MigrationTool
.ui
.println ("Guid value can not be retrieved from inf file. Generate " + mi
.guidvalue
+ " at random!");
87 msaheader
.setGuidValue(mi
.guidvalue
);
88 if (mi
.moduletype
!= null) {
89 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(mi
.getModuleType()));
91 msaheader
.setModuleType(ModuleTypeDef
.Enum
.forString(mi
.moduletype
= Query("Guid Value Not Found! Please Input Guid Value")));
94 msaheader
.setCopyright("Copyright (c) 2006, Intel Corporation");
95 msaheader
.setVersion("1.0");
96 msaheader
.setAbstract("Component name for module " + mi
.modulename
);
97 msaheader
.setDescription("FIX ME!");
98 msaheader
.addNewLicense().setStringValue("All rights reserved.\n" +
99 " This software and associated documentation (if any) is furnished\n" +
100 " under a license and may only be used or copied in accordance\n" +
101 " with the terms of the license. Except as permitted by such\n" +
102 " license, no part of this software or documentation may be\n" +
103 " reproduced, stored in a retrieval system, or transmitted in any\n" +
104 " form or by any means without the express written consent of\n" +
105 " Intel Corporation.");
106 msaheader
.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
108 List
<Enum
> arch
= new ArrayList
<Enum
>();
109 arch
.add(SupportedArchitectures
.IA_32
);
110 arch
.add(SupportedArchitectures
.X_64
);
111 arch
.add(SupportedArchitectures
.IPF
);
112 arch
.add(SupportedArchitectures
.EBC
);
113 md
.setSupportedArchitectures(arch
);
114 md
.setBinaryModule(false);
115 md
.setOutputFileBasename(mi
.modulename
);
117 pd
.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");
118 pd
.addNewPackage().setPackageGuid("68169ab0-d41b-4009-9060-292c253ac43d");
119 externs
.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
120 externs
.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
121 if (mi
.entrypoint
!= null) {
122 externs
.addNewExtern().setModuleEntryPoint(mi
.entrypoint
);
123 org
.tianocore
.ModuleTypeDef
.Enum moduleType
= msaheader
.getModuleType();
124 if (moduleType
== ModuleTypeDef
.PEIM
) {
125 mi
.hashrequiredr9libs
.add("PeimEntryPoint");
127 mi
.hashrequiredr9libs
.add("UefiDriverEntryPoint");
131 it
= mi
.localmodulesources
.iterator();
132 while (it
.hasNext()) {
133 addSourceFiles(it
.next());
135 if (!mi
.protocol
.isEmpty()) {
136 protocols
= msa
.addNewProtocols();
137 it
= mi
.protocol
.iterator();
138 while (it
.hasNext()) {
139 if ((temp
= it
.next()) != null) {
140 ProtocolsDocument
.Protocols
.Protocol pr
= protocols
.addNewProtocol();
141 pr
.setProtocolCName(temp
);
142 pr
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
146 if (!mi
.ppi
.isEmpty()) {
147 ppis
= msa
.addNewPPIs();
148 it
= mi
.ppi
.iterator();
149 while (it
.hasNext()) {
150 if ((temp
= it
.next()) != null) {
151 PPIsDocument
.PPIs
.Ppi pp
= ppis
.addNewPpi();
152 pp
.setPpiCName(temp
);
153 pp
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
157 if (!mi
.guid
.isEmpty()) {
158 guids
= msa
.addNewGuids();
159 it
= mi
.guid
.iterator();
160 while (it
.hasNext()) {
161 if ((temp
= it
.next()) != null) {
162 GuidsDocument
.Guids
.GuidCNames gcn
= guids
.addNewGuidCNames();
163 gcn
.setGuidCName(temp
);
164 gcn
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
168 it
= mi
.hashrequiredr9libs
.iterator();
169 while (it
.hasNext()) {
170 if ((temp
= it
.next()) != null && !temp
.matches("%") && !temp
.matches("n/a")) {
171 LibraryClassDocument
.LibraryClass lc
= libclassdefs
.addNewLibraryClass();
173 lc
.setUsage(UsageTypes
.ALWAYS_CONSUMED
);
180 public void flush() throws Exception
{
181 XmlOptions options
= new XmlOptions();
183 options
.setCharacterEncoding("UTF-8");
184 options
.setSavePrettyPrint();
185 options
.setSavePrettyPrintIndent(2);
186 options
.setUseDefaultNamespace();
188 BufferedWriter bw
= new BufferedWriter(new FileWriter(MigrationTool
.ModuleInfoMap
.get(mi
) + File
.separator
+ "Migration_" + mi
.modulename
+ File
.separator
+ mi
.modulename
+ ".msa"));
189 fulfillMsadoc().save(bw
, options
);
190 //MsaTreeEditor.init(mi, ui, msadoc);
195 private static void flush(String path
, ModuleSurfaceAreaDocument msadoc
) throws Exception
{
196 XmlOptions options
= new XmlOptions();
198 options
.setCharacterEncoding("UTF-8");
199 options
.setSavePrettyPrint();
200 options
.setSavePrettyPrintIndent(2);
201 options
.setUseDefaultNamespace();
203 BufferedWriter bw
= new BufferedWriter(new FileWriter(path
));
204 msadoc
.save(bw
, options
);
209 public static final void parse(String msafile
) throws Exception
{
210 ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.parse(msafile
);
211 flush("c:\\temp.msa", msadoc
);