]>
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 | |
1ea59929 | 228 | addPackage("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r |
229 | addPackage("68169ab0-d41b-4009-9060-292c253ac43d");\r | |
230 | return true;\r | |
fd16b4dd | 231 | }\r |
232 | \r | |
233 | public final boolean addPackage (String guid) {\r | |
1ea59929 | 234 | if (packagedependencies.getPackageList().contains(guid)) {\r |
235 | return false;\r | |
236 | } else {\r | |
fd16b4dd | 237 | packagedependencies.addNewPackage().setPackageGuid(guid);\r |
238 | return true;\r | |
1ea59929 | 239 | }\r |
fd16b4dd | 240 | }\r |
241 | \r | |
1ea59929 | 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 | |
fd16b4dd | 246 | }\r |
247 | public final boolean addSupportedArchitectures (Enum arch) {\r | |
1ea59929 | 248 | if (listarch.contains(arch)) {\r |
249 | return false;\r | |
250 | } else {\r | |
251 | listarch.add(arch);\r | |
252 | return true;\r | |
253 | }\r | |
fd16b4dd | 254 | }\r |
255 | \r | |
5c55f71c | 256 | public final boolean addSpecification (String specification) {\r |
257 | if (msaheader.getSpecification() == null) {\r | |
258 | if (specification == null) {\r | |
1ea59929 | 259 | msaheader.setSpecification(SPECIFICATION);\r |
5c55f71c | 260 | } else {\r |
1ea59929 | 261 | msaheader.setSpecification(specification);\r |
5c55f71c | 262 | }\r |
263 | return true;\r | |
264 | } else {\r | |
1ea59929 | 265 | MigrationTool.ui.println ("Warning: Duplicate Specification");\r |
266 | return false;\r | |
5c55f71c | 267 | }\r |
268 | }\r | |
269 | \r | |
270 | public final boolean addLicense (String licensecontent) {\r | |
271 | if (msaheader.getLicense() == null) {\r | |
1ea59929 | 272 | license = msaheader.addNewLicense();\r |
5c55f71c | 273 | if (licensecontent == null) {\r |
1ea59929 | 274 | license.setStringValue(LICENSE);\r |
5c55f71c | 275 | } else {\r |
1ea59929 | 276 | license.setStringValue(licensecontent);\r |
5c55f71c | 277 | }\r |
278 | return true;\r | |
279 | } else {\r | |
1ea59929 | 280 | MigrationTool.ui.println ("Warning: Duplicate License");\r |
281 | return false;\r | |
5c55f71c | 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 | |
1ea59929 | 288 | msaheader.setDescription(DESCRIPTION);\r |
5c55f71c | 289 | } else {\r |
1ea59929 | 290 | msaheader.setDescription(description);\r |
5c55f71c | 291 | }\r |
292 | return true;\r | |
293 | } else {\r | |
1ea59929 | 294 | MigrationTool.ui.println ("Warning: Duplicate Description");\r |
295 | return false;\r | |
5c55f71c | 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 | |
1ea59929 | 302 | msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());\r |
5c55f71c | 303 | } else {\r |
1ea59929 | 304 | msaheader.setVersion(abs);\r |
5c55f71c | 305 | }\r |
306 | return true;\r | |
307 | } else {\r | |
1ea59929 | 308 | MigrationTool.ui.println ("Warning: Duplicate Abstract");\r |
309 | return false;\r | |
5c55f71c | 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 | |
1ea59929 | 316 | msaheader.setVersion(VERSION);\r |
5c55f71c | 317 | } else {\r |
1ea59929 | 318 | msaheader.setVersion(version);\r |
5c55f71c | 319 | }\r |
320 | return true;\r | |
321 | } else {\r | |
1ea59929 | 322 | MigrationTool.ui.println ("Warning: Duplicate Version");\r |
323 | return false;\r | |
5c55f71c | 324 | }\r |
325 | }\r | |
326 | \r | |
327 | public final boolean addCopyRight (String copyright) {\r | |
1ea59929 | 328 | if (msaheader.getCopyright() == null) {\r |
329 | if (copyright == null) {\r | |
5c55f71c | 330 | msaheader.setCopyright(COPYRIGHT);\r |
1ea59929 | 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 | |
5c55f71c | 339 | }\r |
340 | \r | |
341 | public final boolean addModuleType (String moduletype) {\r | |
1ea59929 | 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 | |
5c55f71c | 349 | }\r |
350 | \r | |
351 | public final boolean addGuidValue (String guidvalue) {\r | |
1ea59929 | 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 | |
5c55f71c | 359 | }\r |
360 | \r | |
361 | public final boolean addModuleName (String modulename) {\r | |
1ea59929 | 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 | |
5c55f71c | 369 | }\r |
370 | //-----------------------------msaheader-------------------------------------//\r | |
371 | \r | |
1ea59929 | 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 | |
5c55f71c | 384 | }\r |
385 | \r | |
386 | private final MsaOwner init () {\r | |
1ea59929 | 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 | |
5c55f71c | 397 | }\r |
398 | \r | |
399 | public static final MsaOwner initNewMsaOwner() {\r | |
1ea59929 | 400 | return new MsaOwner().init();\r |
5c55f71c | 401 | }\r |
402 | } |