Author: bentmann Date: Sat Jul 17 20:50:25 2010 New Revision: 965131 URL: http://svn.apache.org/viewvc?rev=965131&view=rev Log: o Tweaked API
Modified: maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java Modified: maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original) +++ maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Sat Jul 17 20:50:25 2010 @@ -183,7 +183,7 @@ public class DefaultProfileManager public List getActiveProfiles() throws ProfileActivationException { - ProfileActivationContext context = new DefaultProfileActivationContext(); + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); context.setActiveProfileIds( activatedIds ); context.setInactiveProfileIds( deactivatedIds ); context.setSystemProperties( System.getProperties() ); Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Sat Jul 17 20:50:25 2010 @@ -240,7 +240,7 @@ public class DefaultModelBuilder DefaultModelProblemCollector problems = new DefaultModelProblemCollector( null ); - ProfileActivationContext profileActivationContext = getProfileActivationContext( request ); + DefaultProfileActivationContext profileActivationContext = getProfileActivationContext( request ); problems.setSource( "(external profiles)" ); List<Profile> activeExternalProfiles = @@ -537,9 +537,9 @@ public class DefaultModelBuilder return model; } - private ProfileActivationContext getProfileActivationContext( ModelBuildingRequest request ) + private DefaultProfileActivationContext getProfileActivationContext( ModelBuildingRequest request ) { - ProfileActivationContext context = new DefaultProfileActivationContext(); + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); context.setActiveProfileIds( request.getActiveProfileIds() ); context.setInactiveProfileIds( request.getInactiveProfileIds() ); Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java Sat Jul 17 20:50:25 2010 @@ -20,8 +20,9 @@ package org.apache.maven.model.profile; */ import java.io.File; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Properties; /** @@ -33,35 +34,36 @@ public class DefaultProfileActivationCon implements ProfileActivationContext { - private List<String> activeProfileIds; + private List<String> activeProfileIds = Collections.emptyList(); - private List<String> inactiveProfileIds; + private List<String> inactiveProfileIds = Collections.emptyList(); - private Properties systemProperties; + private Map<String, String> systemProperties = Collections.emptyMap(); - private Properties userProperties; + private Map<String, String> userProperties = Collections.emptyMap(); private File projectDirectory; public List<String> getActiveProfileIds() { - if ( activeProfileIds == null ) - { - activeProfileIds = new ArrayList<String>(); - } - return activeProfileIds; } + /** + * 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}. + */ public DefaultProfileActivationContext setActiveProfileIds( List<String> activeProfileIds ) { if ( activeProfileIds != null ) { - this.activeProfileIds = new ArrayList<String>( activeProfileIds ); + this.activeProfileIds = Collections.unmodifiableList( activeProfileIds ); } else { - this.activeProfileIds = null; + this.activeProfileIds = Collections.emptyList(); } return this; @@ -69,73 +71,122 @@ public class DefaultProfileActivationCon public List<String> getInactiveProfileIds() { - if ( inactiveProfileIds == null ) - { - inactiveProfileIds = new ArrayList<String>(); - } - return inactiveProfileIds; } + /** + * 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}. + */ public DefaultProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds ) { if ( inactiveProfileIds != null ) { - this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds ); + this.inactiveProfileIds = Collections.unmodifiableList( inactiveProfileIds ); } else { - this.inactiveProfileIds = null; + this.inactiveProfileIds = Collections.emptyList(); } return this; } - public Properties getSystemProperties() + public Map<String, String> getSystemProperties() { - if ( systemProperties == null ) - { - systemProperties = new Properties(); - } - return systemProperties; } + /** + * 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}. + */ + @SuppressWarnings( "unchecked" ) public DefaultProfileActivationContext setSystemProperties( Properties systemProperties ) { if ( systemProperties != null ) { - this.systemProperties = new Properties(); - this.systemProperties.putAll( systemProperties ); + this.systemProperties = Collections.unmodifiableMap( (Map) systemProperties ); } else { - this.systemProperties = null; + this.systemProperties = Collections.emptyMap(); } return this; } - public Properties getUserProperties() + /** + * 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}. + */ + public DefaultProfileActivationContext setSystemProperties( Map<String, String> systemProperties ) { - if ( userProperties == null ) + if ( systemProperties != null ) { - userProperties = new Properties(); + this.systemProperties = Collections.unmodifiableMap( systemProperties ); } + else + { + this.systemProperties = Collections.emptyMap(); + } + + return this; + } + public Map<String, String> getUserProperties() + { return userProperties; } + /** + * 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" ) public DefaultProfileActivationContext setUserProperties( Properties userProperties ) { if ( userProperties != null ) { - this.userProperties = new Properties(); - this.userProperties.putAll( userProperties ); + this.userProperties = Collections.unmodifiableMap( (Map) userProperties ); + } + else + { + this.userProperties = Collections.emptyMap(); + } + + return this; + } + + /** + * 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}. + */ + public DefaultProfileActivationContext setUserProperties( Map<String, String> userProperties ) + { + if ( userProperties != null ) + { + this.userProperties = Collections.unmodifiableMap( userProperties ); } else { - this.userProperties = null; + this.userProperties = Collections.emptyMap(); } return this; @@ -146,7 +197,14 @@ public class DefaultProfileActivationCon return projectDirectory; } - public ProfileActivationContext setProjectDirectory( File projectDirectory ) + /** + * 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. + * @return This context, never {...@code null}. + */ + public DefaultProfileActivationContext setProjectDirectory( File projectDirectory ) { this.projectDirectory = projectDirectory; Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/ProfileActivationContext.java Sat Jul 17 20:50:25 2010 @@ -21,7 +21,7 @@ package org.apache.maven.model.profile; import java.io.File; import java.util.List; -import java.util.Properties; +import java.util.Map; /** * Describes the environmental context used to determine the activation status of profiles. @@ -39,14 +39,6 @@ public interface ProfileActivationContex List<String> getActiveProfileIds(); /** - * 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}. - */ - ProfileActivationContext setActiveProfileIds( List<String> activeProfileIds ); - - /** * Gets the identifiers of those profiles that should be deactivated by explicit demand. * * @return The identifiers of those profiles to deactivate, never {...@code null}. @@ -54,29 +46,12 @@ public interface ProfileActivationContex List<String> getInactiveProfileIds(); /** - * 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}. - */ - ProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds ); - - /** * 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 getSystemProperties(); - - /** - * 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 setSystemProperties( Properties executionProperties ); + Map<String, String> getSystemProperties(); /** * Gets the user properties to use for interpolation and profile activation. The user properties have been @@ -85,17 +60,7 @@ public interface ProfileActivationContex * * @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 ); + Map<String, String> getUserProperties(); /** * Gets the base directory of the current project (if any). @@ -104,13 +69,4 @@ public interface ProfileActivationContex */ File getProjectDirectory(); - /** - * 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. - * @return This context, never {...@code null}. - */ - ProfileActivationContext setProjectDirectory( File projectDirectory ); - } Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java Sat Jul 17 20:50:25 2010 @@ -52,9 +52,9 @@ public class JdkVersionProfileActivator if ( jdk != null ) { - String version = context.getSystemProperties().getProperty( "java.version", "" ); + String version = context.getSystemProperties().get( "java.version" ); - if ( version.length() <= 0 ) + if ( version == null || version.length() <= 0 ) { problems.add( Severity.ERROR, "Failed to determine Java version for profile " + profile.getId(), activation.getLocation( "jdk" ), null ); Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java?rev=965131&r1=965130&r2=965131&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java Sat Jul 17 20:50:25 2010 @@ -66,10 +66,10 @@ public class PropertyProfileActivator return false; } - String sysValue = context.getUserProperties().getProperty( name ); + String sysValue = context.getUserProperties().get( name ); if ( sysValue == null ) { - sysValue = context.getSystemProperties().getProperty( name ); + sysValue = context.getSystemProperties().get( name ); } String propValue = property.getValue();