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