diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java index 29d1ec399b1..e02a6752920 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java @@ -108,6 +108,8 @@ public class BootstrapCoreExtensionManager { private final RepositorySystem repoSystem; + private final Interpolator interpolator; + @Inject public BootstrapCoreExtensionManager( DefaultPluginDependenciesResolver pluginDependenciesResolver, @@ -115,7 +117,8 @@ public BootstrapCoreExtensionManager( CoreExports coreExports, PlexusContainer container, @Nullable @Named("ide") WorkspaceReader ideWorkspaceReader, - RepositorySystem repoSystem) { + RepositorySystem repoSystem, + Interpolator interpolator) { this.pluginDependenciesResolver = pluginDependenciesResolver; this.repositorySystemSessionFactory = repositorySystemSessionFactory; this.coreExports = coreExports; @@ -123,6 +126,7 @@ public BootstrapCoreExtensionManager( this.parentRealm = container.getContainerRealm(); this.ideWorkspaceReader = ideWorkspaceReader; this.repoSystem = repoSystem; + this.interpolator = interpolator; } public List loadCoreExtensions( @@ -230,8 +234,7 @@ private List resolveExtension( } } - private static UnaryOperator createInterpolator(MavenExecutionRequest request) { - Interpolator interpolator = new DefaultInterpolator(); + private UnaryOperator createInterpolator(MavenExecutionRequest request) { UnaryOperator callback = v -> { String r = request.getUserProperties().getProperty(v); if (r == null) { diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/ExtensionConfigurationModule.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/ExtensionConfigurationModule.java index d686577bff7..4a60c67a299 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/ExtensionConfigurationModule.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/ExtensionConfigurationModule.java @@ -36,6 +36,7 @@ public class ExtensionConfigurationModule implements Module { private final CoreExtensionEntry extension; private final UnaryOperator callback; + private final DefaultInterpolator interpolator = new DefaultInterpolator(); public ExtensionConfigurationModule(CoreExtensionEntry extension, UnaryOperator callback) { diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java index 0d63698b357..175eb7bc154 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java @@ -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.impl.model.DefaultInterpolator; import org.apache.maven.settings.v4.SettingsMerger; import org.apache.maven.settings.v4.SettingsTransformer; import org.codehaus.plexus.components.secdispatcher.Dispatcher; @@ -77,13 +76,6 @@ public class DefaultSettingsBuilder implements SettingsBuilder { private final Map 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. */ diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java index 0a5507763fa..f2ce5abd5f8 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultToolchainsBuilder.java @@ -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.impl.model.DefaultInterpolator; import org.apache.maven.toolchain.v4.MavenToolchainsMerger; import org.apache.maven.toolchain.v4.MavenToolchainsTransformer; @@ -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; diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionProfileActivator.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionProfileActivator.java index 5042986d688..95d1be2f4fa 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionProfileActivator.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionProfileActivator.java @@ -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.impl.model.DefaultInterpolator; import static org.apache.maven.impl.model.profile.ConditionParser.toBoolean; @@ -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; } /** @@ -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 registerFunctions( + public Map registerFunctions( ProfileActivationContext context, VersionParser versionParser) { Map functions = new HashMap<>(); @@ -156,9 +160,9 @@ public static Map 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) { diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java index db3d0c33e00..32c6e76005b 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java @@ -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.impl.model.DefaultInterpolator; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -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() diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java index 8a5a5b2a6a6..a1b5028806b 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsValidatorTest.java @@ -19,6 +19,7 @@ package org.apache.maven.impl; import java.util.List; +import java.util.Map; import org.apache.maven.api.services.BuilderProblem; import org.apache.maven.api.services.ProblemCollector; @@ -26,6 +27,7 @@ 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.impl.model.DefaultInterpolator; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,7 +43,7 @@ class DefaultSettingsValidatorTest { @BeforeEach void setUp() throws Exception { - validator = new DefaultSettingsBuilder(); + validator = new DefaultSettingsBuilder(new DefaultSettingsXmlFactory(), new DefaultInterpolator(), Map.of()); } @AfterEach diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java index 0d9c2f9c559..59765701a3d 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java @@ -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); } diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java index 47ad359f645..9086341df88 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionProfileActivatorTest.java @@ -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);