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