+++ /dev/null
-/** @file \r
- The file is used to provide initializing global data.\r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- **/\r
-package org.tianocore.frameworkwizard.common;\r
-\r
-import java.io.IOException;\r
-import java.util.Vector;\r
-\r
-import org.apache.xmlbeans.XmlException;\r
-import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r
-import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
-import org.tianocore.MsaFilesDocument.MsaFiles;\r
-import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
-import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r
-import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
-import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleList;\r
-import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageList;\r
-import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformList;\r
-import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
-import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
-import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
-import org.tianocore.frameworkwizard.workspace.Workspace;\r
-\r
-public class GlobalData {\r
-\r
- public static FrameworkDatabase fdb = null;\r
-\r
- public static OpeningModuleList openingModuleList = new OpeningModuleList();\r
-\r
- public static OpeningPackageList openingPackageList = new OpeningPackageList();\r
-\r
- public static OpeningPlatformList openingPlatformList = new OpeningPlatformList();\r
-\r
- public static Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();\r
-\r
- public static Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();\r
-\r
- public static Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();\r
-\r
- public static void init() {\r
- initDatabase();\r
- initPackage();\r
- initPlatform();\r
- initModule();\r
- }\r
-\r
- public static void initDatabase() {\r
- String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();\r
- strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);\r
- try {\r
- fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);\r
- } catch (XmlException e) {\r
- Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());\r
- return;\r
- } catch (Exception e) {\r
- Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");\r
- return;\r
- }\r
- }\r
-\r
- public static void initModule() {\r
- vModuleList = new Vector<ModuleIdentification>();\r
- openingModuleList = new OpeningModuleList();\r
-\r
- ModuleSurfaceArea msa = null;\r
- Vector<String> modulePaths = new Vector<String>();\r
- Identification id = null;\r
- ModuleIdentification mid = null;\r
- String packagePath = null;\r
- String modulePath = null;\r
-\r
- //\r
- // For each package, get all modules list\r
- //\r
- if (vPackageList.size() > 0) {\r
- for (int indexI = 0; indexI < vPackageList.size(); indexI++) {\r
- packagePath = vPackageList.elementAt(indexI).getPath();\r
- modulePaths = getAllModulesOfPackage(packagePath);\r
-\r
- for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {\r
- try {\r
- modulePath = modulePaths.get(indexJ);\r
- msa = OpenFile.openMsaFile(modulePath);\r
-\r
- } catch (IOException e) {\r
- Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
- continue;\r
- } catch (XmlException e) {\r
- Log.err("Open Module Surface Area " + modulePath, e.getMessage());\r
- continue;\r
- } catch (Exception e) {\r
- Log.err("Open Module Surface Area " + modulePath, "Invalid file type");\r
- continue;\r
- }\r
- id = Tools.getId(modulePath, msa);\r
- mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));\r
- vModuleList.addElement(mid);\r
- openingModuleList.insertToOpeningModuleList(mid, msa);\r
- }\r
- }\r
- Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);\r
- }\r
- }\r
-\r
- public static void initPackage() {\r
- vPackageList = new Vector<PackageIdentification>();\r
- openingPackageList = new OpeningPackageList();\r
- if (fdb != null) {\r
- for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {\r
- String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
- + fdb.getPackageList().getFilenameArray(index).getStringValue();\r
- path = Tools.convertPathToCurrentOsType(path);\r
- PackageSurfaceArea spd = null;\r
- PackageIdentification id = null;\r
- try {\r
- spd = OpenFile.openSpdFile(path);\r
- } catch (IOException e) {\r
- Log.err("Open Package Surface Area " + path, e.getMessage());\r
- continue;\r
- } catch (XmlException e) {\r
- Log.err("Open Package Surface Area " + path, e.getMessage());\r
- continue;\r
- } catch (Exception e) {\r
- Log.err("Open Package Surface Area " + path, "Invalid file type");\r
- continue;\r
- }\r
- id = Tools.getId(path, spd);\r
- vPackageList.addElement(id);\r
- openingPackageList.insertToOpeningPackageList(id, spd);\r
- }\r
- Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);\r
- }\r
- }\r
-\r
- public static void initPlatform() {\r
- vPlatformList = new Vector<PlatformIdentification>();\r
- openingPlatformList = new OpeningPlatformList();\r
-\r
- if (fdb != null) {\r
- for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {\r
- String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR\r
- + fdb.getPlatformList().getFilenameArray(index).getStringValue();\r
- path = Tools.convertPathToCurrentOsType(path);\r
- PlatformSurfaceArea fpd = null;\r
- PlatformIdentification id = null;\r
- try {\r
- fpd = OpenFile.openFpdFile(path);\r
- } catch (IOException e) {\r
- Log.err("Open Platform Surface Area " + path, e.getMessage());\r
- continue;\r
- } catch (XmlException e) {\r
- Log.err("Open Platform Surface Area " + path, e.getMessage());\r
- continue;\r
- } catch (Exception e) {\r
- Log.err("Open Platform Surface Area " + path, "Invalid file type");\r
- continue;\r
- }\r
- id = Tools.getId(path, fpd);\r
- vPlatformList.addElement(new PlatformIdentification(id));\r
- openingPlatformList.insertToOpeningPlatformList(id, fpd);\r
- }\r
- Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);\r
- }\r
- }\r
-\r
- /**\r
- Get all modules' paths from one package\r
- \r
- @return a Vector with all modules' path\r
- \r
- **/\r
- public static Vector<String> getAllModulesOfPackage(String path) {\r
- Vector<String> modulePath = new Vector<String>();\r
- try {\r
- MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();\r
- if (files != null) {\r
- for (int index = 0; index < files.getFilenameList().size(); index++) {\r
- String msaPath = files.getFilenameList().get(index);\r
- msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;\r
- msaPath = Tools.convertPathToCurrentOsType(msaPath);\r
- modulePath.addElement(msaPath);\r
- }\r
- }\r
- } catch (IOException e) {\r
- Log.err("Get all modules from a package " + path, e.getMessage());\r
- } catch (XmlException e) {\r
- Log.err("Get all modules from a package " + path, e.getMessage());\r
- } catch (Exception e) {\r
- Log.err("Get all modules from a package " + path, e.getMessage());\r
- }\r
- return modulePath;\r
- }\r
-\r
- /**\r
- Get a module id\r
- \r
- @param moduleGuid\r
- @param moduleVersion\r
- @param packageGuid\r
- @param packageVersion\r
- @return\r
- \r
- **/\r
- public static ModuleIdentification findModuleId(String moduleGuid, String moduleVersion, String packageGuid,\r
- String packageVersion) {\r
- ModuleIdentification mid = null;\r
- for (int index = 0; index < vModuleList.size(); index++) {\r
- if (vModuleList.elementAt(index).equals(moduleGuid, moduleVersion, packageGuid, packageVersion)) {\r
- mid = vModuleList.elementAt(index);\r
- break;\r
- }\r
- }\r
- return mid;\r
- }\r
-\r
- /**\r
- Get a package id\r
- \r
- @param packageGuid\r
- @param packageVersion\r
- @return\r
- \r
- **/\r
- public static PackageIdentification findPackageId(String packageGuid, String packageVersion) {\r
- PackageIdentification pid = null;\r
- for (int index = 0; index < vPackageList.size(); index++) {\r
- if (vPackageList.elementAt(index).equals(packageGuid, packageVersion)) {\r
- pid = vPackageList.elementAt(index);\r
- break;\r
- }\r
- }\r
- return pid;\r
- }\r
-\r
- /**\r
- Get a platform id \r
- \r
- @param platformGuid\r
- @param platformVersion\r
- @return\r
- \r
- **/\r
- public static PlatformIdentification findPlatformId(String platformGuid, String platformVersion) {\r
- PlatformIdentification pid = null;\r
- for (int index = 0; index < vPlatformList.size(); index++) {\r
- if (vPlatformList.elementAt(index).equals(platformGuid, platformVersion)) {\r
- pid = vPlatformList.elementAt(index);\r
- break;\r
- }\r
- }\r
- return pid;\r
- }\r
-\r
- /**\r
- \r
- @param relativePath\r
- @param mode\r
- @return\r
- \r
- **/\r
- public static boolean isDuplicateRelativePath(String relativePath, int mode) {\r
- if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r
- for (int index = 0; index < vModuleList.size(); index++) {\r
- String path = vModuleList.elementAt(index).getPath();\r
- if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r
- for (int index = 0; index < vPackageList.size(); index++) {\r
- String path = vPackageList.elementAt(index).getPath();\r
- if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r
- for (int index = 0; index < vPlatformList.size(); index++) {\r
- String path = vPlatformList.elementAt(index).getPath();\r
- if (Tools.getFilePathOnly(path).equals(relativePath)) {\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- return false;\r
- }\r
-}\r