You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/09/26 22:29:46 UTC

svn commit: r291735 - in /maven/components/trunk: maven-core-it/ maven-core-it/it0071/ maven-core-it/it0072/ maven-core-it/it1015/ maven-core/src/main/java/org/apache/maven/plugin/ maven-core/src/test/java/org/apache/maven/plugin/ maven-plugins/maven-e...

Author: jdcasey
Date: Mon Sep 26 13:29:20 2005
New Revision: 291735

URL: http://svn.apache.org/viewcvs?rev=291735&view=rev
Log:
Resolving: MNG-885

o Extracting basedir from the project instance when PluginParameterExpressionEvaluator is init'ed if project != null...otherwise, using ${user.dir} from sysprops.

o Extracting values for resolution from POM properties before POM instance during POM interpolation, and adding checks to guard against self-reference of POM elements.

o Added three ITs (one contra) to test these resolutions.


Added:
    maven/components/trunk/maven-core-it/it0071/
    maven/components/trunk/maven-core-it/it0071/expected-results.txt   (with props)
    maven/components/trunk/maven-core-it/it0071/goals.txt   (with props)
    maven/components/trunk/maven-core-it/it0071/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt   (with props)
    maven/components/trunk/maven-core-it/it0072/
    maven/components/trunk/maven-core-it/it0072/expected-results.txt   (with props)
    maven/components/trunk/maven-core-it/it0072/goals.txt   (with props)
    maven/components/trunk/maven-core-it/it0072/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it1015/
    maven/components/trunk/maven-core-it/it1015/expected-results.txt   (with props)
    maven/components/trunk/maven-core-it/it1015/goals.txt   (with props)
    maven/components/trunk/maven-core-it/it1015/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt   (with props)
Modified:
    maven/components/trunk/maven-core-it/README.txt
    maven/components/trunk/maven-core-it/integration-tests.txt
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
    maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
    maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java

Modified: maven/components/trunk/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Mon Sep 26 13:29:20 2005
@@ -190,6 +190,12 @@
 
 it0070: Test a RAR generation.
 
+it0071: Verifies that dotted property references work within plugin
+        configurations.
+
+it0072: Verifies that property references with dotted notation work within
+        POM interpolation.
+
 -------------------------------------------------------------------------------
 
 - generated sources
@@ -248,6 +254,12 @@
 -------------------------------------------------------------------------------
 it1012: Test that the DefaultLifecycleExecutor will throw an exception when
         encountering an unknown packaging.
+
+
+
+-------------------------------------------------------------------------------
+it1015: Test that expressions that self-reference within the POM result in an
+        error during POM interpolation.
 -------------------------------------------------------------------------------
 
 -------------------------------------------------------------------------------

Modified: maven/components/trunk/maven-core-it/integration-tests.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/integration-tests.txt?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/integration-tests.txt (original)
+++ maven/components/trunk/maven-core-it/integration-tests.txt Mon Sep 26 13:29:20 2005
@@ -1,3 +1,5 @@
+it0072
+it0071
 it0070
 it0067
 it0066

Added: maven/components/trunk/maven-core-it/it0071/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0071/expected-results.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0071/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it0071/expected-results.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+target/foo2

Propchange: maven/components/trunk/maven-core-it/it0071/expected-results.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0071/expected-results.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0071/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0071/goals.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0071/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0071/goals.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+core-it:touch

Propchange: maven/components/trunk/maven-core-it/it0071/goals.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0071/goals.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0071/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0071/pom.xml?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0071/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0071/pom.xml Mon Sep 26 13:29:20 2005
@@ -0,0 +1,39 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.it</groupId>
+  <artifactId>maven-core-it0071</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <type>jar</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-core-it-plugin</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <configuration>
+          <pluginItem>${m2.foo}</pluginItem>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>snapshots</id>
+      <name>Maven Central Plugins Development Repository</name>
+      <url>http://snapshots.maven.codehaus.org/maven2</url>
+    </pluginRepository>
+  </pluginRepositories>
+
+  <properties>
+    <m2.foo>foo2</m2.foo>
+  </properties>
+</project>

Propchange: maven/components/trunk/maven-core-it/it0071/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0071/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt (added)
+++ maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+rm ${artifact:org.apache.maven.plugins:maven-core-it-plugin:1.0-SNAPSHOT:maven-plugin}

Propchange: maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0071/prebuild-hook.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0072/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0072/expected-results.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0072/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it0072/expected-results.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+target/maven-core-it0072-1.0-SNAPSHOT.jar

Propchange: maven/components/trunk/maven-core-it/it0072/expected-results.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0072/expected-results.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0072/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0072/goals.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0072/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0072/goals.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+package

Propchange: maven/components/trunk/maven-core-it/it0072/goals.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0072/goals.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0072/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0072/pom.xml?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0072/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0072/pom.xml Mon Sep 26 13:29:20 2005
@@ -0,0 +1,28 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.it</groupId>
+  <artifactId>maven-core-it0072</artifactId>
+  <packaging>jar</packaging>
+  <version>${m2.version}</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <type>jar</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>snapshots</id>
+      <name>Maven Central Plugins Development Repository</name>
+      <url>http://snapshots.maven.codehaus.org/maven2</url>
+    </pluginRepository>
+  </pluginRepositories>
+
+  <properties>
+    <m2.foo>foo2</m2.foo>
+    <m2.version>1.0-SNAPSHOT</m2.version>
+  </properties>
+</project>

Propchange: maven/components/trunk/maven-core-it/it0072/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0072/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it1015/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it1015/expected-results.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it1015/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it1015/expected-results.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+target/maven-core-it1015-1.0-SNAPSHOT.jar

Propchange: maven/components/trunk/maven-core-it/it1015/expected-results.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it1015/expected-results.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it1015/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it1015/goals.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it1015/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it1015/goals.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+core-it:touch

Propchange: maven/components/trunk/maven-core-it/it1015/goals.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it1015/goals.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it1015/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it1015/pom.xml?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it1015/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it1015/pom.xml Mon Sep 26 13:29:20 2005
@@ -0,0 +1,23 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.it</groupId>
+  <artifactId>maven-core-it1015</artifactId>
+  <packaging>jar</packaging>
+  <version>${version}</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <type>jar</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>snapshots</id>
+      <name>Maven Central Plugins Development Repository</name>
+      <url>http://snapshots.maven.codehaus.org/maven2</url>
+    </pluginRepository>
+  </pluginRepositories>
+</project>

Propchange: maven/components/trunk/maven-core-it/it1015/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it1015/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt?rev=291735&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt (added)
+++ maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt Mon Sep 26 13:29:20 2005
@@ -0,0 +1 @@
+rm ${artifact:org.apache.maven.plugins:maven-core-it-plugin:1.0-SNAPSHOT:maven-plugin}

Propchange: maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it1015/prebuild-hook.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java Mon Sep 26 13:29:20 2005
@@ -65,6 +65,8 @@
     private final MojoExecution mojoExecution;
 
     private final MavenProject project;
+    
+    private final String basedir;
 
     public PluginParameterExpressionEvaluator( MavenSession context, MojoExecution mojoExecution,
                                                PathTranslator pathTranslator, Logger logger, MavenProject project )
@@ -74,6 +76,26 @@
         this.pathTranslator = pathTranslator;
         this.logger = logger;
         this.project = project;
+        
+        String basedir = null;
+        
+        if ( project != null )
+        {
+            File projectFile = project.getFile();
+            
+            // this should always be the case for non-super POM instances...
+            if ( projectFile != null )
+            {
+                basedir = projectFile.getParentFile().getAbsolutePath();
+            }
+        }
+
+        if ( basedir == null )
+        {
+            basedir = System.getProperty( "user.dir" );
+        }
+        
+        this.basedir = basedir;
     }
 
     public Object evaluate( String expr )
@@ -224,7 +246,7 @@
         }
         else if ( "basedir".equals( expression ) )
         {
-            value = project.getBasedir().getAbsolutePath();
+            value = basedir;
         }
         else if ( expression.startsWith( "basedir" ) )
         {
@@ -232,7 +254,7 @@
 
             if ( pathSeparator > 0 )
             {
-                value = project.getFile().getParentFile().getAbsolutePath() + expression.substring( pathSeparator );
+                value = basedir + expression.substring( pathSeparator );
             }
             else
             {
@@ -242,10 +264,8 @@
 
         if ( value == null )
         {
-            // Check properties that have been injected via profiles before we default over to
-            // system properties.
-
-            if ( project.getProperties() != null )
+            // Check POM-level properties before we default over to system properties.
+            if ( project != null && project.getProperties() != null )
             {
                 value = project.getProperties().getProperty( expression );
             }

Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java (original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java Mon Sep 26 13:29:20 2005
@@ -38,6 +38,7 @@
 import java.io.File;
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@@ -67,6 +68,71 @@
         String actual = new File( value.toString() ).getCanonicalPath();
 
         assertEquals( expected, actual );
+    }
+
+    public void testPOMPropertyExtractionWithMissingProject_WithDotNotation()
+        throws Exception
+    {
+        String key = "m2.name";
+        String checkValue = "value";
+        
+        Properties properties = new Properties();
+        properties.setProperty( key, checkValue );
+        
+        Model model = new Model();
+        model.setProperties( properties );
+        
+        MavenProject project = new MavenProject( model );
+        
+        ExpressionEvaluator ee = createExpressionEvaluator( project, null );
+
+        Object value = ee.evaluate( "${" + key + "}" );
+
+        assertEquals( checkValue, value );
+    }
+
+    public void testBasedirExtractionWithMissingProject()
+        throws Exception
+    {
+        ExpressionEvaluator ee = createExpressionEvaluator( null, null );
+
+        Object value = ee.evaluate( "${basedir}" );
+
+        assertEquals( System.getProperty( "user.dir" ), value );
+    }
+
+    public void testValueExtractionFromSystemPropertiesWithMissingProject()
+        throws Exception
+    {
+        String sysprop = "PPEET_sysprop1";
+
+        if ( System.getProperty( sysprop ) == null )
+        {
+            System.setProperty( sysprop, "value" );
+        }
+
+        ExpressionEvaluator ee = createExpressionEvaluator( null, null );
+
+        Object value = ee.evaluate( "${" + sysprop + "}" );
+
+        assertEquals( "value", value );
+    }
+
+    public void testValueExtractionFromSystemPropertiesWithMissingProject_WithDotNotation()
+        throws Exception
+    {
+        String sysprop = "PPEET.sysprop2";
+
+        if ( System.getProperty( sysprop ) == null )
+        {
+            System.setProperty( sysprop, "value" );
+        }
+
+        ExpressionEvaluator ee = createExpressionEvaluator( null, null );
+
+        Object value = ee.evaluate( "${" + sysprop + "}" );
+
+        assertEquals( "value", value );
     }
 
     private static MavenSession createSession( PlexusContainer container, ArtifactRepository repo )

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java Mon Sep 26 13:29:20 2005
@@ -31,7 +31,7 @@
  * A base class for EAR-processing related tasks.
  *
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- * @version $Id:  $
+ * @version $Id$
  */
 public abstract class AbstractEarMojo
     extends AbstractMojo

Modified: maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java Mon Sep 26 13:29:20 2005
@@ -26,7 +26,7 @@
  * A Mojo used to build the application.xml file.
  *
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- * @version $Id: $
+ * @version $Id$
  * @goal generate-application-xml
  * @phase generate-resources
  * @requiresDependencyResolution test

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java Mon Sep 26 13:29:20 2005
@@ -24,12 +24,38 @@
 public class ModelInterpolationException
     extends Exception
 {
-    /**
-     * Added: Feb 2, 2005 by jdcasey
-     */
-    public ModelInterpolationException( String expression, Throwable cause )
+    private String expression;
+    private String originalMessage;
+
+    public ModelInterpolationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+    
+    public ModelInterpolationException( String expression, String message, Throwable cause )
+    {
+        super( "The POM expression: " + expression + " could not be evaluated. Reason: " + message, cause );
+
+        this.expression = expression;
+        this.originalMessage = message;
+    }
+    
+    public ModelInterpolationException( String expression, String message )
     {
-        super( "The POM expression: " + expression + " could not be evaluated.", cause );
+        super( "The POM expression: " + expression + " could not be evaluated. Reason: " + message );
 
+        this.expression = expression;
+        this.originalMessage = message;
+    }
+    
+    public String getExpression()
+    {
+        return expression;
+    }
+    
+    public String getOriginalMessage()
+    {
+        return originalMessage;
     }
+    
 }

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java?rev=291735&r1=291734&r2=291735&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java Mon Sep 26 13:29:20 2005
@@ -33,8 +33,11 @@
 import java.util.Map;
 
 /**
+ * Use a regular expression search to find and resolve expressions within the POM.
+ * 
  * @author jdcasey Created on Feb 3, 2005
  * @version $Id$
+ * @todo Consolidate this logic with the PluginParameterExpressionEvaluator, minus deprecations/bans.
  */
 public class RegexBasedModelInterpolator
     extends AbstractLogEnabled
@@ -43,7 +46,14 @@
     private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.)?([^}]+)\\}" );
 
     /**
-     * Added: Feb 3, 2005 by jdcasey
+     * Serialize the inbound Model instance to a StringWriter, perform the regex replacement to resolve 
+     * POM expressions, then re-parse into the resolved Model instance.
+     * <br/>
+     * <b>NOTE:</b> This will result in a different instance of Model being returned!!!
+     * 
+     * @param model The inbound Model instance, to serialize and reference for expression resolution
+     * @param context The other context map to be used during resolution
+     * @return The resolved instance of the inbound Model. This is a different instance!
      */
     public Model interpolate( Model model, Map context )
         throws ModelInterpolationException
@@ -84,10 +94,8 @@
         return model;
     }
 
-    /**
-     * Added: Feb 3, 2005 by jdcasey
-     */
     private String interpolateInternal( String src, Model model, Map context )
+        throws ModelInterpolationException
     {
         String result = src;
         Matcher matcher = EXPRESSION_PATTERN.matcher( result );
@@ -98,17 +106,17 @@
 
             Object value = context.get( realExpr );
 
+            if ( value == null )
+            {
+                value = model.getProperties().getProperty( realExpr );
+            }
+            
             try
             {
                 if ( value == null )
                 {
                     value = ReflectionValueExtractor.evaluate( realExpr, model );
                 }
-                
-                if ( value == null )
-                {
-                    value = model.getProperties().getProperty( realExpr );
-                }
             }
             catch ( Exception e )
             {
@@ -118,6 +126,12 @@
                     logger.debug( "POM interpolation cannot proceed with expression: " + wholeExpr + ". Skipping...",
                                   e );
                 }
+            }
+            
+            // if the expression refers to itself, skip it.
+            if ( wholeExpr.equals( value ) )
+            {
+                throw new ModelInterpolationException( wholeExpr, model.getId() + " references itself." );
             }
 
             if ( value != null )



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r291735 - in /maven/components/trunk: maven-core-it/ maven-core-it/it0071/ maven-core-it/it0072/ maven-core-it/it1015/ maven-core/src/main/java/org/apache/maven/plugin/ maven-core/src/test

Posted by John Casey <jd...@commonjava.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

if the project is null, how exactly do we get module paths??

- -j

Kenney Westerhof wrote:
| On Mon, 26 Sep 2005 jdcasey@apache.org wrote:
|
|
|>o Extracting basedir from the project instance when
|>PluginParameterExpressionEvaluator is init'ed if project !=
|>null...otherwise, using ${user.dir} from sysprops.
|
|
| Isn't it better to get 'cwd'/'pwd', and add module paths?
|
| -- Kenney
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
| For additional commands, e-mail: dev-help@maven.apache.org
|
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDOG4uK3h2CZwO/4URAuUeAJ4nrbq6K8k9QlSpVvoeTh7+kTTXnQCgjjdZ
comHWDJdS3INs6fTIVcf2pw=
=8QYz
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r291735 - in /maven/components/trunk: maven-core-it/ maven-core-it/it0071/ maven-core-it/it0072/ maven-core-it/it1015/ maven-core/src/main/java/org/apache/maven/plugin/ maven-core/src/test

Posted by Kenney Westerhof <fo...@neonics.com>.
On Mon, 26 Sep 2005 jdcasey@apache.org wrote:

> o Extracting basedir from the project instance when
> PluginParameterExpressionEvaluator is init'ed if project !=
> null...otherwise, using ${user.dir} from sysprops.

Isn't it better to get 'cwd'/'pwd', and add module paths?

-- Kenney

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org