Skip to content
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

[MNG-8524] DefaultInterpolator should be used by injection #2049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,25 @@ public class BootstrapCoreExtensionManager {

private final RepositorySystem repoSystem;

private final Interpolator interpolator;

@Inject
public BootstrapCoreExtensionManager(
DefaultPluginDependenciesResolver pluginDependenciesResolver,
RepositorySystemSessionFactory repositorySystemSessionFactory,
CoreExports coreExports,
PlexusContainer container,
@Nullable @Named("ide") WorkspaceReader ideWorkspaceReader,
RepositorySystem repoSystem) {
RepositorySystem repoSystem,
Interpolator interpolator) {
this.pluginDependenciesResolver = pluginDependenciesResolver;
this.repositorySystemSessionFactory = repositorySystemSessionFactory;
this.coreExports = coreExports;
this.classWorld = ((DefaultPlexusContainer) container).getClassWorld();
this.parentRealm = container.getContainerRealm();
this.ideWorkspaceReader = ideWorkspaceReader;
this.repoSystem = repoSystem;
this.interpolator = interpolator;
}

public List<CoreExtensionEntry> loadCoreExtensions(
Expand Down Expand Up @@ -230,8 +234,7 @@ private List<Artifact> resolveExtension(
}
}

private static UnaryOperator<String> createInterpolator(MavenExecutionRequest request) {
Interpolator interpolator = new DefaultInterpolator();
private UnaryOperator<String> createInterpolator(MavenExecutionRequest request) {
UnaryOperator<String> callback = v -> {
String r = request.getUserProperties().getProperty(v);
if (r == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ExtensionConfigurationModule implements Module {

private final CoreExtensionEntry extension;
private final UnaryOperator<String> callback;

private final DefaultInterpolator interpolator = new DefaultInterpolator();

public ExtensionConfigurationModule(CoreExtensionEntry extension, UnaryOperator<String> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.apache.maven.api.settings.RepositoryPolicy;
import org.apache.maven.api.settings.Server;
import org.apache.maven.api.settings.Settings;
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.settings.v4.SettingsMerger;
import org.apache.maven.settings.v4.SettingsTransformer;
import org.codehaus.plexus.components.secdispatcher.Dispatcher;
Expand All @@ -77,13 +76,6 @@ public class DefaultSettingsBuilder implements SettingsBuilder {

private final Map<String, Dispatcher> dispatchers;

/**
* This ctor is used in legacy components.
*/
public DefaultSettingsBuilder() {
this(new DefaultSettingsXmlFactory(), new DefaultInterpolator(), Map.of());
}

/**
* In Maven4 the {@link SecDispatcher} is injected and build settings are fully decrypted as well.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.maven.api.services.xml.XmlReaderException;
import org.apache.maven.api.services.xml.XmlReaderRequest;
import org.apache.maven.api.toolchain.PersistedToolchains;
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.toolchain.v4.MavenToolchainsMerger;
import org.apache.maven.toolchain.v4.MavenToolchainsTransformer;

Expand All @@ -57,10 +56,6 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder {

private final ToolchainsXmlFactory toolchainsXmlFactory;

public DefaultToolchainsBuilder() {
this(new DefaultInterpolator(), new DefaultToolchainsXmlFactory());
}

@Inject
public DefaultToolchainsBuilder(Interpolator interpolator, ToolchainsXmlFactory toolchainsXmlFactory) {
this.interpolator = interpolator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.Profile;
import org.apache.maven.api.services.BuilderProblem.Severity;
import org.apache.maven.api.services.Interpolator;
import org.apache.maven.api.services.ModelProblem.Version;
import org.apache.maven.api.services.ModelProblemCollector;
import org.apache.maven.api.services.VersionParser;
import org.apache.maven.api.services.model.ProfileActivationContext;
import org.apache.maven.api.services.model.ProfileActivator;
import org.apache.maven.internal.impl.model.DefaultInterpolator;

import static org.apache.maven.internal.impl.model.profile.ConditionParser.toBoolean;

Expand All @@ -47,14 +47,18 @@ public class ConditionProfileActivator implements ProfileActivator {

private final VersionParser versionParser;

private final Interpolator interpolator;

/**
* Constructs a new ConditionProfileActivator with the necessary dependencies.
*
* @param versionParser The parser for handling version comparisons
* @param interpolator The interpolator for interpolating the values in the given map using the provided callback function
*/
@Inject
public ConditionProfileActivator(VersionParser versionParser) {
public ConditionProfileActivator(VersionParser versionParser, Interpolator interpolator) {
this.versionParser = versionParser;
this.interpolator = interpolator;
}

/**
Expand Down Expand Up @@ -106,7 +110,7 @@ public boolean presentInConfig(Profile profile, ProfileActivationContext context
* @param versionParser The parser for handling version comparisons
* @return A map of function names to their implementations
*/
public static Map<String, ConditionParser.ExpressionFunction> registerFunctions(
public Map<String, ConditionParser.ExpressionFunction> registerFunctions(
ProfileActivationContext context, VersionParser versionParser) {
Map<String, ConditionParser.ExpressionFunction> functions = new HashMap<>();

Expand Down Expand Up @@ -156,9 +160,9 @@ public static Map<String, ConditionParser.ExpressionFunction> registerFunctions(
* @return The value of the property, or null if not found
* @throws IllegalArgumentException if the number of arguments is not exactly one
*/
static String property(ProfileActivationContext context, String name) {
String property(ProfileActivationContext context, String name) {
String value = doGetProperty(context, name);
return new DefaultInterpolator().interpolate(value, s -> doGetProperty(context, s));
return interpolator.interpolate(value, s -> doGetProperty(context, s));
}

static String doGetProperty(ProfileActivationContext context, String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.api.services.SettingsBuilderResult;
import org.apache.maven.api.services.Source;
import org.apache.maven.api.services.xml.SettingsXmlFactory;
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -61,7 +62,8 @@ void setup() {

@Test
void testCompleteWiring() {
SettingsBuilder builder = new DefaultSettingsBuilder();
SettingsBuilder builder =
new DefaultSettingsBuilder(new DefaultSettingsXmlFactory(), new DefaultInterpolator(), Map.of());
assertNotNull(builder);

SettingsBuilderRequest request = SettingsBuilderRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
package org.apache.maven.internal.impl;

import java.util.List;
import java.util.Map;

import org.apache.maven.api.services.BuilderProblem;
import org.apache.maven.api.services.ProblemCollector;
import org.apache.maven.api.services.SettingsBuilder;
import org.apache.maven.api.settings.Profile;
import org.apache.maven.api.settings.Repository;
import org.apache.maven.api.settings.Settings;
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -41,7 +43,7 @@ class DefaultSettingsValidatorTest {

@BeforeEach
void setUp() throws Exception {
validator = new DefaultSettingsBuilder();
validator = new DefaultSettingsBuilder(new DefaultSettingsXmlFactory(), new DefaultInterpolator(), Map.of());
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ void setUp() {
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme()));
DefaultRootLocator rootLocator = new DefaultRootLocator();

functions = ConditionProfileActivator.registerFunctions(context, versionParser);
propertyResolver = s -> ConditionProfileActivator.property(context, s);
ConditionProfileActivator activator = new ConditionProfileActivator(versionParser, new DefaultInterpolator());
functions = activator.registerFunctions(context, versionParser);
propertyResolver = s -> activator.property(context, s);
parser = new ConditionParser(functions, propertyResolver);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
@Override
void setUp() throws Exception {
activator = new ConditionProfileActivator(
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())));
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())),
new DefaultInterpolator());

Path file = tempDir.resolve("file.txt");
Files.createFile(file);
Expand Down
Loading