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