Search in sources :

Example 1 with Replace

use of com.google.copybara.transform.Replace in project copybara by google.

the class Core method mapImports.

@StarlarkMethod(name = "replace_mapper", doc = "A mapping function that applies a list of replaces until one replaces the text" + " (Unless `all = True` is used). This should be used with core.filter_replace or" + " other transformations that accept text mapping as parameter.", parameters = { @Param(name = "mapping", allowedTypes = { @ParamType(type = net.starlark.java.eval.Sequence.class, generic1 = Transformation.class) }, named = true, doc = "The list of core.replace transformations"), @Param(name = "all", named = true, positional = false, doc = "Run all the mappings despite a replace happens.", defaultValue = "False") })
public ReplaceMapper mapImports(// <Transformation>
net.starlark.java.eval.Sequence<?> mapping, Boolean all) throws EvalException {
    check(!mapping.isEmpty(), "Empty mapping is not allowed");
    ImmutableList.Builder<Replace> replaces = ImmutableList.builder();
    for (Transformation t : net.starlark.java.eval.Sequence.cast(mapping, Transformation.class, "mapping")) {
        check(t instanceof Replace, "Only core.replace can be used as mapping, but got: %S", t.describe());
        Replace replace = (Replace) t;
        check(replace.getPaths().equals(Glob.ALL_FILES), "core.replace cannot use" + " 'paths' inside core.replace_mapper");
        replaces.add(replace);
    }
    return new ReplaceMapper(replaces.build(), all);
}
Also used : Replace(com.google.copybara.transform.Replace) TodoReplace(com.google.copybara.transform.TodoReplace) FilterReplace(com.google.copybara.transform.FilterReplace) SkylarkTransformation(com.google.copybara.transform.SkylarkTransformation) Transformations.toTransformation(com.google.copybara.transform.Transformations.toTransformation) ReplaceMapper(com.google.copybara.transform.ReplaceMapper) ImmutableList(com.google.common.collect.ImmutableList) StarlarkMethod(net.starlark.java.annot.StarlarkMethod)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 FilterReplace (com.google.copybara.transform.FilterReplace)1 Replace (com.google.copybara.transform.Replace)1 ReplaceMapper (com.google.copybara.transform.ReplaceMapper)1 SkylarkTransformation (com.google.copybara.transform.SkylarkTransformation)1 TodoReplace (com.google.copybara.transform.TodoReplace)1 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1