]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/workspace/WorkspaceTools.java
Changed spelling to manifest
[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
d48c170d 419 public Vector<String> getAllGuidDeclarationsFromPackage(PackageSurfaceArea spd, String type) {\r
a13899c5 420 Vector<String> vector = new Vector<String>();\r
d48c170d 421 boolean isFound = false;\r
a13899c5 422 if (spd.getGuidDeclarations() != null) {\r
423 if (spd.getGuidDeclarations().getEntryList().size() > 0) {\r
424 for (int index = 0; index < spd.getGuidDeclarations().getEntryList().size(); index++) {\r
d48c170d 425 Vector<String> vArch = Tools.convertListToVector(spd.getGuidDeclarations().getEntryList()\r
426 .get(index).getGuidTypeList());\r
427 for (int indexOfArch = 0; indexOfArch < vArch.size(); indexOfArch++) {\r
428 if (vArch.get(indexOfArch).equals(type)) {\r
429 isFound = true;\r
430 break;\r
431 }\r
432 }\r
433 if ((isFound) || (vArch == null) || (vArch.size() < 1)) {\r
434 vector.addElement(spd.getGuidDeclarations().getEntryList().get(index).getCName());\r
435 isFound = false;\r
436 }\r
a13899c5 437 }\r
79cb6fdb 438 }\r
a13899c5 439 }\r
2003a22e 440 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 441 return vector;\r
442 }\r
443\r
444 /**\r
445 Get all Pcd Definitions from a package\r
446 \r
447 @return Vector\r
448 **/\r
9a8d6d9f 449 public PcdVector getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {\r
450 PcdVector vector = new PcdVector();\r
a13899c5 451 if (spd.getPcdDeclarations() != null) {\r
452 if (spd.getPcdDeclarations().getPcdEntryList().size() > 0) {\r
453 for (int index = 0; index < spd.getPcdDeclarations().getPcdEntryList().size(); index++) {\r
9a8d6d9f 454 String name = spd.getPcdDeclarations().getPcdEntryList().get(index).getCName();\r
455 String guidCName = spd.getPcdDeclarations().getPcdEntryList().get(index).getTokenSpaceGuidCName();\r
456 String help = spd.getPcdDeclarations().getPcdEntryList().get(index).getHelpText();\r
457 Vector<String> type = Tools.convertListToVector(spd.getPcdDeclarations().getPcdEntryList()\r
458 .get(index).getValidUsage());\r
459\r
460 vector.addPcd(new PcdIdentification(name, guidCName, help, type));\r
a13899c5 461 }\r
79cb6fdb 462 }\r
a13899c5 463 }\r
2003a22e 464 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 465 return vector;\r
466 }\r
467\r
468 public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {\r
a13899c5 469 Vector<String> vector = new Vector<String>();\r
739c6b04 470 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
471 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList\r
472 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
473 .get(index)));\r
474 if (v != null && v.size() > 0) {\r
475 vector.addAll(v);\r
a13899c5 476 }\r
739c6b04 477\r
a13899c5 478 }\r
2003a22e 479 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 480 return vector;\r
481 }\r
e08433ef 482\r
c25ad66c 483 public Vector<String> getAllLibraryClassDefinitionsFromPackages(Vector<PackageIdentification> vpid) {\r
484 Vector<String> vector = new Vector<String>();\r
485 for (int index = 0; index < vpid.size(); index++) {\r
486 Vector<String> v = getAllLibraryClassDefinitionsFromPackage(GlobalData.openingPackageList\r
e08433ef 487 .getPackageSurfaceAreaFromId(vpid\r
488 .get(index)));\r
c25ad66c 489 if (v != null && v.size() > 0) {\r
490 vector.addAll(v);\r
491 }\r
492\r
493 }\r
494 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
495 return vector;\r
496 }\r
a13899c5 497\r
498 public Vector<String> getAllProtocolDeclarationsFromWorkspace() {\r
a13899c5 499 Vector<String> vector = new Vector<String>();\r
739c6b04 500 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
501 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList\r
502 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
503 .get(index)));\r
504 if (v != null && v.size() > 0) {\r
505 vector.addAll(v);\r
a13899c5 506 }\r
507 }\r
2003a22e 508 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 509 return vector;\r
510 }\r
511\r
c25ad66c 512 public Vector<String> getAllProtocolDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
513 Vector<String> vector = new Vector<String>();\r
514 for (int index = 0; index < vpid.size(); index++) {\r
515 Vector<String> v = getAllProtocolDeclarationsFromPackage(GlobalData.openingPackageList\r
516 .getPackageSurfaceAreaFromId(vpid\r
517 .get(index)));\r
518 if (v != null && v.size() > 0) {\r
519 vector.addAll(v);\r
520 }\r
521 }\r
522 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
523 return vector;\r
524 }\r
525\r
a13899c5 526 public Vector<String> getAllPpiDeclarationsFromWorkspace() {\r
a13899c5 527 Vector<String> vector = new Vector<String>();\r
739c6b04 528 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
529 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList\r
530 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
531 .get(index)));\r
532 if (v != null && v.size() > 0) {\r
533 vector.addAll(v);\r
a13899c5 534 }\r
535 }\r
2003a22e 536 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 537 return vector;\r
538 }\r
539\r
c25ad66c 540 public Vector<String> getAllPpiDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
541 Vector<String> vector = new Vector<String>();\r
542 for (int index = 0; index < vpid.size(); index++) {\r
543 Vector<String> v = getAllPpiDeclarationsFromPackage(GlobalData.openingPackageList\r
544 .getPackageSurfaceAreaFromId(vpid\r
545 .get(index)));\r
546 if (v != null && v.size() > 0) {\r
547 vector.addAll(v);\r
548 }\r
549 }\r
550 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
551 return vector;\r
552 }\r
553\r
d48c170d 554 public Vector<String> getAllGuidDeclarationsFromWorkspace(String type) {\r
a13899c5 555 Vector<String> vector = new Vector<String>();\r
739c6b04 556 for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r
d48c170d 557 Vector<String> v = getAllGuidDeclarationsFromPackage(\r
558 GlobalData.openingPackageList\r
739c6b04 559 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
d48c170d 560 .get(index)),\r
561 type);\r
739c6b04 562 if (v != null && v.size() > 0) {\r
563 vector.addAll(v);\r
a13899c5 564 }\r
739c6b04 565\r
a13899c5 566 }\r
2003a22e 567 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 568 return vector;\r
569 }\r
570\r
d48c170d 571 public Vector<String> getAllGuidDeclarationsFromPackages(Vector<PackageIdentification> vpid, String type) {\r
c25ad66c 572 Vector<String> vector = new Vector<String>();\r
573 for (int index = 0; index < vpid.size(); index++) {\r
d48c170d 574 Vector<String> v = getAllGuidDeclarationsFromPackage(\r
575 GlobalData.openingPackageList\r
c25ad66c 576 .getPackageSurfaceAreaFromId(vpid\r
d48c170d 577 .get(index)),\r
578 type);\r
c25ad66c 579 if (v != null && v.size() > 0) {\r
580 vector.addAll(v);\r
581 }\r
582\r
583 }\r
584 Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r
585 return vector;\r
586 }\r
587\r
9a8d6d9f 588 public PcdVector getAllPcdDeclarationsFromWorkspace() {\r
9a8d6d9f 589 PcdVector vector = new PcdVector();\r
739c6b04 590 for (int index = 0; index < GlobalData.openingPackageList.size(); index++) {\r
591 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList\r
592 .getPackageSurfaceAreaFromId(GlobalData.vPackageList\r
593 .get(index)));\r
594 if (v != null && v.size() > 0) {\r
595 vector.addAll(v);\r
a13899c5 596 }\r
739c6b04 597\r
a13899c5 598 }\r
2003a22e 599 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
a13899c5 600 return vector;\r
601 }\r
602\r
c25ad66c 603 public PcdVector getAllPcdDeclarationsFromPackages(Vector<PackageIdentification> vpid) {\r
604 PcdVector vector = new PcdVector();\r
605 for (int index = 0; index < vpid.size(); index++) {\r
606 PcdVector v = getAllPcdDeclarationsFromPackage(GlobalData.openingPackageList\r
607 .getPackageSurfaceAreaFromId(vpid\r
608 .get(index)));\r
609 if (v != null && v.size() > 0) {\r
610 vector.addAll(v);\r
611 }\r
612\r
613 }\r
614 Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r
615 return vector;\r
616 }\r
617\r
a13899c5 618 /**\r
619 Find a module's package's id\r
620 \r
621 @param id input module id\r
622 @return package id\r
623 \r
624 **/\r
625 public PackageIdentification getPackageIdByModuleId(Identification id) {\r
a13899c5 626 Vector<String> modulePaths = new Vector<String>();\r
627 Identification mid = null;\r
628 String packagePath = null;\r
629 String modulePath = null;\r
630\r
631 //\r
632 // For each package, get all modules list\r
633 //\r
739c6b04 634 for (int indexI = 0; indexI < GlobalData.vPackageList.size(); indexI++) {\r
635 packagePath = GlobalData.vPackageList.elementAt(indexI).getPath();\r
a13899c5 636 modulePaths = this.getAllModulesOfPackage(packagePath);\r
a13899c5 637 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
79cb6fdb 638 modulePath = modulePaths.get(indexJ);\r
739c6b04 639 mid = GlobalData.openingModuleList.getIdByPath(modulePath);\r
640 //\r
641 // Check id\r
642 //\r
643 if (mid.equals(id)) {\r
644 return GlobalData.vPackageList.elementAt(indexI);\r
a13899c5 645 }\r
739c6b04 646\r
a13899c5 647 }\r
648 }\r
649\r
650 return null;\r
651 }\r
652\r
a13899c5 653 /**\r
654 Add module information to package surface area\r
655 \r
656 @param mid\r
657 @throws IOException\r
658 @throws XmlException\r
659 @throws Exception\r
660 \r
661 **/\r
662 public void addModuleToPackage(ModuleIdentification mid, PackageSurfaceArea spd) throws IOException, XmlException,\r
663 Exception {\r
664 String packagePath = mid.getPackageId().getPath();\r
665 String modulePath = mid.getPath();\r
666 if (spd == null) {\r
667 spd = OpenFile.openSpdFile(packagePath);\r
668 }\r
669 MsaFiles msaFile = spd.getMsaFiles();\r
670 if (msaFile == null) {\r
671 msaFile = MsaFiles.Factory.newInstance();\r
672 }\r
673 packagePath = packagePath.substring(0, packagePath.lastIndexOf(DataType.FILE_SEPARATOR));\r
674 String fn = Tools.getRelativePath(modulePath, packagePath);\r
675 msaFile.addNewFilename();\r
676 msaFile.setFilenameArray(msaFile.getFilenameList().size() - 1, fn);\r
677 spd.setMsaFiles(msaFile);\r
678 SaveFile.saveSpdFile(mid.getPackageId().getPath(), spd);\r
679 }\r
680\r
681 /**\r
682 Add input package into database\r
683 \r
684 @param id\r
685 * @throws Exception \r
686 \r
687 **/\r
688 public void addPackageToDatabase(PackageIdentification id) throws Exception {\r
689 String path = id.getPath();\r
690 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
739c6b04 691\r
a13899c5 692 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
693 filename.setStringValue(path);\r
739c6b04 694 GlobalData.fdb.getPackageList().addNewFilename();\r
695 GlobalData.fdb.getPackageList().setFilenameArray(GlobalData.fdb.getPackageList().sizeOfFilenameArray() - 1,\r
696 filename);\r
a13899c5 697 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
698 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
739c6b04 699 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
a13899c5 700 }\r
701\r
702 /**\r
703 Add input package into database\r
704 \r
705 @param id\r
706 * @throws Exception \r
707 \r
708 **/\r
709 public void addPlatformToDatabase(PlatformIdentification id) throws Exception {\r
710 String path = id.getPath();\r
711 path = Tools.getRelativePath(path, Workspace.getCurrentWorkspace());\r
739c6b04 712\r
a13899c5 713 DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r
714 filename.setStringValue(path);\r
739c6b04 715 GlobalData.fdb.getPlatformList().addNewFilename();\r
716 GlobalData.fdb.getPlatformList().setFilenameArray(GlobalData.fdb.getPlatformList().sizeOfFilenameArray() - 1,\r
717 filename);\r
a13899c5 718 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
719 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
739c6b04 720 SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r
a13899c5 721 }\r
79cb6fdb 722\r
723 /**\r
724 Get all file's path from one module\r
725 \r
726 @param path\r
727 @return\r
728 @throws IOException\r
729 @throws XmlException\r
730 @throws Exception\r
731 \r
732 **/\r
739c6b04 733 public Vector<String> getAllFilesPathOfModule(String path) {\r
79cb6fdb 734 Vector<String> v = new Vector<String>();\r
735 path = Tools.convertPathToCurrentOsType(path);\r
736 v.addElement(path);\r
739c6b04 737 ModuleSurfaceArea msa = GlobalData.openingModuleList\r
738 .getModuleSurfaceAreaFromId(GlobalData.openingModuleList\r
739 .getIdByPath(path));\r
79cb6fdb 740 if (msa != null) {\r
741 //\r
742 // Get all files' path of a module\r
743 //\r
744 SourceFiles sf = msa.getSourceFiles();\r
745 if (sf != null) {\r
746 for (int index = 0; index < sf.getFilenameList().size(); index++) {\r
747 String temp = sf.getFilenameList().get(index).getStringValue();\r
748 temp = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + temp;\r
749 v.addElement(Tools.convertPathToCurrentOsType(temp));\r
750 }\r
751 }\r
752 }\r
753\r
754 return v;\r
755 }\r
756\r
757 /**\r
758 Get all file's path from one package\r
759 \r
760 @param path\r
761 @return\r
762 @throws IOException\r
763 @throws XmlException\r
764 @throws Exception\r
765 \r
766 **/\r
739c6b04 767 public Vector<String> getAllFilesPathOfPakcage(String path) {\r
79cb6fdb 768 Vector<String> v = new Vector<String>();\r
769 path = Tools.convertPathToCurrentOsType(path);\r
770 //\r
771 // First add package\r
772 //\r
773 v.addElement(path);\r
55a2762d 774\r
79cb6fdb 775 //\r
8f9acbd7 776 // Add the package's industry std includes one by one\r
79cb6fdb 777 //\r
778 Vector<String> f1 = new Vector<String>();\r
8f9acbd7 779 f1 = getAllIndustryStdIncludesOfPackage(path);\r
780 for (int index = 0; index < f1.size(); index++) {\r
781 v.addElement(f1.get(index));\r
782 }\r
55a2762d 783\r
8f9acbd7 784 //\r
785 // Add module's files one by one\r
786 //\r
787 f1 = new Vector<String>();\r
79cb6fdb 788 f1 = getAllModulesOfPackage(path);\r
789 for (int indexI = 0; indexI < f1.size(); indexI++) {\r
739c6b04 790 Vector<String> f2 = getAllFilesPathOfModule(f1.get(indexI));\r
79cb6fdb 791 for (int indexJ = 0; indexJ < f2.size(); indexJ++) {\r
792 v.addElement(f2.get(indexJ));\r
793 }\r
794 }\r
79cb6fdb 795\r
796 return v;\r
797 }\r
c25ad66c 798\r
799 /**\r
800 Get a module's all package dependencies\r
801 \r
802 @param mid The module id\r
803 @return A vector of all package dependency ids\r
804 \r
805 **/\r
806 public Vector<PackageIdentification> getPackageDependenciesOfModule(ModuleIdentification mid) {\r
807 Vector<PackageIdentification> vpid = new Vector<PackageIdentification>();\r
808 ModuleSurfaceArea msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(mid);\r
809 if (msa != null) {\r
810 PackageDependencies pd = msa.getPackageDependencies();\r
811 if (pd != null) {\r
812 for (int index = 0; index < pd.getPackageList().size(); index++) {\r
813 String guid = pd.getPackageList().get(index).getPackageGuid();\r
814 String version = pd.getPackageList().get(index).getPackageVersion();\r
815 PackageIdentification pid = GlobalData.openingPackageList.getIdByGuidVersion(guid, version);\r
816 if (pid != null) {\r
817 vpid.addElement(pid);\r
818 }\r
819 }\r
820 }\r
821 }\r
822 return vpid;\r
823 }\r
e08433ef 824\r
b63cc1b6 825 public Vector<String> getAllModuleGuidXref() {\r
826 Vector<String> v = new Vector<String>();\r
827 for (int index = 0; index < GlobalData.openingModuleList.size(); index++) {\r
828 ModuleIdentification id = GlobalData.openingModuleList.getOpeningModuleByIndex(index).getId();\r
829 v.addElement(id.getGuid() + " " + id.getName());\r
830 }\r
831 return v;\r
832 }\r
e08433ef 833\r
834 public Vector<String> getModuleArch(ModuleIdentification id) {\r
835 Vector<String> v = new Vector<String>();\r
836 ModuleSurfaceArea msa = null;\r
837 if (id != null) {\r
838 msa = GlobalData.openingModuleList.getModuleSurfaceAreaFromId(id);\r
839 }\r
840 if (msa != null) {\r
841 if (msa.getModuleDefinitions() != null) {\r
842 v = Tools.convertListToVector(msa.getModuleDefinitions().getSupportedArchitectures());\r
843 }\r
844 }\r
845 return v;\r
846 }\r
a13899c5 847}\r