mirror of https://github.com/apache/maven.git
[MNG-7395] Support interpolation in extensions.xml
This adds support for property interpolation in extensions.xml to allow advanced use cases where one wants to contribute certain things via the commandline. This closes #665
This commit is contained in:
parent
62cf29bab3
commit
2798ee9196
|
@ -40,6 +40,10 @@ import org.codehaus.plexus.DefaultPlexusContainer;
|
|||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.Interpolator;
|
||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
|
@ -83,14 +87,16 @@ public class BootstrapCoreExtensionManager
|
|||
{
|
||||
RepositorySystemSession repoSession = repositorySystemSessionFactory.newRepositorySession( request );
|
||||
List<RemoteRepository> repositories = RepositoryUtils.toRepos( request.getPluginArtifactRepositories() );
|
||||
Interpolator interpolator = createInterpolator( request );
|
||||
|
||||
return resolveCoreExtensions( repoSession, repositories, providedArtifacts, extensions );
|
||||
return resolveCoreExtensions( repoSession, repositories, providedArtifacts, extensions, interpolator );
|
||||
}
|
||||
|
||||
private List<CoreExtensionEntry> resolveCoreExtensions( RepositorySystemSession repoSession,
|
||||
List<RemoteRepository> repositories,
|
||||
Set<String> providedArtifacts,
|
||||
List<CoreExtension> configuration )
|
||||
List<CoreExtension> configuration,
|
||||
Interpolator interpolator )
|
||||
throws Exception
|
||||
{
|
||||
List<CoreExtensionEntry> extensions = new ArrayList<>();
|
||||
|
@ -99,7 +105,8 @@ public class BootstrapCoreExtensionManager
|
|||
|
||||
for ( CoreExtension extension : configuration )
|
||||
{
|
||||
List<Artifact> artifacts = resolveExtension( extension, repoSession, repositories, dependencyFilter );
|
||||
List<Artifact> artifacts = resolveExtension( extension, repoSession, repositories,
|
||||
dependencyFilter, interpolator );
|
||||
if ( !artifacts.isEmpty() )
|
||||
{
|
||||
extensions.add( createExtension( extension, artifacts ) );
|
||||
|
@ -127,18 +134,20 @@ public class BootstrapCoreExtensionManager
|
|||
}
|
||||
|
||||
private List<Artifact> resolveExtension( CoreExtension extension, RepositorySystemSession repoSession,
|
||||
List<RemoteRepository> repositories, DependencyFilter dependencyFilter )
|
||||
List<RemoteRepository> repositories, DependencyFilter dependencyFilter,
|
||||
Interpolator interpolator )
|
||||
throws ExtensionResolutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: enhance the PluginDependenciesResolver to provide a
|
||||
// TODO: resolveCoreExtension method which uses a CoreExtension
|
||||
// TODO: object instead of a Plugin as this makes no sense
|
||||
/* TODO: Enhance the PluginDependenciesResolver to provide a
|
||||
* resolveCoreExtension method which uses a CoreExtension
|
||||
* object instead of a Plugin as this makes no sense.
|
||||
*/
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setGroupId( extension.getGroupId() );
|
||||
plugin.setArtifactId( extension.getArtifactId() );
|
||||
plugin.setVersion( extension.getVersion() );
|
||||
plugin.setGroupId( interpolator.interpolate( extension.getGroupId() ) );
|
||||
plugin.setArtifactId( interpolator.interpolate( extension.getArtifactId() ) );
|
||||
plugin.setVersion( interpolator.interpolate( extension.getVersion() ) );
|
||||
|
||||
DependencyNode root = pluginDependenciesResolver
|
||||
.resolveCoreExtension( plugin, dependencyFilter, repositories, repoSession );
|
||||
|
@ -151,6 +160,18 @@ public class BootstrapCoreExtensionManager
|
|||
{
|
||||
throw new ExtensionResolutionException( extension, e.getCause() );
|
||||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
throw new ExtensionResolutionException( extension, e );
|
||||
}
|
||||
}
|
||||
|
||||
private static Interpolator createInterpolator( MavenExecutionRequest request )
|
||||
{
|
||||
StringSearchInterpolator interpolator = new StringSearchInterpolator();
|
||||
interpolator.addValueSource( new MapBasedValueSource( request.getUserProperties() ) );
|
||||
interpolator.addValueSource( new MapBasedValueSource( request.getSystemProperties() ) );
|
||||
return interpolator;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue