use of org.eclipse.virgo.util.parser.manifest.ManifestParser in project winery by eclipse.
the class TOSCAMetaFileParser method parse.
/**
* Parses and validates the <code>toscaMetaFile</code>.
*
* @param toscaMetaFile path to the metadata file to process
* @return <code>TOSCAMetaFile</code> that gives access to the content of
* the TOSCA meta file. If the given file doesn't exist or is invalid <code>null</code>.
*/
public TOSCAMetaFile parse(Path toscaMetaFile) {
FileReader reader = null;
ManifestParser parser;
ManifestContents manifestContent;
TOSCAMetaFile toscaMetaFileContent = null;
try {
parser = new RecoveringManifestParser();
reader = new FileReader(toscaMetaFile.toFile());
TOSCAMetaFileParser.LOGGER.debug("Parsing TOSCA meta file \"{}\"...", toscaMetaFile.getFileName().toString());
manifestContent = parser.parse(reader);
reader.close();
// counts the errors during parsing
int numErrors = 0;
for (ManifestProblem problem : parser.getProblems()) {
this.logManifestProblem(problem);
numErrors++;
}
toscaMetaFileContent = this.parse(manifestContent, numErrors);
} catch (FileNotFoundException exc) {
TOSCAMetaFileParser.LOGGER.error("\"{}\" doesn't exist or is not a file.", toscaMetaFile, exc);
} catch (IOException exc) {
TOSCAMetaFileParser.LOGGER.error("An IO Exception occured.", exc);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException exc) {
TOSCAMetaFileParser.LOGGER.warn("An IOException occured.", exc);
}
}
}
return toscaMetaFileContent;
}
Aggregations