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;
}
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;
}
Aggregations