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