+++ /dev/null
-/** @file\r
- This file is for surface area information retrieval.\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
- **/\r
-package org.tianocore.frameworkwizard.platform.ui.global;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Stack;\r
-import java.util.Vector;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.BuildTargetList;\r
-import org.tianocore.LibraryClassDocument;\r
-import org.tianocore.ModuleSurfaceAreaDocument;\r
-import org.tianocore.PackageDependenciesDocument;\r
-import org.tianocore.PackageSurfaceAreaDocument;\r
-import org.tianocore.FilenameDocument.Filename;\r
-\r
-import org.tianocore.frameworkwizard.common.GlobalData;\r
-import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
-import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
-\r
-/**\r
- * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
- * mbd, spd and fpd files.\r
- * \r
- * This class should not instantiated. All the public interfaces is static.\r
- * \r
- * @since GenBuild 1.0\r
- */\r
-public class SurfaceAreaQuery {\r
-\r
- public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";\r
-\r
- // /\r
- // / Contains name/value pairs of Surface Area document object. The name is\r
- // / always the top level element name.\r
- // /\r
- private static Map<String, XmlObject> map = null;\r
-\r
- // /\r
- // / mapStack is used to do nested query\r
- // /\r
- private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();\r
-\r
- // /\r
- // / prefix of name space\r
- // /\r
- private static String nsPrefix = "sans";\r
-\r
- // /\r
- // / xmlbeans needs a name space for each Xpath element\r
- // /\r
- private static String ns = null;\r
-\r
- // /\r
- // / keep the namep declaration for xmlbeans Xpath query\r
- // /\r
- private static String queryDeclaration = null;\r
-\r
- /**\r
- * Set a Surface Area document for query later\r
- * \r
- * @param map\r
- * A Surface Area document in TopLevelElementName/XmlObject\r
- * format.\r
- */\r
- public static void setDoc(Map<String, XmlObject> map) {\r
- ns = prefix;\r
- queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
- SurfaceAreaQuery.map = map;\r
- }\r
-\r
- /**\r
- * Push current used Surface Area document into query stack. The given new\r
- * document will be used for any immediately followed getXXX() callings,\r
- * untill pop() is called.\r
- * \r
- * @param newMap\r
- * The TopLevelElementName/XmlObject format of a Surface Area\r
- * document.\r
- */\r
- public static void push(Map<String, XmlObject> newMap) {\r
- mapStack.push(SurfaceAreaQuery.map);\r
- SurfaceAreaQuery.map = newMap;\r
- }\r
-\r
- /**\r
- * Discard current used Surface Area document and use the top document in\r
- * stack instead.\r
- */\r
- public static void pop() {\r
- SurfaceAreaQuery.map = mapStack.pop();\r
- }\r
-\r
- // /\r
- // / Convert xPath to be namespace qualified, which is necessary for\r
- // XmlBeans\r
- // / selectPath(). For example, converting /MsaHeader/ModuleType to\r
- // / /ns:MsaHeader/ns:ModuleType\r
- // /\r
- private static String normalizeQueryString(String[] exp, String from) {\r
- StringBuffer normQueryString = new StringBuffer(4096);\r
-\r
- int i = 0;\r
- while (i < exp.length) {\r
- String newExp = from + exp[i];\r
- Pattern pattern = Pattern.compile("([^/]*)(/|//)([^/]+)");\r
- Matcher matcher = pattern.matcher(newExp);\r
-\r
- while (matcher.find()) {\r
- String starter = newExp.substring(matcher.start(1), matcher\r
- .end(1));\r
- String seperator = newExp.substring(matcher.start(2), matcher\r
- .end(2));\r
- String token = newExp.substring(matcher.start(3), matcher\r
- .end(3));\r
-\r
- normQueryString.append(starter);\r
- normQueryString.append(seperator);\r
- normQueryString.append(nsPrefix);\r
- normQueryString.append(":");\r
- normQueryString.append(token);\r
- }\r
-\r
- ++i;\r
- if (i < exp.length) {\r
- normQueryString.append(" | ");\r
- }\r
- }\r
-\r
- return normQueryString.toString();\r
- }\r
-\r
- /**\r
- * Search all XML documents stored in "map" for the specified xPath, using\r
- * relative path (starting with '$this')\r
- * \r
- * @param xPath\r
- * xpath query string array\r
- * @returns An array of XmlObject if elements are found at the specified\r
- * xpath\r
- * @returns NULL if nothing is at the specified xpath\r
- */\r
- public static XmlObject[] get(String[] xPath) {\r
- if (map == null) {\r
- return null;\r
- }\r
-\r
- String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
- List<XmlObject> result = new ArrayList<XmlObject>();\r
- for (int i = 0; i < keys.length; ++i) {\r
- XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
- if (rootNode == null) {\r
- continue;\r
- }\r
-\r
- String query = queryDeclaration\r
- + normalizeQueryString(xPath, "$this/" + keys[i]);\r
- XmlObject[] tmp = rootNode.selectPath(query);\r
- for (int j = 0; j < tmp.length; ++j) {\r
- result.add(tmp[j]);\r
- }\r
- }\r
-\r
- int size = result.size();\r
- if (size <= 0) {\r
- return null;\r
- }\r
-\r
- return (XmlObject[]) result.toArray(new XmlObject[size]);\r
- }\r
-\r
- /**\r
- * Search XML documents named by "rootName" for the given xPath, using\r
- * relative path (starting with '$this')\r
- * \r
- * @param rootName\r
- * The top level element name\r
- * @param xPath\r
- * The xpath query string array\r
- * @returns An array of XmlObject if elements are found at the given xpath\r
- * @returns NULL if nothing is found at the given xpath\r
- */\r
- public static XmlObject[] get(String rootName, String[] xPath) {\r
- if (map == null) {\r
- return null;\r
- }\r
-\r
- XmlObject root = (XmlObject) map.get(rootName);\r
- if (root == null) {\r
- return null;\r
- }\r
-\r
- String query = queryDeclaration\r
- + normalizeQueryString(xPath, "$this/" + rootName);\r
- XmlObject[] result = root.selectPath(query);\r
- if (result.length > 0) {\r
- return result;\r
- }\r
-\r
- query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
- result = root.selectPath(query);\r
- if (result.length > 0) {\r
- return result;\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Retrieve SourceFiles/Filename for specified ARCH type\r
- * \r
- * @param arch\r
- * architecture name\r
- * @returns An 2 dimension string array if elements are found at the known\r
- * xpath\r
- * @returns NULL if nothing is found at the known xpath\r
- */\r
- public static String[][] getSourceFiles(String arch) {\r
- String[] xPath;\r
- XmlObject[] returns;\r
-\r
- if (arch == null || arch.equals("")) {\r
- xPath = new String[] { "/Filename" };\r
- } else {\r
- xPath = new String[] { "/Filename[not(@SupArchList) or @SupArchList='"\r
- + arch + "']" };\r
- }\r
-\r
- returns = get("SourceFiles", xPath);\r
-\r
- if (returns == null || returns.length == 0) {\r
- return null;\r
- }\r
-\r
- Filename[] sourceFileNames = (Filename[]) returns;\r
- String[][] outputString = new String[sourceFileNames.length][2];\r
- for (int i = 0; i < sourceFileNames.length; i++) {\r
- outputString[i][0] = sourceFileNames[i].getToolCode();\r
- outputString[i][1] = sourceFileNames[i].getStringValue();\r
- }\r
- return outputString;\r
- }\r
-\r
- /**\r
- * Retrieve /PlatformDefinitions/OutputDirectory from FPD\r
- * \r
- * @returns Directory names array if elements are found at the known xpath\r
- * @returns Empty if nothing is found at the known xpath\r
- */\r
- public static String getFpdOutputDirectory() {\r
- String[] xPath = new String[] { "/PlatformDefinitions/OutputDirectory" };\r
-\r
- XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
- if (returns != null && returns.length > 0) {\r
- // String TBD\r
- }\r
-\r
- return null;\r
- }\r
-\r
- public static String getFpdIntermediateDirectories() {\r
- String[] xPath = new String[] { "/PlatformDefinitions/IntermediateDirectories" };\r
-\r
- XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
- if (returns != null && returns.length > 0) {\r
- // TBD\r
- }\r
- return "UNIFIED";\r
- }\r
-\r
- public static String getBuildTarget() {\r
- String[] xPath = new String[] { "/PlatformDefinitions/BuildTargets" };\r
-\r
- XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
- if (returns != null && returns.length > 0) {\r
- return ((BuildTargetList) returns[0]).getStringValue();\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * Retrieve <xxxHeader>/ModuleType\r
- * \r
- * @returns The module type name if elements are found at the known xpath\r
- * @returns null if nothing is there\r
- */\r
- public static String getModuleType(ModuleIdentification mi) {\r
- ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = WorkspaceProfile.getModuleXmlObject(mi);\r
-\r
- return msa.getMsaHeader().getModuleType()+"";\r
- }\r
-\r
- /**\r
- * Retrieve PackageDependencies/Package\r
- * \r
- * @param arch\r
- * Architecture name\r
- * \r
- * @returns package name list if elements are found at the known xpath\r
- * @returns null if nothing is there\r
- */\r
-\r
- public static PackageIdentification[] getDependencePkg(String arch, ModuleIdentification mi) throws Exception{\r
- \r
- String packageGuid = null;\r
- String packageVersion = null;\r
-\r
- ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile.getModuleXmlObject(mi);\r
- if (msa.getPackageDependencies() == null) {\r
- return new PackageIdentification[0];\r
- }\r
- int size = msa.getPackageDependencies().getPackageList().size();\r
- XmlObject[] returns = new XmlObject[size];\r
- for (int i = 0; i < size; ++i) {\r
- returns[i] = msa.getPackageDependencies().getPackageList().get(i);\r
- }\r
-\r
- PackageIdentification[] packageIdList = new PackageIdentification[returns.length];\r
- for (int i = 0; i < returns.length; i++) {\r
- PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];\r
- packageGuid = item.getPackageGuid();\r
- packageVersion = item.getPackageVersion();\r
-\r
- Iterator<PackageIdentification> ispi = GlobalData.vPackageList.iterator();\r
- String ver = "";\r
- while(ispi.hasNext()) {\r
- PackageIdentification pi = ispi.next();\r
- if (packageVersion != null) {\r
- if (pi.getGuid().equalsIgnoreCase(packageGuid) && pi.getVersion().equals(packageVersion)) {\r
- packageIdList[i] = pi;\r
- break;\r
- } \r
- }\r
- else {\r
- if (pi.getGuid().equalsIgnoreCase(packageGuid)) {\r
- if (pi.getVersion() != null && pi.getVersion().compareTo(ver) > 0){\r
- ver = pi.getVersion();\r
- packageIdList[i] = pi;\r
- }\r
- else if (packageIdList[i] == null){\r
- packageIdList[i] = pi;\r
- }\r
- }\r
- }\r
- \r
- }\r
- }\r
- return packageIdList;\r
- }\r
-\r
- /**\r
- * Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
- * \r
- * @param usage\r
- * Library class usage\r
- * \r
- * @returns LibraryClass objects list if elements are found at the known\r
- * xpath\r
- * @returns null if nothing is there\r
- */\r
- public static Vector<String> getLibraryClasses(String usage, ModuleIdentification mi) throws Exception{\r
- ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);\r
- Vector<String> libraryClassName = new Vector<String>();\r
- if (msa.getLibraryClassDefinitions() == null) {\r
- return libraryClassName;\r
- }\r
- \r
- int size = msa.getLibraryClassDefinitions().getLibraryClassList().size();\r
- \r
- for (int i = 0; i < size; i++) {\r
- LibraryClassDocument.LibraryClass libClass = msa.getLibraryClassDefinitions().getLibraryClassList().get(i);\r
- if (usage.equals(libClass.getUsage().toString())) {\r
- libraryClassName.add(libClass.getKeyword());\r
- }\r
- }\r
- \r
- return libraryClassName;\r
- }\r
-\r
- public static XmlObject[] getSpdPcdDeclarations(PackageIdentification pi) {\r
- XmlObject[] returns = null;\r
- PackageSurfaceAreaDocument.PackageSurfaceArea psa = WorkspaceProfile.getPackageXmlObject(pi);\r
- if (psa.getPcdDeclarations() != null && psa.getPcdDeclarations().getPcdEntryList() != null) {\r
- int size = psa.getPcdDeclarations().getPcdEntryList().size();\r
- returns = new XmlObject[size];\r
- for (int i = 0; i < size; ++i) {\r
- returns[i] = psa.getPcdDeclarations().getPcdEntryList().get(i);\r
- }\r
- }\r
- \r
- return returns;\r
- }\r
-\r
-}
\ No newline at end of file