]>
Commit | Line | Data |
---|---|---|
db0e6906 | 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 | |
6ef5feb5 | 13 | package org.tianocore.migration;\r |
14 | \r | |
1ea59929 | 15 | import java.io.BufferedWriter;\r |
16 | import java.io.FileWriter;\r | |
fd16b4dd | 17 | import java.util.*;\r |
18 | \r | |
1ea59929 | 19 | import org.apache.xmlbeans.XmlOptions;\r |
5c55f71c | 20 | import org.tianocore.*;\r |
fd16b4dd | 21 | import org.tianocore.SupportedArchitectures.Enum;\r |
5c55f71c | 22 | \r |
23 | public class MsaOwner {\r | |
1ea59929 | 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 | |
5c55f71c | 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 | |
1ea59929 | 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 | |
5c55f71c | 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 | |
fd16b4dd | 48 | private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;\r |
5c55f71c | 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 | |
fd16b4dd | 53 | private PackageDependenciesDocument.PackageDependencies packagedependencies = null;\r |
5c55f71c | 54 | private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;\r |
55 | private ExternsDocument.Externs externs = null;\r | |
fd16b4dd | 56 | \r |
57 | private List<Enum> listarch = new ArrayList<Enum>();\r | |
1ea59929 | 58 | //private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written\r |
b8817061 | 59 | //private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();\r |
5c55f71c | 60 | \r |
61 | //-----------------------------msaheader-------------------------------------//\r | |
b8817061 | 62 | \r |
63 | public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {\r | |
8270b34d | 64 | /*\r |
65 | if (!libclassdefs.getLibraryClassList().contains(name)) {\r | |
66 | LibraryClassDocument.LibraryClass classname;\r | |
67 | classname = libclassdefs.addNewLibraryClass();\r | |
68 | classname.setKeyword(name);\r | |
69 | classname.setUsage(usage);\r | |
70 | return true;\r | |
71 | } else {\r | |
72 | return false;\r | |
73 | }\r | |
74 | */\r | |
75 | if (name == null) {\r | |
76 | return false;\r | |
77 | } else {\r | |
78 | Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();\r | |
79 | while (classit.hasNext()) {\r | |
80 | if (classit.next().getKeyword().matches(name)) {\r | |
81 | //MigrationTool.ui.println ("Warning: Duplicate LibraryClass");\r | |
82 | return false;\r | |
83 | }\r | |
1ea59929 | 84 | }\r |
8270b34d | 85 | \r |
86 | LibraryClassDocument.LibraryClass classname;\r | |
87 | classname = libclassdefs.addNewLibraryClass();\r | |
88 | classname.setKeyword(name);\r | |
89 | classname.setUsage(usage);\r | |
90 | return true;\r | |
91 | \r | |
92 | }\r | |
b8817061 | 93 | }\r |
94 | \r | |
95 | public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r | |
1ea59929 | 96 | if (guids == null) {\r |
97 | guids = msa.addNewGuids();\r | |
98 | }\r | |
99 | \r | |
100 | Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();\r | |
101 | while (guidit.hasNext()) {\r | |
102 | if (guidit.next().getGuidCName() == guidname) {\r | |
8270b34d | 103 | //MigrationTool.ui.println ("Warning: Duplicate Guid");\r |
1ea59929 | 104 | return false;\r |
105 | }\r | |
106 | }\r | |
107 | \r | |
108 | GuidsDocument.Guids.GuidCNames guid;\r | |
1ea59929 | 109 | guid = guids.addNewGuidCNames();\r |
110 | guid.setGuidCName(guidname);\r | |
190293ab | 111 | guid.setUsage(usage);\r |
1ea59929 | 112 | return true;\r |
b8817061 | 113 | }\r |
114 | \r | |
115 | \r | |
116 | public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r | |
1ea59929 | 117 | if (ppis == null) {\r |
118 | ppis = msa.addNewPPIs();\r | |
119 | }\r | |
120 | \r | |
121 | Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();\r | |
122 | while (ppiit.hasNext()) {\r | |
123 | if (ppiit.next().getPpiCName() == ppiname) {\r | |
8270b34d | 124 | //MigrationTool.ui.println ("Warning: Duplicate Ppi");\r |
1ea59929 | 125 | return false;\r |
126 | }\r | |
127 | }\r | |
128 | \r | |
129 | PPIsDocument.PPIs.Ppi ppi;\r | |
1ea59929 | 130 | ppi = ppis.addNewPpi();\r |
131 | ppi.setPpiCName(ppiname);\r | |
190293ab | 132 | ppi.setUsage(usage);\r |
1ea59929 | 133 | return true;\r |
b8817061 | 134 | }\r |
135 | \r | |
136 | /*\r | |
fd16b4dd | 137 | private final boolean installProtocols () {\r |
1ea59929 | 138 | if (mapprotocols.isEmpty()) {\r |
139 | return false;\r | |
140 | }\r | |
141 | Set<String> setprotocols = mapprotocols.keySet();\r | |
142 | ProtocolsDocument.Protocols.Protocol protocol;\r | |
143 | Iterator<String> it = setprotocols.iterator();\r | |
144 | while (it.hasNext()) {\r | |
145 | protocol = protocols.addNewProtocol();\r | |
146 | protocol.setProtocolCName(it.next());\r | |
147 | protocol.setUsage(mapprotocols.get(protocol.getProtocolCName()));\r | |
148 | }\r | |
149 | return true;\r | |
fd16b4dd | 150 | }\r |
151 | \r | |
152 | public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {\r | |
1ea59929 | 153 | if (mapprotocols.containsKey(protocol)) {\r |
154 | return false;\r | |
155 | } else {\r | |
156 | mapprotocols.put(protocol, usage);\r | |
157 | return true;\r | |
158 | }\r | |
fd16b4dd | 159 | }\r |
b8817061 | 160 | */\r |
161 | public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r | |
1ea59929 | 162 | if (protocols == null) {\r |
163 | protocols = msa.addNewProtocols();\r | |
164 | }\r | |
190293ab | 165 | \r |
1ea59929 | 166 | Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();\r |
167 | while (proit.hasNext()) {\r | |
168 | if (proit.next().getProtocolCName() == proname) {\r | |
8270b34d | 169 | //MigrationTool.ui.println ("Warning: Duplicate Protocol");\r |
1ea59929 | 170 | return false;\r |
171 | }\r | |
172 | }\r | |
190293ab | 173 | \r |
1ea59929 | 174 | ProtocolsDocument.Protocols.Protocol protocol;\r |
1ea59929 | 175 | protocol = protocols.addNewProtocol();\r |
176 | protocol.setProtocolCName(proname);\r | |
190293ab | 177 | protocol.setUsage(usage);\r |
1ea59929 | 178 | return true;\r |
b8817061 | 179 | }\r |
fd16b4dd | 180 | \r |
b8817061 | 181 | /*\r |
fd16b4dd | 182 | private final boolean installHashFilename () {\r |
1ea59929 | 183 | if (mapfilenames.isEmpty()) {\r |
184 | return false;\r | |
185 | }\r | |
186 | Set<String> setfilename = mapfilenames.keySet();\r | |
187 | FilenameDocument.Filename filename;\r | |
188 | List<Enum> arch = new ArrayList<Enum>();\r | |
189 | Iterator<String> it = setfilename.iterator();\r | |
190 | while (it.hasNext()) {\r | |
191 | filename = sourcefiles.addNewFilename();\r | |
192 | filename.setStringValue(it.next());\r | |
193 | arch.add(mapfilenames.get(filename.getStringValue()));\r | |
194 | filename.setSupArchList(arch);\r | |
195 | }\r | |
196 | return true;\r | |
fd16b4dd | 197 | }\r |
198 | \r | |
1ea59929 | 199 | public final boolean addSourceFile (String filename, Enum arch) { // dummy & null how to imply?\r |
200 | if (mapfilenames.containsKey(filename)) {\r | |
201 | return false;\r | |
202 | } else {\r | |
fd16b4dd | 203 | mapfilenames.put(filename, arch);\r |
204 | return true;\r | |
1ea59929 | 205 | }\r |
fd16b4dd | 206 | }\r |
b8817061 | 207 | */\r |
208 | public final boolean addSourceFile (String name, Enum en) {\r | |
1ea59929 | 209 | Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();\r |
210 | while (fileit.hasNext()) {\r | |
211 | if (fileit.next().getStringValue() == name) {\r | |
212 | MigrationTool.ui.println ("Warning: Duplicate SourceFileName");\r | |
213 | return false;\r | |
214 | }\r | |
215 | }\r | |
216 | \r | |
217 | FilenameDocument.Filename filename;\r | |
218 | List<Enum> arch = new ArrayList<Enum>();\r | |
219 | filename = sourcefiles.addNewFilename();\r | |
220 | filename.setStringValue(name);\r | |
221 | arch.add(en);\r | |
222 | filename.setSupArchList(arch);\r | |
223 | return true;\r | |
b8817061 | 224 | }\r |
fd16b4dd | 225 | \r |
226 | // entry point todo\r | |
227 | \r | |
228 | public final boolean setupExternSpecification () {\r | |
1ea59929 | 229 | addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");\r |
230 | addExternSpecification("EDK_RELEASE_VERSION 0x00020000");\r | |
231 | return true;\r | |
fd16b4dd | 232 | }\r |
233 | \r | |
234 | public final boolean addExternSpecification (String specification) {\r | |
1ea59929 | 235 | if (externs.getSpecificationList().contains(specification)) {\r |
236 | return false;\r | |
237 | } else {\r | |
238 | externs.addSpecification(specification);\r | |
239 | return true;\r | |
240 | }\r | |
fd16b4dd | 241 | }\r |
242 | \r | |
243 | public final boolean setupPackageDependencies() {\r | |
9c0e70cb | 244 | Iterator<String> it;\r |
245 | //\r | |
246 | // For now, simply add all package guids in the database. \r | |
247 | // \r | |
248 | it = MigrationTool.db.dumpAllPkgGuid();\r | |
249 | while (it.hasNext()) {\r | |
250 | packagedependencies.addNewPackage().setPackageGuid(it.next());\r | |
251 | }\r | |
1ea59929 | 252 | return true;\r |
fd16b4dd | 253 | }\r |
254 | \r | |
255 | public final boolean addPackage (String guid) {\r | |
1ea59929 | 256 | if (packagedependencies.getPackageList().contains(guid)) {\r |
257 | return false;\r | |
258 | } else {\r | |
fd16b4dd | 259 | packagedependencies.addNewPackage().setPackageGuid(guid);\r |
260 | return true;\r | |
1ea59929 | 261 | }\r |
fd16b4dd | 262 | }\r |
263 | \r | |
1ea59929 | 264 | public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo\r |
265 | moduledefinitions.setBinaryModule(false);\r | |
266 | moduledefinitions.setOutputFileBasename(msaheader.getModuleName());\r | |
267 | return true;\r | |
fd16b4dd | 268 | }\r |
269 | public final boolean addSupportedArchitectures (Enum arch) {\r | |
1ea59929 | 270 | if (listarch.contains(arch)) {\r |
271 | return false;\r | |
272 | } else {\r | |
273 | listarch.add(arch);\r | |
274 | return true;\r | |
275 | }\r | |
fd16b4dd | 276 | }\r |
277 | \r | |
5c55f71c | 278 | public final boolean addSpecification (String specification) {\r |
279 | if (msaheader.getSpecification() == null) {\r | |
280 | if (specification == null) {\r | |
1ea59929 | 281 | msaheader.setSpecification(SPECIFICATION);\r |
5c55f71c | 282 | } else {\r |
1ea59929 | 283 | msaheader.setSpecification(specification);\r |
5c55f71c | 284 | }\r |
285 | return true;\r | |
286 | } else {\r | |
1ea59929 | 287 | MigrationTool.ui.println ("Warning: Duplicate Specification");\r |
288 | return false;\r | |
5c55f71c | 289 | }\r |
290 | }\r | |
291 | \r | |
292 | public final boolean addLicense (String licensecontent) {\r | |
293 | if (msaheader.getLicense() == null) {\r | |
1ea59929 | 294 | license = msaheader.addNewLicense();\r |
5c55f71c | 295 | if (licensecontent == null) {\r |
1ea59929 | 296 | license.setStringValue(LICENSE);\r |
5c55f71c | 297 | } else {\r |
1ea59929 | 298 | license.setStringValue(licensecontent);\r |
5c55f71c | 299 | }\r |
300 | return true;\r | |
301 | } else {\r | |
1ea59929 | 302 | MigrationTool.ui.println ("Warning: Duplicate License");\r |
303 | return false;\r | |
5c55f71c | 304 | }\r |
305 | }\r | |
306 | \r | |
307 | public final boolean addDescription (String description) {\r | |
308 | if (msaheader.getDescription() == null) {\r | |
309 | if (description == null) {\r | |
1ea59929 | 310 | msaheader.setDescription(DESCRIPTION);\r |
5c55f71c | 311 | } else {\r |
1ea59929 | 312 | msaheader.setDescription(description);\r |
5c55f71c | 313 | }\r |
314 | return true;\r | |
315 | } else {\r | |
1ea59929 | 316 | MigrationTool.ui.println ("Warning: Duplicate Description");\r |
317 | return false;\r | |
5c55f71c | 318 | }\r |
319 | }\r | |
320 | \r | |
321 | public final boolean addAbstract (String abs) {\r | |
322 | if (msaheader.getAbstract() == null) {\r | |
323 | if (abs == null) {\r | |
1ea59929 | 324 | msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r |
5c55f71c | 325 | } else {\r |
1ea59929 | 326 | msaheader.setVersion(abs);\r |
5c55f71c | 327 | }\r |
328 | return true;\r | |
329 | } else {\r | |
1ea59929 | 330 | MigrationTool.ui.println ("Warning: Duplicate Abstract");\r |
331 | return false;\r | |
5c55f71c | 332 | }\r |
333 | }\r | |
334 | \r | |
335 | public final boolean addVersion (String version) {\r | |
336 | if (msaheader.getVersion() == null) {\r | |
337 | if (version == null) {\r | |
1ea59929 | 338 | msaheader.setVersion(VERSION);\r |
5c55f71c | 339 | } else {\r |
1ea59929 | 340 | msaheader.setVersion(version);\r |
5c55f71c | 341 | }\r |
342 | return true;\r | |
343 | } else {\r | |
1ea59929 | 344 | MigrationTool.ui.println ("Warning: Duplicate Version");\r |
345 | return false;\r | |
5c55f71c | 346 | }\r |
347 | }\r | |
348 | \r | |
349 | public final boolean addCopyRight (String copyright) {\r | |
1ea59929 | 350 | if (msaheader.getCopyright() == null) {\r |
351 | if (copyright == null) {\r | |
5c55f71c | 352 | msaheader.setCopyright(COPYRIGHT);\r |
1ea59929 | 353 | } else {\r |
354 | msaheader.setCopyright(copyright);\r | |
355 | }\r | |
356 | return true;\r | |
357 | } else {\r | |
358 | MigrationTool.ui.println ("Warning: Duplicate CopyRight");\r | |
359 | return false;\r | |
360 | }\r | |
5c55f71c | 361 | }\r |
362 | \r | |
363 | public final boolean addModuleType (String moduletype) {\r | |
1ea59929 | 364 | if (msaheader.getModuleType() == null) {\r |
365 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));\r | |
366 | return true;\r | |
367 | } else {\r | |
368 | MigrationTool.ui.println ("Warning: Duplicate ModuleType");\r | |
369 | return false;\r | |
370 | }\r | |
5c55f71c | 371 | }\r |
372 | \r | |
373 | public final boolean addGuidValue (String guidvalue) {\r | |
1ea59929 | 374 | if (msaheader.getGuidValue() == null) {\r |
375 | msaheader.setGuidValue(guidvalue);\r | |
376 | return true;\r | |
377 | } else {\r | |
378 | MigrationTool.ui.println ("Warning: Duplicate GuidValue");\r | |
379 | return false;\r | |
380 | }\r | |
5c55f71c | 381 | }\r |
382 | \r | |
383 | public final boolean addModuleName (String modulename) {\r | |
1ea59929 | 384 | if (msaheader.getModuleName() == null) {\r |
385 | msaheader.setModuleName(modulename);\r | |
386 | return true;\r | |
387 | } else {\r | |
388 | MigrationTool.ui.println ("Warning: Duplicate ModuleName");\r | |
389 | return false;\r | |
390 | }\r | |
5c55f71c | 391 | }\r |
392 | //-----------------------------msaheader-------------------------------------//\r | |
393 | \r | |
8270b34d | 394 | private final void fullfill () throws Exception {\r |
395 | addCopyRight(null);\r | |
396 | addVersion(null);\r | |
397 | addAbstract(null);\r | |
398 | addDescription(null);\r | |
399 | addLicense(null);\r | |
400 | addSpecification(null);\r | |
401 | }\r | |
402 | \r | |
1ea59929 | 403 | public final void flush(String outputpath) throws Exception {\r |
404 | XmlOptions options = new XmlOptions();\r | |
405 | \r | |
406 | options.setCharacterEncoding("UTF-8");\r | |
407 | options.setSavePrettyPrint();\r | |
408 | options.setSavePrettyPrintIndent(2);\r | |
409 | options.setUseDefaultNamespace();\r | |
410 | \r | |
411 | BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));\r | |
8270b34d | 412 | fullfill();\r |
1ea59929 | 413 | msadoc.save(bw, options);\r |
414 | bw.flush();\r | |
415 | bw.close();\r | |
5c55f71c | 416 | }\r |
417 | \r | |
418 | private final MsaOwner init () {\r | |
1ea59929 | 419 | msa = msadoc.addNewModuleSurfaceArea();\r |
420 | msaheader = msa.addNewMsaHeader();\r | |
421 | moduledefinitions = msa.addNewModuleDefinitions();\r | |
422 | moduledefinitions.setSupportedArchitectures(listarch);\r | |
423 | \r | |
424 | sourcefiles = msa.addNewSourceFiles();\r | |
425 | packagedependencies = msa.addNewPackageDependencies();\r | |
426 | libclassdefs = msa.addNewLibraryClassDefinitions();\r | |
427 | externs = msa.addNewExterns();\r | |
428 | return this;\r | |
5c55f71c | 429 | }\r |
430 | \r | |
431 | public static final MsaOwner initNewMsaOwner() {\r | |
1ea59929 | 432 | return new MsaOwner().init();\r |
5c55f71c | 433 | }\r |
434 | } |