Updated Branches: refs/heads/MNG-5418 [created] db73d0bcd
[MNG-5418] Can't activate a profile by checking for the presence of a file in ${myProperty}. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/db73d0bc Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/db73d0bc Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/db73d0bc Branch: refs/heads/MNG-5418 Commit: db73d0bcddba3755840969b476199b3471f160e4 Parents: 57d9c68 Author: olivier lamy <ol...@apache.org> Authored: Sat Jan 5 00:21:31 2013 +0100 Committer: olivier lamy <ol...@apache.org> Committed: Sat Jan 5 00:21:31 2013 +0100 ---------------------------------------------------------------------- .../maven/model/building/DefaultModelBuilder.java | 2 + .../profile/DefaultProfileActivationContext.java | 61 ++++++++++++--- .../model/profile/ProfileActivationContext.java | 7 ++ .../profile/activation/FileProfileActivator.java | 2 + 4 files changed, 61 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/db73d0bc/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java ---------------------------------------------------------------------- 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 90a20eb..25d9eab 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 @@ -278,6 +278,8 @@ public class DefaultModelBuilder modelNormalizer.mergeDuplicates( tmpModel, request, problems ); + profileActivationContext.setProjectProperties( tmpModel.getProperties() ); + List<Profile> activePomProfiles = profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems ); currentData.setActiveProfiles( activePomProfiles ); http://git-wip-us.apache.org/repos/asf/maven/blob/db73d0bc/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java ---------------------------------------------------------------------- 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 7258b8b..5bd1c58 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 @@ -21,13 +21,15 @@ package org.apache.maven.model.profile; import java.io.File; import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; /** * Describes the environmental context used to determine the activation status of profiles. - * + * * @author Benjamin Bentmann */ public class DefaultProfileActivationContext @@ -42,6 +44,8 @@ public class DefaultProfileActivationContext private Map<String, String> userProperties = Collections.emptyMap(); + private Map<String, String> projectProperties = Collections.emptyMap(); + private File projectDirectory; public List<String> getActiveProfileIds() @@ -51,7 +55,7 @@ public class DefaultProfileActivationContext /** * Sets the identifiers of those profiles that should be activated by explicit demand. - * + * * @param activeProfileIds The identifiers of those profiles to activate, may be {@code null}. * @return This context, never {@code null}. */ @@ -76,7 +80,7 @@ public class DefaultProfileActivationContext /** * Sets the identifiers of those profiles that should be deactivated by explicit demand. - * + * * @param inactiveProfileIds The identifiers of those profiles to deactivate, may be {@code null}. * @return This context, never {@code null}. */ @@ -102,11 +106,11 @@ public class DefaultProfileActivationContext /** * 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 context, never {@code null}. */ - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public DefaultProfileActivationContext setSystemProperties( Properties systemProperties ) { if ( systemProperties != null ) @@ -124,7 +128,7 @@ public class DefaultProfileActivationContext /** * 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 context, never {@code null}. */ @@ -151,11 +155,11 @@ public class DefaultProfileActivationContext * 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}. */ - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public DefaultProfileActivationContext setUserProperties( Properties userProperties ) { if ( userProperties != null ) @@ -174,7 +178,7 @@ public class DefaultProfileActivationContext * 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}. */ @@ -199,9 +203,9 @@ public class DefaultProfileActivationContext /** * Sets the base directory of the current project. - * + * * @param projectDirectory The base directory of the current project, may be {@code null} if profile activation - * happens in the context of metadata retrieval rather than project building. + * happens in the context of metadata retrieval rather than project building. * @return This context, never {@code null}. */ public DefaultProfileActivationContext setProjectDirectory( File projectDirectory ) @@ -211,4 +215,39 @@ public class DefaultProfileActivationContext return this; } + public Map<String, String> getProjectProperties() + { + return projectProperties; + } + + public DefaultProfileActivationContext setProjectProperties( Properties projectProperties ) + { + if ( projectProperties != null ) + { + + this.projectProperties = Collections.unmodifiableMap( toMap( projectProperties ) ); + } + else + { + this.projectProperties = Collections.emptyMap(); + } + + return this; + } + + private Map<String, String> toMap( Properties properties ) + { + if ( properties == null ) + { + return Collections.emptyMap(); + } + Map<String, String> map = new HashMap<String, String>(); + Enumeration keys = properties.keys(); + while ( keys.hasMoreElements() ) + { + String key = (String) keys.nextElement(); + map.put( key, properties.getProperty( key ) ); + } + return map; + } } http://git-wip-us.apache.org/repos/asf/maven/blob/db73d0bc/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java ---------------------------------------------------------------------- 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 63540f2..fb9ea0c 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 @@ -69,4 +69,11 @@ public interface ProfileActivationContext */ File getProjectDirectory(); + /** + * Gets current calculated project properties + * + * @return The project properties, never {@code null}. + */ + Map<String, String> getProjectProperties(); + } http://git-wip-us.apache.org/repos/asf/maven/blob/db73d0bc/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java ---------------------------------------------------------------------- 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 aa35bcc..b4ecf26 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 @@ -118,6 +118,8 @@ public class FileProfileActivator return false; } + interpolator.addValueSource( new MapBasedValueSource( context.getProjectProperties() ) ); + interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) ); interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) );