Repository: maven
Updated Branches:
  refs/heads/master faccffe26 -> 425c66358


Add solution to http://jira.codehaus.org/browse/MNG-4565

Signed-off-by: Jason van Zyl <ja...@tesla.io>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/c6529932
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/c6529932
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/c6529932

Branch: refs/heads/master
Commit: c6529932f9e3efdfc86ed73f59a307a8f8b6ea5f
Parents: faccffe
Author: Mysterion <pericov...@gmail.com>
Authored: Tue May 27 00:18:08 2014 +0400
Committer: Jason van Zyl <ja...@tesla.io>
Committed: Tue Jun 10 16:46:10 2014 -0400

----------------------------------------------------------------------
 .../model/profile/DefaultProfileSelector.java   | 12 +++-
 .../activation/FileProfileActivator.java        | 19 +++++++
 .../activation/JdkVersionProfileActivator.java  | 19 +++++++
 .../OperatingSystemProfileActivator.java        | 19 +++++++
 .../profile/activation/ProfileActivator.java    | 13 +++++
 .../activation/PropertyProfileActivator.java    | 19 +++++++
 .../model/building/ComplexActivationTest.java   | 60 ++++++++++++++++++++
 .../src/test/resources/poms/factory/complex.xml | 49 ++++++++++++++++
 8 files changed, 207 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
index c376c99..0aeed9d 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
@@ -104,13 +104,19 @@ public class DefaultProfileSelector
 
     private boolean isActive( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems )
     {
+        boolean isActive = false;
+        for ( ProfileActivator activator : activators ) {
+            if ( activator.presentInConfig( profile, context, problems ) ) {
+                isActive = true;
+            }
+        }
         for ( ProfileActivator activator : activators )
         {
             try
             {
-                if ( activator.isActive( profile, context, problems ) )
+                if ( activator.presentInConfig( profile, context, problems ) )
                 {
-                    return true;
+                    isActive &=  activator.isActive( profile, context, 
problems );
                 }
             }
             catch ( RuntimeException e )
@@ -122,7 +128,7 @@ public class DefaultProfileSelector
                 return false;
             }
         }
-        return false;
+        return isActive;
     }
 
     private boolean isActiveByDefault( Profile profile )

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java
index 07ba79b..b1d0442 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java
@@ -167,4 +167,23 @@ public class FileProfileActivator
         return missing ? !fileExists : fileExists;
     }
 
+    @Override
+    public boolean presentInConfig( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems )
+    {
+        Activation activation = profile.getActivation();
+
+        if ( activation == null )
+        {
+            return false;
+        }
+
+        ActivationFile file = activation.getFile();
+
+        if ( file == null )
+        {
+            return false;
+        }
+        return true;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
index 62b6cfb..10747de 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
@@ -83,6 +83,25 @@ public class JdkVersionProfileActivator
         }
     }
 
+    @Override
+    public boolean presentInConfig( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems )
+    {
+        Activation activation = profile.getActivation();
+
+        if ( activation == null )
+        {
+            return false;
+        }
+
+        String jdk = activation.getJdk();
+
+        if ( jdk == null )
+        {
+            return false;
+        }
+        return true;
+    }
+
     private static boolean isInRange( String value, List<RangeValue> range )
     {
         int leftRelation = getRelationOrder( value, range.get( 0 ), true );

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
index 94d380c..b6d3f05 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java
@@ -76,6 +76,25 @@ public class OperatingSystemProfileActivator
         return active;
     }
 
+    @Override
+    public boolean presentInConfig( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems )
+    {
+        Activation activation = profile.getActivation();
+
+        if ( activation == null )
+        {
+            return false;
+        }
+
+        ActivationOS os = activation.getOs();
+
+        if ( os == null )
+        {
+            return false;
+        }
+        return true;
+    }
+
     private boolean ensureAtLeastOneNonNull( ActivationOS os )
     {
         return os.getArch() != null || os.getFamily() != null || os.getName() 
!= null || os.getVersion() != null;

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java
index 142dddf..7094a3f 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/ProfileActivator.java
@@ -43,4 +43,17 @@ public interface ProfileActivator
      */
     boolean isActive( Profile profile, ProfileActivationContext context, 
ModelProblemCollector problems );
 
+    /**
+     * Determines whether specified activation method is present in 
configuration or not. It should help to have AND between
+     * activation conditions
+     * Need for solving http://jira.codehaus.org/browse/MNG-4565
+     * @param profile The profile whose activation status should be 
determined, must not be {@code null}.
+     * @param context The environmental context used to determine the 
activation status of the profile, must not be
+     *            {@code null}.
+     * @param problems The container used to collect problems (e.g. bad 
syntax) that were encountered, must not be
+     *            {@code null}.
+     * @return {@code true} if the profile is active, {@code false} otherwise.
+     */
+    boolean presentInConfig( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems );
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java
index 374647f..e8e6e99 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/PropertyProfileActivator.java
@@ -103,4 +103,23 @@ public class PropertyProfileActivator
         }
     }
 
+    @Override
+    public boolean presentInConfig( Profile profile, ProfileActivationContext 
context, ModelProblemCollector problems )
+    {
+        Activation activation = profile.getActivation();
+
+        if ( activation == null )
+        {
+            return false;
+        }
+
+        ActivationProperty property = activation.getProperty();
+
+        if ( property == null )
+        {
+            return false;
+        }
+        return true;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java
 
b/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java
new file mode 100644
index 0000000..9ef31b3
--- /dev/null
+++ 
b/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java
@@ -0,0 +1,60 @@
+package org.apache.maven.model.building;
+
+  /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * @author Konstantin Perikov
+ */
+public class ComplexActivationTest
+        extends TestCase
+{
+
+    private File getPom( String name )
+    {
+        return new File( "src/test/resources/poms/factory/" + name + ".xml" 
).getAbsoluteFile();
+    }
+
+    public void testAndConditionInActivation()
+            throws Exception
+    {
+        Properties sysProperties = new Properties();
+        sysProperties.setProperty( "myproperty", "test" );
+
+        ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
+        assertNotNull( builder );
+
+        DefaultModelBuildingRequest request = new 
DefaultModelBuildingRequest();
+        request.setProcessPlugins( true );
+        request.setPomFile( getPom( "complex" ) );
+        request.setSystemProperties( sysProperties );
+
+        ModelBuildingResult result = builder.build( request );
+        assertNotNull( result );
+        assertNotNull( result.getEffectiveModel() );
+        assertEquals( "activated-1", 
result.getEffectiveModel().getProperties().get( "profile.file" ) );
+        assertNull( result.getEffectiveModel().getProperties().get( 
"profile.miss" ) );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/c6529932/maven-model-builder/src/test/resources/poms/factory/complex.xml
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/test/resources/poms/factory/complex.xml 
b/maven-model-builder/src/test/resources/poms/factory/complex.xml
new file mode 100644
index 0000000..80060ff
--- /dev/null
+++ b/maven-model-builder/src/test/resources/poms/factory/complex.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>test</groupId>
+    <artifactId>test</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <my.filter.value>hello</my.filter.value>
+    </properties>
+
+    <profiles>
+        <profile>
+            <id>two-conditions</id>
+            <activation>
+                <file>
+                    <exists>simple.xml</exists>
+                </file>
+                <property>
+                    <name>myproperty</name>
+                    <value>test</value>
+                </property>
+            </activation>
+            <properties>
+                <profile.file>activated-1</profile.file>
+            </properties>
+        </profile>
+        <profile>
+            <id>another-two-conditions</id>
+            <activation>
+                <property>
+                    <name>myproperty</name>
+                    <value>test</value>
+                </property>
+                <file>
+                    <missing>simple.xml</missing>
+                </file>
+            </activation>
+            <properties>
+                <profile.miss>activated-2</profile.miss>
+            </properties>
+        </profile>
+    </profiles>
+</project>

Reply via email to