maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Heinz Marbaise (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (MNG-6070) [REGRESSION] Profile activation based on a property does not work correctly
Date Sat, 23 Jul 2016 17:46:20 GMT

    [ https://issues.apache.org/jira/browse/MNG-6070?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15390785#comment-15390785
] 

Karl Heinz Marbaise edited comment on MNG-6070 at 7/23/16 5:46 PM:
-------------------------------------------------------------------

For test purposes I have change the class {{PropertyProfileActivator.java}} by using the following
content which just prints out some supplemental informations:
{code:java}
package org.apache.maven.model.profile.activation;

/*
 * 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 org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;

/**
 * Determines profile activation based on the existence or value of some execution property.
 *
 * @author Benjamin Bentmann
 * @see ActivationProperty
 */
@Component( role = ProfileActivator.class, hint = "property" )
public class PropertyProfileActivator
    implements ProfileActivator
{
    @Override
    public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector
problems )
    {
        System.out.println( "PropertyProfileActivator" );

        Activation activation = profile.getActivation();

        if ( activation == null )
        {
            return false;
        }

        ActivationProperty property = activation.getProperty();

        if ( property == null )
        {
            return false;
        }

        String name = property.getName();
        boolean reverseName = false;

        System.out.println( "PropertyProfileActivator name: " + name  );

        if ( name != null && name.startsWith( "!" ) )
        {
            reverseName = true;
            name = name.substring( 1 );
        }

        if ( name == null || name.length() <= 0 )
        {
            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
                    .setMessage( "The property name is required to activate the profile "
+ profile.getId() )
                    .setLocation( property.getLocation( "" ) ) );
            return false;
        }

        System.out.println( "PropertyProfileActivator name: " + name  );

        String sysValue = context.getUserProperties().get( name );
        if ( sysValue == null )
        {
            sysValue = context.getSystemProperties().get( name );
        }

        String propValue = property.getValue();
        System.out.println( "PropertyProfileActivator propValue: " + propValue  );
        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...
            boolean result = propValue.equals( sysValue );

            System.out.println( "PropertyProfileActivator propValue:" + propValue + "=" +
sysValue + " result: " + result );

            return reverseValue ? !result : result;
        }
        else
        {
            boolean result = StringUtils.isNotEmpty( sysValue );

            return reverseName ? !result : result;
        }
    }

    @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;
    }

}
{code}
And now the important things are coming:
If I use Maven 3.3.9 with the above modification I got this here:
{code}
~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.3.9/bin/mvn initialize
[INFO] Scanning for projects...
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.270 s
[INFO] Finished at: 2016-07-23T19:31:45+02:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------
{code}
And now if we take a look into Maven 3.4.0-SNASHOT with the same modifications:
{code}
~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.4.0-SNAPSHOT/bin/mvn
initialize
[INFO] Scanning for projects...
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: !env.TRAVIS
PropertyProfileActivator name: env.TRAVIS
PropertyProfileActivator propValue: null
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] --- echo-maven-plugin:0.3.0:echo (default) @ example ---
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: !env.TRAVIS
PropertyProfileActivator name: env.TRAVIS
PropertyProfileActivator propValue: null
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO] Profile: performRelease property is activated '${performRelease}'.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.677 s
[INFO] Finished at: 2016-07-23T19:34:14+02:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
{code}

The above gives me the hint that the profile from my Plugin (echo-maven-plugin) is somehow
leaking into the current project which I can identify based on the variable: {{!env.TRAVIS}}
which is defined in the pom file of the {{echo-maven-plugin}} or be more accurate in it's
parent...


was (Author: khmarbaise):
For test purposes I have change the class {...} by using the following content which just
prints out some supplemental informations:
{code:java}
package org.apache.maven.model.profile.activation;

/*
 * 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 org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;

/**
 * Determines profile activation based on the existence or value of some execution property.
 *
 * @author Benjamin Bentmann
 * @see ActivationProperty
 */
@Component( role = ProfileActivator.class, hint = "property" )
public class PropertyProfileActivator
    implements ProfileActivator
{
    @Override
    public boolean isActive( Profile profile, ProfileActivationContext context, ModelProblemCollector
problems )
    {
        System.out.println( "PropertyProfileActivator" );

        Activation activation = profile.getActivation();

        if ( activation == null )
        {
            return false;
        }

        ActivationProperty property = activation.getProperty();

        if ( property == null )
        {
            return false;
        }

        String name = property.getName();
        boolean reverseName = false;

        System.out.println( "PropertyProfileActivator name: " + name  );

        if ( name != null && name.startsWith( "!" ) )
        {
            reverseName = true;
            name = name.substring( 1 );
        }

        if ( name == null || name.length() <= 0 )
        {
            problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
                    .setMessage( "The property name is required to activate the profile "
+ profile.getId() )
                    .setLocation( property.getLocation( "" ) ) );
            return false;
        }

        System.out.println( "PropertyProfileActivator name: " + name  );

        String sysValue = context.getUserProperties().get( name );
        if ( sysValue == null )
        {
            sysValue = context.getSystemProperties().get( name );
        }

        String propValue = property.getValue();
        System.out.println( "PropertyProfileActivator propValue: " + propValue  );
        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...
            boolean result = propValue.equals( sysValue );

            System.out.println( "PropertyProfileActivator propValue:" + propValue + "=" +
sysValue + " result: " + result );

            return reverseValue ? !result : result;
        }
        else
        {
            boolean result = StringUtils.isNotEmpty( sysValue );

            return reverseName ? !result : result;
        }
    }

    @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;
    }

}
{code}
And now the important things are coming:
If I use Maven 3.3.9 with the above modification I got this here:
{code}
~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.3.9/bin/mvn initialize
[INFO] Scanning for projects...
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.270 s
[INFO] Finished at: 2016-07-23T19:31:45+02:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------
{code}
And now if we take a look into Maven 3.4.0-SNASHOT with the same modifications:
{code}
~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.4.0-SNAPSHOT/bin/mvn
initialize
[INFO] Scanning for projects...
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: !env.TRAVIS
PropertyProfileActivator name: env.TRAVIS
PropertyProfileActivator propValue: null
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO]
[INFO] --- echo-maven-plugin:0.3.0:echo (default) @ example ---
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: !env.TRAVIS
PropertyProfileActivator name: env.TRAVIS
PropertyProfileActivator propValue: null
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
PropertyProfileActivator
PropertyProfileActivator name: performRelease
PropertyProfileActivator name: performRelease
PropertyProfileActivator propValue: true
PropertyProfileActivator propValue:true=null result: false
[INFO] Profile: performRelease property is activated '${performRelease}'.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.677 s
[INFO] Finished at: 2016-07-23T19:34:14+02:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
{code}

The above gives me the hint that the profile from my Plugin (echo-maven-plugin) is somehow
leaking into the current project which I can identify based on the variable: {{!env.TRAVIS}}
which is defined in the pom file of the {{echo-maven-plugin}} or be more accurate in it's
parent...

> [REGRESSION] Profile activation based on a property does not work correctly
> ---------------------------------------------------------------------------
>
>                 Key: MNG-6070
>                 URL: https://issues.apache.org/jira/browse/MNG-6070
>             Project: Maven
>          Issue Type: Bug
>    Affects Versions: 3.4.0
>         Environment: ~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.4.0-SNAPSHOT/bin/mvn
--version
> Apache Maven 3.4.0-SNAPSHOT (90f26c279af9738735be8f84f60dcf21b6244e24; 2016-07-23T16:24:50+02:00)
> Maven home: /Users/kama/tools/maven-test/apache-maven-3.4.0-SNAPSHOT
> Java version: 1.7.0_79, vendor: Oracle Corporation
> Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "Mac OS X", version: "10.8.5", arch: "x86_64", family: "Unix"
>            Reporter: Karl Heinz Marbaise
>            Priority: Blocker
>             Fix For: 3.4.0
>
>
> I have created a simple example project with the following pom file:
> {code:xml}
> <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>com.soebes.maven.example</groupId>
>   <artifactId>example</artifactId>
>   <packaging>jar</packaging>
>   <version>1.0-SNAPSHOT</version>
>   <properties>
>     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>   </properties>
>   <build>
>     <pluginManagement>
>       <plugins>
>         <plugin>
>           <groupId>com.soebes.maven.plugins</groupId>
>           <artifactId>echo-maven-plugin</artifactId>
>           <version>0.3.0</version>
>         </plugin>
>       </plugins>
>     </pluginManagement>
>   </build>
>   <profiles>
>     <profile>
>       <activation>
>         <property>
>           <name>performRelease</name>
>           <value>true</value>
>         </property>
>       </activation>
>       <build>
>         <plugins>
>           <plugin>
>             <groupId>com.soebes.maven.plugins</groupId>
>             <artifactId>echo-maven-plugin</artifactId>
>             <executions>
>               <execution>
>                 <phase>initialize</phase>
>                 <goals>
>                   <goal>echo</goal>
>                 </goals>
>               </execution>
>             </executions>
>             <configuration>
>               <echos>
>                 <echo>Profile: performRelease property is activated '${performRelease}'.</echo>
>               </echos>
>             </configuration>
>           </plugin>
>         </plugins>
>       </build>
>     </profile>
>   </profiles>
> </project>
> {code}
> If I use Maven 3.3.9 (also 3.0.5, 3.1.1, 3.2.5) and run it like this:
> {code}
> ~/ws-git-maven-bugs/profiles (master)$ mvn initialize
> [INFO] Scanning for projects...
> [INFO]
> [INFO] ------------------------------------------------------------------------
> [INFO] Building example 1.0-SNAPSHOT
> [INFO] ------------------------------------------------------------------------
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 0.401 s
> [INFO] Finished at: 2016-07-23T18:11:47+02:00
> [INFO] Final Memory: 7M/245M
> [INFO] ------------------------------------------------------------------------
> {code}
> If I run the current master of Maven Core (sha: 90f26c279af9738735be8f84f60dcf21b6244e24)
I got the following result:
> {code}
> ~/ws-git-maven-bugs/profiles (master)$ ~/tools/maven-test/apache-maven-3.4.0-SNAPSHOT/bin/mvn
initialize
> [INFO] Scanning for projects...
> [INFO]
> [INFO] ------------------------------------------------------------------------
> [INFO] Building example 1.0-SNAPSHOT
> [INFO] ------------------------------------------------------------------------
> [INFO]
> [INFO] --- echo-maven-plugin:0.3.0:echo (default) @ example ---
> [INFO] Profile: performRelease property is activated '${performRelease}'.
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 0.478 s
> [INFO] Finished at: 2016-07-23T18:12:54+02:00
> [INFO] Final Memory: 9M/245M
> [INFO] ------------------------------------------------------------------------
> {code}
> This means the profile will be erroneously activated but the property does not contain
a value.
> If I add an id to the profile like this:
> {code:xml}
>   <profiles>
>     <profile>
>       <id>an-other-profile</id>
>       <activation>
>         <property>
>           <name>performRelease</name>
>           <value>true</value>
>         </property>
>       </activation>
>   ..
> {code}
> It will produce the following (correct) result:
> {code}
> ~/ws-git-maven-bugs/profiles (master *)$ ~/tools/maven-test/apache-maven-3.4.0-SNAPSHOT/bin/mvn
initialize
> [INFO] Scanning for projects...
> [INFO]
> [INFO] ------------------------------------------------------------------------
> [INFO] Building example 1.0-SNAPSHOT
> [INFO] ------------------------------------------------------------------------
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 0.279 s
> [INFO] Finished at: 2016-07-23T18:18:23+02:00
> [INFO] Final Memory: 8M/245M
> [INFO] ------------------------------------------------------------------------
> {code}
> I have create a full working example here: https://github.com/khmarbaise/mng-6070



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message