mirror of https://github.com/apache/maven.git
Fixing MNG-3355 and MNG-2339.
This commit introduces three changes: user-level properties that are separated from the execution properties, where execution properties contain envars, sysprops, and user-level properties...user-level properties are useful for POM interpolation for 2339 and 3355. Second, a ProjectBuilderConfiguration interface and default implementation, to stem the proliferation of method parameters to projectBuilder methods. This was a natural place to introduce it, as user-level properties had to be passed in separately from the execution properties, for interpolation. Finally, interpolation has been switched to use the new plexus-interpolation project, which is based on the classes in plexus-utils. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@644354 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
05e92de35e
commit
1d9d014cde
|
@ -23,9 +23,9 @@ public aspect MavenExecErrorReporterAspect
|
|||
execution( List DefaultMaven.getProjects( MavenExecutionRequest ) )
|
||||
&& args( request );
|
||||
|
||||
private pointcut dm_collectProjects( ArtifactRepository localRepository, ProfileManager globalProfileManager ):
|
||||
execution( List DefaultMaven.collectProjects( List, ArtifactRepository, boolean, ProfileManager, boolean ) )
|
||||
&& args( *, localRepository, *, globalProfileManager, * );
|
||||
private pointcut dm_collectProjects( MavenExecutionRequest request ):
|
||||
execution( List DefaultMaven.collectProjects( List, MavenExecutionRequest, boolean ) )
|
||||
&& args( *, request, * );
|
||||
|
||||
private MavenProject currentProject;
|
||||
private ArtifactVersion mavenVersion;
|
||||
|
@ -40,7 +40,7 @@ public aspect MavenExecErrorReporterAspect
|
|||
|
||||
MavenProject around()
|
||||
throws ProjectBuildingException:
|
||||
cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) )
|
||||
cflow( dm_collectProjects( MavenExecutionRequest ) )
|
||||
&& within( DefaultMaven )
|
||||
&& call( MavenProject MavenProjectBuilder+.build( .. ) )
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ public aspect MavenExecErrorReporterAspect
|
|||
|
||||
MavenExecutionException around():
|
||||
cflow( dm_getProjects( MavenExecutionRequest ) )
|
||||
&& cflow( dm_collectProjects( ArtifactRepository, ProfileManager ) )
|
||||
&& cflow( dm_collectProjects( MavenExecutionRequest ) )
|
||||
&& call( MavenExecutionException.new( String, File ) )
|
||||
{
|
||||
MavenExecutionException err = proceed();
|
||||
|
@ -67,7 +67,7 @@ public aspect MavenExecErrorReporterAspect
|
|||
getReporter().reportMissingModulePom( err );
|
||||
}
|
||||
|
||||
after(): dm_collectProjects( ArtifactRepository, ProfileManager )
|
||||
after(): dm_collectProjects( MavenExecutionRequest )
|
||||
{
|
||||
currentProject = null;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
|
@ -36,7 +35,6 @@
|
|||
import org.apache.maven.monitor.event.DeprecationEventDispatcher;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
@ -106,7 +104,7 @@ public ReactorManager createReactorManager( MavenExecutionRequest request,
|
|||
|
||||
if ( projects.isEmpty() )
|
||||
{
|
||||
projects.add( projectBuilder.buildStandaloneSuperProject( request.getProfileManager() ) );
|
||||
projects.add( projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingConfiguration() ) );
|
||||
|
||||
request.setProjectPresent( false );
|
||||
}
|
||||
|
@ -281,15 +279,13 @@ private List getProjects( MavenExecutionRequest request )
|
|||
throw new MavenExecutionException( "Error scanning for extensions: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), request.getProfileManager(), !request.useReactor() );
|
||||
projects = collectProjects( files, request, !request.useReactor() );
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
private List collectProjects( List files,
|
||||
ArtifactRepository localRepository,
|
||||
boolean recursive,
|
||||
ProfileManager globalProfileManager,
|
||||
MavenExecutionRequest request,
|
||||
boolean isRoot )
|
||||
throws MavenExecutionException
|
||||
{
|
||||
|
@ -313,7 +309,7 @@ private List collectProjects( List files,
|
|||
MavenProject project;
|
||||
try
|
||||
{
|
||||
project = projectBuilder.build( file, localRepository, globalProfileManager );
|
||||
project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
|
@ -337,7 +333,7 @@ private List collectProjects( List files,
|
|||
}
|
||||
}
|
||||
|
||||
if ( ( project.getModules() != null ) && !project.getModules().isEmpty() && recursive )
|
||||
if ( ( project.getModules() != null ) && !project.getModules().isEmpty() && request.isRecursive() )
|
||||
{
|
||||
// TODO: Really should fail if it was not? What if it is aggregating - eg "ear"?
|
||||
project.setPackaging( "pom" );
|
||||
|
@ -396,8 +392,7 @@ else if ( moduleFile.isDirectory() )
|
|||
moduleFiles.add( moduleFile );
|
||||
}
|
||||
|
||||
List collectedProjects = collectProjects( moduleFiles, localRepository, recursive,
|
||||
globalProfileManager, false );
|
||||
List collectedProjects = collectProjects( moduleFiles, request, false );
|
||||
|
||||
projects.addAll( collectedProjects );
|
||||
project.setCollectedProjects( collectedProjects );
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.wagon.events.TransferListener;
|
||||
|
@ -92,6 +94,8 @@ public class DefaultMavenExecutionRequest
|
|||
|
||||
private Properties properties;
|
||||
|
||||
private Properties userProperties;
|
||||
|
||||
private Date startTime;
|
||||
|
||||
private boolean showErrors = false;
|
||||
|
@ -361,6 +365,13 @@ public MavenExecutionRequest setProperty( String key, String value )
|
|||
|
||||
properties.setProperty( key, value );
|
||||
|
||||
if ( userProperties == null )
|
||||
{
|
||||
userProperties = new Properties();
|
||||
}
|
||||
|
||||
userProperties.setProperty( key, value );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -579,6 +590,9 @@ public MavenExecutionRequest setRecursive( boolean recursive )
|
|||
|
||||
private ProfileActivationContext profileActivationContext;
|
||||
|
||||
// calculated from request attributes.
|
||||
private ProjectBuilderConfiguration projectBuildingConfiguration;
|
||||
|
||||
public MavenExecutionRequest setSettings( Settings settings )
|
||||
{
|
||||
this.settings = settings;
|
||||
|
@ -708,4 +722,29 @@ public MavenExecutionRequest setWorkspaceMonitor( MavenWorkspaceMonitor workspac
|
|||
this.workspaceMonitor = workspaceMonitor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Properties getUserProperties()
|
||||
{
|
||||
return userProperties;
|
||||
}
|
||||
|
||||
public MavenExecutionRequest setUserProperties( Properties userProperties )
|
||||
{
|
||||
this.userProperties = userProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectBuilderConfiguration getProjectBuildingConfiguration()
|
||||
{
|
||||
if ( projectBuildingConfiguration == null )
|
||||
{
|
||||
projectBuildingConfiguration = new DefaultProjectBuilderConfiguration();
|
||||
projectBuildingConfiguration.setLocalRepository( getLocalRepository() );
|
||||
projectBuildingConfiguration.setExecutionProperties( getProperties() );
|
||||
projectBuildingConfiguration.setGlobalProfileManager( getProfileManager() );
|
||||
projectBuildingConfiguration.setUserProperties( getUserProperties() );
|
||||
}
|
||||
|
||||
return projectBuildingConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.wagon.events.TransferListener;
|
||||
|
@ -97,6 +98,9 @@ public interface MavenExecutionRequest
|
|||
MavenExecutionRequest setProperty( String key, String value );
|
||||
Properties getProperties();
|
||||
|
||||
MavenExecutionRequest setUserProperties( Properties userProperties );
|
||||
Properties getUserProperties();
|
||||
|
||||
// Reactor
|
||||
MavenExecutionRequest setReactorFailureBehavior( String failureBehavior );
|
||||
String getReactorFailureBehavior();
|
||||
|
@ -220,4 +224,6 @@ public interface MavenExecutionRequest
|
|||
|
||||
MavenExecutionRequest setWorkspaceMonitor( MavenWorkspaceMonitor workspaceMonitor );
|
||||
MavenWorkspaceMonitor getWorkspaceMonitor();
|
||||
|
||||
ProjectBuilderConfiguration getProjectBuildingConfiguration();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.build.model.ModelLineage;
|
||||
import org.apache.maven.project.build.model.ModelLineageBuilder;
|
||||
|
@ -129,11 +130,11 @@ private void scanInternal( File pom,
|
|||
|
||||
try
|
||||
{
|
||||
List originalRemoteRepositories = getInitialRemoteRepositories();
|
||||
List originalRemoteRepositories = getInitialRemoteRepositories( request.getProjectBuildingConfiguration() );
|
||||
|
||||
getLogger().debug( "Pre-scanning POM lineage of: " + pom + " for build extensions." );
|
||||
|
||||
ModelLineage lineage = buildModelLineage( pom, request, originalRemoteRepositories );
|
||||
ModelLineage lineage = buildModelLineage( pom, request.getProjectBuildingConfiguration(), originalRemoteRepositories );
|
||||
|
||||
Map inheritedInterpolationValues = new HashMap();
|
||||
|
||||
|
@ -161,7 +162,7 @@ private void scanInternal( File pom,
|
|||
inheritedInterpolationValues = new HashMap();
|
||||
}
|
||||
|
||||
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
|
||||
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, request.getUserProperties(), false );
|
||||
|
||||
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
|
||||
|
||||
|
@ -398,14 +399,14 @@ private void checkModelBuildForExtensions( Model model,
|
|||
}
|
||||
}
|
||||
|
||||
private ModelLineage buildModelLineage( File pom, MavenExecutionRequest request,
|
||||
private ModelLineage buildModelLineage( File pom, ProjectBuilderConfiguration config,
|
||||
List originalRemoteRepositories )
|
||||
throws ExtensionScanningException
|
||||
{
|
||||
ProfileManager profileManager = request.getProfileManager();
|
||||
ProfileManager profileManager = config.getGlobalProfileManager();
|
||||
|
||||
ProfileActivationContext profileActivationContext = profileManager == null
|
||||
? new DefaultProfileActivationContext( System.getProperties(), false )
|
||||
? new DefaultProfileActivationContext( config.getExecutionProperties(), false )
|
||||
: profileManager.getProfileActivationContext();
|
||||
|
||||
boolean suppressActivatorFailure = profileActivationContext.isCustomActivatorFailureSuppressed();
|
||||
|
@ -420,8 +421,8 @@ private ModelLineage buildModelLineage( File pom, MavenExecutionRequest request,
|
|||
// the last parameter here and determine whether it's appropriate for the POM to have
|
||||
// an accompanying profiles.xml file.
|
||||
profileActivationContext.setCustomActivatorFailureSuppressed( true );
|
||||
lineage = modelLineageBuilder.buildModelLineage( pom, request.getLocalRepository(), originalRemoteRepositories,
|
||||
request.getProfileManager(), false, true );
|
||||
|
||||
lineage = modelLineageBuilder.buildModelLineage( pom, config, originalRemoteRepositories, false, true );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
|
@ -436,14 +437,14 @@ private ModelLineage buildModelLineage( File pom, MavenExecutionRequest request,
|
|||
return lineage;
|
||||
}
|
||||
|
||||
private List getInitialRemoteRepositories()
|
||||
private List getInitialRemoteRepositories( ProjectBuilderConfiguration config )
|
||||
throws ExtensionScanningException
|
||||
{
|
||||
if ( basicSuperProject == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
basicSuperProject = projectBuilder.buildStandaloneSuperProject();
|
||||
basicSuperProject = projectBuilder.buildStandaloneSuperProject( config );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
@ -112,11 +113,11 @@ public void testIncludePluginWhenExtensionsFlagDirectlySet()
|
|||
ModelLineage ml = new DefaultModelLineage();
|
||||
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, false );
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
|
||||
|
||||
|
@ -126,7 +127,8 @@ public void testIncludePluginWhenExtensionsFlagDirectlySet()
|
|||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject();
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
@ -189,15 +191,15 @@ public void testIncludePluginWhenExtensionsFlagSetInPluginManagement()
|
|||
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
ml.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, false );
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( new FirstArgFileMatcher() );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE);
|
||||
|
||||
modelInterpolator.interpolate( parentModel, null, false );
|
||||
modelInterpolator.interpolate( parentModel, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionManager.addPluginAsExtension( plugin, model, Collections.EMPTY_LIST, request );
|
||||
|
@ -206,7 +208,8 @@ public void testIncludePluginWhenExtensionsFlagSetInPluginManagement()
|
|||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject();
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
@ -295,21 +298,21 @@ public void testIncludePluginWithExtensionsFlagDeclaredInParentPluginManagementR
|
|||
moduleMl.addParent( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
moduleMl.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( new FirstArgFileMatcher() );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( modulePomFile, null, null, null, false, true );
|
||||
modelLineageBuilder.buildModelLineage( modulePomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setReturnValue( moduleMl, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, false );
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( new FirstArgModelIdMatcher() );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( parentModel, null, false );
|
||||
modelInterpolator.interpolate( parentModel, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( module, null, false );
|
||||
modelInterpolator.interpolate( module, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( module, MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionManager.addPluginAsExtension( plugin, module, Collections.EMPTY_LIST, request );
|
||||
|
@ -318,7 +321,8 @@ public void testIncludePluginWithExtensionsFlagDeclaredInParentPluginManagementR
|
|||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject();
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
|
|
@ -214,12 +214,15 @@ else if ( quiet )
|
|||
loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO;
|
||||
}
|
||||
|
||||
Properties executionProperties = getExecutionProperties( commandLine );
|
||||
Properties executionProperties = new Properties();
|
||||
Properties userProperties = new Properties();
|
||||
populateProperties( commandLine, executionProperties, userProperties );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setBaseDirectory( baseDirectory )
|
||||
.setGoals( goals )
|
||||
.setProperties( executionProperties ) // optional
|
||||
.setUserProperties( userProperties ) // optional
|
||||
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
|
||||
.setRecursive( recursive ) // default: true
|
||||
.setUseReactor( useReactor ) // default: false
|
||||
|
@ -248,10 +251,8 @@ else if ( quiet )
|
|||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
static Properties getExecutionProperties( CommandLine commandLine )
|
||||
static void populateProperties( CommandLine commandLine, Properties executionProperties, Properties userProperties )
|
||||
{
|
||||
Properties executionProperties = new Properties();
|
||||
|
||||
// add the env vars to the property set, with the "env." prefix
|
||||
// XXX support for env vars should probably be removed from the ModelInterpolator
|
||||
try
|
||||
|
@ -283,14 +284,14 @@ static Properties getExecutionProperties( CommandLine commandLine )
|
|||
{
|
||||
for ( int i = 0; i < defStrs.length; ++i )
|
||||
{
|
||||
setCliProperty( defStrs[i], executionProperties );
|
||||
setCliProperty( defStrs[i], userProperties );
|
||||
}
|
||||
}
|
||||
|
||||
executionProperties.putAll( userProperties );
|
||||
}
|
||||
|
||||
executionProperties.putAll( System.getProperties() );
|
||||
|
||||
return executionProperties;
|
||||
}
|
||||
|
||||
private static void setCliProperty( String property,
|
||||
|
|
|
@ -193,15 +193,30 @@ private void reporter( MavenExecutionRequest request,
|
|||
private void executionProperties( MavenExecutionRequest request,
|
||||
Configuration configuration )
|
||||
{
|
||||
if ( request.getProperties() == null )
|
||||
Properties requestProperties = request.getProperties();
|
||||
|
||||
if ( requestProperties == null )
|
||||
{
|
||||
Properties props = configuration.getSystemProperties();
|
||||
if ( props == null )
|
||||
requestProperties = configuration.getSystemProperties();
|
||||
if ( requestProperties == null )
|
||||
{
|
||||
props = System.getProperties();
|
||||
requestProperties = System.getProperties();
|
||||
}
|
||||
|
||||
request.setProperties( props );
|
||||
request.setProperties( requestProperties );
|
||||
}
|
||||
|
||||
Properties userProperties = request.getUserProperties();
|
||||
if ( userProperties != null )
|
||||
{
|
||||
for ( Iterator it = userProperties.keySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
String key = (String) it.next();
|
||||
if ( !requestProperties.containsKey( key ) )
|
||||
{
|
||||
requestProperties.setProperty( key, userProperties.getProperty( key ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,20 +68,31 @@ public void testGetExecutionProperties()
|
|||
{
|
||||
System.setProperty( "test.property.1", "1.0" );
|
||||
System.setProperty( "test.property.2", "2.0" );
|
||||
Properties p = CLIRequestUtils.getExecutionProperties( new CLIManager().parse( new String[] {
|
||||
Properties execProperties = new Properties();
|
||||
Properties userProperties = new Properties();
|
||||
|
||||
CLIRequestUtils.populateProperties( ( new CLIManager() ).parse( new String[] {
|
||||
"-Dtest.property.2=2.1",
|
||||
"-Dtest.property.3=3.0" } ) );
|
||||
"-Dtest.property.3=3.0"
|
||||
} ), execProperties, userProperties );
|
||||
|
||||
// assume that everybody has a PATH env var
|
||||
String envPath = p.getProperty( "env.PATH" );
|
||||
String envPath = execProperties.getProperty( "env.PATH" );
|
||||
String envPath2 = userProperties.getProperty( "env.PATH" );
|
||||
if ( envPath == null )
|
||||
{
|
||||
envPath = p.getProperty( "env.Path" );
|
||||
envPath = execProperties.getProperty( "env.Path" );
|
||||
envPath2 = userProperties.getProperty( "env.Path" );
|
||||
}
|
||||
assertNotNull( envPath );
|
||||
|
||||
assertEquals( "1.0", p.getProperty( "test.property.1" ) );
|
||||
assertEquals( "3.0", p.getProperty( "test.property.3" ) );
|
||||
assertNotNull( envPath );
|
||||
assertNull( envPath2 );
|
||||
|
||||
assertEquals( "1.0", execProperties.getProperty( "test.property.1" ) );
|
||||
assertNull( userProperties.getProperty( "test.property.1" ) );
|
||||
|
||||
assertEquals( "3.0", execProperties.getProperty( "test.property.3" ) );
|
||||
assertEquals( "3.0", userProperties.getProperty( "test.property.3" ) );
|
||||
|
||||
// sys props should override cmdline props
|
||||
//assertEquals( "2.0", p.getProperty( "test.property.2" ) );
|
||||
|
|
|
@ -51,6 +51,10 @@ under the License.
|
|||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-interpolation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.artifact</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.apache.maven.project.build.model.DefaultModelLineageBuilder;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.model.Parent;
|
||||
|
||||
|
@ -14,20 +15,20 @@ public privileged aspect ProjectArtifactErrorReporterAspect
|
|||
extends AbstractProjectErrorReporterAspect
|
||||
{
|
||||
|
||||
private pointcut mlbldr_resolveParentFromRepositories( Parent parentRef, ArtifactRepository localRepo,
|
||||
private pointcut mlbldr_resolveParentFromRepositories( Parent parentRef, ProjectBuilderConfiguration config,
|
||||
List remoteRepos, String childId, File childPomFile ):
|
||||
execution( private File DefaultModelLineageBuilder.resolveParentFromRepositories( Parent, ArtifactRepository, List, String, File ) )
|
||||
&& args( parentRef, localRepo, remoteRepos, childId, childPomFile );
|
||||
execution( private File DefaultModelLineageBuilder.resolveParentFromRepositories( Parent, ProjectBuilderConfiguration, List, String, File ) )
|
||||
&& args( parentRef, config, remoteRepos, childId, childPomFile );
|
||||
|
||||
private pointcut mlbldr_parentArtifactNotFound( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ):
|
||||
cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) )
|
||||
private pointcut mlbldr_parentArtifactNotFound( Parent parentRef, ProjectBuilderConfiguration config, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ):
|
||||
cflow( mlbldr_resolveParentFromRepositories( parentRef, config, remoteRepos, childId, childPomFile ) )
|
||||
&& call( ProjectBuildingException.new( .., ArtifactNotFoundException ) )
|
||||
&& within( DefaultModelLineageBuilder )
|
||||
&& args( .., cause )
|
||||
&& notWithinAspect();
|
||||
|
||||
private pointcut mlbldr_parentArtifactUnresolvable( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ):
|
||||
cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) )
|
||||
private pointcut mlbldr_parentArtifactUnresolvable( Parent parentRef, ProjectBuilderConfiguration config, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ):
|
||||
cflow( mlbldr_resolveParentFromRepositories( parentRef, config, remoteRepos, childId, childPomFile ) )
|
||||
&& call( ProjectBuildingException.new( .., ArtifactResolutionException ) )
|
||||
&& within( DefaultModelLineageBuilder )
|
||||
&& args( .., cause )
|
||||
|
@ -43,10 +44,10 @@ public privileged aspect ProjectArtifactErrorReporterAspect
|
|||
// --> thrown ArtifactNotFoundException
|
||||
// <---------- ProjectBuildingException
|
||||
// =========================================================================
|
||||
before( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ):
|
||||
mlbldr_parentArtifactNotFound( parentRef, localRepo, remoteRepos, childId, childPomFile, cause )
|
||||
before( Parent parentRef, ProjectBuilderConfiguration config, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ):
|
||||
mlbldr_parentArtifactNotFound( parentRef, config, remoteRepos, childId, childPomFile, cause )
|
||||
{
|
||||
getReporter().reportParentPomArtifactNotFound( parentRef, localRepo, remoteRepos, childId, childPomFile, cause );
|
||||
getReporter().reportParentPomArtifactNotFound( parentRef, config, remoteRepos, childId, childPomFile, cause );
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
|
@ -59,9 +60,9 @@ public privileged aspect ProjectArtifactErrorReporterAspect
|
|||
// --> thrown ArtifactResolutionException
|
||||
// <---------- ProjectBuildingException
|
||||
// =========================================================================
|
||||
before( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ):
|
||||
mlbldr_parentArtifactUnresolvable( parentRef, localRepo, remoteRepos, childId, childPomFile, cause )
|
||||
before( Parent parentRef, ProjectBuilderConfiguration config, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ):
|
||||
mlbldr_parentArtifactUnresolvable( parentRef, config, remoteRepos, childId, childPomFile, cause )
|
||||
{
|
||||
getReporter().reportParentPomArtifactUnresolvable( parentRef, localRepo, remoteRepos, childId, childPomFile, cause );
|
||||
getReporter().reportParentPomArtifactUnresolvable( parentRef, config, remoteRepos, childId, childPomFile, cause );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,17 @@ public MavenProject build( File projectDescriptor,
|
|||
ProfileManager profileManager )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager );
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
|
||||
.setGlobalProfileManager( profileManager );
|
||||
|
||||
return buildFromSourceFileInternal( projectDescriptor, config );
|
||||
}
|
||||
|
||||
public MavenProject build( File projectDescriptor,
|
||||
ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return buildFromSourceFileInternal( projectDescriptor, config );
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
|
@ -223,7 +233,9 @@ public MavenProject buildFromRepository( Artifact artifact,
|
|||
|
||||
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
|
||||
|
||||
project = buildInternal( model, localRepository, remoteArtifactRepositories, artifact.getFile(), null,
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
|
||||
|
||||
project = buildInternal( model, config, remoteArtifactRepositories, artifact.getFile(),
|
||||
false, false, false );
|
||||
}
|
||||
else
|
||||
|
@ -241,11 +253,18 @@ public MavenProject buildStandaloneSuperProject()
|
|||
throws ProjectBuildingException
|
||||
{
|
||||
//TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable
|
||||
return buildStandaloneSuperProject( null );
|
||||
return buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
}
|
||||
|
||||
public MavenProject buildStandaloneSuperProject( ProfileManager profileManager )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
//TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable
|
||||
return buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration().setGlobalProfileManager( profileManager ) );
|
||||
}
|
||||
|
||||
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model superModel = getSuperModel();
|
||||
|
||||
|
@ -257,6 +276,8 @@ public MavenProject buildStandaloneSuperProject( ProfileManager profileManager )
|
|||
|
||||
superModel = ModelUtils.cloneModel( superModel );
|
||||
|
||||
ProfileManager profileManager = config.getGlobalProfileManager();
|
||||
|
||||
List activeProfiles = new ArrayList();
|
||||
if ( profileManager != null )
|
||||
{
|
||||
|
@ -286,7 +307,7 @@ public MavenProject buildStandaloneSuperProject( ProfileManager profileManager )
|
|||
|
||||
try
|
||||
{
|
||||
processProjectLogic( project, null, null, null, true, false );
|
||||
processProjectLogic( project, null, config, null, true, true );
|
||||
|
||||
project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
|
||||
project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
|
||||
|
@ -458,8 +479,7 @@ else if ( map == null )
|
|||
}
|
||||
|
||||
private MavenProject buildFromSourceFileInternal( File projectDescriptor,
|
||||
ArtifactRepository localRepository,
|
||||
ProfileManager profileManager )
|
||||
ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
getLogger().debug( "Checking cache-hit on project (in build*): " + projectDescriptor );
|
||||
|
@ -473,10 +493,9 @@ private MavenProject buildFromSourceFileInternal( File projectDescriptor,
|
|||
Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
|
||||
|
||||
project = buildInternal( model,
|
||||
localRepository,
|
||||
config,
|
||||
buildArtifactRepositories( getSuperModel() ),
|
||||
projectDescriptor,
|
||||
profileManager,
|
||||
STRICT_MODEL_PARSING,
|
||||
true,
|
||||
true );
|
||||
|
@ -655,10 +674,9 @@ private void checkStatusAndUpdate( Artifact projectArtifact,
|
|||
// We've got a mixture of things going in the USD and from the repository, sometimes the descriptor
|
||||
// is a real file and sometimes null which makes things confusing.
|
||||
private MavenProject buildInternal( Model model,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
List parentSearchRepositories,
|
||||
File projectDescriptor,
|
||||
ProfileManager externalProfileManager,
|
||||
boolean strict, boolean validProfilesXmlLocation,
|
||||
boolean fromSourceTree )
|
||||
throws ProjectBuildingException
|
||||
|
@ -672,6 +690,7 @@ private MavenProject buildInternal( Model model,
|
|||
// FIXME: Find a way to pass in this context, so it's never null!
|
||||
ProfileActivationContext profileActivationContext;
|
||||
|
||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
||||
if ( externalProfileManager != null )
|
||||
{
|
||||
// used to trigger the caching of SystemProperties in the container context...
|
||||
|
@ -688,7 +707,7 @@ private MavenProject buildInternal( Model model,
|
|||
}
|
||||
else
|
||||
{
|
||||
profileActivationContext = new DefaultProfileActivationContext( System.getProperties(), false );
|
||||
profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
|
||||
}
|
||||
|
||||
LinkedHashSet activeInSuperPom = new LinkedHashSet();
|
||||
|
@ -721,7 +740,7 @@ private MavenProject buildInternal( Model model,
|
|||
|
||||
try
|
||||
{
|
||||
project = assembleLineage( model, lineage, localRepository, projectDescriptor, aggregatedRemoteWagonRepositories, externalProfileManager, strict, validProfilesXmlLocation );
|
||||
project = assembleLineage( model, lineage, config, projectDescriptor, aggregatedRemoteWagonRepositories, strict, validProfilesXmlLocation );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
@ -780,7 +799,7 @@ private MavenProject buildInternal( Model model,
|
|||
|
||||
try
|
||||
{
|
||||
project = processProjectLogic( project, projectDescriptor, localRepository, repositories, strict, false );
|
||||
project = processProjectLogic( project, projectDescriptor, config, repositories, strict, false );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
|
@ -926,10 +945,10 @@ private List buildArtifactRepositories( Model model )
|
|||
*/
|
||||
private MavenProject processProjectLogic( MavenProject project,
|
||||
File pomFile,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepositories,
|
||||
boolean strict,
|
||||
boolean superPom )
|
||||
boolean isSuperPom )
|
||||
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
|
||||
{
|
||||
Model model = project.getModel();
|
||||
|
@ -940,41 +959,37 @@ private MavenProject processProjectLogic( MavenProject project,
|
|||
// [BP] - Can this above comment be explained?
|
||||
// We don't need all the project methods that are added over those in the model, but we do need basedir
|
||||
// mkleint - using System.getProperties() is almost definitely bad for embedding.
|
||||
Map context = new HashMap( System.getProperties() );
|
||||
Map context = new HashMap();
|
||||
|
||||
// [MNG-2339] ensure the system properties are still interpolated for backwards compat, but the model values must win
|
||||
if ( config.getExecutionProperties() != null && !config.getExecutionProperties().isEmpty() )
|
||||
{
|
||||
context.putAll( config.getExecutionProperties() );
|
||||
}
|
||||
|
||||
File projectDir = null;
|
||||
|
||||
if ( pomFile != null )
|
||||
{
|
||||
File projectDir = pomFile.getAbsoluteFile().getParentFile();
|
||||
projectDir = pomFile.getAbsoluteFile().getParentFile();
|
||||
|
||||
context.put( "basedir", pomFile.getParentFile().getAbsolutePath() );
|
||||
context.put( "basedir", projectDir.getAbsolutePath() );
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
// MNG-1927, MNG-2124, MNG-3355:
|
||||
// If the build section is present and the project directory is non-null, we should make
|
||||
// sure interpolation of the directories below uses translated paths.
|
||||
// Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
|
||||
// code below...
|
||||
context.put( "build.directory", pathTranslator.alignToBaseDirectory( build.getDirectory(), projectDir ) );
|
||||
context.put( "build.outputDirectory", pathTranslator.alignToBaseDirectory( build.getOutputDirectory(), projectDir ) );
|
||||
context.put( "build.testOutputDirectory", pathTranslator.alignToBaseDirectory( build.getTestOutputDirectory(), projectDir ) );
|
||||
context.put( "build.sourceDirectory", pathTranslator.alignToBaseDirectory( build.getSourceDirectory(), projectDir ) );
|
||||
context.put( "build.testSourceDirectory", pathTranslator.alignToBaseDirectory( build.getTestSourceDirectory(), projectDir ) );
|
||||
}
|
||||
|
||||
model = modelInterpolator.interpolate( model, context, strict );
|
||||
Map overrideContext = new HashMap();
|
||||
if ( !isSuperPom && config.getUserProperties() != null && !config.getUserProperties().isEmpty() )
|
||||
{
|
||||
overrideContext.putAll( config.getUserProperties() );
|
||||
}
|
||||
|
||||
// [MNG-2339] ensure the system properties are still interpolated for backwards compat, but the model values must win
|
||||
context.putAll( System.getProperties() );
|
||||
model = modelInterpolator.interpolate( model, context, strict );
|
||||
model = modelInterpolator.interpolate( model, context, overrideContext, projectDir, true );
|
||||
|
||||
// We must inject any imported dependencyManagement information ahead of the defaults injection.
|
||||
if ( !superPom )
|
||||
if ( !isSuperPom )
|
||||
{
|
||||
// TODO: [jdcasey] This line appears to be part of the problem for MNG-3391...
|
||||
// the same line is in 2.0.x, so this is related to caching changes too...need to figure out how the two interact.
|
||||
mergeManagedDependencies( model, localRepository, remoteRepositories );
|
||||
mergeManagedDependencies( model, config.getLocalRepository(), remoteRepositories );
|
||||
}
|
||||
|
||||
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
||||
|
@ -1081,10 +1096,9 @@ private void validateModel( Model model,
|
|||
*/
|
||||
private MavenProject assembleLineage( Model model,
|
||||
LinkedList lineage,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
File pomFile,
|
||||
Set aggregatedRemoteWagonRepositories,
|
||||
ProfileManager externalProfileManager,
|
||||
boolean strict, boolean validProfilesXmlLocation )
|
||||
throws ProjectBuildingException, InvalidRepositoryException
|
||||
{
|
||||
|
@ -1092,10 +1106,11 @@ private MavenProject assembleLineage( Model model,
|
|||
|
||||
modelLineage.setOrigin( model, pomFile, new ArrayList( aggregatedRemoteWagonRepositories ), validProfilesXmlLocation );
|
||||
|
||||
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict );
|
||||
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, config, !strict );
|
||||
|
||||
// FIXME: Find a way to pass in this context, so it's never null!
|
||||
ProfileActivationContext profileActivationContext;
|
||||
ProfileManager externalProfileManager = config.getGlobalProfileManager();
|
||||
|
||||
if ( externalProfileManager != null )
|
||||
{
|
||||
|
@ -1103,7 +1118,7 @@ private MavenProject assembleLineage( Model model,
|
|||
}
|
||||
else
|
||||
{
|
||||
profileActivationContext = new DefaultProfileActivationContext( System.getProperties(), false );
|
||||
profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
|
||||
}
|
||||
|
||||
MavenProject lastProject = null;
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class DefaultProjectBuilderConfiguration
|
||||
implements ProjectBuilderConfiguration
|
||||
{
|
||||
|
||||
private ProfileManager globalProfileManager;
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
private Properties userProperties;
|
||||
|
||||
private Properties executionProperties = System.getProperties();
|
||||
|
||||
public DefaultProjectBuilderConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
public ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager )
|
||||
{
|
||||
this.globalProfileManager = globalProfileManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProfileManager getGlobalProfileManager()
|
||||
{
|
||||
return globalProfileManager;
|
||||
}
|
||||
|
||||
public ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public ProjectBuilderConfiguration setUserProperties( Properties userProperties )
|
||||
{
|
||||
this.userProperties = userProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Properties getUserProperties()
|
||||
{
|
||||
if ( userProperties == null )
|
||||
{
|
||||
userProperties = new Properties();
|
||||
}
|
||||
|
||||
return userProperties;
|
||||
}
|
||||
|
||||
public Properties getExecutionProperties()
|
||||
{
|
||||
return executionProperties;
|
||||
}
|
||||
|
||||
public ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties )
|
||||
{
|
||||
this.executionProperties = executionProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -38,11 +38,17 @@ public interface MavenProjectBuilder
|
|||
|
||||
boolean STRICT_MODEL_PARSING = true;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link MavenProjectBuilder#build(File, ProjectBuilderConfiguration)} instead.
|
||||
*/
|
||||
MavenProject build( File project,
|
||||
ArtifactRepository localRepository,
|
||||
ProfileManager globalProfileManager )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
MavenProject build( File project, ProjectBuilderConfiguration configuration )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
MavenProject buildWithDependencies( File project,
|
||||
ArtifactRepository localRepository,
|
||||
ProfileManager globalProfileManager )
|
||||
|
@ -67,12 +73,17 @@ MavenProject buildFromRepository( Artifact artifact,
|
|||
throws ProjectBuildingException;
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @throws ProjectBuildingException
|
||||
* @deprecated Use {@link MavenProjectBuilder#buildStandaloneSuperProject(ProjectBuilderConfiguration)} instead.
|
||||
*/
|
||||
MavenProject buildStandaloneSuperProject()
|
||||
throws ProjectBuildingException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link MavenProjectBuilder#buildStandaloneSuperProject(ProjectBuilderConfiguration)} instead.
|
||||
*/
|
||||
MavenProject buildStandaloneSuperProject( ProfileManager profileManager )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface ProjectBuilderConfiguration
|
||||
{
|
||||
|
||||
ArtifactRepository getLocalRepository();
|
||||
|
||||
ProfileManager getGlobalProfileManager();
|
||||
|
||||
Properties getUserProperties();
|
||||
|
||||
Properties getExecutionProperties();
|
||||
|
||||
ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager );
|
||||
|
||||
ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository );
|
||||
|
||||
ProjectBuilderConfiguration setUserProperties( Properties userProperties );
|
||||
|
||||
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
|
||||
|
||||
}
|
|
@ -23,17 +23,16 @@
|
|||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.profiles.build.ProfileAdvisor;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.workspace.ProjectWorkspace;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
|
@ -88,9 +87,8 @@ public DefaultModelLineageBuilder( ArtifactResolver resolver,
|
|||
* @see org.apache.maven.project.build.model.ModelLineageBuilder#buildModelLineage(java.io.File, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List)
|
||||
*/
|
||||
public ModelLineage buildModelLineage( File pom,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepositories,
|
||||
ProfileManager profileManager,
|
||||
boolean allowStubs,
|
||||
boolean validProfilesXmlLocation )
|
||||
throws ProjectBuildingException
|
||||
|
@ -127,12 +125,12 @@ public ModelLineage buildModelLineage( File pom,
|
|||
currentRemoteRepositories = updateRepositorySet( current.getModel(),
|
||||
currentRemoteRepositories,
|
||||
current.getFile(),
|
||||
profileManager,
|
||||
config,
|
||||
current.isValidProfilesXmlLocation() );
|
||||
|
||||
current = resolveParentPom( current,
|
||||
currentRemoteRepositories,
|
||||
localRepository,
|
||||
config,
|
||||
allowStubs );
|
||||
}
|
||||
while ( current != null );
|
||||
|
@ -141,8 +139,7 @@ public ModelLineage buildModelLineage( File pom,
|
|||
}
|
||||
|
||||
public void resumeBuildingModelLineage( ModelLineage lineage,
|
||||
ArtifactRepository localRepository,
|
||||
ProfileManager profileManager,
|
||||
ProjectBuilderConfiguration config,
|
||||
boolean allowStubs )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
@ -166,7 +163,7 @@ public void resumeBuildingModelLineage( ModelLineage lineage,
|
|||
// use the above information to re-bootstrap the resolution chain...
|
||||
current = resolveParentPom( current,
|
||||
currentRemoteRepositories,
|
||||
localRepository,
|
||||
config,
|
||||
allowStubs );
|
||||
|
||||
while ( current != null )
|
||||
|
@ -179,12 +176,12 @@ public void resumeBuildingModelLineage( ModelLineage lineage,
|
|||
currentRemoteRepositories = updateRepositorySet( current.getModel(),
|
||||
currentRemoteRepositories,
|
||||
current.getFile(),
|
||||
profileManager,
|
||||
config,
|
||||
current.isValidProfilesXmlLocation() );
|
||||
|
||||
current = resolveParentPom( current,
|
||||
currentRemoteRepositories,
|
||||
localRepository,
|
||||
config,
|
||||
allowStubs );
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +234,7 @@ private Model readModel( File pomFile )
|
|||
private List updateRepositorySet( Model model,
|
||||
List oldArtifactRepositories,
|
||||
File pomFile,
|
||||
ProfileManager externalProfileManager,
|
||||
ProjectBuilderConfiguration config,
|
||||
boolean useProfilesXml )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
@ -256,7 +253,7 @@ private List updateRepositorySet( Model model,
|
|||
|
||||
loadActiveProfileRepositories( remoteRepos,
|
||||
model,
|
||||
externalProfileManager,
|
||||
config,
|
||||
projectDir,
|
||||
useProfilesXml );
|
||||
|
||||
|
@ -279,7 +276,7 @@ private List updateRepositorySet( Model model,
|
|||
|
||||
private void loadActiveProfileRepositories( List repositories,
|
||||
Model model,
|
||||
ProfileManager profileManager,
|
||||
ProjectBuilderConfiguration config,
|
||||
File pomFile,
|
||||
boolean useProfilesXml )
|
||||
throws ProjectBuildingException
|
||||
|
@ -289,18 +286,18 @@ private void loadActiveProfileRepositories( List repositories,
|
|||
// FIXME: Find a way to pass in this context, so it's never null!
|
||||
ProfileActivationContext context;
|
||||
|
||||
if ( profileManager != null )
|
||||
if ( config.getGlobalProfileManager() != null )
|
||||
{
|
||||
context = profileManager.getProfileActivationContext();
|
||||
context = config.getGlobalProfileManager().getProfileActivationContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
context = new DefaultProfileActivationContext( System.getProperties(), false );
|
||||
context = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
|
||||
}
|
||||
|
||||
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model,
|
||||
pomFile,
|
||||
profileManager );
|
||||
config.getGlobalProfileManager() );
|
||||
|
||||
getLogger().debug( "Got external-profile repositories: " + profileRepos );
|
||||
|
||||
|
@ -327,7 +324,7 @@ private void loadActiveProfileRepositories( List repositories,
|
|||
*/
|
||||
private ModelAndFile resolveParentPom( ModelAndFile child,
|
||||
List remoteRepositories,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
boolean allowStubs )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
@ -371,7 +368,7 @@ private ModelAndFile resolveParentPom( ModelAndFile child,
|
|||
getLogger().debug( "Attempting to resolve parent POM: " + modelParent.getId() + " using repositories:\n" + StringUtils.join( remoteRepositories.iterator(), "\n" ) );
|
||||
|
||||
parentPomFile = resolveParentFromRepositories( modelParent,
|
||||
localRepository,
|
||||
config,
|
||||
remoteRepositories,
|
||||
model.getId(),
|
||||
modelPomFile );
|
||||
|
@ -467,7 +464,7 @@ else if ( StringUtils.isEmpty( modelParent.getVersion() ) )
|
|||
}
|
||||
|
||||
private File resolveParentFromRepositories( Parent modelParent,
|
||||
ArtifactRepository localRepository,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepositories,
|
||||
String childId,
|
||||
File childPomFile )
|
||||
|
@ -480,7 +477,7 @@ private File resolveParentFromRepositories( Parent modelParent,
|
|||
|
||||
try
|
||||
{
|
||||
artifactResolver.resolve( parentPomArtifact, remoteRepositories, localRepository );
|
||||
artifactResolver.resolve( parentPomArtifact, remoteRepositories, config.getLocalRepository() );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -50,8 +49,8 @@ public interface ModelLineageBuilder
|
|||
* @param allowStubs Whether stubbed-out Model instances should be constructed in the event that
|
||||
* a parent-POM cannot be resolved.
|
||||
*/
|
||||
ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, List remoteRepositories,
|
||||
ProfileManager profileManager, boolean allowStubs, boolean validProfilesXmlLocation )
|
||||
ModelLineage buildModelLineage( File pom, ProjectBuilderConfiguration config, List remoteRepositories,
|
||||
boolean allowStubs, boolean validProfilesXmlLocation )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
/**
|
||||
|
@ -65,8 +64,7 @@ ModelLineage buildModelLineage( File pom, ArtifactRepository localRepository, Li
|
|||
* @param allowStubs Whether stubbed-out Model instances should be constructed in the event that
|
||||
* a parent-POM cannot be resolved.
|
||||
*/
|
||||
void resumeBuildingModelLineage( ModelLineage lineage, ArtifactRepository localRepository,
|
||||
ProfileManager profileManager, boolean allowStubs )
|
||||
void resumeBuildingModelLineage( ModelLineage lineage, ProjectBuilderConfiguration config, boolean allowStubs )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
import org.apache.maven.project.InvalidProjectModelException;
|
||||
import org.apache.maven.project.InvalidProjectVersionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.build.model.ModelAndFile;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
|
@ -679,27 +680,27 @@ public void reportErrorParsingParentProjectModel( ModelAndFile childInfo,
|
|||
}
|
||||
|
||||
public void reportParentPomArtifactNotFound( Parent parentRef,
|
||||
ArtifactRepository localRepo,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepos,
|
||||
String childId,
|
||||
File childPomFile,
|
||||
ArtifactNotFoundException cause )
|
||||
{
|
||||
reportArtifactError( parentRef, localRepo, remoteRepos, childId, childPomFile, cause );
|
||||
reportArtifactError( parentRef, config, remoteRepos, childId, childPomFile, cause );
|
||||
}
|
||||
|
||||
public void reportParentPomArtifactUnresolvable( Parent parentRef,
|
||||
ArtifactRepository localRepo,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepos,
|
||||
String childId,
|
||||
File childPomFile,
|
||||
ArtifactResolutionException cause )
|
||||
{
|
||||
reportArtifactError( parentRef, localRepo, remoteRepos, childId, childPomFile, cause );
|
||||
reportArtifactError( parentRef, config, remoteRepos, childId, childPomFile, cause );
|
||||
}
|
||||
|
||||
private void reportArtifactError( Parent parentRef,
|
||||
ArtifactRepository localRepo,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepos,
|
||||
String childId,
|
||||
File childPomFile,
|
||||
|
@ -727,7 +728,7 @@ private void reportArtifactError( Parent parentRef,
|
|||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Local Repository: " );
|
||||
writer.write( localRepo.getBasedir() );
|
||||
writer.write( config.getLocalRepository().getBasedir() );
|
||||
|
||||
if ( ( remoteRepos != null ) && !remoteRepos.isEmpty() )
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
|
@ -17,6 +16,7 @@
|
|||
import org.apache.maven.project.InvalidProjectModelException;
|
||||
import org.apache.maven.project.InvalidProjectVersionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.build.model.ModelAndFile;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
|
@ -352,7 +352,7 @@ void reportErrorParsingParentProjectModel( ModelAndFile childInfo,
|
|||
* </pre>
|
||||
*/
|
||||
void reportParentPomArtifactNotFound( Parent parentRef,
|
||||
ArtifactRepository localRepo,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepos,
|
||||
String childId,
|
||||
File childPomFile,
|
||||
|
@ -371,7 +371,7 @@ void reportParentPomArtifactNotFound( Parent parentRef,
|
|||
* </pre>
|
||||
*/
|
||||
void reportParentPomArtifactUnresolvable( Parent parentRef,
|
||||
ArtifactRepository localRepo,
|
||||
ProjectBuilderConfiguration config,
|
||||
List remoteRepos,
|
||||
String childId,
|
||||
File childPomFile,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -32,9 +33,25 @@ public interface ModelInterpolator
|
|||
{
|
||||
String ROLE = ModelInterpolator.class.getName();
|
||||
|
||||
Model interpolate( Model project, Map context )
|
||||
Model interpolate( Model project,
|
||||
Map context )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
Model interpolate( Model model, Map context, boolean strict )
|
||||
Model interpolate( Model model,
|
||||
Map context,
|
||||
boolean strict )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
Model interpolate( Model model,
|
||||
Map context,
|
||||
Map overrideContext,
|
||||
boolean outputDebugMessages )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
Model interpolate( Model model,
|
||||
Map context,
|
||||
Map overrideContext,
|
||||
File projectDir,
|
||||
boolean outputDebugMessages )
|
||||
throws ModelInterpolationException;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.interpolation.AbstractFunctionValueSourceWrapper;
|
||||
import org.codehaus.plexus.interpolation.ValueSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class PathTranslatingValueSource
|
||||
extends AbstractFunctionValueSourceWrapper
|
||||
{
|
||||
|
||||
private final List unprefixedPathKeys;
|
||||
private final File projectDir;
|
||||
private final PathTranslator pathTranslator;
|
||||
|
||||
protected PathTranslatingValueSource( ValueSource valueSource, List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
|
||||
{
|
||||
super( valueSource );
|
||||
this.unprefixedPathKeys = unprefixedPathKeys;
|
||||
this.projectDir = projectDir;
|
||||
this.pathTranslator = pathTranslator;
|
||||
}
|
||||
|
||||
protected Object executeFunction( String expression,
|
||||
Object value )
|
||||
{
|
||||
if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) )
|
||||
{
|
||||
return pathTranslator.alignToBaseDirectory( String.valueOf( value ), projectDir );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,18 +22,31 @@
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
|
||||
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
|
||||
import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper;
|
||||
import org.codehaus.plexus.interpolation.RecursionInterceptor;
|
||||
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
|
||||
import org.codehaus.plexus.interpolation.ValueSource;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.cli.CommandLineUtils;
|
||||
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -48,20 +61,55 @@ public class RegexBasedModelInterpolator
|
|||
extends AbstractLogEnabled
|
||||
implements ModelInterpolator
|
||||
{
|
||||
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" );
|
||||
private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{([^}]+)\\}" );
|
||||
|
||||
private Properties envars;
|
||||
private static final List PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
|
||||
private static final List TRANSLATED_PATH_EXPRESSIONS;
|
||||
|
||||
static
|
||||
{
|
||||
List translatedPrefixes = new ArrayList();
|
||||
|
||||
// MNG-1927, MNG-2124, MNG-3355:
|
||||
// If the build section is present and the project directory is non-null, we should make
|
||||
// sure interpolation of the directories below uses translated paths.
|
||||
// Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
|
||||
// code below...
|
||||
translatedPrefixes.add( "build.directory" );
|
||||
translatedPrefixes.add( "build.outputDirectory" );
|
||||
translatedPrefixes.add( "build.testOutputDirectory" );
|
||||
translatedPrefixes.add( "build.sourceDirectory" );
|
||||
translatedPrefixes.add( "build.testSourceDirectory" );
|
||||
|
||||
TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes;
|
||||
}
|
||||
|
||||
private PathTranslator pathTranslator;
|
||||
|
||||
public RegexBasedModelInterpolator()
|
||||
throws IOException
|
||||
{
|
||||
envars = CommandLineUtils.getSystemEnvVars();
|
||||
}
|
||||
|
||||
public Model interpolate( Model model, Map context )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
return interpolate( model, context, true );
|
||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
||||
}
|
||||
|
||||
public Model interpolate( Model model, Map context, boolean strict )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
||||
}
|
||||
|
||||
public Model interpolate( Model model,
|
||||
Map context,
|
||||
Map overrideContext,
|
||||
boolean strict )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
return interpolate( model, context, Collections.EMPTY_MAP, null, true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,10 +120,15 @@ public Model interpolate( Model model, Map context )
|
|||
*
|
||||
* @param model The inbound Model instance, to serialize and reference for expression resolution
|
||||
* @param context The other context map to be used during resolution
|
||||
* @param overrideContext The context map which should be used to OVERRIDE
|
||||
* values from everything else. This will come from the CLI
|
||||
* or userProperties in the execution request.
|
||||
* @param projectDir The directory from which the current model's pom was read.
|
||||
* @param strict This parameter is ignored!
|
||||
* @param outputDebugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
|
||||
* @return The resolved instance of the inbound Model. This is a different instance!
|
||||
*/
|
||||
public Model interpolate( Model model, Map context, boolean strict )
|
||||
public Model interpolate( Model model, Map context, Map overrideContext, File projectDir, boolean outputDebugMessages )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
|
@ -91,7 +144,7 @@ public Model interpolate( Model model, Map context, boolean strict )
|
|||
}
|
||||
|
||||
String serializedModel = sWriter.toString();
|
||||
serializedModel = interpolateInternal( serializedModel, model, context );
|
||||
serializedModel = interpolateInternal( serializedModel, model, context, overrideContext, projectDir, outputDebugMessages );
|
||||
|
||||
StringReader sReader = new StringReader( serializedModel );
|
||||
|
||||
|
@ -125,85 +178,57 @@ public Model interpolate( Model model, Map context, boolean strict )
|
|||
* with the value, and continue to find other expressions.</li>
|
||||
* <li>If the value is null, get it from the model properties.</li>
|
||||
* <li>
|
||||
*
|
||||
*
|
||||
* @param overrideContext
|
||||
* @param outputDebugMessages
|
||||
*/
|
||||
private String interpolateInternal( String src, Model model, Map context )
|
||||
private String interpolateInternal( String src, Model model, Map context, Map overrideContext, File projectDir, boolean outputDebugMessages )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
Logger logger = getLogger();
|
||||
|
||||
boolean isSnapshotModel = ( model.getVersion() == null
|
||||
? model.getParent() == null ? "" : model.getParent().getVersion()
|
||||
: model.getVersion() ).indexOf( "SNAPSHOT" ) >= 0;
|
||||
ValueSource baseModelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
|
||||
ValueSource modelValueSource1 = new PathTranslatingValueSource( baseModelValueSource1,
|
||||
TRANSLATED_PATH_EXPRESSIONS,
|
||||
projectDir, pathTranslator );
|
||||
|
||||
ValueSource baseModelValueSource2 = new ObjectBasedValueSource( model );
|
||||
ValueSource modelValueSource2 = new PathTranslatingValueSource( baseModelValueSource2,
|
||||
TRANSLATED_PATH_EXPRESSIONS,
|
||||
projectDir, pathTranslator );
|
||||
|
||||
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
|
||||
|
||||
// NOTE: Order counts here!
|
||||
interpolator.addValueSource( new MapBasedValueSource( overrideContext ) );
|
||||
interpolator.addValueSource( modelValueSource1 );
|
||||
interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( model.getProperties() ), PROJECT_PREFIXES, true ) );
|
||||
interpolator.addValueSource( modelValueSource2 );
|
||||
interpolator.addValueSource( new MapBasedValueSource( context ) );
|
||||
|
||||
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
|
||||
|
||||
String result = src;
|
||||
Matcher matcher = EXPRESSION_PATTERN.matcher( result );
|
||||
while ( matcher.find() )
|
||||
{
|
||||
String wholeExpr = matcher.group( 0 );
|
||||
String prefix = matcher.group( 1 );
|
||||
String realExpr = matcher.group( 2 );
|
||||
|
||||
prefix = prefix == null ? "" : prefix;
|
||||
Object value;
|
||||
try
|
||||
{
|
||||
value = interpolator.interpolate( wholeExpr, "", recursionInterceptor );
|
||||
}
|
||||
catch( InterpolationException e )
|
||||
{
|
||||
throw new ModelInterpolationException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
Object value = null;
|
||||
|
||||
boolean isPomExpression = "pom.".equals( prefix ) || "project.".equals( prefix );
|
||||
|
||||
// Check for special expressions that should NOT be interpolated.
|
||||
// See DefaultProjectBuilder and MNG-2124/MNG-1927.
|
||||
if ( ( context.get( realExpr ) == null ) && context.containsKey( realExpr ) )
|
||||
if ( value == null || value.equals( wholeExpr ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// I don't think we should deprecate this as it's used in plugin params aswell,
|
||||
// and project.build.outputDirectory etc. are documented.
|
||||
// For now I'll allow both pom. and project.
|
||||
// Perhaps pom. should be deprecated instead?
|
||||
// if ( isSnapshotModel && logger != null && "project.".equals( prefix ) )
|
||||
// {
|
||||
// logger.warn( "Deprecated expression: " + wholeExpr + " - 'project.' prefix is deprecated."
|
||||
// + " Use 'pom.': ${pom." + realExpr + "} (model: " + model.getId() + ")" );
|
||||
// }
|
||||
|
||||
if ( isPomExpression )
|
||||
{
|
||||
value = getValueFromModel( realExpr, model, wholeExpr, logger );
|
||||
}
|
||||
|
||||
if ( value == null )
|
||||
{
|
||||
value = context.get( realExpr );
|
||||
}
|
||||
|
||||
if ( value == null )
|
||||
{
|
||||
value = model.getProperties().getProperty( realExpr );
|
||||
}
|
||||
|
||||
if ( value == null )
|
||||
{
|
||||
value = envars.getProperty( realExpr );
|
||||
}
|
||||
|
||||
// Any expression, not just artifactId, version etc., but also scm.repository
|
||||
// were evaluated against the model, even if there is no prefix.
|
||||
// If the 2.1 strategy fails, try the legacy approach. If it yields a result, warn for it.
|
||||
if ( ( value == null ) && ( prefix.length() == 0 ) )
|
||||
{
|
||||
value = getValueFromModel( realExpr, model, wholeExpr, logger );
|
||||
|
||||
if ( isSnapshotModel && ( value != null ) && ( logger != null ) )
|
||||
{
|
||||
// TODO: Bring this back into the open once we're ready to deal with it.
|
||||
logger.debug( "Expression: " + wholeExpr + " is missing its prefix. Instead, use ${pom."
|
||||
+ realExpr + "} (model: " + model.getId() + ")" );
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Does this account for the case where ${project.build.directory} -> ${build.directory}??
|
||||
if ( value != null )
|
||||
{
|
||||
// if the expression refers to itself, skip it.
|
||||
|
@ -223,7 +248,6 @@ private String interpolateInternal( String src, Model model, Map context )
|
|||
matcher.reset( result );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the
|
||||
// timing of executing the interpolation
|
||||
|
@ -236,26 +260,50 @@ private String interpolateInternal( String src, Model model, Map context )
|
|||
*/
|
||||
}
|
||||
|
||||
if ( outputDebugMessages )
|
||||
{
|
||||
List feedback = interpolator.getFeedback();
|
||||
if ( feedback != null && !feedback.isEmpty() )
|
||||
{
|
||||
logger.debug( "Maven encountered the following problems during initial POM interpolation:" );
|
||||
|
||||
Object last = null;
|
||||
for ( Iterator it = feedback.iterator(); it.hasNext(); )
|
||||
{
|
||||
Object next = it.next();
|
||||
|
||||
if ( next instanceof Throwable )
|
||||
{
|
||||
if ( last == null )
|
||||
{
|
||||
logger.debug( "", ( (Throwable) next ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug( String.valueOf( last ), ( (Throwable) next ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( last != null )
|
||||
{
|
||||
logger.debug( String.valueOf( last ) );
|
||||
}
|
||||
|
||||
last = next;
|
||||
}
|
||||
}
|
||||
|
||||
if ( last != null )
|
||||
{
|
||||
logger.debug( String.valueOf( last ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interpolator.clearFeedback();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Object getValueFromModel( String realExpr, Model model, String wholeExpr, Logger logger )
|
||||
{
|
||||
try
|
||||
{
|
||||
// NOTE: We've already trimmed off any leading expression parts like 'project.'
|
||||
// or 'pom.', and now we have to ensure that the ReflectionValueExtractor
|
||||
// doesn't try to do it again.
|
||||
return ReflectionValueExtractor.evaluate( realExpr, model, false );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
if ( logger != null )
|
||||
{
|
||||
logger.debug( "POM interpolation cannot proceed with expression: " + wholeExpr + ". Skipping...", e );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,11 @@ under the License.
|
|||
<component>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
<implementation>org.apache.maven.project.interpolation.RegexBasedModelInterpolator</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.error.ProjectErrorReporter;
|
||||
import org.apache.maven.project.error.ProjectReporterManager;
|
||||
|
@ -117,8 +118,7 @@ public void testShouldReadSinglePomWithNoParents()
|
|||
}
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile,
|
||||
null,
|
||||
null,
|
||||
new DefaultProjectBuilderConfiguration(),
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
@ -183,9 +183,8 @@ public void testReadPOMWithTwoAncestorsInLocalRepository()
|
|||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.EMPTY_LIST,
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
@ -234,9 +233,8 @@ public void testReadPOMWithMissingParentAndAllowStubsSetToTrue()
|
|||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.EMPTY_LIST,
|
||||
null,
|
||||
true,
|
||||
true );
|
||||
|
||||
|
@ -321,9 +319,8 @@ public void testReadPOMWithParentInLocalRepositoryAndAncestorInRemoteRepository(
|
|||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.singletonList( remoteRepository ),
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
@ -384,9 +381,8 @@ public void testReadPOMWithParentInSiblingDirectoryUsingSpecifiedRelativePathTha
|
|||
defaultLayout );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.EMPTY_LIST,
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
@ -457,9 +453,9 @@ public void testReadPOMWithParentInRepoBroughtInViaExternalProfile()
|
|||
profileManager.explicitlyActivate( profile.getId() );
|
||||
|
||||
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
|
||||
.setGlobalProfileManager( profileManager ),
|
||||
Collections.EMPTY_LIST,
|
||||
profileManager,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
@ -615,9 +611,8 @@ public void testReadPOMWithParentMissingFromRepository()
|
|||
try
|
||||
{
|
||||
modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.EMPTY_LIST,
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
@ -650,9 +645,8 @@ public void testReadPOM_HandleErrorWhenFileDoesntExist()
|
|||
try
|
||||
{
|
||||
modelLineageBuilder.buildModelLineage( currentPOM,
|
||||
localRepository,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
|
||||
Collections.EMPTY_LIST,
|
||||
null,
|
||||
false,
|
||||
true );
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import org.apache.maven.profiles.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.build.model.ModelAndFile;
|
||||
import org.apache.maven.project.build.model.ModelLineage;
|
||||
|
@ -113,9 +114,8 @@ public void testResolveParentPom_PreferCachedInstance()
|
|||
projectWorkspace.storeModelAndFile( maf );
|
||||
|
||||
ModelLineage lineage = lineageBuilder.buildModelLineage( childPomFile,
|
||||
localRepo,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
|
||||
Collections.EMPTY_LIST,
|
||||
profileManager,
|
||||
false,
|
||||
false );
|
||||
|
||||
|
@ -133,9 +133,8 @@ public void testResolveParentPom_StoreByFileAndGAVIfUncached()
|
|||
String ver = "1";
|
||||
|
||||
ModelLineage lineage = lineageBuilder.buildModelLineage( childPomFile,
|
||||
localRepo,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
|
||||
Collections.EMPTY_LIST,
|
||||
profileManager,
|
||||
false,
|
||||
false );
|
||||
|
||||
|
@ -164,9 +163,8 @@ public void testReadModel_PreferModelInstanceCachedByFile()
|
|||
projectWorkspace.storeModelAndFile( maf );
|
||||
|
||||
ModelLineage lineage = lineageBuilder.buildModelLineage( pomFile,
|
||||
localRepo,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
|
||||
Collections.EMPTY_LIST,
|
||||
profileManager,
|
||||
false,
|
||||
false );
|
||||
|
||||
|
@ -183,9 +181,8 @@ public void testBuildModelLineage_StoreByFileAndGAVIfUncached()
|
|||
String ver = "1";
|
||||
|
||||
ModelLineage lineage = lineageBuilder.buildModelLineage( pomFile,
|
||||
localRepo,
|
||||
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
|
||||
Collections.EMPTY_LIST,
|
||||
profileManager,
|
||||
false,
|
||||
false );
|
||||
|
||||
|
|
Loading…
Reference in New Issue