You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/09/13 05:23:33 UTC
svn commit: r280476 - in /maven/components/trunk: maven-model/
maven-profile/ maven-profile/src/main/java/org/apache/maven/profiles/
maven-project/src/main/java/org/apache/maven/profiles/
maven-project/src/main/java/org/apache/maven/profiles/activation...
Author: jdcasey
Date: Mon Sep 12 20:23:16 2005
New Revision: 280476
URL: http://svn.apache.org/viewcvs?rev=280476&view=rev
Log:
Resolving: MNG-835. Using activateByDefault within activation in the profile.
Added:
maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/
maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java (with props)
Modified:
maven/components/trunk/maven-model/maven.mdo
maven/components/trunk/maven-profile/profiles.mdo
maven/components/trunk/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
maven/components/trunk/maven-settings/settings.mdo
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java
Modified: maven/components/trunk/maven-model/maven.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-model/maven.mdo?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-model/maven.mdo (original)
+++ maven/components/trunk/maven-model/maven.mdo Mon Sep 12 20:23:16 2005
@@ -2611,6 +2611,12 @@
]]></description>
<fields>
<field>
+ <name>activeByDefault</name>
+ <version>4.0.0</version>
+ <type>boolean</type>
+ <description>Flag specifying whether this profile is active as a default.</description>
+ </field>
+ <field>
<name>jdk</name>
<version>4.0.0</version>
<type>String</type>
Modified: maven/components/trunk/maven-profile/profiles.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-profile/profiles.mdo?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-profile/profiles.mdo (original)
+++ maven/components/trunk/maven-profile/profiles.mdo Mon Sep 12 20:23:16 2005
@@ -113,6 +113,12 @@
]]></description>
<fields>
<field>
+ <name>activeByDefault</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <description>Flag specifying whether this profile is active as a default.</description>
+ </field>
+ <field>
<name>jdk</name>
<version>1.0.0</version>
<type>String</type>
Modified: maven/components/trunk/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java (original)
+++ maven/components/trunk/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java Mon Sep 12 20:23:16 2005
@@ -44,6 +44,8 @@
if ( profileActivation != null )
{
Activation activation = new Activation();
+
+ activation.setActiveByDefault( profileActivation.isActiveByDefault() );
activation.setJdk( profileActivation.getJdk() );
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java Mon Sep 12 20:23:16 2005
@@ -1,5 +1,6 @@
package org.apache.maven.profiles;
+import org.apache.maven.model.Activation;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.activation.ProfileActivator;
@@ -38,6 +39,7 @@
private Set activatedIds = new HashSet();
private Set deactivatedIds = new HashSet();
+ private Set defaultIds = new HashSet();
private Map profilesById = new HashMap();
@@ -86,6 +88,13 @@
}
profilesById.put( profile.getId(), profile );
+
+ Activation activation = profile.getActivation();
+
+ if ( activation != null && activation.isActiveByDefault() )
+ {
+ activateAsDefault( profileId );
+ }
}
/* (non-Javadoc)
@@ -158,6 +167,18 @@
}
}
+ if ( active.isEmpty() )
+ {
+ for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
+ {
+ String profileId = (String) it.next();
+
+ Profile profile = (Profile) profilesById.get( profileId );
+
+ active.add( profile );
+ }
+ }
+
return active;
}
@@ -209,6 +230,11 @@
addProfile( profile );
}
+ }
+
+ public void activateAsDefault( String profileId )
+ {
+ defaultIds.add( profileId );
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/ProfileManager.java Mon Sep 12 20:23:16 2005
@@ -19,6 +19,8 @@
void explicitlyDeactivate( String profileId );
void explicitlyDeactivate( List profileIds );
+
+ void activateAsDefault( String profileId );
List getActiveProfiles()
throws ProfileActivationException;
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java Mon Sep 12 20:23:16 2005
@@ -30,9 +30,26 @@
Activation activation = profile.getActivation();
String jdk = activation.getJdk();
+
+ boolean reverse = false;
+
+ if ( jdk.startsWith( "!" ) )
+ {
+ reverse = true;
+ jdk = jdk.substring( 1 );
+ }
// null case is covered by canDetermineActivation(), so we can do a straight startsWith() here.
- return JDK_VERSION.startsWith( jdk );
+ boolean result = JDK_VERSION.startsWith( jdk );
+
+ if ( reverse )
+ {
+ return !result;
+ }
+ else
+ {
+ return result;
+ }
}
protected boolean canDetectActivation( Profile profile )
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java Mon Sep 12 20:23:16 2005
@@ -37,17 +37,51 @@
if ( property != null )
{
- String sysValue = System.getProperty( property.getName() );
+ String name = property.getName();
+ boolean reverseName = false;
+
+ if ( name.startsWith("!") )
+ {
+ reverseName = true;
+ name = name.substring( 1 );
+ }
+
+ String sysValue = System.getProperty( name );
String propValue = property.getValue();
if ( StringUtils.isNotEmpty( propValue ) )
{
+ boolean reverseValue = false;
+ if ( propValue.startsWith( "!" ) )
+ {
+ reverseValue = true;
+ propValue = propValue.substring( 1 );
+ }
+
// we have a value, so it has to match the system value...
- return propValue.equals( sysValue );
+ boolean result = propValue.equals( sysValue );
+
+ if ( reverseValue )
+ {
+ return !result;
+ }
+ else
+ {
+ return result;
+ }
}
else
{
- return StringUtils.isNotEmpty( sysValue );
+ boolean result = StringUtils.isNotEmpty( sysValue );
+
+ if ( reverseName )
+ {
+ return !result;
+ }
+ else
+ {
+ return result;
+ }
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Mon Sep 12 20:23:16 2005
@@ -861,11 +861,20 @@
if ( root != null )
{
+ List active = root.getActiveProfiles();
+
+ if( active != null && !active.isEmpty() )
+ {
+ profileManager.explicitlyActivate( root.getActiveProfiles() );
+ }
+
for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
- profileManager.addProfile( ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile ) );
+ Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile );
+
+ profileManager.addProfile( converted );
}
}
}
Added: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java?rev=280476&view=auto
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java (added)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java Mon Sep 12 20:23:16 2005
@@ -0,0 +1,159 @@
+package org.apache.maven.profiles;
+
+import org.apache.maven.model.Activation;
+import org.apache.maven.model.ActivationProperty;
+import org.apache.maven.model.Profile;
+import org.apache.maven.profiles.activation.ProfileActivationException;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.util.List;
+
+public class DefaultProfileManagerTest
+ extends PlexusTestCase
+{
+
+ public void testShouldActivateDefaultProfile() throws ProfileActivationException
+ {
+ Profile notActivated = new Profile();
+ notActivated.setId("notActivated");
+
+ Activation nonActivation = new Activation();
+
+ nonActivation.setJdk("19.2");
+
+ notActivated.setActivation( nonActivation );
+
+ Profile defaultActivated = new Profile();
+ defaultActivated.setId("defaultActivated");
+
+ Activation defaultActivation = new Activation();
+
+ defaultActivation.setActiveByDefault(true);
+
+ defaultActivated.setActivation( defaultActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager(getContainer());
+
+ profileManager.addProfile(notActivated);
+ profileManager.addProfile(defaultActivated);
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 1, active.size() );
+ assertEquals("defaultActivated", ((Profile)active.get(0)).getId());
+ }
+
+ public void testShouldNotActivateDefaultProfile() throws ProfileActivationException
+ {
+ Profile syspropActivated = new Profile();
+ syspropActivated.setId("syspropActivated");
+
+ Activation syspropActivation = new Activation();
+
+ ActivationProperty syspropProperty = new ActivationProperty();
+ syspropProperty.setName("java.version");
+
+ syspropActivation.setProperty(syspropProperty);
+
+ syspropActivated.setActivation( syspropActivation );
+
+ Profile defaultActivated = new Profile();
+ defaultActivated.setId("defaultActivated");
+
+ Activation defaultActivation = new Activation();
+
+ defaultActivation.setActiveByDefault(true);
+
+ defaultActivated.setActivation( defaultActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager(getContainer());
+
+ profileManager.addProfile(syspropActivated);
+ profileManager.addProfile(defaultActivated);
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 1, active.size() );
+ assertEquals("syspropActivated", ((Profile)active.get(0)).getId());
+ }
+
+ public void testShouldNotActivateReversalOfPresentSystemProperty() throws ProfileActivationException
+ {
+ Profile syspropActivated = new Profile();
+ syspropActivated.setId("syspropActivated");
+
+ Activation syspropActivation = new Activation();
+
+ ActivationProperty syspropProperty = new ActivationProperty();
+ syspropProperty.setName("!java.version");
+
+ syspropActivation.setProperty(syspropProperty);
+
+ syspropActivated.setActivation( syspropActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager(getContainer());
+
+ profileManager.addProfile(syspropActivated);
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 0, active.size() );
+ }
+
+ public void testShouldOverrideAndActivateInactiveProfile() throws ProfileActivationException
+ {
+ Profile syspropActivated = new Profile();
+ syspropActivated.setId("syspropActivated");
+
+ Activation syspropActivation = new Activation();
+
+ ActivationProperty syspropProperty = new ActivationProperty();
+ syspropProperty.setName("!java.version");
+
+ syspropActivation.setProperty(syspropProperty);
+
+ syspropActivated.setActivation( syspropActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager(getContainer());
+
+ profileManager.addProfile(syspropActivated);
+
+ profileManager.explicitlyActivate("syspropActivated");
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 1, active.size() );
+ assertEquals( "syspropActivated", ((Profile)active.get(0)).getId());
+ }
+
+ public void testShouldOverrideAndDeactivateActiveProfile() throws ProfileActivationException
+ {
+ Profile syspropActivated = new Profile();
+ syspropActivated.setId("syspropActivated");
+
+ Activation syspropActivation = new Activation();
+
+ ActivationProperty syspropProperty = new ActivationProperty();
+ syspropProperty.setName("java.version");
+
+ syspropActivation.setProperty(syspropProperty);
+
+ syspropActivated.setActivation( syspropActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager(getContainer());
+
+ profileManager.addProfile(syspropActivated);
+
+ profileManager.explicitlyDeactivate("syspropActivated");
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 0, active.size() );
+ }
+
+}
Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/components/trunk/maven-settings/settings.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/settings.mdo?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-settings/settings.mdo (original)
+++ maven/components/trunk/maven-settings/settings.mdo Mon Sep 12 20:23:16 2005
@@ -560,6 +560,12 @@
]]></description>
<fields>
<field>
+ <name>activeByDefault</name>
+ <version>1.0.0</version>
+ <type>boolean</type>
+ <description>Flag specifying whether this profile is active as a default.</description>
+ </field>
+ <field>
<name>jdk</name>
<version>1.0.0</version>
<type>String</type>
Modified: maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java?rev=280476&r1=280475&r2=280476&view=diff
==============================================================================
--- maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java (original)
+++ maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java Mon Sep 12 20:23:16 2005
@@ -147,6 +147,8 @@
{
org.apache.maven.model.Activation activation = new org.apache.maven.model.Activation();
+ activation.setActiveByDefault( settingsActivation.isActiveByDefault() );
+
activation.setJdk( settingsActivation.getJdk() );
ActivationProperty settingsProp = settingsActivation.getProperty();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org