]>
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 | |
1ea59929 | 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 | |
1ea59929 | 73 | classname = libclassdefs.addNewLibraryClass();\r |
74 | classname.setKeyword(name);\r | |
190293ab | 75 | classname.setUsage(usage);\r |
1ea59929 | 76 | return true;\r |
b8817061 | 77 | }\r |
78 | \r | |
79 | public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r | |
1ea59929 | 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 | |
1ea59929 | 93 | guid = guids.addNewGuidCNames();\r |
94 | guid.setGuidCName(guidname);\r | |
190293ab | 95 | guid.setUsage(usage);\r |
1ea59929 | 96 | return true;\r |
b8817061 | 97 | }\r |
98 | \r | |
99 | \r | |
100 | public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r | |
1ea59929 | 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 | |
1ea59929 | 114 | ppi = ppis.addNewPpi();\r |
115 | ppi.setPpiCName(ppiname);\r | |
190293ab | 116 | ppi.setUsage(usage);\r |
1ea59929 | 117 | return true;\r |
b8817061 | 118 | }\r |
119 | \r | |
120 | /*\r | |
fd16b4dd | 121 | private final boolean installProtocols () {\r |
1ea59929 | 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 | |
fd16b4dd | 134 | }\r |
135 | \r | |
136 | public final boolean addProtocols (String protocol, UsageTypes.Enum usage) {\r | |
1ea59929 | 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 | |
fd16b4dd | 143 | }\r |
b8817061 | 144 | */\r |
145 | public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r | |
1ea59929 | 146 | if (protocols == null) {\r |
147 | protocols = msa.addNewProtocols();\r | |
148 | }\r | |
190293ab | 149 | \r |
1ea59929 | 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 | |
190293ab | 157 | \r |
1ea59929 | 158 | ProtocolsDocument.Protocols.Protocol protocol;\r |
1ea59929 | 159 | protocol = protocols.addNewProtocol();\r |
160 | protocol.setProtocolCName(proname);\r | |
190293ab | 161 | protocol.setUsage(usage);\r |
1ea59929 | 162 | return true;\r |
b8817061 | 163 | }\r |
fd16b4dd | 164 | \r |
b8817061 | 165 | /*\r |
fd16b4dd | 166 | private final boolean installHashFilename () {\r |
1ea59929 | 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 | |
fd16b4dd | 181 | }\r |
182 | \r | |
1ea59929 | 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 | |
fd16b4dd | 187 | mapfilenames.put(filename, arch);\r |
188 | return true;\r | |
1ea59929 | 189 | }\r |
fd16b4dd | 190 | }\r |
b8817061 | 191 | */\r |
192 | public final boolean addSourceFile (String name, Enum en) {\r | |
1ea59929 | 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 | |
b8817061 | 208 | }\r |
fd16b4dd | 209 | \r |
210 | // entry point todo\r | |
211 | \r | |
212 | public final boolean setupExternSpecification () {\r | |
1ea59929 | 213 | addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");\r |
214 | addExternSpecification("EDK_RELEASE_VERSION 0x00020000");\r | |
215 | return true;\r | |
fd16b4dd | 216 | }\r |
217 | \r | |
218 | public final boolean addExternSpecification (String specification) {\r | |
1ea59929 | 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 | |
fd16b4dd | 225 | }\r |
226 | \r | |
227 | public final boolean setupPackageDependencies() {\r | |
9c0e70cb | 228 | Iterator<String> it;\r |
229 | //\r | |
230 | // For now, simply add all package guids in the database. \r | |
231 | // \r | |
232 | it = MigrationTool.db.dumpAllPkgGuid();\r | |
233 | while (it.hasNext()) {\r | |
234 | packagedependencies.addNewPackage().setPackageGuid(it.next());\r | |
235 | }\r | |
1ea59929 | 236 | return true;\r |
fd16b4dd | 237 | }\r |
238 | \r | |
239 | public final boolean addPackage (String guid) {\r | |
1ea59929 | 240 | if (packagedependencies.getPackageList().contains(guid)) {\r |
241 | return false;\r | |
242 | } else {\r | |
fd16b4dd | 243 | packagedependencies.addNewPackage().setPackageGuid(guid);\r |
244 | return true;\r | |
1ea59929 | 245 | }\r |
fd16b4dd | 246 | }\r |
247 | \r | |
1ea59929 | 248 | public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo\r |
249 | moduledefinitions.setBinaryModule(false);\r | |
250 | moduledefinitions.setOutputFileBasename(msaheader.getModuleName());\r | |
251 | return true;\r | |
fd16b4dd | 252 | }\r |
253 | public final boolean addSupportedArchitectures (Enum arch) {\r | |
1ea59929 | 254 | if (listarch.contains(arch)) {\r |
255 | return false;\r | |
256 | } else {\r | |
257 | listarch.add(arch);\r | |
258 | return true;\r | |
259 | }\r | |
fd16b4dd | 260 | }\r |
261 | \r | |
5c55f71c | 262 | public final boolean addSpecification (String specification) {\r |
263 | if (msaheader.getSpecification() == null) {\r | |
264 | if (specification == null) {\r | |
1ea59929 | 265 | msaheader.setSpecification(SPECIFICATION);\r |
5c55f71c | 266 | } else {\r |
1ea59929 | 267 | msaheader.setSpecification(specification);\r |
5c55f71c | 268 | }\r |
269 | return true;\r | |
270 | } else {\r | |
1ea59929 | 271 | MigrationTool.ui.println ("Warning: Duplicate Specification");\r |
272 | return false;\r | |
5c55f71c | 273 | }\r |
274 | }\r | |
275 | \r | |
276 | public final boolean addLicense (String licensecontent) {\r | |
277 | if (msaheader.getLicense() == null) {\r | |
1ea59929 | 278 | license = msaheader.addNewLicense();\r |
5c55f71c | 279 | if (licensecontent == null) {\r |
1ea59929 | 280 | license.setStringValue(LICENSE);\r |
5c55f71c | 281 | } else {\r |
1ea59929 | 282 | license.setStringValue(licensecontent);\r |
5c55f71c | 283 | }\r |
284 | return true;\r | |
285 | } else {\r | |
1ea59929 | 286 | MigrationTool.ui.println ("Warning: Duplicate License");\r |
287 | return false;\r | |
5c55f71c | 288 | }\r |
289 | }\r | |
290 | \r | |
291 | public final boolean addDescription (String description) {\r | |
292 | if (msaheader.getDescription() == null) {\r | |
293 | if (description == null) {\r | |
1ea59929 | 294 | msaheader.setDescription(DESCRIPTION);\r |
5c55f71c | 295 | } else {\r |
1ea59929 | 296 | msaheader.setDescription(description);\r |
5c55f71c | 297 | }\r |
298 | return true;\r | |
299 | } else {\r | |
1ea59929 | 300 | MigrationTool.ui.println ("Warning: Duplicate Description");\r |
301 | return false;\r | |
5c55f71c | 302 | }\r |
303 | }\r | |
304 | \r | |
305 | public final boolean addAbstract (String abs) {\r | |
306 | if (msaheader.getAbstract() == null) {\r | |
307 | if (abs == null) {\r | |
1ea59929 | 308 | msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r |
5c55f71c | 309 | } else {\r |
1ea59929 | 310 | msaheader.setVersion(abs);\r |
5c55f71c | 311 | }\r |
312 | return true;\r | |
313 | } else {\r | |
1ea59929 | 314 | MigrationTool.ui.println ("Warning: Duplicate Abstract");\r |
315 | return false;\r | |
5c55f71c | 316 | }\r |
317 | }\r | |
318 | \r | |
319 | public final boolean addVersion (String version) {\r | |
320 | if (msaheader.getVersion() == null) {\r | |
321 | if (version == null) {\r | |
1ea59929 | 322 | msaheader.setVersion(VERSION);\r |
5c55f71c | 323 | } else {\r |
1ea59929 | 324 | msaheader.setVersion(version);\r |
5c55f71c | 325 | }\r |
326 | return true;\r | |
327 | } else {\r | |
1ea59929 | 328 | MigrationTool.ui.println ("Warning: Duplicate Version");\r |
329 | return false;\r | |
5c55f71c | 330 | }\r |
331 | }\r | |
332 | \r | |
333 | public final boolean addCopyRight (String copyright) {\r | |
1ea59929 | 334 | if (msaheader.getCopyright() == null) {\r |
335 | if (copyright == null) {\r | |
5c55f71c | 336 | msaheader.setCopyright(COPYRIGHT);\r |
1ea59929 | 337 | } else {\r |
338 | msaheader.setCopyright(copyright);\r | |
339 | }\r | |
340 | return true;\r | |
341 | } else {\r | |
342 | MigrationTool.ui.println ("Warning: Duplicate CopyRight");\r | |
343 | return false;\r | |
344 | }\r | |
5c55f71c | 345 | }\r |
346 | \r | |
347 | public final boolean addModuleType (String moduletype) {\r | |
1ea59929 | 348 | if (msaheader.getModuleType() == null) {\r |
349 | msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));\r | |
350 | return true;\r | |
351 | } else {\r | |
352 | MigrationTool.ui.println ("Warning: Duplicate ModuleType");\r | |
353 | return false;\r | |
354 | }\r | |
5c55f71c | 355 | }\r |
356 | \r | |
357 | public final boolean addGuidValue (String guidvalue) {\r | |
1ea59929 | 358 | if (msaheader.getGuidValue() == null) {\r |
359 | msaheader.setGuidValue(guidvalue);\r | |
360 | return true;\r | |
361 | } else {\r | |
362 | MigrationTool.ui.println ("Warning: Duplicate GuidValue");\r | |
363 | return false;\r | |
364 | }\r | |
5c55f71c | 365 | }\r |
366 | \r | |
367 | public final boolean addModuleName (String modulename) {\r | |
1ea59929 | 368 | if (msaheader.getModuleName() == null) {\r |
369 | msaheader.setModuleName(modulename);\r | |
370 | return true;\r | |
371 | } else {\r | |
372 | MigrationTool.ui.println ("Warning: Duplicate ModuleName");\r | |
373 | return false;\r | |
374 | }\r | |
5c55f71c | 375 | }\r |
376 | //-----------------------------msaheader-------------------------------------//\r | |
377 | \r | |
1ea59929 | 378 | public final void flush(String outputpath) throws Exception {\r |
379 | XmlOptions options = new XmlOptions();\r | |
380 | \r | |
381 | options.setCharacterEncoding("UTF-8");\r | |
382 | options.setSavePrettyPrint();\r | |
383 | options.setSavePrettyPrintIndent(2);\r | |
384 | options.setUseDefaultNamespace();\r | |
385 | \r | |
386 | BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));\r | |
387 | msadoc.save(bw, options);\r | |
388 | bw.flush();\r | |
389 | bw.close();\r | |
5c55f71c | 390 | }\r |
391 | \r | |
392 | private final MsaOwner init () {\r | |
1ea59929 | 393 | msa = msadoc.addNewModuleSurfaceArea();\r |
394 | msaheader = msa.addNewMsaHeader();\r | |
395 | moduledefinitions = msa.addNewModuleDefinitions();\r | |
396 | moduledefinitions.setSupportedArchitectures(listarch);\r | |
397 | \r | |
398 | sourcefiles = msa.addNewSourceFiles();\r | |
399 | packagedependencies = msa.addNewPackageDependencies();\r | |
400 | libclassdefs = msa.addNewLibraryClassDefinitions();\r | |
401 | externs = msa.addNewExterns();\r | |
402 | return this;\r | |
5c55f71c | 403 | }\r |
404 | \r | |
405 | public static final MsaOwner initNewMsaOwner() {\r | |
1ea59929 | 406 | return new MsaOwner().init();\r |
5c55f71c | 407 | }\r |
408 | } |