o Re-introduced distinction between user properties and system properties. We have use cases like interpolation and SUREFIRE-121 where we would like to handle user-specified props specially so a single properties soup is not up to the job. However, I opted not to follow the approach from 2.x where we also collect both system properties and user properties in a combined set called execution properties. Code that embeds Maven and programmatically creates an execution request should be not required to assemble such a mixed properties instance, it would enable bad behavior from Maven by subtle API misuse. Also, for things like the lifecycle participant that wants to inject properties, it should be cristal clear whether it injects a user or a system property, the semantics of something like getExecutionProperties().setProperty() would be unclear however.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@796900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-22 22:43:05 +00:00
parent cf295ef70a
commit 88216c6532
31 changed files with 381 additions and 116 deletions

View File

@ -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<String> inactiveProfileIds )
{

View File

@ -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() );

View File

@ -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() );

View File

@ -99,9 +99,42 @@ public interface MavenExecutionRequest
List<String> 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 );

View File

@ -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()

View File

@ -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 );

View File

@ -52,7 +52,7 @@ public class DefaultProjectBuilderConfiguration
public ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties )
{
super.setExecutionProperties( executionProperties );
super.setSystemProperties( executionProperties );
return this;
}

View File

@ -52,7 +52,9 @@ public class DefaultProjectBuildingRequest
private List<String> inactiveProfileIds;
private Properties executionProperties;
private Properties systemProperties;
private Properties userProperties;
private Date buildStartTime;
@ -62,7 +64,8 @@ public class DefaultProjectBuildingRequest
profiles = new ArrayList<Profile>();
activeProfileIds = new ArrayList<String>();
inactiveProfileIds = new ArrayList<String>();
executionProperties = new Properties();
systemProperties = new Properties();
userProperties = new Properties();
remoteRepositories = new ArrayList<ArtifactRepository>();
pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
}
@ -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;

View File

@ -20,7 +20,7 @@ public interface ProjectBuilderConfiguration
ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties );
Properties getExecutionProperties();
Properties getSystemProperties();
void setTopLevelProjectForReactor(MavenProject mavenProject);

View File

@ -22,9 +22,41 @@ public interface ProjectBuildingRequest
List<ArtifactRepository> 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);

View File

@ -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
{

View File

@ -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() );

View File

@ -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;

View File

@ -65,7 +65,7 @@ public class MavenLifecycleParticipantTest
@Override
public void afterSessionStart( MavenSession session )
{
session.getExecutionProperties().setProperty( "injected", "bar" );
session.getUserProperties().setProperty( "injected", "bar" );
}
}

View File

@ -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 );

View File

@ -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 );

View File

@ -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<Object, Object> 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

View File

@ -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 )
{

View File

@ -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" ) );
}
}

View File

@ -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;

View File

@ -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;

View File

@ -51,7 +51,9 @@ public class DefaultModelBuildingRequest
private List<String> 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;

View File

@ -180,19 +180,40 @@ public interface ModelBuildingRequest
ModelBuildingRequest setInactiveProfileIds( List<String> 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.

View File

@ -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 );
}
} );

View File

@ -37,7 +37,9 @@ public class DefaultProfileActivationContext
private List<String> 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;

View File

@ -62,19 +62,40 @@ public interface ProfileActivationContext
ProfileActivationContext setInactiveProfileIds( List<String> 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).

View File

@ -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
{

View File

@ -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 )
{

View File

@ -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 ) )

View File

@ -71,9 +71,10 @@ public abstract class AbstractProfileActivatorTest<T extends ProfileActivator>
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 );
}
}

View File

@ -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" ) ) ) );
}
}