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