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