diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/ProfileActivationContext.java b/maven-compat/src/main/java/org/apache/maven/profiles/ProfileActivationContext.java index 2ffec57493..95abe3ffa7 100644 --- a/maven-compat/src/main/java/org/apache/maven/profiles/ProfileActivationContext.java +++ b/maven-compat/src/main/java/org/apache/maven/profiles/ProfileActivationContext.java @@ -48,7 +48,12 @@ public class ProfileActivationContext this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed; } - public Properties getExecutionProperties() + public Properties getSystemProperties() + { + return executionProperties; + } + + public Properties getUserProperties() { return executionProperties; } @@ -169,14 +174,18 @@ public class ProfileActivationContext return this; } - public org.apache.maven.model.profile.ProfileActivationContext setExecutionProperties( - Properties executionProperties ) + public org.apache.maven.model.profile.ProfileActivationContext setSystemProperties( Properties systemProperties ) { this.executionProperties.clear(); - this.executionProperties.putAll( executionProperties ); + this.executionProperties.putAll( systemProperties ); return this; } + public org.apache.maven.model.profile.ProfileActivationContext setUserProperties( Properties userProperties ) + { + return setSystemProperties( userProperties ); + } + public org.apache.maven.model.profile.ProfileActivationContext setInactiveProfileIds( List inactiveProfileIds ) { diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 0de0226bfb..c782f09e27 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -77,7 +77,7 @@ public class DefaultMaven //TODO: Need a general way to inject standard properties if ( request.getStartTime() != null ) { - request.getProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) ); + request.getSystemProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) ); } request.setStartTime( new Date() ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 5a31fec96a..383f9cd5be 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -91,7 +91,9 @@ public class DefaultMavenExecutionRequest private String makeBehavior; - private Properties properties; + private Properties systemProperties; + + private Properties userProperties; private Date startTime; @@ -143,7 +145,8 @@ public class DefaultMavenExecutionRequest copy.setGoals( original.getGoals() ); copy.setRecursive( original.isRecursive() ); copy.setPom( original.getPom() ); - copy.setProperties( original.getProperties() ); + copy.setSystemProperties( original.getSystemProperties() ); + copy.setUserProperties( original.getUserProperties() ); copy.setShowErrors( original.isShowErrors() ); copy.setActiveProfiles( original.getActiveProfiles() ); copy.setInactiveProfiles( original.getInactiveProfiles() ); @@ -186,14 +189,24 @@ public class DefaultMavenExecutionRequest return goals; } - public Properties getProperties() + public Properties getSystemProperties() { - if ( properties == null ) + if ( systemProperties == null ) { - properties = new Properties(); + systemProperties = new Properties(); } - return properties; + return systemProperties; + } + + public Properties getUserProperties() + { + if ( userProperties == null ) + { + userProperties = new Properties(); + } + + return userProperties; } public File getPom() @@ -411,24 +424,32 @@ public class DefaultMavenExecutionRequest return this; } - public MavenExecutionRequest setProperties( Properties properties ) + public MavenExecutionRequest setSystemProperties( Properties properties ) { if ( properties != null ) { - this.properties = new Properties(); - this.properties.putAll( properties ); + this.systemProperties = new Properties(); + this.systemProperties.putAll( properties ); } else { - this.properties = null; + this.systemProperties = null; } return this; } - public MavenExecutionRequest setProperty( String key, String value ) + public MavenExecutionRequest setUserProperties( Properties userProperties ) { - getProperties().setProperty( key, value ); + if ( userProperties != null ) + { + this.userProperties = new Properties(); + this.userProperties.putAll( userProperties ); + } + else + { + this.userProperties = null; + } return this; } @@ -868,7 +889,8 @@ public class DefaultMavenExecutionRequest { projectBuildingRequest = new DefaultProjectBuildingRequest(); projectBuildingRequest.setLocalRepository( getLocalRepository() ); - projectBuildingRequest.setExecutionProperties( getProperties() ); + projectBuildingRequest.setSystemProperties( getSystemProperties() ); + projectBuildingRequest.setUserProperties( getUserProperties() ); projectBuildingRequest.setRemoteRepositories( getRemoteRepositories() ); projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() ); projectBuildingRequest.setActiveProfileIds( getActiveProfiles() ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index c111cb470a..7954488506 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -99,9 +99,42 @@ public interface MavenExecutionRequest List getGoals(); // Properties - MavenExecutionRequest setProperties( Properties properties ); - MavenExecutionRequest setProperty( String key, String value ); - Properties getProperties(); + + /** + * Sets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. + * + * @param systemProperties The system properties, may be {@code null}. + * @return This request, never {@code null}. + */ + MavenExecutionRequest setSystemProperties( Properties systemProperties ); + + /** + * Gets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. + * + * @return The system properties, never {@code null}. + */ + Properties getSystemProperties(); + + /** + * Sets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @param userProperties The user properties, may be {@code null}. + * @return This request, never {@code null}. + */ + MavenExecutionRequest setUserProperties( Properties userProperties ); + + /** + * Gets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @return The user properties, never {@code null}. + */ + Properties getUserProperties(); // Reactor MavenExecutionRequest setReactorFailureBehavior( String failureBehavior ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 043915a03a..b2b7c78c5a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -45,7 +45,9 @@ public class MavenSession private MavenExecutionRequest request; private MavenExecutionResult result; - + + private Properties executionProperties; + private MavenProject currentProject; /** @@ -109,9 +111,43 @@ public class MavenSession return request.getGoals(); } + /** + * Gets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @return The user properties, never {@code null}. + */ + public Properties getUserProperties() + { + return request.getUserProperties(); + } + + /** + * Gets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. + * + * @return The system properties, never {@code null}. + */ + public Properties getSystemProperties() + { + return request.getSystemProperties(); + } + + /** + * @deprecated Use either {@link #getUserProperties()} or {@link #getSystemProperties()}. + */ + @Deprecated public Properties getExecutionProperties() { - return request.getProperties(); + if ( executionProperties == null ) + { + executionProperties = new Properties(); + executionProperties.putAll( request.getSystemProperties() ); + executionProperties.putAll( request.getUserProperties() ); + } + + return executionProperties; } public Settings getSettings() diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 1260595108..cb446adc64 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -211,7 +211,8 @@ public class DefaultProjectBuilder request.setProfiles( configuration.getProfiles() ); request.setActiveProfileIds( configuration.getActiveProfileIds() ); request.setInactiveProfileIds( configuration.getInactiveProfileIds() ); - request.setExecutionProperties( configuration.getExecutionProperties() ); + request.setSystemProperties( configuration.getSystemProperties() ); + request.setUserProperties( configuration.getUserProperties() ); request.setBuildStartTime( configuration.getBuildStartTime() ); request.setModelResolver( resolver ); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java index ac4210e75f..d23167ae56 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java @@ -52,7 +52,7 @@ public class DefaultProjectBuilderConfiguration public ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties ) { - super.setExecutionProperties( executionProperties ); + super.setSystemProperties( executionProperties ); return this; } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java index 12d9688b6e..aca691a5dd 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java @@ -52,7 +52,9 @@ public class DefaultProjectBuildingRequest private List inactiveProfileIds; - private Properties executionProperties; + private Properties systemProperties; + + private Properties userProperties; private Date buildStartTime; @@ -62,7 +64,8 @@ public class DefaultProjectBuildingRequest profiles = new ArrayList(); activeProfileIds = new ArrayList(); inactiveProfileIds = new ArrayList(); - executionProperties = new Properties(); + systemProperties = new Properties(); + userProperties = new Properties(); remoteRepositories = new ArrayList(); pluginArtifactRepositories = new ArrayList(); } @@ -126,21 +129,41 @@ public class DefaultProjectBuildingRequest return this; } - public Properties getExecutionProperties() + public Properties getSystemProperties() { - return executionProperties; + return systemProperties; } - public ProjectBuildingRequest setExecutionProperties( Properties executionProperties ) + public ProjectBuildingRequest setSystemProperties( Properties systemProperties ) { - if ( executionProperties != null ) + if ( systemProperties != null ) { - this.executionProperties = new Properties(); - this.executionProperties.putAll( executionProperties ); + this.systemProperties = new Properties(); + this.systemProperties.putAll( systemProperties ); } else { - this.executionProperties.clear(); + this.systemProperties.clear(); + } + + return this; + } + + public Properties getUserProperties() + { + return userProperties; + } + + public ProjectBuildingRequest setUserProperties( Properties userProperties ) + { + if ( userProperties != null ) + { + this.userProperties = new Properties(); + this.userProperties.putAll( userProperties ); + } + else + { + this.userProperties.clear(); } return this; diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java index 2d8a2bd1af..5874fac956 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java @@ -20,7 +20,7 @@ public interface ProjectBuilderConfiguration ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties ); - Properties getExecutionProperties(); + Properties getSystemProperties(); void setTopLevelProjectForReactor(MavenProject mavenProject); diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java index fd86254ea7..2ba6a0c41f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java @@ -22,9 +22,41 @@ public interface ProjectBuildingRequest List getPluginArtifactRepositories(); - ProjectBuildingRequest setExecutionProperties( Properties executionProperties ); + /** + * Sets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. + * + * @param systemProperties The system properties, may be {@code null}. + * @return This request, never {@code null}. + */ + ProjectBuildingRequest setSystemProperties( Properties systemProperties ); - Properties getExecutionProperties(); + /** + * Gets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. + * + * @return The system properties, never {@code null}. + */ + Properties getSystemProperties(); + + /** + * Sets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @param userProperties The user properties, may be {@code null}. + * @return This request, never {@code null}. + */ + ProjectBuildingRequest setUserProperties( Properties userProperties ); + + /** + * Gets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @return The user properties, never {@code null}. + */ + Properties getUserProperties(); void setTopLevelProjectForReactor(MavenProject mavenProject); diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 0ab9f4df8a..c0fedcd88b 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -119,7 +119,7 @@ public class MavenMetadataSource // We don't care about processing plugins here, all we're interested in is the dependencies. configuration.setProcessPlugins( false ); // FIXME: We actually need the execution properties here... - configuration.setExecutionProperties( System.getProperties() ); + configuration.setSystemProperties( System.getProperties() ); try { diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index a3ffb36dfe..da4e3ae729 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -131,7 +131,9 @@ public class DefaultMavenSettingsBuilder RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); - interpolator.addValueSource( new PropertiesBasedValueSource( request.getProperties() ) ); + interpolator.addValueSource( new PropertiesBasedValueSource( request.getUserProperties() ) ); + + interpolator.addValueSource( new PropertiesBasedValueSource( request.getSystemProperties() ) ); interpolator.addValueSource( new EnvarBasedValueSource() ); diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 7aa9a8331b..062357470c 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -92,8 +92,7 @@ public abstract class AbstractCoreMavenComponentTestCase .setLocalRepository( getLocalRepository() ) .setRemoteRepositories( getRemoteRepositories() ) .setPluginArtifactRepositories( getPluginArtifactRepositories() ) - .setGoals( Arrays.asList( new String[] { "package" } ) ) - .setProperties( new Properties() ); + .setGoals( Arrays.asList( new String[] { "package" } ) ); return request; } @@ -116,7 +115,7 @@ public abstract class AbstractCoreMavenComponentTestCase .setLocalRepository( request.getLocalRepository() ) .setRemoteRepositories( request.getRemoteRepositories() ) .setPluginArtifactRepositories( request.getPluginArtifactRepositories() ) - .setExecutionProperties( executionProperties ); + .setSystemProperties( executionProperties ); MavenProject project = null; diff --git a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java index e54cf0ae76..d23b06dd3a 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenLifecycleParticipantTest.java @@ -65,7 +65,7 @@ public class MavenLifecycleParticipantTest @Override public void afterSessionStart( MavenSession session ) { - session.getExecutionProperties().setProperty( "injected", "bar" ); + session.getUserProperties().setProperty( "injected", "bar" ); } } diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 20a4acb310..af635409b8 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -331,7 +331,7 @@ public class PluginParameterExpressionEvaluatorTest throws CycleDetectedException, DuplicateProjectException { MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setProperties( properties ) + .setSystemProperties( properties ) .setGoals( Collections.EMPTY_LIST ) .setBaseDirectory( new File( "" ) ) .setLocalRepository( repo ); diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 74e5305513..fa5d0d025d 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -1677,7 +1677,8 @@ public class PomConstructionTest localRepoUrl = "file://" + localRepoUrl; config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) ); config.setActiveProfileIds( Arrays.asList( profileIds ) ); - config.setExecutionProperties( executionProperties ); + config.setSystemProperties( executionProperties ); + config.setUserProperties( executionProperties ); config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 : ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java index dd6ef47b15..7add401fc8 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java @@ -221,9 +221,9 @@ public final class CLIRequestUtils loggingLevel = MavenExecutionRequest.LOGGING_LEVEL_INFO; } - Properties executionProperties = new Properties(); + Properties systemProperties = new Properties(); Properties userProperties = new Properties(); - populateProperties( commandLine, executionProperties, userProperties ); + populateProperties( commandLine, systemProperties, userProperties ); File userToolchainsFile; if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) ) @@ -238,7 +238,8 @@ public final class CLIRequestUtils MavenExecutionRequest request = new DefaultMavenExecutionRequest() .setBaseDirectory( baseDirectory ) .setGoals( goals ) - .setProperties( executionProperties ) // optional + .setSystemProperties( systemProperties ) + .setUserProperties( userProperties ) .setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast .setRecursive( recursive ) // default: true .setShowErrors( showErrors ) // default: false @@ -297,7 +298,12 @@ public final class CLIRequestUtils request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_BOTH ); } - String localRepoProperty = request.getProperties().getProperty( MavenCli.LOCAL_REPO_PROPERTY ); + String localRepoProperty = request.getUserProperties().getProperty( MavenCli.LOCAL_REPO_PROPERTY ); + + if ( localRepoProperty == null ) + { + localRepoProperty = request.getSystemProperties().getProperty( MavenCli.LOCAL_REPO_PROPERTY ); + } if ( localRepoProperty != null ) { @@ -311,7 +317,7 @@ public final class CLIRequestUtils // System properties handling // ---------------------------------------------------------------------- - static void populateProperties( CommandLine commandLine, Properties executionProperties, Properties userProperties ) + static void populateProperties( CommandLine commandLine, Properties systemProperties, Properties userProperties ) { // add the env vars to the property set, with the "env." prefix // XXX support for env vars should probably be removed from the ModelInterpolator @@ -320,7 +326,7 @@ public final class CLIRequestUtils Properties envVars = CommandLineUtils.getSystemEnvVars(); for ( Entry e : envVars.entrySet() ) { - executionProperties.setProperty( "env." + e.getKey().toString(), e.getValue().toString() ); + systemProperties.setProperty( "env." + e.getKey().toString(), e.getValue().toString() ); } } catch ( IOException e ) @@ -345,14 +351,12 @@ public final class CLIRequestUtils setCliProperty( defStrs[i], userProperties ); } } - - executionProperties.putAll( userProperties ); } - executionProperties.putAll( System.getProperties() ); + systemProperties.putAll( System.getProperties() ); } - private static void setCliProperty( String property, Properties executionProperties ) + private static void setCliProperty( String property, Properties properties ) { String name; @@ -373,7 +377,7 @@ public final class CLIRequestUtils value = property.substring( i + 1 ).trim(); } - executionProperties.setProperty( name, value ); + properties.setProperty( name, value ); // ---------------------------------------------------------------------- // I'm leaving the setting of system properties here as not to break diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 1925ec6663..6daab60ed9 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -253,7 +253,7 @@ public class MavenCli configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ); } - String localRepoProperty = request.getProperties().getProperty( LOCAL_REPO_PROPERTY ); + String localRepoProperty = request.getUserProperties().getProperty( LOCAL_REPO_PROPERTY ); if ( localRepoProperty != null ) { diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java index 9581ffa220..0b1606b552 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIRequestUtilsTest.java @@ -55,9 +55,9 @@ public class CLIRequestUtilsTest MavenExecutionRequest request = CLIRequestUtils.buildRequest( commandLine, false, false, false ); - Properties execProperties = request.getProperties(); + Properties userProperties = request.getUserProperties(); - assertEquals( value, execProperties.getProperty( key ) ); + assertEquals( value, userProperties.getProperty( key ) ); List goals = request.getGoals(); assertTrue( ( goals == null ) || goals.isEmpty() ); @@ -93,8 +93,5 @@ public class CLIRequestUtilsTest 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" ) ); } } diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java index e40e0d1c52..0745876831 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java @@ -98,7 +98,7 @@ public abstract class AbstractCoreMavenComponentTestCase .setRemoteRepositories( getRemoteRepositories() ) .setPluginArtifactRepositories( getPluginArtifactRepositories() ) .setGoals( Arrays.asList( new String[] { "package" } ) ) - .setProperties( new Properties() ); + .setSystemProperties( new Properties() ); return request; } @@ -121,7 +121,7 @@ public abstract class AbstractCoreMavenComponentTestCase .setLocalRepository( request.getLocalRepository() ) .setRemoteRepositories( request.getRemoteRepositories() ) .setPluginArtifactRepositories( request.getPluginArtifactRepositories() ) - .setExecutionProperties( executionProperties ); + .setSystemProperties( executionProperties ); MavenProject project = null; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 8279073440..0c55c3d0ad 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -315,7 +315,8 @@ public class DefaultModelBuilder context.setActiveProfileIds( request.getActiveProfileIds() ); context.setInactiveProfileIds( request.getInactiveProfileIds() ); - context.setExecutionProperties( request.getExecutionProperties() ); + context.setSystemProperties( request.getSystemProperties() ); + context.setUserProperties( request.getUserProperties() ); context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null ); return context; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java index 56e40d0b28..9baea57691 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java @@ -51,7 +51,9 @@ public class DefaultModelBuildingRequest private List inactiveProfileIds; - private Properties executionProperties; + private Properties systemProperties; + + private Properties userProperties; private Date buildStartTime; @@ -179,26 +181,51 @@ public class DefaultModelBuildingRequest return this; } - public Properties getExecutionProperties() + public Properties getSystemProperties() { - if ( executionProperties == null ) + if ( systemProperties == null ) { - executionProperties = new Properties(); + systemProperties = new Properties(); } - return executionProperties; + return systemProperties; } - public DefaultModelBuildingRequest setExecutionProperties( Properties executionProperties ) + public DefaultModelBuildingRequest setSystemProperties( Properties systemProperties ) { - if ( executionProperties != null ) + if ( systemProperties != null ) { - this.executionProperties = new Properties(); - this.executionProperties.putAll( executionProperties ); + this.systemProperties = new Properties(); + this.systemProperties.putAll( systemProperties ); } else { - this.executionProperties = null; + this.systemProperties = null; + } + + return this; + } + + public Properties getUserProperties() + { + if ( userProperties == null ) + { + userProperties = new Properties(); + } + + return userProperties; + } + + public DefaultModelBuildingRequest setUserProperties( Properties userProperties ) + { + if ( userProperties != null ) + { + this.userProperties = new Properties(); + this.userProperties.putAll( userProperties ); + } + else + { + this.userProperties = null; } return this; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java index 20093f793b..d2e5acf478 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java @@ -180,19 +180,40 @@ public interface ModelBuildingRequest ModelBuildingRequest setInactiveProfileIds( List inactiveProfileIds ); /** - * Gets the execution properties. + * Gets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. * - * @return The execution properties, never {@code null}. + * @return The system properties, never {@code null}. */ - Properties getExecutionProperties(); + Properties getSystemProperties(); /** - * Sets the execution properties. + * Sets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. * - * @param executionProperties The execution properties, may be {@code null}. + * @param systemProperties The system properties, may be {@code null}. * @return This request, never {@code null}. */ - ModelBuildingRequest setExecutionProperties( Properties executionProperties ); + ModelBuildingRequest setSystemProperties( Properties systemProperties ); + + /** + * Gets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @return The user properties, never {@code null}. + */ + Properties getUserProperties(); + + /** + * Sets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @param userProperties The user properties, may be {@code null}. + * @return This request, never {@code null}. + */ + ModelBuildingRequest setUserProperties( Properties userProperties ); /** * Gets the start time of the build. diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java index 437fbd55ae..83045a41c8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java @@ -151,15 +151,17 @@ public abstract class AbstractStringBasedModelInterpolator valueSources.add( modelValueSource1 ); - valueSources.add( new MapBasedValueSource( config.getExecutionProperties() ) ); + valueSources.add( new MapBasedValueSource( config.getUserProperties() ) ); valueSources.add( new MapBasedValueSource( modelProperties ) ); + valueSources.add( new MapBasedValueSource( config.getSystemProperties() ) ); + valueSources.add( new AbstractValueSource( false ) { public Object getValue( String expression ) { - return config.getExecutionProperties().getProperty( "env." + expression ); + return config.getSystemProperties().getProperty( "env." + expression ); } } ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java index 0566ff4f01..5a8ffc756e 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java @@ -37,7 +37,9 @@ public class DefaultProfileActivationContext private List inactiveProfileIds; - private Properties executionProperties; + private Properties systemProperties; + + private Properties userProperties; private File projectDirectory; @@ -89,26 +91,51 @@ public class DefaultProfileActivationContext return this; } - public Properties getExecutionProperties() + public Properties getSystemProperties() { - if ( executionProperties == null ) + if ( systemProperties == null ) { - executionProperties = new Properties(); + systemProperties = new Properties(); } - return executionProperties; + return systemProperties; } - public DefaultProfileActivationContext setExecutionProperties( Properties executionProperties ) + public DefaultProfileActivationContext setSystemProperties( Properties systemProperties ) { - if ( executionProperties != null ) + if ( systemProperties != null ) { - this.executionProperties = new Properties(); - this.executionProperties.putAll( executionProperties ); + this.systemProperties = new Properties(); + this.systemProperties.putAll( systemProperties ); } else { - this.executionProperties = null; + this.systemProperties = null; + } + + return this; + } + + public Properties getUserProperties() + { + if ( userProperties == null ) + { + userProperties = new Properties(); + } + + return userProperties; + } + + public DefaultProfileActivationContext setUserProperties( Properties userProperties ) + { + if ( userProperties != null ) + { + this.userProperties = new Properties(); + this.userProperties.putAll( userProperties ); + } + else + { + this.userProperties = null; } return this; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java index 4c74ccfb7c..f98a661bfc 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java @@ -62,19 +62,40 @@ public interface ProfileActivationContext ProfileActivationContext setInactiveProfileIds( List inactiveProfileIds ); /** - * Gets the execution properties. + * Gets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. * * @return The execution properties, never {@code null}. */ - Properties getExecutionProperties(); + Properties getSystemProperties(); /** - * Sets the execution properties. + * Sets the system properties to use for interpolation and profile activation. The system properties are collected + * from the runtime environment like {@link System#getProperties()} and environment variables. * * @param executionProperties The execution properties, may be {@code null}. * @return This context, never {@code null}. */ - ProfileActivationContext setExecutionProperties( Properties executionProperties ); + ProfileActivationContext setSystemProperties( Properties executionProperties ); + + /** + * Gets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @return The user properties, never {@code null}. + */ + Properties getUserProperties(); + + /** + * Sets the user properties to use for interpolation and profile activation. The user properties have been + * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command + * line. + * + * @param userProperties The user properties, may be {@code null}. + * @return This context, never {@code null}. + */ + ProfileActivationContext setUserProperties( Properties userProperties ); /** * Gets the base directory of the current project (if any). diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java index 32d216c353..c20459a16c 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java @@ -109,7 +109,9 @@ public class FileProfileActivator return false; } - interpolator.addValueSource( new MapBasedValueSource( context.getExecutionProperties() ) ); + interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) ); + + interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) ); try { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java index d76e5727a4..665ba14782 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java @@ -52,7 +52,7 @@ public class JdkVersionProfileActivator if ( jdk != null ) { - String version = context.getExecutionProperties().getProperty( "java.version", "" ); + String version = context.getSystemProperties().getProperty( "java.version", "" ); if ( version.length() <= 0 ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java index 2a32286791..a0df222645 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java @@ -65,7 +65,11 @@ public class PropertyProfileActivator name = name.substring( 1 ); } - String sysValue = context.getExecutionProperties().getProperty( name ); + String sysValue = context.getUserProperties().getProperty( name ); + if ( sysValue == null ) + { + sysValue = context.getSystemProperties().getProperty( name ); + } String propValue = property.getValue(); if ( StringUtils.isNotEmpty( propValue ) ) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java index b0b2e1ae62..f5a332a775 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -71,9 +71,10 @@ public abstract class AbstractProfileActivatorTest super.tearDown(); } - protected ProfileActivationContext newContext( final Properties executionProperties ) + protected ProfileActivationContext newContext( final Properties userProperties, final Properties systemProperties ) { - return new DefaultProfileActivationContext().setExecutionProperties( executionProperties ); + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); + return context.setUserProperties( userProperties ).setSystemProperties( systemProperties ); } } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java index 78ae3dbc26..ef915beeae 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -61,11 +61,11 @@ public class JdkVersionProfileActivatorTest { Profile p = new Profile(); - assertFalse( activator.isActive( p, newContext( new Properties() ) ) ); + assertFalse( activator.isActive( p, newContext( null, null ) ) ); p.setActivation( new Activation() ); - assertFalse( activator.isActive( p, newContext( new Properties() ) ) ); + assertFalse( activator.isActive( p, newContext( null, null ) ) ); } public void testPrefix() @@ -73,13 +73,13 @@ public class JdkVersionProfileActivatorTest { Profile profile = newProfile( "1.4" ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.4" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.4" ) ) ) ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.4.2" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.4.2" ) ) ) ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.3" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.3" ) ) ) ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.5" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.5" ) ) ) ); } public void testPrefixNegated() @@ -87,13 +87,13 @@ public class JdkVersionProfileActivatorTest { Profile profile = newProfile( "!1.4" ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.4" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.4" ) ) ) ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.4.2" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.4.2" ) ) ) ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.3" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.3" ) ) ) ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.5" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.5" ) ) ) ); } public void testVersionRange() @@ -101,13 +101,13 @@ public class JdkVersionProfileActivatorTest { Profile profile = newProfile( "(1.3,1.6)" ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.5.0_16" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.5.0_16" ) ) ) ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.3" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.3" ) ) ) ); - assertTrue( activator.isActive( profile, newContext( newProperties( "1.3.1" ) ) ) ); + assertTrue( activator.isActive( profile, newContext( null, newProperties( "1.3.1" ) ) ) ); - assertFalse( activator.isActive( profile, newContext( newProperties( "1.6" ) ) ) ); + assertFalse( activator.isActive( profile, newContext( null, newProperties( "1.6" ) ) ) ); } }