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