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