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