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