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