You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/08/13 19:45:19 UTC

svn commit: r685622 - in /maven/plugins/trunk/maven-invoker-plugin/src: it/pom-filtering/ it/pom-filtering/src/ it/pom-filtering/src/it/ it/pom-filtering/src/it/project/ main/java/org/apache/maven/plugin/invoker/

Author: bentmann
Date: Wed Aug 13 10:45:18 2008
New Revision: 685622

URL: http://svn.apache.org/viewvc?rev=685622&view=rev
Log:
[MINVOKER-53] Filtering erroneously interpolates expressions from the POM even if prefix is neither project nor pom

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh   (with props)
Modified:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml?rev=685622&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml Wed Aug 13 10:45:18 2008
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<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.plugins.invoker</groupId>
+  <artifactId>pom-filtering</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <name>PASSED</name>
+  <description>Test to check for proper filtering of IT POMs</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <propertyFromPropertiesSection>PROPERTY-FROM-PROPERTIES-SECTION</propertyFromPropertiesSection>
+    <itProperty>FAILED</itProperty>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <debug>true</debug>
+          <projectsDirectory>src/it</projectsDirectory>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>*/pom.xml</pomInclude>
+          </pomIncludes>
+          <goals>
+            <goal>process-resources</goal>
+          </goals>
+          <filterProperties>
+            <propertyFromPluginConfig>PROPERTY-FROM-PLUGIN-CONFIG</propertyFromPluginConfig>
+            <project-is-not-the-pom.version>PASSED</project-is-not-the-pom.version>
+            <project.name>FAILED</project.name>
+            <itProperty>PASSED</itProperty>
+            <project.nonExistingPomValue>PASSED</project.nonExistingPomValue>
+          </filterProperties>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml?rev=685622&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml Wed Aug 13 10:45:18 2008
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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>test</groupId>
+  <artifactId>pom-filtering</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <!-- ${...} must be left unfiltered -->
+    <prop0>${project.version}</prop0>
+    <!-- these must be filtered -->
+    <prop1>@project.version@</prop1>
+    <prop2>@propertyFromPluginConfig@</prop2>
+    <prop3>@propertyFromPropertiesSection@</prop3>
+    <!-- this must not be resolved to project.version, i.e. the prefix matters -->
+    <prop4>@project-is-not-the-pom.version@</prop4>
+    <!-- POM values must precede other properties -->
+    <prop5>@project.name@</prop5>
+    <prop6>@pom.name@</prop6>
+    <!-- properties from the plugin config must precede values from the POM's <properties> section -->
+    <prop7>@itProperty@</prop7>
+    <!-- properties with prefix "project"/"pom" must fallback to plugin config if no matching POM value exists -->
+    <prop8>@project.nonExistingPomValue@</prop8>
+  </properties>
+
+  <build>
+    <!-- using the Resources Plugin to create a backup of the executed POM for later inspection by the parent build -->
+    <resources>
+      <resource>
+        <directory>${basedir}</directory>
+        <filtering>false</filtering>
+        <includes>
+          <include>*.xml</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/project/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml?rev=685622&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml Wed Aug 13 10:45:18 2008
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<settings>
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <repositories>
+        <repository>
+          <id>local.central</id>
+          <url>file://@localRepository@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </repository>
+      </repositories>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>local.central</id>
+          <url>file://@localRepository@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</settings>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/src/it/settings.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh?rev=685622&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh Wed Aug 13 10:45:18 2008
@@ -0,0 +1,46 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.codehaus.plexus.util.*;
+
+try
+{
+    File pomFile = new File( basedir, "target/it/project/target/classes/interpolated-pom.xml" );
+    System.out.println( "Checking for existence of interpolated IT POM: " + pomFile );
+    if ( !pomFile.exists() )
+    {
+        System.out.println( "FAILED!" );
+        return false;
+    }
+
+    String xml = FileUtils.fileRead( pomFile, "UTF-8" );
+    
+    String[] values = {
+            "<prop0>${project.version}</prop0>",
+            "<prop1>1.0-SNAPSHOT</prop1>",
+            "<prop2>PROPERTY-FROM-PLUGIN-CONFIG</prop2>",
+            "<prop3>PROPERTY-FROM-PROPERTIES-SECTION</prop3>",
+            "<prop4>PASSED</prop4>",
+            "<prop5>PASSED</prop5>",
+            "<prop6>PASSED</prop6>",
+            "<prop7>PASSED</prop7>",
+            "<prop8>PASSED</prop8>",
+        };
+    for ( String value : values )
+    {
+        System.out.println( "Checking for occurrence of: " + value );
+        if ( xml.indexOf( value ) < 0 )
+        {
+            System.out.println( "FAILED!" );
+            return false;
+        }
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/pom-filtering/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java?rev=685622&r1=685621&r2=685622&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/CompositeMap.java Wed Aug 13 10:45:18 2008
@@ -79,21 +79,29 @@
      */
     public boolean containsKey( Object key )
     {
-        if ( key == null )
+        if ( !( key instanceof String ) )
         {
             return false;
         }
-        try
-        {
-            Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject );
-            return evaluated == null;
-        }
-        catch ( Exception e )
+
+        String expression = (String) key;
+        if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
         {
-            // uhm do we have to throw a RuntimeException here ?
+            try
+            {
+                Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
+                if ( evaluated != null )
+                {
+                    return true;
+                }
+            }
+            catch ( Exception e )
+            {
+                // uhm do we have to throw a RuntimeException here ?
+            }
         }
 
-        return ( mavenProject.getProperties().containsKey( key ) || properties.containsKey( key ) );
+        return properties.containsKey( key ) || mavenProject.getProperties().containsKey( key );
     }
 
     /**
@@ -117,21 +125,26 @@
      */
     public Object get( Object key )
     {
-        if ( key == null )
+        if ( !( key instanceof String ) )
         {
             return null;
         }
-        try
+
+        String expression = (String) key;
+        if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
         {
-            Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject );
-            if ( evaluated != null )
+            try
             {
-                return evaluated;
+                Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
+                if ( evaluated != null )
+                {
+                    return evaluated;
+                }
+            }
+            catch ( Exception e )
+            {
+                // uhm do we have to throw a RuntimeException here ?
             }
-        }
-        catch ( Exception e )
-        {
-            // uhm do we have to throw a RuntimeException here ?
         }
 
         Object value = properties.get( key );