use of org.yaml.snakeyaml.scanner.ScannerException in project winery by eclipse.
the class Reader method readServiceTemplate.
/**
* Reads a file and converts it to a ServiceTemplate
*
* @return ServiceTemplate
* @throws MultiException the ServiceTemplate or the file is invalid.
*/
private TServiceTemplate readServiceTemplate(Path path, Path file, String namespace) throws MultiException {
Path filePath;
if (Objects.isNull(path)) {
filePath = file;
} else {
filePath = path.resolve(file);
}
//
if (!fileChanged(filePath)) {
if (exceptionBuffer.containsKey(filePath)) {
throw exceptionBuffer.get(filePath);
}
if (serviceTemplateBuffer.containsKey(filePath)) {
return serviceTemplateBuffer.get(filePath);
}
}
logger.debug("Read Service Template: {}", filePath);
try {
// pre parse checking
try {
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(readObject(filePath));
} catch (ConstructorException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (ScannerException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (YAMLParserException e) {
throw new MultiException().add(e);
}
// parse checking
TServiceTemplate result = buildServiceTemplate(readObject(filePath), namespace);
// post parse checking
Validator validator = new Validator(path);
validator.validate(result, namespace);
serviceTemplateBuffer.put(filePath, result);
return result;
} catch (MultiException e) {
exceptionBuffer.put(filePath, e);
throw e.add(file.toString());
}
}
use of org.yaml.snakeyaml.scanner.ScannerException in project google-cloud-intellij by GoogleCloudPlatform.
the class DefaultAppEngineProjectService method getValueFromAppYaml.
/**
* Returns the value of a key-value pair for a given {@code key}, on the file located at {@code
* appYamlPathString}.
*
* @return a String with the value, or an empty Optional if app.yaml isn't a regular file, or if
* there is any error getting the value
* @throws MalformedYamlFileException when an app.yaml isn't syntactically well formed
*/
private Optional<String> getValueFromAppYaml(@NotNull String appYamlPathString, @NotNull String key) throws MalformedYamlFileException {
Yaml yamlParser = new Yaml();
Path appYamlPath = Paths.get(appYamlPathString);
if (!Files.isRegularFile(appYamlPath)) {
return Optional.empty();
}
try (BufferedReader reader = Files.newBufferedReader(appYamlPath, Charset.defaultCharset())) {
Object parseResult = yamlParser.load(reader);
if (!(parseResult instanceof Map)) {
return Optional.empty();
}
// It's possible to get rid of this unchecked cast using a loadAs(file,
// AppEngineYamlWebApp.class) sort of approach.
Map<String, String> yamlMap = (Map<String, String>) parseResult;
return yamlMap.containsKey(key) ? Optional.of(yamlMap.get(key)) : Optional.empty();
} catch (ScannerException se) {
throw new MalformedYamlFileException(se);
} catch (InvalidPathException | IOException ioe) {
return Optional.empty();
}
}
use of org.yaml.snakeyaml.scanner.ScannerException in project jPOS by jpos.
the class Environment method readYAML.
private boolean readYAML(String n, Properties properties) throws IOException {
errorString = null;
File f = new File(envDir + "/" + n + ".yml");
if (f.exists() && f.canRead()) {
try (InputStream fis = new FileInputStream(f)) {
Yaml yaml = new Yaml();
Iterable<Object> document = yaml.loadAll(fis);
document.forEach(d -> {
flat(properties, null, (Map<String, Object>) d, false);
});
propRef.set(properties);
return true;
} catch (ScannerException e) {
errorString = "Environment (" + getName() + ") error " + e.getMessage();
}
}
return false;
}
use of org.yaml.snakeyaml.scanner.ScannerException in project winery by eclipse.
the class YamlReader method readServiceTemplate.
/**
* Reads a file and converts it to a ServiceTemplate
*
* @return ServiceTemplate
* @throws MultiException the ServiceTemplate or the file is invalid.
*/
private YTServiceTemplate readServiceTemplate(InputStream inputStream, String namespace) throws MultiException {
Object object = null;
// pre parse checking
try {
object = readObjectFromInputStream(inputStream);
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(object);
} catch (ConstructorException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (ScannerException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (InvalidToscaSyntax invalidToscaSyntax) {
invalidToscaSyntax.printStackTrace();
}
// parse checking
return buildServiceTemplate(object, namespace);
}
use of org.yaml.snakeyaml.scanner.ScannerException in project halyard by spinnaker.
the class HalconfigParser method getHalconfig.
/**
* Returns the current halconfig stored at the halconfigPath.
*
* @return the fully parsed halconfig.
* @see Halconfig
*/
public Halconfig getHalconfig() {
Halconfig local = (Halconfig) DaemonTaskHandler.getContext();
if (local == null) {
try {
InputStream is = getHalconfigStream();
local = parseHalconfig(is);
} catch (FileNotFoundException ignored) {
// leave res as `null`
} catch (ParserException e) {
throw new ParseConfigException(e);
} catch (ScannerException e) {
throw new ParseConfigException(e);
} catch (IllegalArgumentException e) {
throw new ParseConfigException(e);
}
}
local = transformHalconfig(local);
DaemonTaskHandler.setContext(local);
return local;
}
Aggregations