use of alien4cloud.utils.version.InvalidVersionException in project alien4cloud by alien4cloud.
the class LaxImportParser method parse.
@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
String valueAsString = scalarParser.parse(node, context);
if (StringUtils.isNotBlank(valueAsString)) {
if (valueAsString.contains(":")) {
String[] dependencyStrs = valueAsString.split(":");
if (dependencyStrs.length == 2) {
String dependencyName = dependencyStrs[0];
String dependencyVersion = dependencyStrs[1];
// check that version has the righ format
try {
VersionUtil.parseVersion(dependencyVersion);
} catch (InvalidVersionException e) {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Version specified in the dependency is not a valid version.", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
return null;
}
return new CSARDependency(dependencyName, dependencyVersion);
}
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Import definition is not valid", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
} else {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Relative import is currently not supported in Alien 4 Cloud", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
}
}
return null;
}
Aggregations