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