]>
Commit | Line | Data |
---|---|---|
1 | package org.tianocore.migration;\r | |
2 | \r | |
3 | import java.io.BufferedWriter;\r | |
4 | import java.io.FileWriter;\r | |
5 | import java.util.*;\r | |
6 | \r | |
7 | import org.apache.xmlbeans.XmlOptions;\r | |
8 | import org.tianocore.*;\r | |
9 | import org.tianocore.SupportedArchitectures.Enum;\r | |
10 | \r | |
11 | public class MsaOwner {\r | |
12 | public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";\r | |
13 | public static final String VERSION = "1.0";\r | |
14 | public static final String ABSTRACT = "Component name for module ";\r | |
15 | public static final String DESCRIPTION = "FIX ME!";\r | |
16 | public static final String LICENSE = "All rights reserved.\n" +\r | |
17 | " This software and associated documentation (if any) is furnished\n" +\r | |
18 | " under a license and may only be used or copied in accordance\n" +\r | |
19 | " with the terms of the license. Except as permitted by such\n" +\r | |
20 | " license, no part of this software or documentation may be\n" +\r | |
21 | " reproduced, stored in a retrieval system, or transmitted in any\n" +\r | |
22 | " form or by any means without the express written consent of\n" +\r | |
23 | " Intel Corporation.";\r | |
24 | public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r | |
25 | \r | |
26 | public static final Enum IA32 = SupportedArchitectures.IA_32;\r | |
27 | public static final Enum X64 = SupportedArchitectures.X_64;\r | |
28 | public static final Enum IPF = SupportedArchitectures.IPF;\r | |
29 | public static final Enum EBC = SupportedArchitectures.EBC;\r | |
30 | \r | |
31 | private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r | |
32 | \r | |
33 | private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;\r | |
34 | private MsaHeaderDocument.MsaHeader msaheader = null;\r | |
35 | private LicenseDocument.License license = null;\r | |
36 | private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;\r | |
37 | private SourceFilesDocument.SourceFiles sourcefiles = null; //found local .h files are not written\r | |
38 | private GuidsDocument.Guids guids = null;\r | |
39 | private ProtocolsDocument.Protocols protocols = null;\r | |
40 | private PPIsDocument.PPIs ppis = null;\r | |
41 | private PackageDependenciesDocument.PackageDependencies packagedependencies = null;\r | |
42 | private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;\r | |
43 | private ExternsDocument.Externs externs = null;\r | |
44 | \r | |
45 | private List<Enum> listarch = new ArrayList<Enum>();\r | |
46 | //private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written\r | |
47 | //private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();\r | |
48 | \r | |
49 | //-----------------------------msaheader-------------------------------------//\r | |
50 | \r | |
51 | public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {\r | |
52 | Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();\r | |
53 | while (classit.hasNext()) {\r | |
54 | if (classit.next().getKeyword() == name) {\r | |
55 | MigrationTool.ui.println ("Warning: Duplicate LibraryClass");\r | |
56 | return false;\r | |
57 | }\r | |
58 | }\r | |
59 | \r | |
60 | LibraryClassDocument.LibraryClass classname;\r | |
61 | classname = libclassdefs.addNewLibraryClass();\r | |
62 | classname.setKeyword(name);\r | |
63 | classname.setUsage(usage);\r | |
64 | return true;\r | |
65 | }\r | |
66 | \r | |
67 | public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r | |
68 | if (guids == null) {\r | |
69 | guids = msa.addNewGuids();\r | |
70 | }\r | |
71 | \r | |
72 | Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();\r | |
73 | while (guidit.hasNext()) {\r | |
74 | if (guidit.next().getGuidCName() == guidname) {\r | |
75 | MigrationTool.ui.println ("Warning: Duplicate Guid");\r | |
76 | return false;\r | |
77 | }\r | |
78 | }\r | |
79 | \r | |
80 | GuidsDocument.Guids.GuidCNames guid;\r | |
81 | guid = guids.addNewGuidCNames();\r | |
82 | guid.setGuidCName(guidname);\r | |
83 | guid.setUsage(usage);\r | |
84 | return true;\r | |
85 | }\r | |
86 | \r | |
87 | \r | |
88 | public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r | |
89 | if (ppis == null) {\r | |
90 | ppis = msa.addNewPPIs();\r | |
91 | }\r | |
92 | \r | |
93 | Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();\r | |
94 | while (ppiit.hasNext()) {\r | |
95 | if (ppiit.next().getPpiCName() == ppiname) {\r | |
96 | MigrationTool.ui.println ("Warning: Duplicate Ppi");\r | |
97 | return false;\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
101 | PPIsDocument.PPIs.Ppi ppi;\r | |
102 | ppi = ppis.addNewPpi();\r | |
103 | ppi.setPpiCName(ppiname);\r | |
104 | ppi.setUsage(usage);\r | |
105 | return true;\r | |
106 | }\r | |
107 | \r | |
108 | /*\r | |
109 | private final boolean installProtocols () {\r | |
110 | if (mapprotocols.isEmpty()) {\r | |
111 | return false;\r | |
112 | }\r | |
113 | Set<String> setprotocols = mapprotocols.keySet();\r | |
114 | ProtocolsDocument.Protocols.Protocol protocol;\r | |
115 | Iterator<String> it = setprotocols.iterator();\r | |
116 | while (it.hasNext()) {\r | |
117 | protocol = protocols.addNewProtocol();\r | |
118 | protocol.setProtocolCName(it.next());\r | |
119 | protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));\r | |
120 | }\r | |
121 | return true;\r | |
122 | }\r | |
123 | \r | |
124 | public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {\r | |
125 | if (mapprotocols.containsKey(protocol)) {\r | |
126 | return false;\r | |
127 | } else {\r | |
128 | mapprotocols.put(protocol, usage);\r | |
129 | return true;\r | |
130 | }\r | |
131 | }\r | |
132 | */\r | |
133 | public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r | |
134 | if (protocols == null) {\r | |
135 | protocols = msa.addNewProtocols();\r | |
136 | }\r | |
137 | \r | |
138 | Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();\r | |
139 | while (proit.hasNext()) {\r | |
140 | if (proit.next().getProtocolCName() == proname) {\r | |
141 | MigrationTool.ui.println ("Warning: Duplicate Protocol");\r | |
142 | return false;\r | |
143 | }\r | |
144 | }\r | |
145 | \r | |
146 | ProtocolsDocument.Protocols.Protocol protocol;\r | |
147 | protocol = protocols.addNewProtocol();\r | |
148 | protocol.setProtocolCName(proname);\r | |
149 | protocol.setUsage(usage);\r | |
150 | return true;\r | |
151 | }\r | |
152 | \r | |
153 | /*\r | |
154 | private final boolean installHashFilename () {\r | |
155 | if (mapfilenames.isEmpty()) {\r | |
156 | return false;\r | |
157 | }\r | |
158 | Set<String> setfilename = mapfilenames.keySet();\r | |
159 | FilenameDocument.Filename filename;\r | |
160 | List<Enum> arch = new ArrayList<Enum>();\r | |
161 | Iterator<String> it = setfilename.iterator();\r | |
162 | while (it.hasNext()) {\r | |
163 | filename = sourcefiles.addNewFilename();\r | |
164 | filename.setStringValue(it.next());\r | |
165 | arch.add(mapfilenames.get(filename.getStringValue()));\r | |
166 | filename.setSupArchList(arch);\r | |
167 | }\r | |
168 | return true;\r | |
169 | }\r | |
170 | \r | |
171 | public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?\r | |
172 | if (mapfilenames.containsKey(filename)) {\r | |
173 | return false;\r | |
174 | } else {\r | |
175 | mapfilenames.put(filename, arch);\r | |
176 | return true;\r | |
177 | }\r | |
178 | }\r | |
179 | */\r | |
180 | public final boolean addSourceFile (String name, Enum en) {\r | |
181 | Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();\r | |
182 | while (fileit.hasNext()) {\r | |
183 | if (fileit.next().getStringValue() == name) {\r | |
184 | MigrationTool.ui.println ("Warning: Duplicate SourceFileName");\r | |
185 | return false;\r | |
186 | }\r | |
187 | }\r | |
188 | \r | |
189 | FilenameDocument.Filename filename;\r | |
190 | List<Enum> arch = new ArrayList<Enum>();\r | |
191 | filename = sourcefiles.addNewFilename();\r | |
192 | filename.setStringValue(name);\r | |
193 | arch.add(en);\r | |
194 | filename.setSupArchList(arch);\r | |
195 | return true;\r | |
196 | }\r | |
197 | \r | |
198 | // entry point todo\r | |
199 | \r | |
200 | public final boolean setupExternSpecification () {\r | |
201 | addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");\r | |
202 | addExternSpecification("EDK_RELEASE_VERSION 0x00020000");\r | |
203 | return true;\r | |
204 | }\r | |
205 | \r | |
206 | public final boolean addExternSpecification (String specification) {\r | |
207 | if (externs.getSpecificationList().contains(specification)) {\r | |
208 | return false;\r | |
209 | } else {\r | |
210 | externs.addSpecification(specification);\r | |
211 | return true;\r | |
212 | }\r | |
213 | }\r | |
214 | \r | |
215 | public final boolean setupPackageDependencies() {\r | |
216 | addPackage("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r | |
217 | addPackage("68169ab0-d41b-4009-9060-292c253ac43d");\r | |
218 | return true;\r | |
219 | }\r | |
220 | \r | |
221 | public final boolean addPackage (String guid) {\r | |
222 | if (packagedependencies.getPackageList().contains(guid)) {\r | |
223 | return false;\r | |
224 | } else {\r | |
225 | packagedependencies.addNewPackage().setPackageGuid(guid);\r | |
226 | return true;\r | |
227 | }\r | |
228 | }\r | |
229 | \r | |
230 | public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo\r | |
231 | moduledefinitions.setBinaryModule(false);\r | |
232 | moduledefinitions.setOutputFileBasename(msaheader.getModuleName());\r | |
233 | return true;\r | |
234 | }\r | |
235 | public final boolean addSupportedArchitectures (Enum arch) {\r | |
236 | if (listarch.contains(arch)) {\r | |
237 | return false;\r | |
238 | } else {\r | |
239 | listarch.add(arch);\r | |
240 | return true;\r | |
241 | }\r | |
242 | }\r | |
243 | \r | |
244 | public final boolean addSpecification (String specification) {\r | |
245 | if (msaheader.getSpecification() == null) {\r | |
246 | if (specification == null) {\r | |
247 | msaheader.setSpecification(SPECIFICATION);\r | |
248 | } else {\r | |
249 | msaheader.setSpecification(specification);\r | |
250 | }\r | |
251 | return true;\r | |
252 | } else {\r | |
253 | MigrationTool.ui.println ("Warning: Duplicate Specification");\r | |
254 | return false;\r | |
255 | }\r | |
256 | }\r | |
257 | \r | |
258 | public final boolean addLicense (String licensecontent) {\r | |
259 | if (msaheader.getLicense() == null) {\r | |
260 | license = msaheader.addNewLicense();\r | |
261 | if (licensecontent == null) {\r | |
262 | license.setStringValue(LICENSE);\r | |
263 | } else {\r | |
264 | license.setStringValue(licensecontent);\r | |
265 | }\r | |
266 | return true;\r | |
267 | } else {\r | |
268 | MigrationTool.ui.println ("Warning: Duplicate License");\r | |
269 | return false;\r | |
270 | }\r | |
271 | }\r | |
272 | \r | |
273 | public final boolean addDescription (String description) {\r | |
274 | if (msaheader.getDescription() == null) {\r | |
275 | if (description == null) {\r | |
276 | msaheader.setDescription(DESCRIPTION);\r | |
277 | } else {\r | |
278 | msaheader.setDescription(description);\r | |
279 | }\r | |
280 | return true;\r | |
281 | } else {\r | |
282 | MigrationTool.ui.println ("Warning: Duplicate Description");\r | |
283 | return false;\r | |
284 | }\r | |
285 | }\r | |
286 | \r | |
287 | public final boolean addAbstract (String abs) {\r | |
288 | if (msaheader.getAbstract() == null) {\r | |
289 | if (abs == null) {\r | |
290 | msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r | |
291 | } else {\r | |
292 | msaheader.setVersion(abs);\r | |
293 | }\r | |
294 | return true;\r | |
295 | } else {\r | |
296 | MigrationTool.ui.println ("Warning: Duplicate Abstract");\r | |
297 | return false;\r | |
298 | }\r | |
299 | }\r | |
300 | \r | |
301 | public final boolean addVersion (String version) {\r | |
302 | if (msaheader.getVersion() == null) {\r | |
303 | if (version == null) {\r | |
304 | msaheader.setVersion(VERSION);\r | |
305 | } else {\r | |
306 | msaheader.setVersion(version);\r | |
307 | }\r | |
308 | return true;\r | |
309 | } else {\r | |
310 | MigrationTool.ui.println ("Warning: Duplicate Version");\r | |
311 | return false;\r | |
312 | }\r | |
313 | }\r | |
314 | \r | |
315 | public final boolean addCopyRight (String copyright) {\r | |
316 | if (msaheader.getCopyright() == null) {\r | |
317 | if (copyright == null) {\r | |
318 | msaheader.setCopyright(COPYRIGHT);\r | |
319 | } else {\r | |
320 | msaheader.setCopyright(copyright);\r | |
321 | }\r | |
322 | return true;\r | |
323 | } else {\r | |
324 | MigrationTool.ui.println ("Warning: Duplicate CopyRight");\r | |
325 | return false;\r | |
326 | }\r | |
327 | }\r | |
328 | \r | |
329 | public final boolean addModuleType (String moduletype) {\r | |
330 | if (msaheader.getModuleType() == null) {\r | |
331 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));\r | |
332 | return true;\r | |
333 | } else {\r | |
334 | MigrationTool.ui.println ("Warning: Duplicate ModuleType");\r | |
335 | return false;\r | |
336 | }\r | |
337 | }\r | |
338 | \r | |
339 | public final boolean addGuidValue (String guidvalue) {\r | |
340 | if (msaheader.getGuidValue() == null) {\r | |
341 | msaheader.setGuidValue(guidvalue);\r | |
342 | return true;\r | |
343 | } else {\r | |
344 | MigrationTool.ui.println ("Warning: Duplicate GuidValue");\r | |
345 | return false;\r | |
346 | }\r | |
347 | }\r | |
348 | \r | |
349 | public final boolean addModuleName (String modulename) {\r | |
350 | if (msaheader.getModuleName() == null) {\r | |
351 | msaheader.setModuleName(modulename);\r | |
352 | return true;\r | |
353 | } else {\r | |
354 | MigrationTool.ui.println ("Warning: Duplicate ModuleName");\r | |
355 | return false;\r | |
356 | }\r | |
357 | }\r | |
358 | //-----------------------------msaheader-------------------------------------//\r | |
359 | \r | |
360 | public final void flush(String outputpath) throws Exception {\r | |
361 | XmlOptions options = new XmlOptions();\r | |
362 | \r | |
363 | options.setCharacterEncoding("UTF-8");\r | |
364 | options.setSavePrettyPrint();\r | |
365 | options.setSavePrettyPrintIndent(2);\r | |
366 | options.setUseDefaultNamespace();\r | |
367 | \r | |
368 | BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));\r | |
369 | msadoc.save(bw, options);\r | |
370 | bw.flush();\r | |
371 | bw.close();\r | |
372 | }\r | |
373 | \r | |
374 | private final MsaOwner init () {\r | |
375 | msa = msadoc.addNewModuleSurfaceArea();\r | |
376 | msaheader = msa.addNewMsaHeader();\r | |
377 | moduledefinitions = msa.addNewModuleDefinitions();\r | |
378 | moduledefinitions.setSupportedArchitectures(listarch);\r | |
379 | \r | |
380 | sourcefiles = msa.addNewSourceFiles();\r | |
381 | packagedependencies = msa.addNewPackageDependencies();\r | |
382 | libclassdefs = msa.addNewLibraryClassDefinitions();\r | |
383 | externs = msa.addNewExterns();\r | |
384 | return this;\r | |
385 | }\r | |
386 | \r | |
387 | public static final MsaOwner initNewMsaOwner() {\r | |
388 | return new MsaOwner().init();\r | |
389 | }\r | |
390 | } |