From bd6aa12253c17ae6d6bf9732d8bea30577306b68 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 10 Mar 2006 17:00:30 +0000 Subject: [PATCH] (Merged from 384847.) [MNG-2136] Modifying 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 --- maven-core-it/README.txt | 3 + maven-core-it/integration-tests.txt | 1 + maven-core-it/it0102/goals.txt | 1 + maven-core-it/it0102/pom.xml | 67 +++++++++++++++++++ maven-core-it/it0102/profiles.xml | 14 ++++ .../src/test/verifier/verifications.xml | 12 ++++ .../maven/profiles/DefaultProfileManager.java | 31 +++++++-- .../RegexBasedModelInterpolatorTest.java | 52 +++++++++----- 8 files changed, 157 insertions(+), 24 deletions(-) create mode 100644 maven-core-it/it0102/goals.txt create mode 100644 maven-core-it/it0102/pom.xml create mode 100644 maven-core-it/it0102/profiles.xml create mode 100644 maven-core-it/it0102/src/test/verifier/verifications.xml diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt index 5b5c949759..78c1ff9ede 100644 --- a/maven-core-it/README.txt +++ b/maven-core-it/README.txt @@ -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 calculations for profile activation only + use profiles defined in the POM. [MNG-2136] + ------------------------------------------------------------------------------- - generated sources diff --git a/maven-core-it/integration-tests.txt b/maven-core-it/integration-tests.txt index 7dcccdf7bb..9a110d7dc0 100644 --- a/maven-core-it/integration-tests.txt +++ b/maven-core-it/integration-tests.txt @@ -1,3 +1,4 @@ +it0102 it0101 it0100 it0099 diff --git a/maven-core-it/it0102/goals.txt b/maven-core-it/it0102/goals.txt new file mode 100644 index 0000000000..0b5987362f --- /dev/null +++ b/maven-core-it/it0102/goals.txt @@ -0,0 +1 @@ +verify diff --git a/maven-core-it/it0102/pom.xml b/maven-core-it/it0102/pom.xml new file mode 100644 index 0000000000..7a12b6512c --- /dev/null +++ b/maven-core-it/it0102/pom.xml @@ -0,0 +1,67 @@ + + 4.0.0 + org.apache.maven.it0102 + parent + pom + 1.0 + parent + + + + + maven-help-plugin + + + output-pom + generate-resources + + target/effective-pom.txt + + + effective-pom + + + + + + maven-antrun-plugin + + + validate + + + value from external profile: ${profilesXmlValue} + test output: ${testOutput} + + + + run + + + + + + + + + + testInternal + + true + + + Failure + + + + testInternal2 + + user.name + + + Success + + + + diff --git a/maven-core-it/it0102/profiles.xml b/maven-core-it/it0102/profiles.xml new file mode 100644 index 0000000000..090ea76e99 --- /dev/null +++ b/maven-core-it/it0102/profiles.xml @@ -0,0 +1,14 @@ + + + + test + + Present + + + + + test + + + diff --git a/maven-core-it/it0102/src/test/verifier/verifications.xml b/maven-core-it/it0102/src/test/verifier/verifications.xml new file mode 100644 index 0000000000..af46897f46 --- /dev/null +++ b/maven-core-it/it0102/src/test/verifier/verifications.xml @@ -0,0 +1,12 @@ + + + + target/effective-pom.txt + value from external profile: Present + + + target/effective-pom.txt + test output: Success + + + diff --git a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index 7bee6782b1..78a68a0697 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -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 ) diff --git a/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java b/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java index be719a098b..bbf04caf54 100644 --- a/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java @@ -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 {