]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java
dedbdddf20b48c45d4355a0c14eaa102630ea3a3
[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 vector.addPcd(new PcdIdentification(name, guidCName, help, type));
463 }
464 }
465 }
466 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
467 return vector;
468 }
469
470 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {
471 Vector<String> vector = new Vector<String>();
472 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
473 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList
474 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
475 .get(index)));
476 if (v != null && v.size() > 0) {
477 vector.addAll(v);
478 }
479
480 }
481 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
482 return vector;
483 }
484
485 public Vector<String> getAllLibraryClassDefinitionsFromPackages(Vector<PackageIdentification> vpid) {
486 Vector<String> vector = new Vector<String>();
487 for (int index = 0; index < vpid.size(); index++) {
488 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList
489 .getPackageSurfaceAreaFromId(vpid
490 .get(index)));
491 if (v != null && v.size() > 0) {
492 vector.addAll(v);
493 }
494
495 }
496 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
497 return vector;
498 }
499
500 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {
501 Vector<String> vector = new Vector<String>();
502 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
503 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList
504 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
505 .get(index)));
506 if (v != null && v.size() > 0) {
507 vector.addAll(v);
508 }
509 }
510 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
511 return vector;
512 }
513
514 public Vector<String> getAllProtocolDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
515 Vector<String> vector = new Vector<String>();
516 for (int index = 0; index < vpid.size(); index++) {
517 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList
518 .getPackageSurfaceAreaFromId(vpid
519 .get(index)));
520 if (v != null && v.size() > 0) {
521 vector.addAll(v);
522 }
523 }
524 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
525 return vector;
526 }
527
528 public Vector<String> getAllPpiDeclarationsFromWorkspace() {
529 Vector<String> vector = new Vector<String>();
530 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
531 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList
532 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
533 .get(index)));
534 if (v != null && v.size() > 0) {
535 vector.addAll(v);
536 }
537 }
538 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
539 return vector;
540 }
541
542 public Vector<String> getAllPpiDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
543 Vector<String> vector = new Vector<String>();
544 for (int index = 0; index < vpid.size(); index++) {
545 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList
546 .getPackageSurfaceAreaFromId(vpid
547 .get(index)));
548 if (v != null && v.size() > 0) {
549 vector.addAll(v);
550 }
551 }
552 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
553 return vector;
554 }
555
556 public Vector<String> getAllGuidDeclarationsFromWorkspace(String type) {
557 Vector<String> vector = new Vector<String>();
558 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {
559 Vector<String> v = getAllGuidDeclarationsFromPackage(
560 GlobalData.openingPackageList
561 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
562 .get(index)),
563 type);
564 if (v != null && v.size() > 0) {
565 vector.addAll(v);
566 }
567
568 }
569 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
570 return vector;
571 }
572
573 public Vector<String> getAllGuidDeclarationsFromPackages(Vector<PackageIdentification> vpid, String type) {
574 Vector<String> vector = new Vector<String>();
575 for (int index = 0; index < vpid.size(); index++) {
576 Vector<String> v = getAllGuidDeclarationsFromPackage(
577 GlobalData.openingPackageList
578 .getPackageSurfaceAreaFromId(vpid
579 .get(index)),
580 type);
581 if (v != null && v.size() > 0) {
582 vector.addAll(v);
583 }
584
585 }
586 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);
587 return vector;
588 }
589
590 public PcdVector getAllPcdDeclarationsFromWorkspace() {
591 PcdVector vector = new PcdVector();
592 for (int index = 0; index < GlobalData.openingPackageList.size(); index++) {
593 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList
594 .getPackageSurfaceAreaFromId(GlobalData.vPackageList
595 .get(index)));
596 if (v != null && v.size() > 0) {
597 vector.addAll(v);
598 }
599
600 }
601 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
602 return vector;
603 }
604
605 public PcdVector getAllPcdDeclarationsFromPackages(Vector<PackageIdentification> vpid) {
606 PcdVector vector = new PcdVector();
607 for (int index = 0; index < vpid.size(); index++) {
608 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList
609 .getPackageSurfaceAreaFromId(vpid
610 .get(index)));
611 if (v != null && v.size() > 0) {
612 vector.addAll(v);
613 }
614
615 }
616 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);
617 return vector;
618 }
619
620 /**
621 Find a module's package's id
622
623 @param id input module id
624 @return package id
625
626 **/
627 public PackageIdentification getPackageIdByModuleId(Identification id) {
628 Vector<String> modulePaths = new Vector<String>();
629 Identification mid = null;
630 String packagePath = null;
631 String modulePath = null;
632
633 //
634 // For each package, get all modules list
635 //
636 for (int indexI = 0; indexI < GlobalData.vPackageList.size(); indexI++) {
637 packagePath = GlobalData.vPackageList.elementAt(indexI).getPath();
638 modulePaths = this.getAllModulesOfPackage(packagePath);
639 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {
640 modulePath = modulePaths.get(indexJ);
641 mid = GlobalData.openingModuleList.getIdByPath(modulePath);
642 //
643 // Check id
644 //
645 if (mid.equals(id)) {
646 return GlobalData.vPackageList.elementAt(indexI);
647 }
648
649 }
650 }
651
652 return null;
653 }
654
655 /**
656 Add module information to package surface area
657
658 @param mid
659 @throws IOException
660 @throws XmlException
661 @throws Exception
662
663 **/
664 public void addModuleToPackage(ModuleIdentification mid, PackageSurfaceArea spd) throws IOException, XmlException,
665 Exception {
666 String packagePath = mid.getPackageId().getPath();
667 String modulePath = mid.getPath();
668 if (spd == null) {
669 spd = OpenFile.openSpdFile(packagePath);
670 }
671 MsaFiles msaFile = spd.getMsaFiles();
672 if (msaFile == null) {
673 msaFile = MsaFiles.Factory.newInstance();
674 }
675 packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR));
676 String fn = Tools.getRelativePath(modulePath, packagePath);
677 msaFile.addNewFilename();
678 msaFile.setFilenameArray(msaFile.getFilenameList().size() - 1, fn);
679 spd.setMsaFiles(msaFile);
680 SaveFile.saveSpdFile(mid.getPackageId().getPath(), spd);
681 //
682 // Update GlobalData
683 //
684 GlobalData.openingPackageList.getPackageSurfaceAreaFromId(mid.getPackageId()).setMsaFiles(msaFile);
685 }
686
687 /**
688 Add input package into database
689
690 @param id
691 * @throws Exception
692
693 **/
694 public void addPackageToDatabase(PackageIdentification id) throws Exception {
695 String path = id.getPath();
696 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());
697
698 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();
699 filename.setStringValue(path);
700 GlobalData.fdb.getPackageList().addNewFilename();
701 GlobalData.fdb.getPackageList().setFilenameArray(GlobalData.fdb.getPackageList().sizeOfFilenameArray() - 1,
702 filename);
703 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
704 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
705 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
706 }
707
708 /**
709 Add input package into database
710
711 @param id
712 * @throws Exception
713
714 **/
715 public void addPlatformToDatabase(PlatformIdentification id) throws Exception {
716 String path = id.getPath();
717 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());
718
719 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();
720 filename.setStringValue(path);
721 GlobalData.fdb.getPlatformList().addNewFilename();
722 GlobalData.fdb.getPlatformList().setFilenameArray(GlobalData.fdb.getPlatformList().sizeOfFilenameArray() - 1,
723 filename);
724 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
725 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
726 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);
727 }
728
729 /**
730 Get all file's path from one module
731
732 @param path
733 @return
734 @throws IOException
735 @throws XmlException
736 @throws Exception
737
738 **/
739 public Vector<String> getAllFilesPathOfModule(String path) {
740 Vector<String> v = new Vector<String>();
741 path = Tools.convertPathToCurrentOsType(path);
742
743 //
744 // First add msa file's path
745 //
746 v.addElement(path);
747
748 ModuleSurfaceArea msa = GlobalData.openingModuleList
749 .getModuleSurfaceAreaFromId(GlobalData.openingModuleList
750 .getIdByPath(path));
751 //
752 // Get common defined files of module
753 //
754 if (msa != null) {
755 //
756 // Get all files' path of a module
757 //
758 SourceFiles sf = msa.getSourceFiles();
759 if (sf != null) {
760 for (int index = 0; index < sf.getFilenameList().size(); index++) {
761 String temp = sf.getFilenameList().get(index).getStringValue();
762 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;
763 v.addElement(Tools.convertPathToCurrentOsType(temp));
764 }
765 }
766 }
767
768 //
769 // Get include header files for this module
770 //
771 if (msa.getLibraryClassDefinitions() != null) {
772 LibraryClassDefinitions lcd = msa.getLibraryClassDefinitions();
773 for (int index = 0; index < lcd.sizeOfLibraryClassArray(); index++) {
774 if (lcd.getLibraryClassList().get(index).getUsage().toString()
775 .equals(DataType.USAGE_TYPE_ALWAYS_PRODUCED)
776 || lcd.getLibraryClassList().get(index).getUsage().toString()
777 .equals(DataType.USAGE_TYPE_SOMETIMES_PRODUCED)) {
778 //
779 // Get library class name
780 //
781 String name = lcd.getLibraryClassList().get(index).getKeyword();
782
783 //
784 // Find file path for this class
785 //
786 PackageIdentification pid = GlobalData.openingModuleList.getIdByPath(path).getPackageId();
787 PackageSurfaceArea spd = GlobalData.openingPackageList.getPackageSurfaceAreaFromId(pid);
788 if (spd != null) {
789 if (spd.getLibraryClassDeclarations() != null) {
790 LibraryClassDeclarations lcdl = spd.getLibraryClassDeclarations();
791 for (int indexOfLibOfSpd = 0; indexOfLibOfSpd < lcdl.sizeOfLibraryClassArray(); indexOfLibOfSpd++) {
792 if (lcdl.getLibraryClassList().get(indexOfLibOfSpd).getName().equals(name)) {
793 v.addElement(Tools.convertPathToCurrentOsType(Tools.getFilePathOnly(pid.getPath())
794 + DataType.FILE_SEPARATOR
795 + lcdl.getLibraryClassList()
796 .get(indexOfLibOfSpd)
797 .getIncludeHeader()));
798 }
799 }
800 }
801 }
802 }
803 }
804 }
805
806 return v;
807 }
808
809 /**
810 Get all file's path from one package
811
812 @param path
813 @return
814 @throws IOException
815 @throws XmlException
816 @throws Exception
817
818 **/
819 public Vector<String> getAllFilesPathOfPakcage(String path) {
820 Vector<String> v = new Vector<String>();
821 path = Tools.convertPathToCurrentOsType(path);
822 //
823 // First add package
824 //
825 v.addElement(path);
826
827 //
828 // Add the package's industry std includes one by one
829 //
830 Vector<String> f1 = new Vector<String>();
831 f1 = getAllIndustryStdIncludesOfPackage(path);
832 for (int index = 0; index < f1.size(); index++) {
833 v.addElement(f1.get(index));
834 }
835
836 //
837 // Add module's files one by one
838 //
839 f1 = new Vector<String>();
840 f1 = getAllModulesOfPackage(path);
841 for (int indexI = 0; indexI < f1.size(); indexI++) {
842 Vector<String> f2 = getAllFilesPathOfModule(f1.get(indexI));
843 for (int indexJ = 0; indexJ < f2.size(); indexJ++) {
844 v.addElement(f2.get(indexJ));
845 }
846 }
847
848 return v;
849 }
850
851 /**
852 Get a module's all package dependencies
853
854 @param mid The module id
855 @return A vector of all package dependency ids
856
857 **/
858 public Vector<PackageIdentification> getPackageDependenciesOfModule(ModuleIdentification mid) {
859 Vector<PackageIdentification> vpid = new Vector<PackageIdentification>();
860 ModuleSurfaceArea msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(mid);
861 if (msa != null) {
862 PackageDependencies pd = msa.getPackageDependencies();
863 if (pd != null) {
864 for (int index = 0; index < pd.getPackageList().size(); index++) {
865 String guid = pd.getPackageList().get(index).getPackageGuid();
866 String version = pd.getPackageList().get(index).getPackageVersion();
867 PackageIdentification pid = GlobalData.openingPackageList.getIdByGuidVersion(guid, version);
868 if (pid != null) {
869 vpid.addElement(pid);
870 }
871 }
872 }
873 }
874 return vpid;
875 }
876
877 public Vector<String> getAllModuleGuidXref() {
878 Vector<String> v = new Vector<String>();
879 for (int index = 0; index < GlobalData.openingModuleList.size(); index++) {
880 ModuleIdentification id = GlobalData.openingModuleList.getOpeningModuleByIndex(index).getId();
881 v.addElement(id.getGuid() + " " + id.getName());
882 }
883 return v;
884 }
885
886 public Vector<String> getModuleArch(ModuleIdentification id) {
887 Vector<String> v = new Vector<String>();
888 ModuleSurfaceArea msa = null;
889 if (id != null) {
890 msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(id);
891 }
892 if (msa != null) {
893 if (msa.getModuleDefinitions() != null) {
894 v = Tools.convertListToVector(msa.getModuleDefinitions().getSupportedArchitectures());
895 }
896 }
897 return v;
898 }
899 }