mirror of https://github.com/apache/maven.git
(Merged from 384847.) [MNG-2136] Modifying <activeByDefault/> processing to only use profiles embedded in the POM as a basis for computing whether or not to activate.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@384851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e1771d550
commit
bd6aa12253
|
@ -274,6 +274,9 @@ it0101: Test that properties defined in an active profile in the user's
|
|||
settings are available for interpolation of systemPath in a dependency.
|
||||
[MNG-2052]
|
||||
|
||||
it0102: Test that <activeByDefault/> calculations for profile activation only
|
||||
use profiles defined in the POM. [MNG-2136]
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
- generated sources
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
it0102
|
||||
it0101
|
||||
it0100
|
||||
it0099
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
verify
|
|
@ -0,0 +1,67 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.it0102</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0</version>
|
||||
<name>parent</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-help-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>output-pom</id>
|
||||
<phase>generate-resources</phase>
|
||||
<configuration>
|
||||
<output>target/effective-pom.txt</output>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>effective-pom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>value from external profile: ${profilesXmlValue}</echo>
|
||||
<echo>test output: ${testOutput}</echo>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>testInternal</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<testOutput>Failure</testOutput>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>testInternal2</id>
|
||||
<activation>
|
||||
<property><name>user.name</name></property>
|
||||
</activation>
|
||||
<properties>
|
||||
<testOutput>Success</testOutput>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<profilesXml>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>test</id>
|
||||
<properties>
|
||||
<profilesXmlValue>Present</profilesXmlValue>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<activeProfiles>
|
||||
<activeProfile>test</activeProfile>
|
||||
</activeProfiles>
|
||||
</profilesXml>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<verifications>
|
||||
<files>
|
||||
<file>
|
||||
<location>target/effective-pom.txt</location>
|
||||
<contains>value from external profile: Present</contains>
|
||||
</file>
|
||||
<file>
|
||||
<location>target/effective-pom.txt</location>
|
||||
<contains>test output: Success</contains>
|
||||
</file>
|
||||
</files>
|
||||
</verifications>
|
|
@ -145,7 +145,8 @@ public class DefaultProfileManager
|
|||
public List getActiveProfiles()
|
||||
throws ProfileActivationException
|
||||
{
|
||||
List active = new ArrayList( profilesById.size() );
|
||||
List activeFromPom = new ArrayList();
|
||||
List activeExternal = new ArrayList();
|
||||
|
||||
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
|
@ -154,17 +155,30 @@ public class DefaultProfileManager
|
|||
String profileId = (String) entry.getKey();
|
||||
Profile profile = (Profile) entry.getValue();
|
||||
|
||||
boolean shouldAdd = false;
|
||||
if ( activatedIds.contains( profileId ) )
|
||||
{
|
||||
active.add( profile );
|
||||
shouldAdd = true;
|
||||
}
|
||||
else if ( !deactivatedIds.contains( profileId ) && isActive( profile ) )
|
||||
{
|
||||
active.add( profile );
|
||||
shouldAdd = true;
|
||||
}
|
||||
|
||||
if ( shouldAdd )
|
||||
{
|
||||
if ( "pom".equals( profile.getSource() ) )
|
||||
{
|
||||
activeFromPom.add( profile );
|
||||
}
|
||||
else
|
||||
{
|
||||
activeExternal.add( profile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( active.isEmpty() )
|
||||
if ( activeFromPom.isEmpty() )
|
||||
{
|
||||
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
|
||||
{
|
||||
|
@ -172,11 +186,16 @@ public class DefaultProfileManager
|
|||
|
||||
Profile profile = (Profile) profilesById.get( profileId );
|
||||
|
||||
active.add( profile );
|
||||
activeFromPom.add( profile );
|
||||
}
|
||||
}
|
||||
|
||||
List allActive = new ArrayList( activeFromPom.size() + activeExternal.size() );
|
||||
|
||||
allActive.addAll( activeExternal );
|
||||
allActive.addAll( activeFromPom );
|
||||
|
||||
return active;
|
||||
return allActive;
|
||||
}
|
||||
|
||||
private boolean isActive( Profile profile )
|
||||
|
|
|
@ -20,6 +20,7 @@ import junit.framework.TestCase;
|
|||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Organization;
|
||||
import org.apache.maven.model.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -43,6 +44,24 @@ public class RegexBasedModelInterpolatorTest
|
|||
context = Collections.singletonMap( "basedir", "myBasedir" );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateOrganizationNameCorrectly()
|
||||
throws Exception
|
||||
{
|
||||
String orgName = "MyCo";
|
||||
|
||||
Model model = new Model();
|
||||
model.setName( "${pom.organization.name} Tools" );
|
||||
|
||||
Organization org = new Organization();
|
||||
org.setName( orgName );
|
||||
|
||||
model.setOrganization( org );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( orgName + " Tools", out.getName() );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -70,20 +89,20 @@ public class RegexBasedModelInterpolatorTest
|
|||
|
||||
model.addDependency( dep );
|
||||
|
||||
/*
|
||||
// This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the
|
||||
// timing of executing the interpolation
|
||||
/*
|
||||
// This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the
|
||||
// timing of executing the interpolation
|
||||
|
||||
try
|
||||
{
|
||||
new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
fail( "Should have failed to interpolate with invalid reference" );
|
||||
}
|
||||
catch ( ModelInterpolationException expected )
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
*/
|
||||
try
|
||||
{
|
||||
new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
fail( "Should have failed to interpolate with invalid reference" );
|
||||
}
|
||||
catch ( ModelInterpolationException expected )
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
*/
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
|
@ -122,8 +141,7 @@ public class RegexBasedModelInterpolatorTest
|
|||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "file://localhost/myBasedir/temp-repo",
|
||||
( (Repository) out.getRepositories().get( 0 ) ).getUrl() );
|
||||
assertEquals( "file://localhost/myBasedir/temp-repo", ( (Repository) out.getRepositories().get( 0 ) ).getUrl() );
|
||||
}
|
||||
|
||||
public void testEnvars()
|
||||
|
@ -161,13 +179,11 @@ public class RegexBasedModelInterpolatorTest
|
|||
|
||||
Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context );
|
||||
|
||||
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
|
||||
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
|
||||
|
||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testExpressionThatEvaluatesToNullReturnsTheLiteralString()
|
||||
throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue