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