mirror of https://github.com/apache/maven.git
[MNG-8515] Replace plexus interpolator with the new interpolator service
This commit is contained in:
parent
82f159adb9
commit
8af006a931
|
@ -18,10 +18,10 @@
|
|||
*/
|
||||
package org.apache.maven.api.cli;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
|
@ -201,11 +201,11 @@ public interface Options {
|
|||
/**
|
||||
* Returns a new instance of {@link Options} with values interpolated using the given properties.
|
||||
*
|
||||
* @param properties a collection of property maps to use for interpolation
|
||||
* @param callback the callback to use for interpolation
|
||||
* @return a new {@link Options} instance with interpolated values
|
||||
*/
|
||||
@Nonnull
|
||||
Options interpolate(@Nonnull Collection<Map<String, String>> properties);
|
||||
Options interpolate(@Nonnull Function<String, String> callback);
|
||||
|
||||
/**
|
||||
* Emits warning messages if deprecated options are used.
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
*/
|
||||
package org.apache.maven.api.cli.mvn;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
|
@ -217,11 +216,11 @@ public interface MavenOptions extends Options {
|
|||
Optional<List<String>> goals();
|
||||
|
||||
/**
|
||||
* Returns a new instance of {@link MavenOptions} with values interpolated using the given properties.
|
||||
* Returns a new instance of {@link MavenOptions} with values interpolated using the given callback.
|
||||
*
|
||||
* @param properties a collection of property maps to use for interpolation
|
||||
* @param callback a callback to use for interpolation
|
||||
* @return a new MavenOptions instance with interpolated values
|
||||
*/
|
||||
@Nonnull
|
||||
MavenOptions interpolate(@Nonnull Collection<Map<String, String>> properties);
|
||||
MavenOptions interpolate(@Nonnull Function<String, String> callback);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
*/
|
||||
package org.apache.maven.api.cli.mvnenc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
|
@ -61,9 +60,9 @@ public interface EncryptOptions extends Options {
|
|||
/**
|
||||
* Returns a new instance of EncryptOptions with values interpolated using the given properties.
|
||||
*
|
||||
* @param properties a collection of property maps to use for interpolation
|
||||
* @param callback a callback to use for interpolation
|
||||
* @return a new EncryptOptions instance with interpolated values
|
||||
*/
|
||||
@Nonnull
|
||||
EncryptOptions interpolate(Collection<Map<String, String>> properties);
|
||||
EncryptOptions interpolate(Function<String, String> callback);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
*/
|
||||
package org.apache.maven.api.cli.mvnsh;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
|
@ -36,9 +35,9 @@ public interface ShellOptions extends Options {
|
|||
/**
|
||||
* Returns a new instance of ShellOptions with values interpolated using the given properties.
|
||||
*
|
||||
* @param properties a collection of property maps to use for interpolation
|
||||
* @param callback a callback to use for interpolation
|
||||
* @return a new EncryptOptions instance with interpolated values
|
||||
*/
|
||||
@Nonnull
|
||||
ShellOptions interpolate(Collection<Map<String, String>> properties);
|
||||
ShellOptions interpolate(Function<String, String> callback);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.maven.api.cli.Parser;
|
|||
import org.apache.maven.api.cli.ParserException;
|
||||
import org.apache.maven.api.cli.ParserRequest;
|
||||
import org.apache.maven.api.cli.extensions.CoreExtension;
|
||||
import org.apache.maven.api.services.Interpolator;
|
||||
import org.apache.maven.cling.internal.extension.io.CoreExtensionsStaxReader;
|
||||
import org.apache.maven.cling.props.MavenPropertiesLoader;
|
||||
import org.apache.maven.cling.utils.CLIReportingUtils;
|
||||
|
@ -122,8 +123,8 @@ public abstract class BaseParser implements Parser {
|
|||
context.userProperties = populateUserProperties(context);
|
||||
|
||||
// options: interpolate
|
||||
context.options = context.options.interpolate(
|
||||
Arrays.asList(context.extraInterpolationSource(), context.userProperties, context.systemProperties));
|
||||
context.options = context.options.interpolate(Interpolator.chain(
|
||||
context.extraInterpolationSource()::get, context.userProperties::get, context.systemProperties::get));
|
||||
|
||||
// core extensions
|
||||
context.extensions = readCoreExtensionsDescriptor(context);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.maven.cling.invoker;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
@ -30,12 +29,11 @@ import java.util.function.Function;
|
|||
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
import org.apache.maven.api.annotations.Nullable;
|
||||
import org.apache.maven.api.services.Interpolator;
|
||||
import org.apache.maven.api.services.model.RootLocator;
|
||||
import org.apache.maven.cling.logging.Slf4jConfiguration;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.codehaus.plexus.interpolation.AbstractValueSource;
|
||||
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
|
||||
import org.apache.maven.internal.impl.model.DefaultInterpolator;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
@ -90,21 +88,8 @@ public final class Utils {
|
|||
}
|
||||
|
||||
@Nonnull
|
||||
public static BasicInterpolator createInterpolator(Collection<Map<String, String>> properties) {
|
||||
StringSearchInterpolator interpolator = new StringSearchInterpolator();
|
||||
interpolator.addValueSource(new AbstractValueSource(false) {
|
||||
@Override
|
||||
public Object getValue(String expression) {
|
||||
for (Map<String, String> props : properties) {
|
||||
String val = props.get(expression);
|
||||
if (val != null) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return interpolator;
|
||||
public static Interpolator createInterpolator() {
|
||||
return new DefaultInterpolator();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -19,19 +19,18 @@
|
|||
package org.apache.maven.cling.invoker.mvn;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||
import org.apache.maven.api.services.Interpolator;
|
||||
import org.apache.maven.api.services.InterpolatorException;
|
||||
import org.apache.maven.cling.invoker.CommonsCliOptions;
|
||||
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
|
||||
import static org.apache.maven.cling.invoker.Utils.createInterpolator;
|
||||
|
||||
|
@ -46,27 +45,27 @@ public class CommonsCliMavenOptions extends CommonsCliOptions implements MavenOp
|
|||
}
|
||||
|
||||
private static CommonsCliMavenOptions interpolate(
|
||||
CommonsCliMavenOptions options, Collection<Map<String, String>> properties) {
|
||||
CommonsCliMavenOptions options, Function<String, String> callback) {
|
||||
try {
|
||||
// now that we have properties, interpolate all arguments
|
||||
BasicInterpolator interpolator = createInterpolator(properties);
|
||||
Interpolator interpolator = createInterpolator();
|
||||
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
|
||||
commandLineBuilder.setDeprecatedHandler(o -> {});
|
||||
for (Option option : options.commandLine.getOptions()) {
|
||||
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
|
||||
List<String> values = option.getValuesList();
|
||||
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
|
||||
it.set(interpolator.interpolate(it.next()));
|
||||
it.set(interpolator.interpolate(it.next(), callback));
|
||||
}
|
||||
}
|
||||
commandLineBuilder.addOption(option);
|
||||
}
|
||||
for (String arg : options.commandLine.getArgList()) {
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg));
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg, callback));
|
||||
}
|
||||
return new CommonsCliMavenOptions(
|
||||
options.source, (CLIManager) options.cliManager, commandLineBuilder.build());
|
||||
} catch (InterpolationException e) {
|
||||
} catch (InterpolatorException e) {
|
||||
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
|
||||
}
|
||||
}
|
||||
|
@ -249,8 +248,8 @@ public class CommonsCliMavenOptions extends CommonsCliOptions implements MavenOp
|
|||
}
|
||||
|
||||
@Override
|
||||
public MavenOptions interpolate(Collection<Map<String, String>> properties) {
|
||||
return interpolate(this, properties);
|
||||
public MavenOptions interpolate(Function<String, String> callback) {
|
||||
return interpolate(this, callback);
|
||||
}
|
||||
|
||||
protected static class CLIManager extends CommonsCliOptions.CLIManager {
|
||||
|
|
|
@ -21,9 +21,9 @@ package org.apache.maven.cling.invoker.mvn;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||
import org.apache.maven.cling.invoker.LayeredOptions;
|
||||
|
@ -160,10 +160,10 @@ public class LayeredMavenOptions<O extends MavenOptions> extends LayeredOptions<
|
|||
}
|
||||
|
||||
@Override
|
||||
public MavenOptions interpolate(Collection<Map<String, String>> properties) {
|
||||
public MavenOptions interpolate(Function<String, String> callback) {
|
||||
ArrayList<MavenOptions> interpolatedOptions = new ArrayList<>(options.size());
|
||||
for (MavenOptions o : options) {
|
||||
interpolatedOptions.add(o.interpolate(properties));
|
||||
interpolatedOptions.add(o.interpolate(callback));
|
||||
}
|
||||
return layerMavenOptions(interpolatedOptions);
|
||||
}
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
*/
|
||||
package org.apache.maven.cling.invoker.mvnenc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Option;
|
||||
|
@ -31,9 +30,9 @@ import org.apache.commons.cli.ParseException;
|
|||
import org.apache.maven.api.cli.Options;
|
||||
import org.apache.maven.api.cli.ParserRequest;
|
||||
import org.apache.maven.api.cli.mvnenc.EncryptOptions;
|
||||
import org.apache.maven.api.services.Interpolator;
|
||||
import org.apache.maven.api.services.InterpolatorException;
|
||||
import org.apache.maven.cling.invoker.CommonsCliOptions;
|
||||
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
|
||||
import static org.apache.maven.cling.invoker.Utils.createInterpolator;
|
||||
|
||||
|
@ -51,27 +50,27 @@ public class CommonsCliEncryptOptions extends CommonsCliOptions implements Encry
|
|||
}
|
||||
|
||||
private static CommonsCliEncryptOptions interpolate(
|
||||
CommonsCliEncryptOptions options, Collection<Map<String, String>> properties) {
|
||||
CommonsCliEncryptOptions options, Function<String, String> callback) {
|
||||
try {
|
||||
// now that we have properties, interpolate all arguments
|
||||
BasicInterpolator interpolator = createInterpolator(properties);
|
||||
Interpolator interpolator = createInterpolator();
|
||||
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
|
||||
commandLineBuilder.setDeprecatedHandler(o -> {});
|
||||
for (Option option : options.commandLine.getOptions()) {
|
||||
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
|
||||
List<String> values = option.getValuesList();
|
||||
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
|
||||
it.set(interpolator.interpolate(it.next()));
|
||||
it.set(interpolator.interpolate(it.next(), callback));
|
||||
}
|
||||
}
|
||||
commandLineBuilder.addOption(option);
|
||||
}
|
||||
for (String arg : options.commandLine.getArgList()) {
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg));
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg, callback));
|
||||
}
|
||||
return new CommonsCliEncryptOptions(
|
||||
options.source, (CLIManager) options.cliManager, commandLineBuilder.build());
|
||||
} catch (InterpolationException e) {
|
||||
} catch (InterpolatorException e) {
|
||||
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
|
||||
}
|
||||
}
|
||||
|
@ -101,8 +100,8 @@ public class CommonsCliEncryptOptions extends CommonsCliOptions implements Encry
|
|||
}
|
||||
|
||||
@Override
|
||||
public EncryptOptions interpolate(Collection<Map<String, String>> properties) {
|
||||
return interpolate(this, properties);
|
||||
public EncryptOptions interpolate(Function<String, String> callback) {
|
||||
return interpolate(this, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,19 +18,18 @@
|
|||
*/
|
||||
package org.apache.maven.cling.invoker.mvnsh;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.api.cli.Options;
|
||||
import org.apache.maven.api.cli.mvnsh.ShellOptions;
|
||||
import org.apache.maven.api.services.Interpolator;
|
||||
import org.apache.maven.api.services.InterpolatorException;
|
||||
import org.apache.maven.cling.invoker.CommonsCliOptions;
|
||||
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
|
||||
import static org.apache.maven.cling.invoker.Utils.createInterpolator;
|
||||
|
||||
|
@ -48,34 +47,34 @@ public class CommonsCliShellOptions extends CommonsCliOptions implements ShellOp
|
|||
}
|
||||
|
||||
private static CommonsCliShellOptions interpolate(
|
||||
CommonsCliShellOptions options, Collection<Map<String, String>> properties) {
|
||||
CommonsCliShellOptions options, Function<String, String> callback) {
|
||||
try {
|
||||
// now that we have properties, interpolate all arguments
|
||||
BasicInterpolator interpolator = createInterpolator(properties);
|
||||
Interpolator interpolator = createInterpolator();
|
||||
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
|
||||
commandLineBuilder.setDeprecatedHandler(o -> {});
|
||||
for (Option option : options.commandLine.getOptions()) {
|
||||
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
|
||||
List<String> values = option.getValuesList();
|
||||
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
|
||||
it.set(interpolator.interpolate(it.next()));
|
||||
it.set(interpolator.interpolate(it.next(), callback));
|
||||
}
|
||||
}
|
||||
commandLineBuilder.addOption(option);
|
||||
}
|
||||
for (String arg : options.commandLine.getArgList()) {
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg));
|
||||
commandLineBuilder.addArg(interpolator.interpolate(arg, callback));
|
||||
}
|
||||
return new CommonsCliShellOptions(
|
||||
options.source, (CLIManager) options.cliManager, commandLineBuilder.build());
|
||||
} catch (InterpolationException e) {
|
||||
} catch (InterpolatorException e) {
|
||||
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellOptions interpolate(Collection<Map<String, String>> properties) {
|
||||
return interpolate(this, properties);
|
||||
public ShellOptions interpolate(Function<String, String> callback) {
|
||||
return interpolate(this, callback);
|
||||
}
|
||||
|
||||
protected static class CLIManager extends CommonsCliOptions.CLIManager {
|
||||
|
|
Loading…
Reference in New Issue