mirror of https://github.com/apache/maven.git
Resolving: MNG-835. Using activateByDefault within activation in the profile.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280476 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
459737fa5f
commit
c9b6d83c57
|
@ -2610,6 +2610,12 @@
|
|||
the automatic inclusion of the parent build profile.
|
||||
]]></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>
|
||||
|
|
|
@ -112,6 +112,12 @@
|
|||
the automatic inclusion of the parent build profile.
|
||||
]]></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>
|
||||
|
|
|
@ -44,6 +44,8 @@ public class ProfilesConversionUtils
|
|||
if ( profileActivation != null )
|
||||
{
|
||||
Activation activation = new Activation();
|
||||
|
||||
activation.setActiveByDefault( profileActivation.isActiveByDefault() );
|
||||
|
||||
activation.setJdk( profileActivation.getJdk() );
|
||||
|
||||
|
|
|
@ -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 @@ public class DefaultProfileManager implements ProfileManager
|
|||
|
||||
private Set activatedIds = new HashSet();
|
||||
private Set deactivatedIds = new HashSet();
|
||||
private Set defaultIds = new HashSet();
|
||||
|
||||
private Map profilesById = new HashMap();
|
||||
|
||||
|
@ -86,6 +88,13 @@ public class DefaultProfileManager implements ProfileManager
|
|||
}
|
||||
|
||||
profilesById.put( profile.getId(), profile );
|
||||
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
if ( activation != null && activation.isActiveByDefault() )
|
||||
{
|
||||
activateAsDefault( profileId );
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -158,6 +167,18 @@ public class DefaultProfileManager implements ProfileManager
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -210,5 +231,10 @@ public class DefaultProfileManager implements ProfileManager
|
|||
addProfile( profile );
|
||||
}
|
||||
}
|
||||
|
||||
public void activateAsDefault( String profileId )
|
||||
{
|
||||
defaultIds.add( profileId );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ public interface ProfileManager
|
|||
void explicitlyDeactivate( String profileId );
|
||||
|
||||
void explicitlyDeactivate( List profileIds );
|
||||
|
||||
void activateAsDefault( String profileId );
|
||||
|
||||
List getActiveProfiles()
|
||||
throws ProfileActivationException;
|
||||
|
|
|
@ -30,9 +30,26 @@ public class JdkPrefixProfileActivator
|
|||
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 )
|
||||
|
|
|
@ -37,17 +37,51 @@ public class SystemPropertyProfileActivator
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -861,11 +861,20 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -559,6 +559,12 @@
|
|||
the automatic inclusion of the parent build profile.
|
||||
]]></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>
|
||||
|
|
|
@ -147,6 +147,8 @@ public final class SettingsUtils
|
|||
{
|
||||
org.apache.maven.model.Activation activation = new org.apache.maven.model.Activation();
|
||||
|
||||
activation.setActiveByDefault( settingsActivation.isActiveByDefault() );
|
||||
|
||||
activation.setJdk( settingsActivation.getJdk() );
|
||||
|
||||
ActivationProperty settingsProp = settingsActivation.getProperty();
|
||||
|
|
Loading…
Reference in New Issue