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