[MNG-5418] Can't activate a profile by checking for the presence of a file in ${myProperty}.

This commit is contained in:
olivier lamy 2013-01-05 00:21:31 +01:00
parent ff370850cd
commit 2f97f96fb1
4 changed files with 61 additions and 11 deletions

View File

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

View File

@ -21,6 +21,8 @@ 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;
@ -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()
@ -106,7 +110,7 @@ public class DefaultProfileActivationContext
* @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 )
@ -155,7 +159,7 @@ public class DefaultProfileActivationContext
* @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 )
@ -201,7 +205,7 @@ 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;
}
}

View File

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

View File

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