[MNG-7891] Abstract ExtensionConfigurationModule from CliRequest (#1272)

Follow-up to MNG-7891 to make Maven Daemon integration easier.
This commit is contained in:
Guillaume Nodet 2023-10-17 19:53:33 +02:00 committed by GitHub
parent 80a8e41540
commit 32d67322ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -18,6 +18,8 @@
*/
package org.apache.maven.cli;
import java.util.Arrays;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.name.Names;
@ -28,17 +30,17 @@ import org.apache.maven.internal.xml.XmlPlexusConfiguration;
import org.apache.maven.model.v4.MavenTransformer;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.codehaus.plexus.interpolation.ValueSource;
class ExtensionConfigurationModule implements Module {
public class ExtensionConfigurationModule implements Module {
private final CoreExtensionEntry extension;
private final CliRequest cliRequest;
private final Iterable<ValueSource> valueSources;
ExtensionConfigurationModule(CoreExtensionEntry extension, CliRequest cliRequest) {
public ExtensionConfigurationModule(CoreExtensionEntry extension, ValueSource... valueSources) {
this.extension = extension;
this.cliRequest = cliRequest;
this.valueSources = Arrays.asList(valueSources);
}
@Override
@ -66,8 +68,7 @@ class ExtensionConfigurationModule implements Module {
super(null);
interpolator = new StringSearchInterpolator();
interpolator.setCacheAnswers(true);
interpolator.addValueSource(new PropertiesBasedValueSource(cliRequest.userProperties));
interpolator.addValueSource(new PropertiesBasedValueSource(cliRequest.systemProperties));
valueSources.forEach(interpolator::addValueSource);
}
public XmlNode transform(XmlNode node) {

View File

@ -690,12 +690,22 @@ public class MavenCli {
container.setLoggerManager(plexusLoggerManager);
AbstractValueSource extensionSource = new AbstractValueSource(false) {
@Override
public Object getValue(String expression) {
Object value = cliRequest.userProperties.getProperty(expression);
if (value == null) {
value = cliRequest.systemProperties.getProperty(expression);
}
return value;
}
};
for (CoreExtensionEntry extension : extensions) {
container.discoverComponents(
extension.getClassRealm(),
new SessionScopeModule(container),
new MojoExecutionScopeModule(container),
new ExtensionConfigurationModule(extension, cliRequest));
new ExtensionConfigurationModule(extension, extensionSource));
}
customizeContainer(container);