Search in sources :

Example 1 with InvalidVersionException

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;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) InvalidVersionException(alien4cloud.utils.version.InvalidVersionException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Aggregations

ParsingError (alien4cloud.tosca.parser.ParsingError)1 InvalidVersionException (alien4cloud.utils.version.InvalidVersionException)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1