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