Skip to content

Convert MavenFilteringHack, Groovy to Java #72058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.gradle;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.tools.ant.filters.ReplaceTokens;
import org.gradle.api.file.CopySpec;

/**
* Gradle provides "expansion" functionality using groovy's SimpleTemplatingEngine (TODO: check name).
* However, it allows substitutions of the form {@code $foo} (no curlies). Rest tests provide
* some substitution from the test runner, which this form is used for.
*
* This class provides a helper to do maven filtering, where only the form {@code $\{foo\}} is supported.
*
* TODO: we should get rid of this hack, and make the rest tests use some other identifier
* for builtin vars
*/
public class MavenFilteringHack {
/**
* Adds a filter to the given copy spec that will substitute maven variables.
*
*/
static void filter(CopySpec copySpec, Map<Object, Object> substitutions) {
Map<String, String> mavenSubstitutions = new LinkedHashMap<>();
Map<String, Object> argMap = new LinkedHashMap<>();

substitutions.forEach((k, v) -> mavenSubstitutions.put("{" + k.toString(), v.toString()));

argMap.put("tokens", mavenSubstitutions);
argMap.put("beginToken", "$");
argMap.put("endToken", "}");

copySpec.filter(argMap, ReplaceTokens.class);
}
}