From: jwang36 Date: Mon, 23 Oct 2006 08:34:59 +0000 (+0000) Subject: Added code to fetch more detailed error message from XMLBeans when there's error... X-Git-Tag: edk2-stable201903~24046 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=fe6d0f7404c3051f758574e386d31dec02687ff9 Added code to fetch more detailed error message from XMLBeans when there's error in msa/spd/fpd files. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1828 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java index bf4cd430b0..c736952377 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -18,6 +18,8 @@ package org.tianocore.build.global; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -27,11 +29,7 @@ import java.util.Set; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; - -import org.tianocore.common.definitions.ToolDefinitions; -import org.tianocore.common.exception.EdkException; -import org.tianocore.common.logger.EdkLog; -import org.tianocore.pcd.entity.MemoryDatabaseManager; +import org.apache.xmlbeans.XmlOptions; import org.tianocore.DbPathAndFilename; import org.tianocore.FrameworkDatabaseDocument; import org.tianocore.ModuleSurfaceAreaDocument; @@ -45,6 +43,10 @@ import org.tianocore.build.toolchain.ToolChainElement; import org.tianocore.build.toolchain.ToolChainInfo; import org.tianocore.build.toolchain.ToolChainKey; import org.tianocore.build.toolchain.ToolChainMap; +import org.tianocore.common.definitions.ToolDefinitions; +import org.tianocore.common.exception.EdkException; +import org.tianocore.common.logger.EdkLog; +import org.tianocore.pcd.entity.MemoryDatabaseManager; /** GlobalData provide initializing, instoring, querying and update global data. @@ -133,7 +135,6 @@ public class GlobalData { private static Map msaBuildOption = new HashMap(); private static Map msaFamilyBuildOption = new HashMap(); -// private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); /** Parse framework database (DB) and all SPD files listed in DB to initialize the environment for next build. This method will only be executed only once @@ -173,14 +174,9 @@ public class GlobalData { // Parse Framework Database // File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile); + FrameworkDatabaseDocument db = null; try { - FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile); - // - // validate FrameworkDatabaseFile - // - if (!db.validate()) { - throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); - } + db = (FrameworkDatabaseDocument)parseXmlFile(dbFile); // // Get package list // @@ -203,7 +199,18 @@ public class GlobalData { spdTable.put(spd.getPackageId(), spd); } } + } catch(IOException ex) { + EdkException edkException = new EdkException("Parse of WORKSPACE Database file [" + dbFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parse of WORKSPACE Database file [" + dbFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } + File fpdFile = null; + try { // // Get platform list // @@ -212,17 +219,11 @@ public class GlobalData { Iterator iter = platforms.iterator(); while (iter.hasNext()) { String fileName = iter.next().getStringValue().trim(); - File fpdFile = new File(workspaceDir + File.separatorChar + fileName); + fpdFile = new File(workspaceDir + File.separatorChar + fileName); if ( !fpdFile.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 EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); - } + XmlObject fpdDoc = parseXmlFile(fpdFile); // // We can change Map to XmlObject // @@ -244,11 +245,11 @@ public class GlobalData { } } } catch(IOException ex) { - EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + EdkException edkException = new EdkException("Parse of platform definition file [" + fpdFile.getPath() + "] failed!\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 edkException = new EdkException("Parse of platform definition file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage()); edkException.setStackTrace(ex.getStackTrace()); throw edkException; } @@ -416,13 +417,7 @@ public class GlobalData { throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); } try { - ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile); - // - // Validate File if they accord with XML Schema - // - if ( !doc.validate()){ - throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); - } + ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)parseXmlFile(msaFile); // // parse MSA file // @@ -441,11 +436,11 @@ public class GlobalData { msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true)); return msaMap; } catch(IOException ex) { - EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + EdkException edkException = new EdkException("Parse of MSA file [" + msaFile.getPath() + "] failed!\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 edkException = new EdkException("Parse of MSA file [" + msaFile.getPath() + "] failed!\n" + ex.getMessage()); edkException.setStackTrace(ex.getStackTrace()); throw edkException; } @@ -908,5 +903,29 @@ public class GlobalData { return pcdBuildDef; } + + public static XmlObject parseXmlFile(File xmlFile) throws IOException, XmlException { + Collection errors = new ArrayList(); + XmlOptions opt = new XmlOptions(); + + opt.setLoadLineNumbers(); + opt.setLoadMessageDigest(); + opt.setErrorListener(errors); + + XmlObject doc = XmlObject.Factory.parse(xmlFile, opt); + // + // Validate File if they accord with XML Schema + // + if (!doc.validate(opt)){ + StringBuilder errorMessage = new StringBuilder(1024); + for (Iterator it = errors.iterator(); it.hasNext(); ) { + errorMessage.append(it.next()); + errorMessage.append("\n"); + } + throw new XmlException(errorMessage.toString()); + } + + return doc; + } } diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/global/Spd.java b/Tools/Java/Source/GenBuild/org/tianocore/build/global/Spd.java index 965e8ef499..951817f64c 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/global/Spd.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/global/Spd.java @@ -98,13 +98,7 @@ public class Spd { throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!"); } try { - XmlObject spdDoc = XmlObject.Factory.parse(packageFile); - // - // Verify SPD file, if is invalid, throw Exception - // - if (! spdDoc.validate()) { - throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!"); - } + XmlObject spdDoc = GlobalData.parseXmlFile(packageFile); // // We can change Map to XmlObject //