Search in sources :

Example 1 with Parser

use of com.google.copybara.templatetoken.Parser in project copybara by google.

the class Core method getChangeIdentity.

private static ImmutableList<Token> getChangeIdentity(Object changeIdentityObj) throws EvalException {
    String changeIdentity = convertFromNoneable(changeIdentityObj, null);
    if (changeIdentity == null) {
        return ImmutableList.of();
    }
    ImmutableList<Token> result = new Parser().parse(changeIdentity);
    boolean configVarFound = false;
    for (Token token : result) {
        if (token.getType() != TokenType.INTERPOLATION) {
            continue;
        }
        if (token.getValue().equals(COPYBARA_CONFIG_PATH_IDENTITY_VAR)) {
            configVarFound = true;
            continue;
        }
        if (token.getValue().equals(Workflow.COPYBARA_WORKFLOW_NAME_IDENTITY_VAR) || token.getValue().equals(Workflow.COPYBARA_REFERENCE_IDENTITY_VAR) || token.getValue().startsWith(Workflow.COPYBARA_REFERENCE_LABEL_VAR)) {
            continue;
        }
        throw Starlark.errorf("Unrecognized variable: %s", token.getValue());
    }
    check(configVarFound, "${%s} variable is required", COPYBARA_CONFIG_PATH_IDENTITY_VAR);
    return result;
}
Also used : Token(com.google.copybara.templatetoken.Token) Parser(com.google.copybara.templatetoken.Parser)

Example 2 with Parser

use of com.google.copybara.templatetoken.Parser in project copybara by google.

the class Core method getChangeIdentity.

private static ImmutableList<Token> getChangeIdentity(Object changeIdentityObj, Location location) throws EvalException {
    String changeIdentity = SkylarkUtil.convertFromNoneable(changeIdentityObj, null);
    if (changeIdentity == null) {
        return ImmutableList.of();
    }
    ImmutableList<Token> result = new Parser(location).parse(changeIdentity);
    boolean configVarFound = false;
    for (Token token : result) {
        if (token.getType() != TokenType.INTERPOLATION) {
            continue;
        }
        if (token.getValue().equals(Workflow.COPYBARA_CONFIG_PATH_IDENTITY_VAR)) {
            configVarFound = true;
            continue;
        }
        if (token.getValue().equals(Workflow.COPYBARA_WORKFLOW_NAME_IDENTITY_VAR) || token.getValue().equals(Workflow.COPYBARA_REFERENCE_IDENTITY_VAR) || token.getValue().startsWith(Workflow.COPYBARA_REFERENCE_LABEL_VAR)) {
            continue;
        }
        throw new EvalException(location, String.format("Unrecognized variable: %s", token.getValue()));
    }
    if (!configVarFound) {
        throw new EvalException(location, String.format("${%s} variable is required", Workflow.COPYBARA_CONFIG_PATH_IDENTITY_VAR));
    }
    return result;
}
Also used : Token(com.google.copybara.templatetoken.Token) EvalException(com.google.devtools.build.lib.syntax.EvalException) Parser(com.google.copybara.templatetoken.Parser)

Aggregations

Parser (com.google.copybara.templatetoken.Parser)2 Token (com.google.copybara.templatetoken.Token)2 EvalException (com.google.devtools.build.lib.syntax.EvalException)1