Search in sources :

Example 1 with ManifestProblem

use of org.eclipse.virgo.util.parser.manifest.ManifestProblem 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;
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) ManifestParser(org.eclipse.virgo.util.parser.manifest.ManifestParser) RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) ManifestProblem(org.eclipse.virgo.util.parser.manifest.ManifestProblem) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ManifestContents (org.eclipse.virgo.util.parser.manifest.ManifestContents)1 ManifestParser (org.eclipse.virgo.util.parser.manifest.ManifestParser)1 ManifestProblem (org.eclipse.virgo.util.parser.manifest.ManifestProblem)1 RecoveringManifestParser (org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser)1