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
This commit is contained in:
@ -18,6 +18,8 @@ package org.tianocore.build.global;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -27,11 +29,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
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.tianocore.DbPathAndFilename;
|
import org.tianocore.DbPathAndFilename;
|
||||||
import org.tianocore.FrameworkDatabaseDocument;
|
import org.tianocore.FrameworkDatabaseDocument;
|
||||||
import org.tianocore.ModuleSurfaceAreaDocument;
|
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.ToolChainInfo;
|
||||||
import org.tianocore.build.toolchain.ToolChainKey;
|
import org.tianocore.build.toolchain.ToolChainKey;
|
||||||
import org.tianocore.build.toolchain.ToolChainMap;
|
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.
|
GlobalData provide initializing, instoring, querying and update global data.
|
||||||
@ -133,7 +135,6 @@ public class GlobalData {
|
|||||||
private static Map<ModuleIdentification, ToolChainMap> msaBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
|
private static Map<ModuleIdentification, ToolChainMap> msaBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
|
||||||
private static Map<ModuleIdentification, ToolChainMap> msaFamilyBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
|
private static Map<ModuleIdentification, ToolChainMap> msaFamilyBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();
|
||||||
|
|
||||||
// private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
|
|
||||||
/**
|
/**
|
||||||
Parse framework database (DB) and all SPD files listed in DB to initialize
|
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
|
the environment for next build. This method will only be executed only once
|
||||||
@ -173,14 +174,9 @@ public class GlobalData {
|
|||||||
// Parse Framework Database
|
// Parse Framework Database
|
||||||
//
|
//
|
||||||
File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
|
File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
|
||||||
|
FrameworkDatabaseDocument db = null;
|
||||||
try {
|
try {
|
||||||
FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
|
db = (FrameworkDatabaseDocument)parseXmlFile(dbFile);
|
||||||
//
|
|
||||||
// validate FrameworkDatabaseFile
|
|
||||||
//
|
|
||||||
if (!db.validate()) {
|
|
||||||
throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Get package list
|
// Get package list
|
||||||
//
|
//
|
||||||
@ -203,7 +199,18 @@ public class GlobalData {
|
|||||||
spdTable.put(spd.getPackageId(), spd);
|
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
|
// Get platform list
|
||||||
//
|
//
|
||||||
@ -212,17 +219,11 @@ public class GlobalData {
|
|||||||
Iterator<DbPathAndFilename> iter = platforms.iterator();
|
Iterator<DbPathAndFilename> iter = platforms.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
String fileName = iter.next().getStringValue().trim();
|
String fileName = iter.next().getStringValue().trim();
|
||||||
File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
|
fpdFile = new File(workspaceDir + File.separatorChar + fileName);
|
||||||
if ( !fpdFile.exists() ) {
|
if ( !fpdFile.exists() ) {
|
||||||
throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");
|
throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");
|
||||||
}
|
}
|
||||||
XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
|
XmlObject fpdDoc = parseXmlFile(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!");
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// We can change Map to XmlObject
|
// We can change Map to XmlObject
|
||||||
//
|
//
|
||||||
@ -244,11 +245,11 @@ public class GlobalData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(IOException ex) {
|
} 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());
|
edkException.setStackTrace(ex.getStackTrace());
|
||||||
throw edkException;
|
throw edkException;
|
||||||
} catch(XmlException ex) {
|
} 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());
|
edkException.setStackTrace(ex.getStackTrace());
|
||||||
throw edkException;
|
throw edkException;
|
||||||
}
|
}
|
||||||
@ -416,13 +417,7 @@ public class GlobalData {
|
|||||||
throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");
|
throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
|
ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)parseXmlFile(msaFile);
|
||||||
//
|
|
||||||
// Validate File if they accord with XML Schema
|
|
||||||
//
|
|
||||||
if ( !doc.validate()){
|
|
||||||
throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// parse MSA file
|
// parse MSA file
|
||||||
//
|
//
|
||||||
@ -441,11 +436,11 @@ public class GlobalData {
|
|||||||
msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true));
|
msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true));
|
||||||
return msaMap;
|
return msaMap;
|
||||||
} catch(IOException ex) {
|
} 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());
|
edkException.setStackTrace(ex.getStackTrace());
|
||||||
throw edkException;
|
throw edkException;
|
||||||
} catch(XmlException ex) {
|
} 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());
|
edkException.setStackTrace(ex.getStackTrace());
|
||||||
throw edkException;
|
throw edkException;
|
||||||
}
|
}
|
||||||
@ -908,5 +903,29 @@ public class GlobalData {
|
|||||||
|
|
||||||
return pcdBuildDef;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,13 +98,7 @@ public class Spd {
|
|||||||
throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");
|
throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
XmlObject spdDoc = XmlObject.Factory.parse(packageFile);
|
XmlObject spdDoc = GlobalData.parseXmlFile(packageFile);
|
||||||
//
|
|
||||||
// Verify SPD file, if is invalid, throw Exception
|
|
||||||
//
|
|
||||||
if (! spdDoc.validate()) {
|
|
||||||
throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!");
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// We can change Map to XmlObject
|
// We can change Map to XmlObject
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user