From 892b0e7a05eb655d9734b0e24c7d8bea1ae4929b Mon Sep 17 00:00:00 2001 From: wuyizhong Date: Wed, 6 Sep 2006 09:37:36 +0000 Subject: [PATCH] Update GlobalData, SPD, SurfaceAreaQuery to using EdkException. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1485 6f19259b-4bc3-4df7-8a09-765794883524 --- .../tianocore/build/FrameworkBuildTask.java | 22 +-- .../org/tianocore/build/GenBuildTask.java | 57 ++++++-- .../org/tianocore/build/GenBuildThread.java | 1 - .../build/ModuleBuildFileGenerator.java | 3 +- .../org/tianocore/build/autogen/AutoGen.java | 11 +- .../tianocore/build/fpd/FpdParserTask.java | 25 ---- .../tianocore/build/global/GlobalData.java | 127 +++++++++++------- .../org/tianocore/build/global/Spd.java | 32 +++-- .../build/global/SurfaceAreaQuery.java | 27 ++-- .../build/id/ModuleIdentification.java | 20 +-- .../build/id/PackageIdentification.java | 14 -- 11 files changed, 176 insertions(+), 163 deletions(-) diff --git a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java index 9d68419aa8..14103d7b22 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java @@ -111,6 +111,13 @@ public class FrameworkBuildTask extends Task{ private String type = "all"; public void execute() throws BuildException { + // + // set Logger + // + GenBuildLogger logger = new GenBuildLogger(getProject()); + EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL")); + EdkLog.setLogger(logger); + try { processFrameworkBuild(); } catch (PcdAutogenException e) { @@ -142,13 +149,6 @@ public class FrameworkBuildTask extends Task{ } private void processFrameworkBuild() throws EdkException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException { - // - // set Logger - // - GenBuildLogger logger = new GenBuildLogger(getProject()); - EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL")); - EdkLog.setLogger(logger); - // // Seach build.xml -> .FPD -> .MSA file // @@ -180,8 +180,10 @@ public class FrameworkBuildTask extends Task{ } } } - } catch (IOException e) { - throw new BuildException(e.getMessage()); + } catch (IOException ex) { + BuildException buildException = new BuildException("Scanning current directory error. \n" + ex.getMessage()); + buildException.setStackTrace(ex.getStackTrace()); + throw buildException; } // @@ -426,7 +428,7 @@ public class FrameworkBuildTask extends Task{ if (threadNum > 0) { MAX_CONCURRENT_THREAD_NUMBER = threadNum; } - } catch (Exception enuma) { + } catch (Exception ex) { } } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java index 9b6251a0a2..da866aaa6e 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java @@ -37,6 +37,10 @@ import org.tianocore.common.definitions.ToolDefinitions; import org.tianocore.common.exception.EdkException; import org.tianocore.common.logger.EdkLog; import org.tianocore.build.autogen.AutoGen; +import org.tianocore.build.exception.AutoGenException; +import org.tianocore.build.exception.GenBuildException; +import org.tianocore.build.exception.PcdAutogenException; +import org.tianocore.build.exception.PlatformPcdPreprocessBuildException; import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.OutputManager; @@ -126,6 +130,37 @@ public class GenBuildTask extends Ant { From module build, exception from module surface area invalid. **/ public void execute() throws BuildException { + try { + processGenBuild(); + } catch (PcdAutogenException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); + } catch (AutoGenException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); + } catch (PlatformPcdPreprocessBuildException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); + } catch (GenBuildException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); + } catch (EdkException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); + } + } + + private void processGenBuild() throws EdkException, BuildException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException { if (!FrameworkBuildTask.multithread) { cleanupProperties(); } @@ -147,20 +182,26 @@ public class GenBuildTask extends Ant { String moduleVersion = getProject().getProperty("MODULE_VERSION"); String packageGuid = getProject().getProperty("PACKAGE_GUID"); String packageVersion = getProject().getProperty("PACKAGE_VERSION"); + // + // If one of module Guid or package Guid is not specified, report error + // if (moduleGuid == null || packageGuid == null) { throw new BuildException("GenBuild parameter error."); } + PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion); + GlobalData.refreshPackageIdentification(packageId); moduleId = new ModuleIdentification(moduleGuid, moduleVersion); moduleId.setPackage(packageId); + GlobalData.refreshModuleIdentification(moduleId); Map doc = GlobalData.getNativeMsa(moduleId); saq = new SurfaceAreaQuery(doc); - moduleId = saq.getMsaHeader(); } else { Map doc = GlobalData.getNativeMsa(msaFile); saq = new SurfaceAreaQuery(doc); moduleId = saq.getMsaHeader(); } + String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null); if (producedLibraryClasses.length == 0) { moduleId.setLibrary(false); @@ -176,11 +217,6 @@ public class GenBuildTask extends Ant { // Single Module build // prepareSingleModuleBuild(); - } else { - String packageGuid = getProject().getProperty("PACKAGE_GUID"); - String packageVersion = getProject().getProperty("PACKAGE_VERSION"); - PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion); - moduleId.setPackage(packageId); } // @@ -307,14 +343,15 @@ public class GenBuildTask extends Ant { Database must be unique.

**/ - private void prepareSingleModuleBuild(){ + private void prepareSingleModuleBuild() throws EdkException { // // Find out the package which the module belongs to // TBD: Enhance it!!!! // PackageIdentification packageId = GlobalData.getPackageForModule(moduleId); - + GlobalData.refreshPackageIdentification(packageId); moduleId.setPackage(packageId); + GlobalData.refreshModuleIdentification(moduleId); // // Read ACTIVE_PLATFORM's FPD file @@ -540,7 +577,7 @@ public class GenBuildTask extends Ant { this.type = type; } - private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{ + private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException { // // Call AutoGen to generate AutoGen.c and AutoGen.h // @@ -701,7 +738,7 @@ public class GenBuildTask extends Ant { this.isSingleModuleBuild = isSingleModuleBuild; } - private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) { + private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) throws EdkException{ // // Prepare the includes: PackageDependencies and Output debug direactory // diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java index 416ccd1183..5ab7c0aff7 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java @@ -213,5 +213,4 @@ public class GenBuildThread implements Runnable { public void setStatus(int status) { this.status = status; } - } diff --git a/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java index 548839f135..f8c78b848e 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java +++ b/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java @@ -34,6 +34,7 @@ import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PackageIdentification; +import org.tianocore.common.exception.EdkException; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -296,7 +297,7 @@ public class ModuleBuildFileGenerator { @param document current BaseName_build.xml XML document @param root Root element for current **/ - private void applyLibraryInstance(Document document, Node root) { + private void applyLibraryInstance(Document document, Node root) throws EdkException { ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch()); for (int i = 0; i < libinstances.length; i++) { // diff --git a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java index 08b44f9eb4..117b6bfe17 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java +++ b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java @@ -42,6 +42,7 @@ import org.tianocore.build.id.PackageIdentification; import org.tianocore.build.pcd.action.PCDAutoGenAction; import org.tianocore.common.logger.EdkLog; import org.tianocore.common.definitions.ToolDefinitions; +import org.tianocore.common.exception.EdkException; /** This class is to generate Autogen.h and Autogen.c according to module surface @@ -280,7 +281,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.h. **/ - void moduleGenAutogenH() throws AutoGenException { + void moduleGenAutogenH() throws EdkException, AutoGenException { Set libClassIncludeH; String moduleType; @@ -406,7 +407,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.c. **/ - void moduleGenAutogenC() throws AutoGenException { + void moduleGenAutogenC() throws EdkException, AutoGenException { StringBuffer fileBuffer = new StringBuffer(8192); // @@ -535,7 +536,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.c. **/ - void libGenAutogenH() throws AutoGenException { + void libGenAutogenH() throws EdkException, AutoGenException { Set libClassIncludeH; String moduleType; @@ -699,7 +700,7 @@ public class AutoGen { @return includeStrList List of *.h file. **/ Set LibraryClassToAutogenH(String[] libClassList) - throws AutoGenException { + throws EdkException, AutoGenException { Set includeStrList = new LinkedHashSet(); String includeName[]; String str = ""; @@ -1904,7 +1905,7 @@ public class AutoGen { @param @return **/ - private void collectLibInstanceInfo(){ + private void collectLibInstanceInfo() throws EdkException{ int index; String libConstructName = null; diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java index 99e7cca944..ea14ac350f 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java @@ -64,18 +64,10 @@ import org.tianocore.build.toolchain.ToolChainMap;

The method parseFpdFile is also prepared for single module build.

-

The usage is (take NT32 Platform for example):

- -
-  <FPDParser platformName="Nt32" />
-  
- @since GenBuild 1.0 **/ public class FpdParserTask extends Task { - private String platformName; - private File fpdFile = null; PlatformIdentification platformId; @@ -123,18 +115,6 @@ public class FpdParserTask extends Task { Surface area is not valid. **/ public void execute() throws BuildException { - // - // If fpdFile is not specified, - // then try to get FPD file by platformName - // - if ( fpdFile == null) { - if (platformName == null) { - throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!"); - } - platformId = GlobalData.getPlatformByName(platformName); - fpdFile = platformId.getFpdFile(); - } - // // Parse FPD file // @@ -178,7 +158,6 @@ public class FpdParserTask extends Task { // // Ant call ${PLATFORM}_build.xml // - Ant ant = new Ant(); ant.setProject(getProject()); ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml"); @@ -554,10 +533,6 @@ public class FpdParserTask extends Task { properties.addElement(p); } - public void setPlatformName(String platformName) { - this.platformName = platformName; - } - public void setFpdFile(File fpdFile) { this.fpdFile = fpdFile; } diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java index 4a7b56fc49..52ba681f55 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. package org.tianocore.build.global; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -24,7 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.tools.ant.BuildException; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.common.exception.EdkException; @@ -139,7 +140,7 @@ public class GlobalData { @throws BuildException Framework Dababase or SPD or MSA file is not valid **/ - public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException { + public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException { // // ensure this method will be revoked only once // @@ -161,12 +162,9 @@ public class GlobalData { // CONF dir + tools definition file name // File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename); - EdkLog.log("Init", "Using tool definiton file [" + toolsDefFile.getPath() + "]."); - try { - toolsDef = new ToolChainConfig(toolsDefFile); - } catch (Exception e) { - throw new BuildException(e.getMessage()); - } + EdkLog.log("Init", "Using tool definition file [" + toolsDefFile.getPath() + "]."); + toolsDef = new ToolChainConfig(toolsDefFile); + // // Parse Framework Database @@ -178,7 +176,7 @@ public class GlobalData { // validate FrameworkDatabaseFile // if (!db.validate()) { - throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); + throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); } // // Get package list @@ -190,6 +188,15 @@ public class GlobalData { String fileName = iter.next().getStringValue().trim(); Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName)); packageList.add(spd.getPackageId()); + // + // Report warning if existing two packages with same GUID and Version + // + if (spdTable.containsKey(spd.getPackageId())) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath()); + } spdTable.put(spd.getPackageId(), spd); } } @@ -204,31 +211,43 @@ public class GlobalData { String fileName = iter.next().getStringValue().trim(); File fpdFile = new File(workspaceDir + File.separatorChar + fileName); if ( !fpdFile.exists() ) { - throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. "); + throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. "); } XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile); // // Verify FPD file, if is invalid, throw Exception // if (!fpdDoc.validate()) { - throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); + throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); } // // We can change Map to XmlObject // - // - // TBD check SPD or FPD is existed in FS - // Map fpdDocMap = new HashMap(); fpdDocMap.put("PlatformSurfaceArea", fpdDoc); SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap); PlatformIdentification platformId = saq.getFpdHeader(); platformId.setFpdFile(fpdFile); + // + // Report warning if existing two platfrom with same GUID and Version + // + if (platformList.contains(platformId)) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath()); + } platformList.add(platformId); } } - } catch (Exception e) { - throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage()); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } @@ -245,7 +264,7 @@ public class GlobalData { /** Get the MSA file name with absolute path */ - public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException { + public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException { File msaFile = null; // // TBD. Do only when package is null. @@ -260,13 +279,13 @@ public class GlobalData { } } if (msaFile == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); } else { return msaFile; } } - public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) { + public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException { // // If package already defined in module // @@ -285,7 +304,7 @@ public class GlobalData { } } if (packageId == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); } else { return packageId; } @@ -303,7 +322,7 @@ public class GlobalData { } - public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) { + public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) throws EdkException{ Map result = new HashMap(); Set keySet = doc.keySet(); Iterator iter = keySet.iterator(); @@ -329,7 +348,7 @@ public class GlobalData { @return ModuleSA info and MSA info for fpdModuleId @throws BuildException Can't find MSA **/ - public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws BuildException { + public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{ if (parsedModules.containsKey(fpdModuleId)) { return parsedModules.get(fpdModuleId); } @@ -359,10 +378,11 @@ public class GlobalData { return doc; } - public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws BuildException { + public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws EdkException{ FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch); return getDoc(fpdModuleId); } + /** Query the native MSA information with module base name. @@ -374,7 +394,7 @@ public class GlobalData { @throws BuildException MSA file is not valid **/ - public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws BuildException { + public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws EdkException { if (nativeMsa.containsKey(moduleId)) { return nativeMsa.get(moduleId); } @@ -384,9 +404,9 @@ public class GlobalData { return msaMap; } - public synchronized static Map getNativeMsa(File msaFile) throws BuildException { + public synchronized static Map getNativeMsa(File msaFile) throws EdkException { if (!msaFile.exists()) { - throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); } try { ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile); @@ -394,7 +414,7 @@ public class GlobalData { // Validate File if they accord with XML Schema // if ( !doc.validate()){ - throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); } // // parse MSA file @@ -412,9 +432,14 @@ public class GlobalData { msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); return msaMap; - } - catch (Exception ex){ - throw new BuildException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage() ); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } @@ -422,7 +447,7 @@ public class GlobalData { return fpdBuildOptionsMap; } - public static void setFpdBuildOptions(XmlObject fpdBuildOptions) { + public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException { GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true); fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions); } @@ -449,8 +474,7 @@ public class GlobalData { * The header file path is relative to workspace dir */ public static String[] getLibraryClassHeaderFiles( - PackageIdentification[] packages, String name) - throws BuildException { + PackageIdentification[] packages, String name) throws EdkException{ if (packages == null) { // throw Exception or not???? return new String[0]; @@ -468,7 +492,7 @@ public class GlobalData { // // If can't find library class declaration in every package // - throw new BuildException("Can not find library class [" + name + throw new EdkException("Can not find library class [" + name + "] declaration in any SPD package!"); } @@ -476,7 +500,7 @@ public class GlobalData { * The header file path is relative to workspace dir */ public static String getPackageHeaderFiles(PackageIdentification packages, - String moduleType) throws BuildException { + String moduleType) { if (packages == null) { return new String(""); } @@ -500,8 +524,7 @@ public class GlobalData { /** * return two values: {cName, GuidValue} */ - public static String[] getGuid(List packages, String name) - throws BuildException { + public static String[] getGuid(List packages, String name) { if (packages == null) { // throw Exception or not???? return new String[0]; @@ -525,7 +548,7 @@ public class GlobalData { * return two values: {cName, GuidValue} */ public static String[] getPpiGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -547,7 +570,7 @@ public class GlobalData { * return two values: {cName, GuidValue} */ public static String[] getProtocolGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -566,7 +589,7 @@ public class GlobalData { } - public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException { + public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException { Iterator iter = platformList.iterator(); while(iter.hasNext()){ PlatformIdentification platformId = (PlatformIdentification)iter.next(); @@ -574,10 +597,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!"); + throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!"); } - public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException { + public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException { File file = new File(workspaceDir + File.separatorChar + filename); Iterator iter = platformList.iterator(); while(iter.hasNext()){ @@ -586,10 +609,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!"); + throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!"); } - public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException { + public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException { Iterator iter = packageList.iterator(); while(iter.hasNext()){ PackageIdentification packageItem = (PackageIdentification)iter.next(); @@ -599,15 +622,15 @@ public class GlobalData { return packageId; } } - throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } - public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException { + public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException { PackageIdentification packageId = getPackageForModule(moduleId); moduleId.setPackage(packageId); Spd spd = spdTable.get(packageId); if (spd == null) { - throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } Set modules = spd.getModules(); Iterator iter = modules.iterator(); @@ -620,7 +643,7 @@ public class GlobalData { return moduleId; } } - throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!"); + throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!"); } public synchronized static Set getPackageList(){ @@ -636,7 +659,7 @@ public class GlobalData { @return XmlObject after clone @throws BuildException parse original XmlObject error. **/ - private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException { + private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException { if ( object == null) { return null; } @@ -644,8 +667,10 @@ public class GlobalData { try { result = XmlObject.Factory.parse(object.getDomNode() .cloneNode(deep)); - } catch (Exception ex) { - throw new BuildException(ex.getMessage()); + } catch (XmlException ex) { + EdkException edkException = new EdkException(ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } return result; } diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java b/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java index cfb5dc1f87..965e8ef499 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java @@ -16,21 +16,23 @@ package org.tianocore.build.global; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; -import org.apache.tools.ant.BuildException; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PackageIdentification; +import org.tianocore.common.exception.EdkException; /** This class is to generate a global table for the content of spd file. - **/ +**/ public class Spd { /// /// @@ -88,12 +90,12 @@ public class Spd { This function mainly initialize some member variables. **/ - Spd(File packageFile) throws BuildException { + Spd(File packageFile) throws EdkException { // // If specified package file not exists // if ( ! packageFile.exists()) { - throw new BuildException("Package file [" + packageFile.getPath() + "] does not exist!"); + throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!"); } try { XmlObject spdDoc = XmlObject.Factory.parse(packageFile); @@ -101,15 +103,15 @@ public class Spd { // Verify SPD file, if is invalid, throw Exception // if (! spdDoc.validate()) { - throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!"); + throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!"); } + // // We can change Map to XmlObject + // Map spdDocMap = new HashMap(); spdDocMap.put("PackageSurfaceArea", spdDoc); SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap); - // - // - // + packageId = saq.getSpdHeader(); packageId.setSpdFile(packageFile); @@ -127,7 +129,7 @@ public class Spd { moduleId.setPackage(packageId); moduleId.setMsaFile(msaFile); if (msaInfo.containsKey(moduleId)) { - throw new BuildException("Found two modules with the same GUID and Version in package " + packageId + ".\nThey are module [" + msaInfo.get(moduleId) + "] and MSA file [" + msaFile + "]!"); + throw new EdkException("Found two modules with the same GUID and Version in package " + packageId + ".\nThey are module [" + msaInfo.get(moduleId) + "] and MSA file [" + msaFile + "]!"); } msaInfo.put(moduleId, msaFile); } @@ -196,10 +198,14 @@ public class Spd { } libClassHeaderList.put(libraryClassName, headerFiles); } - } - catch (Exception e) { - throw new BuildException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" - + e.getMessage()); + } catch (IOException ex) { + EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch (XmlException ex) { + EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java b/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java index 3eb024463a..daf2309258 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java @@ -62,6 +62,7 @@ import org.tianocore.ProtocolsDocument.Protocols.Protocol; import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify; import org.tianocore.PcdDriverTypes; +import org.tianocore.common.exception.EdkException; import org.tianocore.common.logger.EdkLog; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; @@ -556,7 +557,7 @@ public class SurfaceAreaQuery { * @returns package name list if elements are found at the known xpath * @returns null if nothing is there */ - public PackageIdentification[] getDependencePkg(String arch) { + public PackageIdentification[] getDependencePkg(String arch) throws EdkException { String[] xPath; String packageGuid = null; String packageVersion = null; @@ -579,19 +580,13 @@ public class SurfaceAreaQuery { if (arch == null || archList == null || contains(archList, arch)) { packageGuid = item.getPackageGuid(); packageVersion = item.getPackageVersion(); - packageIdList.add(new PackageIdentification(null, packageGuid, - packageVersion)); + PackageIdentification pkgId = new PackageIdentification(null, packageGuid, packageVersion); + GlobalData.refreshPackageIdentification(pkgId); + packageIdList.add(pkgId); } } - // - // transfer packageIdentification list to array. - // - PackageIdentification[] packageIdArray = new PackageIdentification[packageIdList.size()]; - for (int i = 0; i < packageIdList.size(); i++) { - packageIdArray[i] = new PackageIdentification(null, packageIdList.get(i).getGuid(),packageIdList.get(i).getVersion()); - } - return packageIdArray; + return packageIdList.toArray(new PackageIdentification[packageIdList.size()]); } /** @@ -1107,7 +1102,7 @@ public class SurfaceAreaQuery { * xpath * @returns null if nothing is there */ - public ModuleIdentification[] getLibraryInstance(String arch) { + public ModuleIdentification[] getLibraryInstance(String arch) throws EdkException { String[] xPath; String saGuid = null; String saVersion = null; @@ -1144,7 +1139,9 @@ public class SurfaceAreaQuery { saVersion); PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion); + GlobalData.refreshPackageIdentification(pkgId); saId.setPackage(pkgId); + GlobalData.refreshModuleIdentification(saId); saIdList[i] = saId; @@ -1308,7 +1305,7 @@ public class SurfaceAreaQuery { * @returns ModuleSA objects list if elements are found at the known xpath * @returns Empty ModuleSA list if nothing is there */ - public Map> getFpdModules() { + public Map> getFpdModules() throws EdkException { String[] xPath = new String[] { "/FrameworkModules/ModuleSA" }; Object[] result = get("PlatformSurfaceArea", xPath); String arch = null; @@ -1362,8 +1359,10 @@ public class SurfaceAreaQuery { // identification. // PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion); + GlobalData.refreshPackageIdentification(pkgId); ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion); - + GlobalData.refreshModuleIdentification(saId); + saId.setPackage(pkgId); // diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java index d7c6f62d5e..87024d13a0 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java +++ b/Tools/Source/GenBuild/org/tianocore/build/id/ModuleIdentification.java @@ -15,7 +15,6 @@ package org.tianocore.build.id; import java.io.File; -import org.tianocore.build.global.GlobalData; /** This class is used to identify a module with Module Guid, Module Version, Package Guid, Package Version. @@ -88,7 +87,6 @@ public class ModuleIdentification extends Identification { @return MSA File **/ public File getMsaFile() { - prepareMsaFile(); return msaFile; } @@ -96,19 +94,12 @@ public class ModuleIdentification extends Identification { @return Module relative path to package **/ public String getModuleRelativePath() { - prepareMsaFile(); if (msaFile.getParent().length() == packageId.getPackageDir().length()) { return "."; } return msaFile.getParent().substring(packageId.getPackageDir().length() + 1); } - private void prepareMsaFile(){ - if (msaFile == null) { - GlobalData.refreshModuleIdentification(this); - } - } - /** @param msaFile Set Msa File **/ @@ -137,10 +128,7 @@ public class ModuleIdentification extends Identification { } } - public String toString(){ - if (name == null) { - GlobalData.refreshModuleIdentification(this); - } + public String toString() { if (version == null || version.trim().equalsIgnoreCase("")) { return "Module [" + name + "] in " + packageId; } @@ -167,9 +155,6 @@ public class ModuleIdentification extends Identification { @return get module type **/ public String getModuleType() { - if (moduleType == null) { - GlobalData.refreshModuleIdentification(this); - } return moduleType; } @@ -181,9 +166,6 @@ public class ModuleIdentification extends Identification { } public String getName() { - if (name == null) { - GlobalData.refreshModuleIdentification(this); - } return name; } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java b/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java index cb0b2a09c0..9371f6afda 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java +++ b/Tools/Source/GenBuild/org/tianocore/build/id/PackageIdentification.java @@ -84,9 +84,6 @@ public class PackageIdentification extends Identification{ } public String toString(){ - if (name == null) { - GlobalData.refreshPackageIdentification(this); - } if (version == null || version.trim().equalsIgnoreCase("")) { return "package [" + name + "]"; } @@ -100,7 +97,6 @@ public class PackageIdentification extends Identification{ @return Package Directory **/ public String getPackageDir(){ - prepareSpdFile(); return spdFile.getParent(); } @@ -109,7 +105,6 @@ public class PackageIdentification extends Identification{ @return package relative directory **/ public String getPackageRelativeDir(){ - prepareSpdFile(); String relativeDir =spdFile.getParent().substring(GlobalData.getWorkspacePath().length()); if(relativeDir.startsWith("\\") || relativeDir.startsWith("/")) { relativeDir = relativeDir.substring(1); @@ -117,16 +112,7 @@ public class PackageIdentification extends Identification{ return relativeDir; } - private void prepareSpdFile(){ - if (spdFile == null) { - GlobalData.refreshPackageIdentification(this); - } - } - public String getName() { - if (name == null) { - GlobalData.refreshPackageIdentification(this); - } return name; } } -- 2.39.2