]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java
1. Fix EDKT344: The algorithm for PCD of msa should be adjusted
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / workspace / WorkspaceTools.java
1 /** @file
2
3 The file is used to init workspace and get basic information of workspace
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 package org.tianocore.frameworkwizard.workspace;
16
17 import java.io.File;
18 import java.io.IOException;
19 import java.util.List;
20 import java.util.Vector;
21
22 import org.apache.xmlbeans.XmlCursor;
23 import org.apache.xmlbeans.XmlException;
24 import org.tianocore.DbPathAndFilename;
25 import org.tianocore.IndustryStdIncludesDocument.IndustryStdIncludes;
26 import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;
27 import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions;
28 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
29 import org.tianocore.MsaFilesDocument.MsaFiles;
30 import org.tianocore.PackageDependenciesDocument.PackageDependencies;
31 import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
32 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
33 import org.tianocore.SourceFilesDocument.SourceFiles;
34 import org.tianocore.frameworkwizard.common.DataType;
35 import org.tianocore.frameworkwizard.common.GlobalData;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.OpenFile;
38 import org.tianocore.frameworkwizard.common.SaveFile;
39 import org.tianocore.frameworkwizard.common.Sort;
40 import org.tianocore.frameworkwizard.common.Tools;
41 import org.tianocore.frameworkwizard.common.Identifications.Identification;
42 import org.tianocore.frameworkwizard.far.FarHeader;
43 import org.tianocore.frameworkwizard.far.FarIdentification;
44 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
45 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdIdentification;
46 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;
47 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
48 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
49
50 public class WorkspaceTools {
51
52 public void addFarToDb(List<String> packageList, List<String> platformList, FarHeader far) {
53 //FrameworkDatabase fdb = openFrameworkDb();
54
55 for (int i = 0; i < packageList.size(); i++) {
56 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();
57 item.setFarGuid(far.getGuidValue());
58 item.setStringValue(packageList.get(i));
59 GlobalData.fdb.getPackageList().getFilenameList().add(item);
60 }
61
62 for (int i = 0; i < platformList.size(); i++) {
63 DbPathAndFilename item = DbPathAndFilename.Factory.newInstance();
64 item.setFarGuid(far.getGuidValue());
65 item.setStringValue(platformList.get(i));
66 GlobalData.fdb.getPlatformList().getFilenameList().add(item);
67 }
68
69 DbPathAndFilename farItem = DbPathAndFilename.Factory.newInstance();
70 farItem.setFarGuid(far.getGuidValue());
71 farItem.setStringValue(far.getFarName());
72 GlobalData.fdb.getFarList().getFilenameList().add(farItem);
73
74 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
75 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
76
77 try {
78 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
79 } catch (Exception e) {
80 Log.err("Save Database File", e.getMessage());
81 }
82 }
83
84 public void removeFarFromDb(FarIdentification far) {
85 //
86 // Remove Packages
87 //
88 XmlCursor cursor = GlobalData.fdb.getPackageList().newCursor();
89 cursor.toFirstChild();
90 do {
91 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();
92
93 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {
94 cursor.removeXml();
95 }
96 } while (cursor.toNextSibling());
97 cursor.dispose();
98
99 //
100 // Remove Platforms
101 //
102 cursor = GlobalData.fdb.getPlatformList().newCursor();
103 cursor.toFirstChild();
104 do {
105 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();
106 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {
107 cursor.removeXml();
108 }
109 } while (cursor.toNextSibling());
110
111 //
112 // Remove Far
113 //
114 cursor = GlobalData.fdb.getFarList().newCursor();
115 cursor.toFirstChild();
116 do {
117 DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();
118 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {
119 cursor.removeXml();
120 }
121 } while (cursor.toNextSibling());
122 cursor.dispose();
123
124 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
125 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
126 try {
127 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
128 } catch (Exception e) {
129 Log.err("Save Database File", e.getMessage());
130 }
131 }
132
133 public String getPackageFarGuid(Identification packageId) {
134 for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {
135 DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);
136 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();
137 File tempFile = new File(path);
138 if (tempFile.getPath().equalsIgnoreCase(packageId.getPath())) {
139 return GlobalData.fdb.getPackageList().getFilenameArray(index).getFarGuid();
140 }
141 }
142
143 return null;
144 }
145
146 public String getPlatformFarGuid(Identification platformId) {
147 for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {
148 DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);
149 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();
150 File tempFile = new File(path);
151 if (tempFile.getPath().equalsIgnoreCase(platformId.getPath())) {
152 return GlobalData.fdb.getPlatformList().getFilenameArray(index).getFarGuid();
153 }
154 }
155
156 return null;
157 }
158
159 public String getModuleFarGuid(Identification moduleId) {
160 PackageIdentification packageId = getPackageIdByModuleId(moduleId);
161 if (packageId != null) {
162 return getPackageFarGuid(packageId);
163 } else {
164 return null;
165 }
166 }
167
168 /**
169 Get all modules' paths from one package
170
171 @return a Vector with all modules' path
172
173 **/
174 public Vector<String> getAllModulesOfPackage(String path) {
175 Vector<String> modulePath = new Vector<String>();
176 PackageIdentification id = new PackageIdentification(null, null, null, path);
177 MsaFiles files = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(id).getMsaFiles();
178 if (files != null) {
179 for (int index = 0; index < files.getFilenameList().size(); index++) {
180 String msaPath = files.getFilenameList().get(index);
181 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;
182 msaPath = Tools.convertPathToCurrentOsType(msaPath);
183 modulePath.addElement(msaPath);
184 }
185 }
186
187 return modulePath;
188 }
189
190 /**
191 Get all Industry Std Includes' paths from one package
192
193 @return a Vector with all paths
194
195 **/
196 public Vector<String> getAllIndustryStdIncludesOfPackage(String path) {
197 Vector<String> includePath = new Vector<String>();
198 PackageIdentification id = new PackageIdentification(null, null, null, path);
199 IndustryStdIncludes files = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(id)
200 .getIndustryStdIncludes();
201 if (files != null) {
202 for (int index = 0; index < files.getIndustryStdHeaderList().size(); index++) {
203 String temp = files.getIndustryStdHeaderList().get(index).getIncludeHeader();
204 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;
205 temp = Tools.convertPathToCurrentOsType(temp);
206 includePath.addElement(temp);
207 }
208 }
209 return includePath;
210 }
211
212 /**
213 Get all package basic information form the FrameworkDatabase.db file
214
215 @return vPackageList A vector includes all packages' basic information
216
217 */
218 public Vector<PackageIdentification> getAllPackages() {
219 return GlobalData.vPackageList;
220 }
221
222 public Vector<FarIdentification> getAllFars() {
223
224 Vector<FarIdentification> v = new Vector<FarIdentification>();
225 for (int index = 0; index < GlobalData.fdb.getFarList().getFilenameList().size(); index++) {
226 DbPathAndFilename item = GlobalData.fdb.getFarList().getFilenameList().get(index);
227 FarIdentification far = new FarIdentification(item.getFarGuid(), item.getMd5Sum(), item.getStringValue());
228 v.addElement(far);
229 }
230 return v;
231 }
232
233 public Vector<PackageIdentification> getPackagesByFar(FarIdentification far) {
234 Identification id = null;
235
236 Vector<PackageIdentification> v = new Vector<PackageIdentification>();
237
238 for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {
239 DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);
240 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();
241 path = Tools.convertPathToCurrentOsType(path);
242
243 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {
244
245 try {
246 id = Tools.getId(path, OpenFile.openSpdFile(path));
247 v.addElement(new PackageIdentification(id));
248 } catch (IOException e) {
249 Log.err("Open Package Surface Area " + path, e.getMessage());
250 } catch (XmlException e) {
251 Log.err("Open Package Surface Area " + path, e.getMessage());
252 } catch (Exception e) {
253 Log.err("Open Package Surface Area " + path, "Invalid file type");
254 }
255 }
256 }
257 return v;
258 }
259
260 public Vector<PlatformIdentification> getPlatformsByFar(FarIdentification far) {
261 Identification id = null;
262
263 Vector<PlatformIdentification> v = new Vector<PlatformIdentification>();
264
265 for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {
266 DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);
267 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + item.getStringValue();
268 path = Tools.convertPathToCurrentOsType(path);
269
270 if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {
271 try {
272 id = Tools.getId(path, OpenFile.openFpdFile(path));
273 v.addElement(new PlatformIdentification(id));
274 } catch (IOException e) {
275 Log.err("Open Platform Surface Area " + path, e.getMessage());
276 } catch (XmlException e) {
277 Log.err("Open Platform Surface Area " + path, e.getMessage());
278 } catch (Exception e) {
279 Log.err("Open Platform Surface Area " + path, "Invalid file type");
280 }
281 }
282 }
283 return v;
284 }
285
286 /**
287 Get all module basic information from a package
288
289 @param id Package id
290 @return A vector includes all modules' basic information
291
292 **/
293 public Vector<ModuleIdentification> getAllModules(PackageIdentification pid) {
294 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();
295 Vector<String> modulePaths = this.getAllModulesOfPackage(pid.getPath());
296 String modulePath = null;
297
298 for (int index = 0; index < modulePaths.size(); index++) {
299 modulePath = modulePaths.get(index);
300 ModuleIdentification id = GlobalData.openingModuleList.getIdByPath(modulePath);
301 if (id != null) {
302 v.addElement(id);
303 }
304 }
305 Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);
306 return v;
307 }
308
309 /**
310 Get all module basic information from a platform
311
312 @param id Package id
313 @return A vector includes all modules' basic information
314
315 **/
316 public Vector<ModuleIdentification> getAllModules(PlatformIdentification fid) {
317 Vector<ModuleIdentification> v = new Vector<ModuleIdentification>();
318 PlatformSurfaceArea fpd = GlobalData.openingPlatformList.getOpeningPlatformById(fid).getXmlFpd();
319 if (fpd.getFrameworkModules() != null) {
320 for (int index = 0; index < fpd.getFrameworkModules().getModuleSAList().size(); index++) {
321 String guid = fpd.getFrameworkModules().getModuleSAList().get(index).getModuleGuid();
322 String version = fpd.getFrameworkModules().getModuleSAList().get(index).getModuleVersion();
323 ModuleIdentification id = GlobalData.openingModuleList.getIdByGuidVersion(guid, version);
324 if (id != null) {
325 boolean isFind = false;
326 for (int indexOfModules = 0; indexOfModules < v.size(); indexOfModules++) {
327 if (v.elementAt(indexOfModules).equals(id)) {
328 isFind = true;
329 break;
330 }
331 }
332 if (!isFind) {
333 v.addElement(id);
334 }
335 }
336 }
337 }
338 Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);
339 return v;
340 }
341
342 /**
343 Get all module basic information form the FrameworkDatabase.db file
344
345 @return vModuleList A vector includes all modules' basic information
346
347 */
348 public Vector<ModuleIdentification> getAllModules() {
349 return GlobalData.vModuleList;
350 }
351
352 /**
353 Get all platform basic information form the FrameworkDatabase.db file
354
355 @return vplatformList A vector includes all platforms' basic information
356
357 */
358 public Vector<PlatformIdentification> getAllPlatforms() {
359 return GlobalData.vPlatformList;
360 }
361
362 /**
363 Get all Library Class Definitions from a package
364
365 @return Vector
366 **/
367 public Vector<String> getAllLibraryClassDefinitionsFromPackage(PackageSurfaceArea spd) {
368 Vector<String> vector = new Vector<String>();
369 if (spd.getLibraryClassDeclarations() != null) {
370 if (spd.getLibraryClassDeclarations().getLibraryClassList().size() > 0) {
371 for (int index = 0; index < spd.getLibraryClassDeclarations().getLibraryClassList().size(); index++) {
372 vector.addElement(spd.getLibraryClassDeclarations().getLibraryClassList().get(index).getName());
373 }
374 }
375 }
376 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
377 return vector;
378 }
379
380 /**
381 Get all Protocol Definitions from a package
382
383 @return Vector
384 **/
385 public Vector<String> getAllProtocolDeclarationsFromPackage(PackageSurfaceArea spd) {
386 Vector<String> vector = new Vector<String>();
387 if (spd.getProtocolDeclarations() != null) {
388 if (spd.getProtocolDeclarations().getEntryList().size() > 0) {
389 for (int index = 0; index < spd.getProtocolDeclarations().getEntryList().size(); index++) {
390 vector.addElement(spd.getProtocolDeclarations().getEntryList().get(index).getCName());
391 }
392 }
393 }
394 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
395 return vector;
396 }
397
398 /**
399 Get all Ppi Definitions from a package
400
401 @return Vector
402 **/
403 public Vector<String> getAllPpiDeclarationsFromPackage(PackageSurfaceArea spd) {
404 Vector<String> vector = new Vector<String>();
405 if (spd.getPpiDeclarations() != null) {
406 if (spd.getPpiDeclarations().getEntryList().size() > 0) {
407 for (int index = 0; index < spd.getPpiDeclarations().getEntryList().size(); index++) {
408 vector.addElement(spd.getPpiDeclarations().getEntryList().get(index).getCName());
409 }
410 }
411 }
412 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
413 return vector;
414 }
415
416 /**
417 Get all Guid Definitions from a package
418
419 @return Vector
420 **/
421 public Vector<String> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd, String type) {
422 Vector<String> vector = new Vector<String>();
423 boolean isFound = false;
424 if (spd.getGuidDeclarations() != null) {
425 if (spd.getGuidDeclarations().getEntryList().size() > 0) {
426 for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) {
427 Vector<String> vArch = Tools.convertListToVector(spd.getGuidDeclarations().getEntryList()
428 .get(index).getGuidTypeList());
429 for (int indexOfArch = 0; indexOfArch < vArch.size(); indexOfArch++) {
430 if (vArch.get(indexOfArch).equals(type)) {
431 isFound = true;
432 break;
433 }
434 }
435 if ((isFound) || (vArch == null) || (vArch.size() < 1)) {
436 vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName());
437 isFound = false;
438 }
439 }
440 }
441 }
442 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
443 return vector;
444 }
445
446 /**
447 Get all Pcd Definitions from a package
448
449 @return Vector
450 **/
451 public PcdVector getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {
452 PcdVector vector = new PcdVector();
453 if (spd.getPcdDeclarations() != null) {
454 if (spd.getPcdDeclarations().getPcdEntryList().size() > 0) {
455 for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) {
456 String name = spd.getPcdDeclarations().getPcdEntryList().get(index).getCName();
457 String guidCName = spd.getPcdDeclarations().getPcdEntryList().get(index).getTokenSpaceGuidCName();
458 String help = spd.getPcdDeclarations().getPcdEntryList().get(index).getHelpText();
459 Vector<String> type = Tools.convertListToVector(spd.getPcdDeclarations().getPcdEntryList()
460 .get(index).getValidUsage());
461 //
462 // The algorithm for PCD of msa should be:
463 // 1. If the type of PCD from Spd is FEATURE_FLAG,
464 // the type of Msa only can be FEATURE_FLAG.
465 // 2. If the type of PCD from Spd is not FEATURE_FLAG,
466 // the type of Msa could be selected from the PCD's all types and "DYNAMIC" type.
467 //
468 boolean hasFEATURE_FLAG = false;
469 boolean hasDYNAMIC = false;
470 for (int indexOfType = 0; indexOfType < type.size(); indexOfType++) {
471 if (type.elementAt(indexOfType).equals(DataType.PCD_ITEM_TYPE_DYNAMIC)) {
472 hasDYNAMIC = true;
473 }
474 if(type.elementAt(indexOfType).equals(DataType.PCD_ITEM_TYPE_FEATURE_FLAG)) {
475 hasFEATURE_FLAG = true;
476 }
477 }
478 if (hasFEATURE_FLAG) {
479 type.removeAllElements();
480 type.addElement(DataType.PCD_ITEM_TYPE_FEATURE_FLAG);
481 } else {
482 if (!hasDYNAMIC) {
483 type.addElement(DataType.PCD_ITEM_TYPE_DYNAMIC);
484 }
485 }
486 vector.addPcd(new PcdIdentification(name, guidCName, help, type));
487 }
488 }
489 }
490 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
491 return vector;
492 }
493
494 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {
495 Vector<String> vector = new Vector<String>();
496 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
497 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList
498 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
499 .get(index)));
500 if (v != null && v.size() > 0) {
501 vector.addAll(v);
502 }
503
504 }
505 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
506 return vector;
507 }
508
509 public Vector<String> getAllLibraryClassDefinitionsFromPackages(Vector<PackageIdentification> vpid) {
510 Vector<String> vector = new Vector<String>();
511 for (int index = 0; index < vpid.size(); index++) {
512 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList
513 .getPackageSurfaceAreaFromId(vpid
514 .get(index)));
515 if (v != null && v.size() > 0) {
516 vector.addAll(v);
517 }
518
519 }
520 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
521 return vector;
522 }
523
524 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {
525 Vector<String> vector = new Vector<String>();
526 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
527 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList
528 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
529 .get(index)));
530 if (v != null && v.size() > 0) {
531 vector.addAll(v);
532 }
533 }
534 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
535 return vector;
536 }
537
538 public Vector<String> getAllProtocolDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
539 Vector<String> vector = new Vector<String>();
540 for (int index = 0; index < vpid.size(); index++) {
541 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList
542 .getPackageSurfaceAreaFromId(vpid
543 .get(index)));
544 if (v != null && v.size() > 0) {
545 vector.addAll(v);
546 }
547 }
548 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
549 return vector;
550 }
551
552 public Vector<String> getAllPpiDeclarationsFromWorkspace() {
553 Vector<String> vector = new Vector<String>();
554 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
555 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList
556 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
557 .get(index)));
558 if (v != null && v.size() > 0) {
559 vector.addAll(v);
560 }
561 }
562 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
563 return vector;
564 }
565
566 public Vector<String> getAllPpiDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
567 Vector<String> vector = new Vector<String>();
568 for (int index = 0; index < vpid.size(); index++) {
569 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList
570 .getPackageSurfaceAreaFromId(vpid
571 .get(index)));
572 if (v != null && v.size() > 0) {
573 vector.addAll(v);
574 }
575 }
576 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
577 return vector;
578 }
579
580 public Vector<String> getAllGuidDeclarationsFromWorkspace(String type) {
581 Vector<String> vector = new Vector<String>();
582 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
583 Vector<String> v = getAllGuidDeclarationsFromPackage(
584 GlobalData.openingPackageList
585 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
586 .get(index)),
587 type);
588 if (v != null && v.size() > 0) {
589 vector.addAll(v);
590 }
591
592 }
593 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
594 return vector;
595 }
596
597 public Vector<String> getAllGuidDeclarationsFromPackages(Vector<PackageIdentification> vpid, String type) {
598 Vector<String> vector = new Vector<String>();
599 for (int index = 0; index < vpid.size(); index++) {
600 Vector<String> v = getAllGuidDeclarationsFromPackage(
601 GlobalData.openingPackageList
602 .getPackageSurfaceAreaFromId(vpid
603 .get(index)),
604 type);
605 if (v != null && v.size() > 0) {
606 vector.addAll(v);
607 }
608
609 }
610 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
611 return vector;
612 }
613
614 public PcdVector getAllPcdDeclarationsFromWorkspace() {
615 PcdVector vector = new PcdVector();
616 for (int index = 0; index < GlobalData.openingPackageList.size(); index++) {
617 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList
618 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
619 .get(index)));
620 if (v != null && v.size() > 0) {
621 vector.addAll(v);
622 }
623
624 }
625 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
626 return vector;
627 }
628
629 public PcdVector getAllPcdDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
630 PcdVector vector = new PcdVector();
631 for (int index = 0; index < vpid.size(); index++) {
632 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList
633 .getPackageSurfaceAreaFromId(vpid
634 .get(index)));
635 if (v != null && v.size() > 0) {
636 vector.addAll(v);
637 }
638
639 }
640 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
641 return vector;
642 }
643
644 /**
645 Find a module's package's id
646
647 @param id input module id
648 @return package id
649
650 **/
651 public PackageIdentification getPackageIdByModuleId(Identification id) {
652 Vector<String> modulePaths = new Vector<String>();
653 Identification mid = null;
654 String packagePath = null;
655 String modulePath = null;
656
657 //
658 // For each package, get all modules list
659 //
660 for (int indexI = 0; indexI < GlobalData.vPackageList.size(); indexI++) {
661 packagePath = GlobalData.vPackageList.elementAt(indexI).getPath();
662 modulePaths = this.getAllModulesOfPackage(packagePath);
663 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {
664 modulePath = modulePaths.get(indexJ);
665 mid = GlobalData.openingModuleList.getIdByPath(modulePath);
666 //
667 // Check id
668 //
669 if (mid.equals(id)) {
670 return GlobalData.vPackageList.elementAt(indexI);
671 }
672
673 }
674 }
675
676 return null;
677 }
678
679 /**
680 Add module information to package surface area
681
682 @param mid
683 @throws IOException
684 @throws XmlException
685 @throws Exception
686
687 **/
688 public void addModuleToPackage(ModuleIdentification mid, PackageSurfaceArea spd) throws IOException, XmlException,
689 Exception {
690 String packagePath = mid.getPackageId().getPath();
691 String modulePath = mid.getPath();
692 if (spd == null) {
693 spd = OpenFile.openSpdFile(packagePath);
694 }
695 MsaFiles msaFile = spd.getMsaFiles();
696 if (msaFile == null) {
697 msaFile = MsaFiles.Factory.newInstance();
698 }
699 packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR));
700 String fn = Tools.getRelativePath(modulePath, packagePath);
701 msaFile.addNewFilename();
702 msaFile.setFilenameArray(msaFile.getFilenameList().size() - 1, fn);
703 spd.setMsaFiles(msaFile);
704 SaveFile.saveSpdFile(mid.getPackageId().getPath(), spd);
705 //
706 // Update GlobalData
707 //
708 GlobalData.openingPackageList.getPackageSurfaceAreaFromId(mid.getPackageId()).setMsaFiles(msaFile);
709 }
710
711 /**
712 Add input package into database
713
714 @param id
715 * @throws Exception
716
717 **/
718 public void addPackageToDatabase(PackageIdentification id) throws Exception {
719 String path = id.getPath();
720 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());
721
722 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();
723 filename.setStringValue(path);
724 GlobalData.fdb.getPackageList().addNewFilename();
725 GlobalData.fdb.getPackageList().setFilenameArray(GlobalData.fdb.getPackageList().sizeOfFilenameArray() - 1,
726 filename);
727 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
728 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
729 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
730 }
731
732 /**
733 Add input package into database
734
735 @param id
736 * @throws Exception
737
738 **/
739 public void addPlatformToDatabase(PlatformIdentification id) throws Exception {
740 String path = id.getPath();
741 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());
742
743 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();
744 filename.setStringValue(path);
745 GlobalData.fdb.getPlatformList().addNewFilename();
746 GlobalData.fdb.getPlatformList().setFilenameArray(GlobalData.fdb.getPlatformList().sizeOfFilenameArray() - 1,
747 filename);
748 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
749 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
750 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
751 }
752
753 /**
754 Get all file's path from one module
755
756 @param path
757 @return
758 @throws IOException
759 @throws XmlException
760 @throws Exception
761
762 **/
763 public Vector<String> getAllFilesPathOfModule(String path) {
764 Vector<String> v = new Vector<String>();
765 path = Tools.convertPathToCurrentOsType(path);
766
767 //
768 // First add msa file's path
769 //
770 v.addElement(path);
771
772 ModuleSurfaceArea msa = GlobalData.openingModuleList
773 .getModuleSurfaceAreaFromId(GlobalData.openingModuleList
774 .getIdByPath(path));
775 //
776 // Get common defined files of module
777 //
778 if (msa != null) {
779 //
780 // Get all files' path of a module
781 //
782 SourceFiles sf = msa.getSourceFiles();
783 if (sf != null) {
784 for (int index = 0; index < sf.getFilenameList().size(); index++) {
785 String temp = sf.getFilenameList().get(index).getStringValue();
786 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;
787 v.addElement(Tools.convertPathToCurrentOsType(temp));
788 }
789 }
790 }
791
792 //
793 // Get include header files for this module
794 //
795 if (msa.getLibraryClassDefinitions() != null) {
796 LibraryClassDefinitions lcd = msa.getLibraryClassDefinitions();
797 for (int index = 0; index < lcd.sizeOfLibraryClassArray(); index++) {
798 if (lcd.getLibraryClassList().get(index).getUsage().toString()
799 .equals(DataType.USAGE_TYPE_ALWAYS_PRODUCED)
800 || lcd.getLibraryClassList().get(index).getUsage().toString()
801 .equals(DataType.USAGE_TYPE_SOMETIMES_PRODUCED)) {
802 //
803 // Get library class name
804 //
805 String name = lcd.getLibraryClassList().get(index).getKeyword();
806
807 //
808 // Find file path for this class
809 //
810 PackageIdentification pid = GlobalData.openingModuleList.getIdByPath(path).getPackageId();
811 PackageSurfaceArea spd = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(pid);
812 if (spd != null) {
813 if (spd.getLibraryClassDeclarations() != null) {
814 LibraryClassDeclarations lcdl = spd.getLibraryClassDeclarations();
815 for (int indexOfLibOfSpd = 0; indexOfLibOfSpd < lcdl.sizeOfLibraryClassArray(); indexOfLibOfSpd++) {
816 if (lcdl.getLibraryClassList().get(indexOfLibOfSpd).getName().equals(name)) {
817 v.addElement(Tools.convertPathToCurrentOsType(Tools.getFilePathOnly(pid.getPath())
818 + DataType.FILE_SEPARATOR
819 + lcdl.getLibraryClassList()
820 .get(indexOfLibOfSpd)
821 .getIncludeHeader()));
822 }
823 }
824 }
825 }
826 }
827 }
828 }
829
830 return v;
831 }
832
833 /**
834 Get all file's path from one package
835
836 @param path
837 @return
838 @throws IOException
839 @throws XmlException
840 @throws Exception
841
842 **/
843 public Vector<String> getAllFilesPathOfPakcage(String path) {
844 Vector<String> v = new Vector<String>();
845 path = Tools.convertPathToCurrentOsType(path);
846 //
847 // First add package
848 //
849 v.addElement(path);
850
851 //
852 // Add the package's industry std includes one by one
853 //
854 Vector<String> f1 = new Vector<String>();
855 f1 = getAllIndustryStdIncludesOfPackage(path);
856 for (int index = 0; index < f1.size(); index++) {
857 v.addElement(f1.get(index));
858 }
859
860 //
861 // Add module's files one by one
862 //
863 f1 = new Vector<String>();
864 f1 = getAllModulesOfPackage(path);
865 for (int indexI = 0; indexI < f1.size(); indexI++) {
866 Vector<String> f2 = getAllFilesPathOfModule(f1.get(indexI));
867 for (int indexJ = 0; indexJ < f2.size(); indexJ++) {
868 v.addElement(f2.get(indexJ));
869 }
870 }
871
872 return v;
873 }
874
875 /**
876 Get a module's all package dependencies
877
878 @param mid The module id
879 @return A vector of all package dependency ids
880
881 **/
882 public Vector<PackageIdentification> getPackageDependenciesOfModule(ModuleIdentification mid) {
883 Vector<PackageIdentification> vpid = new Vector<PackageIdentification>();
884 ModuleSurfaceArea msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(mid);
885 if (msa != null) {
886 PackageDependencies pd = msa.getPackageDependencies();
887 if (pd != null) {
888 for (int index = 0; index < pd.getPackageList().size(); index++) {
889 String guid = pd.getPackageList().get(index).getPackageGuid();
890 String version = pd.getPackageList().get(index).getPackageVersion();
891 PackageIdentification pid = GlobalData.openingPackageList.getIdByGuidVersion(guid, version);
892 if (pid != null) {
893 vpid.addElement(pid);
894 }
895 }
896 }
897 }
898 return vpid;
899 }
900
901 public Vector<String> getAllModuleGuidXref() {
902 Vector<String> v = new Vector<String>();
903 for (int index = 0; index < GlobalData.openingModuleList.size(); index++) {
904 ModuleIdentification id = GlobalData.openingModuleList.getOpeningModuleByIndex(index).getId();
905 v.addElement(id.getGuid() + " " + id.getName());
906 }
907 return v;
908 }
909
910 public Vector<String> getModuleArch(ModuleIdentification id) {
911 Vector<String> v = new Vector<String>();
912 ModuleSurfaceArea msa = null;
913 if (id != null) {
914 msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(id);
915 }
916 if (msa != null) {
917 if (msa.getModuleDefinitions() != null) {
918 v = Tools.convertListToVector(msa.getModuleDefinitions().getSupportedArchitectures());
919 }
920 }
921 return v;
922 }
923 }