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