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