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