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 |
8f9acbd7 |
25 | import org.tianocore.IndustryStdIncludesDocument.IndustryStdIncludes;\r |
a13899c5 |
26 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
27 | import org.tianocore.MsaFilesDocument.MsaFiles;\r |
a13899c5 |
28 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r |
09ef9242 |
29 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r |
79cb6fdb |
30 | import org.tianocore.SourceFilesDocument.SourceFiles;\r |
a13899c5 |
31 | import org.tianocore.frameworkwizard.common.DataType;\r |
739c6b04 |
32 | import org.tianocore.frameworkwizard.common.GlobalData;\r |
a13899c5 |
33 | import org.tianocore.frameworkwizard.common.Log;\r |
f9d0ab92 |
34 | import org.tianocore.frameworkwizard.common.OpenFile;\r |
a13899c5 |
35 | import org.tianocore.frameworkwizard.common.SaveFile;\r |
2003a22e |
36 | import org.tianocore.frameworkwizard.common.Sort;\r |
a13899c5 |
37 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb |
38 | import org.tianocore.frameworkwizard.common.Identifications.Identification;\r |
5a24e806 |
39 | import org.tianocore.frameworkwizard.far.FarHeader;\r |
40 | import org.tianocore.frameworkwizard.far.FarIdentification;\r |
79cb6fdb |
41 | import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r |
9a8d6d9f |
42 | import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdIdentification;\r |
43 | import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;\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 |
a13899c5 |
48 | \r |
5a24e806 |
49 | public void addFarToDb(List<String> packageList, List<String> platformList, FarHeader far) {\r |
739c6b04 |
50 | //FrameworkDatabase fdb = openFrameworkDb();\r |
55a2762d |
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 |
739c6b04 |
56 | GlobalData.fdb.getPackageList().getFilenameList().add(item);\r |
55a2762d |
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 |
739c6b04 |
63 | GlobalData.fdb.getPlatformList().getFilenameList().add(item);\r |
55a2762d |
64 | }\r |
65 | \r |
66 | DbPathAndFilename farItem = DbPathAndFilename.Factory.newInstance();\r |
67 | farItem.setFarGuid(far.getGuidValue());\r |
68 | farItem.setStringValue(far.getFarName());\r |
739c6b04 |
69 | GlobalData.fdb.getFarList().getFilenameList().add(farItem);\r |
55a2762d |
70 | \r |
71 | String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r |
72 | strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r |
73 | \r |
74 | try {\r |
739c6b04 |
75 | SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r |
55a2762d |
76 | } catch (Exception e) {\r |
ed1665f2 |
77 | Log.err("Save Database File", e.getMessage());\r |
55a2762d |
78 | }\r |
5a24e806 |
79 | }\r |
55a2762d |
80 | \r |
5a24e806 |
81 | public void removeFarFromDb(FarIdentification far) {\r |
5a24e806 |
82 | //\r |
83 | // Remove Packages\r |
84 | //\r |
739c6b04 |
85 | XmlCursor cursor = GlobalData.fdb.getPackageList().newCursor();\r |
5a24e806 |
86 | cursor.toFirstChild();\r |
87 | do {\r |
55a2762d |
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 |
5a24e806 |
93 | } while (cursor.toNextSibling());\r |
94 | cursor.dispose();\r |
55a2762d |
95 | \r |
5a24e806 |
96 | //\r |
97 | // Remove Platforms\r |
98 | //\r |
739c6b04 |
99 | cursor = GlobalData.fdb.getPlatformList().newCursor();\r |
5a24e806 |
100 | cursor.toFirstChild();\r |
101 | do {\r |
55a2762d |
102 | DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();\r |
103 | if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r |
104 | cursor.removeXml();\r |
105 | }\r |
5a24e806 |
106 | } while (cursor.toNextSibling());\r |
55a2762d |
107 | \r |
5a24e806 |
108 | //\r |
109 | // Remove Far\r |
110 | //\r |
739c6b04 |
111 | cursor = GlobalData.fdb.getFarList().newCursor();\r |
5a24e806 |
112 | cursor.toFirstChild();\r |
113 | do {\r |
55a2762d |
114 | DbPathAndFilename item = (DbPathAndFilename) cursor.getObject();\r |
115 | if (item.getFarGuid() != null && item.getFarGuid().equalsIgnoreCase(far.getGuid())) {\r |
116 | cursor.removeXml();\r |
117 | }\r |
5a24e806 |
118 | } while (cursor.toNextSibling());\r |
119 | cursor.dispose();\r |
55a2762d |
120 | \r |
5a24e806 |
121 | String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r |
122 | strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r |
123 | try {\r |
739c6b04 |
124 | SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r |
55a2762d |
125 | } catch (Exception e) {\r |
ed1665f2 |
126 | Log.err("Save Database File", e.getMessage());\r |
55a2762d |
127 | }\r |
128 | }\r |
129 | \r |
130 | public String getPackageFarGuid(Identification packageId) {\r |
739c6b04 |
131 | for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {\r |
132 | DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);\r |
55a2762d |
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 |
739c6b04 |
136 | return GlobalData.fdb.getPackageList().getFilenameArray(index).getFarGuid();\r |
55a2762d |
137 | }\r |
138 | }\r |
139 | \r |
5a24e806 |
140 | return null;\r |
5a24e806 |
141 | }\r |
55a2762d |
142 | \r |
143 | public String getPlatformFarGuid(Identification platformId) {\r |
739c6b04 |
144 | for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {\r |
145 | DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);\r |
55a2762d |
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 |
739c6b04 |
149 | return GlobalData.fdb.getPlatformList().getFilenameArray(index).getFarGuid();\r |
55a2762d |
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 |
a13899c5 |
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 |
739c6b04 |
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 |
a13899c5 |
181 | }\r |
a13899c5 |
182 | }\r |
739c6b04 |
183 | \r |
a13899c5 |
184 | return modulePath;\r |
185 | }\r |
55a2762d |
186 | \r |
8f9acbd7 |
187 | /**\r |
55a2762d |
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 |
739c6b04 |
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 |
55a2762d |
204 | }\r |
55a2762d |
205 | }\r |
206 | return includePath;\r |
207 | }\r |
a13899c5 |
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 |
739c6b04 |
216 | return GlobalData.vPackageList;\r |
a13899c5 |
217 | }\r |
5a24e806 |
218 | \r |
219 | public Vector<FarIdentification> getAllFars() {\r |
739c6b04 |
220 | \r |
55a2762d |
221 | Vector<FarIdentification> v = new Vector<FarIdentification>();\r |
739c6b04 |
222 | for (int index = 0; index < GlobalData.fdb.getFarList().getFilenameList().size(); index++) {\r |
223 | DbPathAndFilename item = GlobalData.fdb.getFarList().getFilenameList().get(index);\r |
55a2762d |
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 |
5a24e806 |
230 | public Vector<PackageIdentification> getPackagesByFar(FarIdentification far) {\r |
55a2762d |
231 | Identification id = null;\r |
739c6b04 |
232 | \r |
55a2762d |
233 | Vector<PackageIdentification> v = new Vector<PackageIdentification>();\r |
234 | \r |
739c6b04 |
235 | for (int index = 0; index < GlobalData.fdb.getPackageList().getFilenameList().size(); index++) {\r |
236 | DbPathAndFilename item = GlobalData.fdb.getPackageList().getFilenameArray(index);\r |
55a2762d |
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 |
739c6b04 |
243 | id = Tools.getId(path, OpenFile.openSpdFile(path));\r |
55a2762d |
244 | v.addElement(new PackageIdentification(id));\r |
245 | } catch (IOException e) {\r |
246 | Log.err("Open Package Surface Area " + path, e.getMessage());\r |
55a2762d |
247 | } catch (XmlException e) {\r |
248 | Log.err("Open Package Surface Area " + path, e.getMessage());\r |
55a2762d |
249 | } catch (Exception e) {\r |
250 | Log.err("Open Package Surface Area " + path, "Invalid file type");\r |
55a2762d |
251 | }\r |
252 | }\r |
5a24e806 |
253 | }\r |
55a2762d |
254 | return v;\r |
5a24e806 |
255 | }\r |
55a2762d |
256 | \r |
5a24e806 |
257 | public Vector<PlatformIdentification> getPlatformsByFar(FarIdentification far) {\r |
55a2762d |
258 | Identification id = null;\r |
739c6b04 |
259 | \r |
55a2762d |
260 | Vector<PlatformIdentification> v = new Vector<PlatformIdentification>();\r |
261 | \r |
739c6b04 |
262 | for (int index = 0; index < GlobalData.fdb.getPlatformList().getFilenameList().size(); index++) {\r |
263 | DbPathAndFilename item = GlobalData.fdb.getPlatformList().getFilenameArray(index);\r |
55a2762d |
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 |
739c6b04 |
269 | id = Tools.getId(path, OpenFile.openFpdFile(path));\r |
55a2762d |
270 | v.addElement(new PlatformIdentification(id));\r |
271 | } catch (IOException e) {\r |
272 | Log.err("Open Platform Surface Area " + path, e.getMessage());\r |
55a2762d |
273 | } catch (XmlException e) {\r |
274 | Log.err("Open Platform Surface Area " + path, e.getMessage());\r |
55a2762d |
275 | } catch (Exception e) {\r |
276 | Log.err("Open Platform Surface Area " + path, "Invalid file type");\r |
55a2762d |
277 | }\r |
278 | }\r |
5a24e806 |
279 | }\r |
55a2762d |
280 | return v;\r |
5a24e806 |
281 | }\r |
282 | \r |
92e29378 |
283 | /**\r |
284 | Get all module basic information from a package\r |
55a2762d |
285 | \r |
92e29378 |
286 | @param id Package id\r |
287 | @return A vector includes all modules' basic information\r |
55a2762d |
288 | \r |
289 | **/\r |
92e29378 |
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 |
92e29378 |
293 | String modulePath = null;\r |
55a2762d |
294 | \r |
92e29378 |
295 | for (int index = 0; index < modulePaths.size(); index++) {\r |
739c6b04 |
296 | modulePath = modulePaths.get(index);\r |
297 | ModuleIdentification id = GlobalData.openingModuleList.getIdByPath(modulePath);\r |
94b0f428 |
298 | if (id != null) {\r |
09ef9242 |
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 |
94b0f428 |
333 | }\r |
92e29378 |
334 | }\r |
2003a22e |
335 | Sort.sortModules(v, DataType.SORT_TYPE_ASCENDING);\r |
92e29378 |
336 | return v;\r |
92e29378 |
337 | }\r |
a13899c5 |
338 | \r |
339 | /**\r |
92e29378 |
340 | Get all module basic information form the FrameworkDatabase.db file\r |
a13899c5 |
341 | \r |
92e29378 |
342 | @return vModuleList A vector includes all modules' basic information\r |
a13899c5 |
343 | \r |
344 | */\r |
345 | public Vector<ModuleIdentification> getAllModules() {\r |
739c6b04 |
346 | return GlobalData.vModuleList;\r |
a13899c5 |
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 |
739c6b04 |
356 | return GlobalData.vPlatformList;\r |
a13899c5 |
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 |
2003a22e |
373 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
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 |
2003a22e |
391 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
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 |
79cb6fdb |
407 | }\r |
a13899c5 |
408 | }\r |
2003a22e |
409 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
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 |
79cb6fdb |
425 | }\r |
a13899c5 |
426 | }\r |
2003a22e |
427 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
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 |
9a8d6d9f |
436 | public PcdVector getAllPcdDeclarationsFromPackage(PackageSurfaceArea spd) {\r |
437 | PcdVector vector = new PcdVector();\r |
a13899c5 |
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 |
9a8d6d9f |
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 |
a13899c5 |
448 | }\r |
79cb6fdb |
449 | }\r |
a13899c5 |
450 | }\r |
2003a22e |
451 | Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
452 | return vector;\r |
453 | }\r |
454 | \r |
455 | public Vector<String> getAllLibraryClassDefinitionsFromWorkspace() {\r |
a13899c5 |
456 | Vector<String> vector = new Vector<String>();\r |
739c6b04 |
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 |
a13899c5 |
463 | }\r |
739c6b04 |
464 | \r |
a13899c5 |
465 | }\r |
2003a22e |
466 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
467 | return vector;\r |
468 | }\r |
469 | \r |
470 | public Vector<String> getAllProtocolDeclarationsFromWorkspace() {\r |
a13899c5 |
471 | Vector<String> vector = new Vector<String>();\r |
739c6b04 |
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 |
a13899c5 |
478 | }\r |
479 | }\r |
2003a22e |
480 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
481 | return vector;\r |
482 | }\r |
483 | \r |
484 | public Vector<String> getAllPpiDeclarationsFromWorkspace() {\r |
a13899c5 |
485 | Vector<String> vector = new Vector<String>();\r |
739c6b04 |
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 |
a13899c5 |
492 | }\r |
493 | }\r |
2003a22e |
494 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
495 | return vector;\r |
496 | }\r |
497 | \r |
498 | public Vector<String> getAllGuidDeclarationsFromWorkspace() {\r |
a13899c5 |
499 | Vector<String> vector = new Vector<String>();\r |
739c6b04 |
500 | for (int index = 0; index < GlobalData.vPackageList.size(); index++) {\r |
501 | Vector<String> v = 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 |
a13899c5 |
506 | }\r |
739c6b04 |
507 | \r |
a13899c5 |
508 | }\r |
2003a22e |
509 | Sort.sortVectorString(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
510 | return vector;\r |
511 | }\r |
512 | \r |
9a8d6d9f |
513 | public PcdVector getAllPcdDeclarationsFromWorkspace() {\r |
9a8d6d9f |
514 | PcdVector vector = new PcdVector();\r |
739c6b04 |
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 |
a13899c5 |
521 | }\r |
739c6b04 |
522 | \r |
a13899c5 |
523 | }\r |
2003a22e |
524 | Sort.sortPcds(vector, DataType.SORT_TYPE_ASCENDING);\r |
a13899c5 |
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 |
a13899c5 |
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 |
739c6b04 |
544 | for (int indexI = 0; indexI < GlobalData.vPackageList.size(); indexI++) {\r |
545 | packagePath = GlobalData.vPackageList.elementAt(indexI).getPath();\r |
a13899c5 |
546 | modulePaths = this.getAllModulesOfPackage(packagePath);\r |
a13899c5 |
547 | for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r |
79cb6fdb |
548 | modulePath = modulePaths.get(indexJ);\r |
739c6b04 |
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 |
a13899c5 |
555 | }\r |
739c6b04 |
556 | \r |
a13899c5 |
557 | }\r |
558 | }\r |
559 | \r |
560 | return null;\r |
561 | }\r |
562 | \r |
a13899c5 |
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 |
739c6b04 |
601 | \r |
a13899c5 |
602 | DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r |
603 | filename.setStringValue(path);\r |
739c6b04 |
604 | GlobalData.fdb.getPackageList().addNewFilename();\r |
605 | GlobalData.fdb.getPackageList().setFilenameArray(GlobalData.fdb.getPackageList().sizeOfFilenameArray() - 1,\r |
606 | filename);\r |
a13899c5 |
607 | String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r |
608 | strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r |
739c6b04 |
609 | SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r |
a13899c5 |
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 |
739c6b04 |
622 | \r |
a13899c5 |
623 | DbPathAndFilename filename = DbPathAndFilename.Factory.newInstance();\r |
624 | filename.setStringValue(path);\r |
739c6b04 |
625 | GlobalData.fdb.getPlatformList().addNewFilename();\r |
626 | GlobalData.fdb.getPlatformList().setFilenameArray(GlobalData.fdb.getPlatformList().sizeOfFilenameArray() - 1,\r |
627 | filename);\r |
a13899c5 |
628 | String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r |
629 | strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r |
739c6b04 |
630 | SaveFile.saveDbFile(strFrameworkDbFilePath, GlobalData.fdb);\r |
a13899c5 |
631 | }\r |
79cb6fdb |
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 |
739c6b04 |
643 | public Vector<String> getAllFilesPathOfModule(String path) {\r |
79cb6fdb |
644 | Vector<String> v = new Vector<String>();\r |
645 | path = Tools.convertPathToCurrentOsType(path);\r |
646 | v.addElement(path);\r |
739c6b04 |
647 | ModuleSurfaceArea msa = GlobalData.openingModuleList\r |
648 | .getModuleSurfaceAreaFromId(GlobalData.openingModuleList\r |
649 | .getIdByPath(path));\r |
79cb6fdb |
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 |
739c6b04 |
677 | public Vector<String> getAllFilesPathOfPakcage(String path) {\r |
79cb6fdb |
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 |
55a2762d |
684 | \r |
79cb6fdb |
685 | //\r |
8f9acbd7 |
686 | // Add the package's industry std includes one by one\r |
79cb6fdb |
687 | //\r |
688 | Vector<String> f1 = new Vector<String>();\r |
8f9acbd7 |
689 | f1 = getAllIndustryStdIncludesOfPackage(path);\r |
690 | for (int index = 0; index < f1.size(); index++) {\r |
691 | v.addElement(f1.get(index));\r |
692 | }\r |
55a2762d |
693 | \r |
8f9acbd7 |
694 | //\r |
695 | // Add module's files one by one\r |
696 | //\r |
697 | f1 = new Vector<String>();\r |
79cb6fdb |
698 | f1 = getAllModulesOfPackage(path);\r |
699 | for (int indexI = 0; indexI < f1.size(); indexI++) {\r |
739c6b04 |
700 | Vector<String> f2 = getAllFilesPathOfModule(f1.get(indexI));\r |
79cb6fdb |
701 | for (int indexJ = 0; indexJ < f2.size(); indexJ++) {\r |
702 | v.addElement(f2.get(indexJ));\r |
703 | }\r |
704 | }\r |
79cb6fdb |
705 | \r |
706 | return v;\r |
707 | }\r |
a13899c5 |
708 | }\r |