You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2006/01/11 20:36:59 UTC

svn commit: r368108 - in /maven/components/trunk: integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ maven-core-it/ maven-core-it/it0088/ maven-core-it/it0090/ maven-core-it/it0090/src/ maven-core-it/it0090/src/main/ m...

Author: jvanzyl
Date: Wed Jan 11 11:36:37 2006
New Revision: 368108

URL: http://svn.apache.org/viewcvs?rev=368108&view=rev
Log:
[MNG-1927] This adds the test mojos required to fix ${pom.build.*} expansion to full paths, the problem was the
           new interpolator so the one from 2.0 was used and some envar handling was back ported. Unit tests
           have been added for envar handling as well as an IT. The maven-core-it script will now set
           an envar which is used in it0090.


Added:
    maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java   (with props)
    maven/components/trunk/maven-core-it/it0090/
    maven/components/trunk/maven-core-it/it0090/expected-results.txt   (with props)
    maven/components/trunk/maven-core-it/it0090/goals.txt   (with props)
    maven/components/trunk/maven-core-it/it0090/log.txt   (with props)
    maven/components/trunk/maven-core-it/it0090/pom.xml   (with props)
    maven/components/trunk/maven-core-it/it0090/src/
    maven/components/trunk/maven-core-it/it0090/src/main/
    maven/components/trunk/maven-core-it/it0090/src/main/resources/
    maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties   (with props)
    maven/components/trunk/maven-core-it/it0090/src/test/
    maven/components/trunk/maven-core-it/it0090/src/test/java/
    maven/components/trunk/maven-core-it/it0090/src/test/java/org/
    maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/
    maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/
    maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/
    maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java   (with props)
Modified:
    maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
    maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/PackagingMojo.java
    maven/components/trunk/maven-core-it/it0088/expected-results.txt
    maven/components/trunk/maven-core-it/it0088/pom.xml
    maven/components/trunk/maven-core-it/maven-core-it.bat
    maven/components/trunk/maven-core-it/maven-core-it.sh
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java

Added: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java (added)
+++ maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java Wed Jan 11 11:36:37 2006
@@ -0,0 +1,52 @@
+package org.apache.maven.plugin.coreit;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.util.Properties;
+import java.io.FileOutputStream;
+import java.io.File;
+
+/**
+ * Interpolate some envars that are embedded in the POM and make sure they pass through
+ * the system.
+ * 
+ * @goal generate-envar-properties
+ */
+public class InterpolatedEnvarConfigurationMojo
+    extends AbstractMojo
+{
+    /**
+     * @parameter expression="${basedir}"
+     */
+    private String basedir;
+
+    /**
+     * @parameter expression="${mavenTestEnvar}"
+     */
+    private String mavenTestEnvar;
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        if ( mavenTestEnvar == null )
+        {
+            throw new MojoExecutionException( "The mavenTestEnvar field should not be null! You must run this using the maven-core-it scripts! ");
+        }
+        
+        try
+        {
+            Properties mojoGeneratedPropeties = new Properties();
+
+            mojoGeneratedPropeties.put( "maven.test.envar", mavenTestEnvar );
+
+            FileOutputStream fos = new FileOutputStream( new File( basedir, "target/mojo-generated.properties" ) );
+
+            mojoGeneratedPropeties.store( fos, "# Properties generated by the execution of a mojo that uses interpolated envar values." );
+        }
+        catch( Exception e )
+        {
+            getLog().error( "Error creating mojo generated properties.", e );
+        }
+    }
+}

Propchange: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedEnvarConfigurationMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java (original)
+++ maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java Wed Jan 11 11:36:37 2006
@@ -22,7 +22,7 @@
     private String basedir;
 
     /**
-     * @parameter expression="${project.build.directory}"
+     * @parameter expression="${projectBuildDirectory}"
      */
     private String projectBuildDirectory;
 

Modified: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/PackagingMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/PackagingMojo.java?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/PackagingMojo.java (original)
+++ maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/PackagingMojo.java Wed Jan 11 11:36:37 2006
@@ -78,3 +78,4 @@
     }
 
 }
+                    

Modified: maven/components/trunk/maven-core-it/it0088/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0088/expected-results.txt?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/it0088/expected-results.txt (original)
+++ maven/components/trunk/maven-core-it/it0088/expected-results.txt Wed Jan 11 11:36:37 2006
@@ -1 +1,2 @@
 target/classes/test.properties
+target/mojo-generated.properties

Modified: maven/components/trunk/maven-core-it/it0088/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0088/pom.xml?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/it0088/pom.xml (original)
+++ maven/components/trunk/maven-core-it/it0088/pom.xml Wed Jan 11 11:36:37 2006
@@ -28,7 +28,7 @@
           <execution>
             <phase>process-resources</phase>
             <configuration>
-              <pomBuildDirectory>${project.build.directory}</pomBuildDirectory>
+              <projectBuildDirectory>${project.build.directory}</projectBuildDirectory>
             </configuration>
             <goals>
               <goal>generate-properties</goal>

Added: maven/components/trunk/maven-core-it/it0090/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/expected-results.txt?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it0090/expected-results.txt Wed Jan 11 11:36:37 2006
@@ -0,0 +1 @@
+target/mojo-generated.properties

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

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

Added: maven/components/trunk/maven-core-it/it0090/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/goals.txt?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0090/goals.txt Wed Jan 11 11:36:37 2006
@@ -0,0 +1 @@
+test

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

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

Added: maven/components/trunk/maven-core-it/it0090/log.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/log.txt?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/log.txt (added)
+++ maven/components/trunk/maven-core-it/it0090/log.txt Wed Jan 11 11:36:37 2006
@@ -0,0 +1,38 @@
++ Error stacktraces are turned on.
+[INFO] Scanning for projects...
+[INFO] Searching repository for plugin with prefix: 'clean'.
+[INFO] ----------------------------------------------------------------------------
+[INFO] Building Unnamed - org.apache.maven.it:maven-core-it0090:jar:1.0
+[INFO]    task-segment: [clean:clean, test]
+[INFO] ----------------------------------------------------------------------------
+[INFO] [clean:clean]
+[INFO] Deleting directory /home/jvanzyl/js/org/apache/maven/components/trunk/maven-core-it/it0090/target
+[INFO] [resources:resources]
+[INFO] Using default encoding to copy filtered resources.
+[INFO] [core-it:generate-envar-properties {execution: default}]
+>>>> MAVEN_TEST_ENVAR_VALUE
+[INFO] [compiler:compile]
+[INFO] No sources to compile
+[INFO] [resources:testResources]
+[INFO] Using default encoding to copy filtered resources.
+[INFO] [compiler:testCompile]
+Compiling 1 source file to /home/jvanzyl/js/org/apache/maven/components/trunk/maven-core-it/it0090/target/test-classes
+[INFO] [surefire:test]
+[INFO] Setting reports dir: /home/jvanzyl/js/org/apache/maven/components/trunk/maven-core-it/it0090/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+[surefire] Running org.apache.maven.it0090.PomInterpolationTest
+[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.017 sec
+
+Results :
+[surefire] Tests run: 1, Failures: 0, Errors: 0
+
+[INFO] ----------------------------------------------------------------------------
+[INFO] BUILD SUCCESSFUL
+[INFO] ----------------------------------------------------------------------------
+[INFO] Total time: 2 seconds
+[INFO] Finished at: Wed Jan 11 13:34:32 EST 2006
+[INFO] Final Memory: 4M/13M
+[INFO] ----------------------------------------------------------------------------

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

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

Added: maven/components/trunk/maven-core-it/it0090/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/pom.xml?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0090/pom.xml Wed Jan 11 11:36:37 2006
@@ -0,0 +1,48 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.it</groupId>
+  <artifactId>maven-core-it0090</artifactId>
+  <version>1.0</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <type>jar</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-core-it-plugin</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <phase>process-resources</phase>
+            <configuration>
+              <mavenTestEnvar>${env.MAVEN_TEST_ENVAR}</mavenTestEnvar>
+            </configuration>
+            <goals>
+              <goal>generate-envar-properties</goal>
+            </goals>
+          </execution>
+        </executions>
+      </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>
+</project>

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

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

Added: maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties (added)
+++ maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties Wed Jan 11 11:36:37 2006
@@ -0,0 +1,2 @@
+# When we want to test the filtering of envars
+maven.test.envar=${env.MAVEN_TEST_ENVAR}

Propchange: maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0090/src/main/resources/test.properties
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java?rev=368108&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java (added)
+++ maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java Wed Jan 11 11:36:37 2006
@@ -0,0 +1,35 @@
+package org.apache.maven.it0090;
+
+import junit.framework.TestCase;
+
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+
+public class PomInterpolationTest
+    extends TestCase
+{
+    private String basedir;
+
+    protected void setUp()
+        throws Exception
+    {
+        basedir = System.getProperty( "basedir" );
+    }
+
+    public void testProjectBuildDirectoryAfterForMojoExecution()
+        throws Exception
+    {
+        Properties testProperties = new Properties();
+
+        File testPropertiesFile = new File( basedir, "target/mojo-generated.properties" );
+
+        assertTrue( testPropertiesFile.exists() );
+
+        testProperties.load( new FileInputStream( testPropertiesFile ) );
+
+        File projectBuildDirectory = new File( basedir, "target" );
+
+        assertEquals( testProperties.getProperty( "maven.test.envar" ), "MAVEN_TEST_ENVAR_VALUE" );
+    }
+}

Propchange: maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core-it/it0090/src/test/java/org/apache/maven/it0090/PomInterpolationTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-core-it/maven-core-it.bat
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/maven-core-it.bat?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/maven-core-it.bat (original)
+++ maven/components/trunk/maven-core-it/maven-core-it.bat Wed Jan 11 11:36:37 2006
@@ -20,5 +20,7 @@
 @REM NOTE: for simplicity, only Windows NT/2000/XP is current supported
 @REM This also assumes that M2_HOME and JAVA_HOME are set, which are verified in the bootstrap script only
 
+SET MAVEN_TEST_ENVAR=MAVEN_TEST_ENVAR_VALUE
+
 "%JAVA_HOME%\bin\java.exe" -Dmaven.home="%M2_HOME%" %MAVEN_OPTS% -cp "..\maven-core-it-verifier\target\maven-core-it-verifier.jar" org.apache.maven.it.Verifier %*
 

Modified: maven/components/trunk/maven-core-it/maven-core-it.sh
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/maven-core-it.sh?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/maven-core-it.sh (original)
+++ maven/components/trunk/maven-core-it/maven-core-it.sh Wed Jan 11 11:36:37 2006
@@ -33,5 +33,7 @@
   echo Debugging verifier on port 5005
 fi
 
+export MAVEN_TEST_ENVAR=MAVEN_TEST_ENVAR_VALUE
+
 java "$jvm_m2_home" $opts -cp "$cp" $verifier $@
 

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=368108&r1=368107&r2=368108&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 Wed Jan 11 11:36:37 2006
@@ -20,16 +20,19 @@
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.interpolation.EnvarBasedValueSource;
-import org.codehaus.plexus.util.interpolation.MapBasedValueSource;
-import org.codehaus.plexus.util.interpolation.ObjectBasedValueSource;
-import org.codehaus.plexus.util.interpolation.RegexBasedInterpolator;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * Use a regular expression search to find and resolve expressions within the POM.
@@ -42,10 +45,25 @@
     extends AbstractLogEnabled
     implements ModelInterpolator
 {
-    public Model interpolate( Model project, Map context )
+    private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" );
+
+    private Properties envars;
+
+    public RegexBasedModelInterpolator( Properties envars )
+    {
+        this.envars = envars;
+    }
+
+    public RegexBasedModelInterpolator()
+        throws IOException
+    {
+        envars = CommandLineUtils.getSystemEnvVars();
+    }
+
+    public Model interpolate( Model model, Map context )
         throws ModelInterpolationException
     {
-        return interpolate( project, context, true );
+        return interpolate( model, context, true );
     }
 
     /**
@@ -54,7 +72,7 @@
      * <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 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!
      */
@@ -74,31 +92,14 @@
         }
 
         String serializedModel = sWriter.toString();
-
-        RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
-
-        interpolator.addValueSource( new MapBasedValueSource( context ) );
-        interpolator.addValueSource( new MapBasedValueSource( model.getProperties() ) );
-        interpolator.addValueSource( new ObjectBasedValueSource( model ) );
-
-        try
-        {
-            interpolator.addValueSource( new EnvarBasedValueSource() );
-        }
-        catch ( IOException e )
-        {
-            getLogger().warn( "Cannot initialize environment variables resolver. Skipping environmental resolution." );
-            getLogger().debug( "Failed to initialize envar resolver. Skipping environmental resolution.", e );
-        }
-
-        serializedModel = interpolator.interpolate(serializedModel, "pom|project" );
+        serializedModel = interpolateInternal( serializedModel, model, context );
 
         StringReader sReader = new StringReader( serializedModel );
 
         MavenXpp3Reader modelReader = new MavenXpp3Reader();
         try
         {
-            model = modelReader.read( sReader, strict );
+            model = modelReader.read( sReader );
         }
         catch ( IOException e )
         {
@@ -112,6 +113,73 @@
         }
 
         return model;
+    }
+
+    private String interpolateInternal( String src, Model model, Map context )
+        throws ModelInterpolationException
+    {
+        String result = src;
+        Matcher matcher = EXPRESSION_PATTERN.matcher( result );
+        while ( matcher.find() )
+        {
+            String wholeExpr = matcher.group( 0 );
+            String realExpr = matcher.group( 2 );
+
+            Object value = context.get( realExpr );
+
+            if ( value == null )
+            {
+                value = model.getProperties().getProperty( realExpr );
+            }
+
+            if ( value == null )
+            {
+                try
+                {
+                    value = ReflectionValueExtractor.evaluate( realExpr, model );
+                }
+                catch ( Exception e )
+                {
+                    Logger logger = getLogger();
+                    if ( logger != null )
+                    {
+                        logger.debug( "POM interpolation cannot proceed with expression: " + wholeExpr + ". Skipping...", e );
+                    }
+                }
+            }
+
+            if ( value == null )
+            {
+                value = envars.getProperty( realExpr );
+            }
+
+            // if the expression refers to itself, skip it.
+            if ( wholeExpr.equals( value ) )
+            {
+                throw new ModelInterpolationException( wholeExpr, model.getId() + " references itself." );
+            }
+
+            if ( value != null )
+            {
+                result = StringUtils.replace( result, wholeExpr, String.valueOf( value ) );
+                // could use:
+                // result = matcher.replaceFirst( stringValue );
+                // but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour
+                matcher.reset( result );
+            }
+/*
+        // 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
+
+            else
+            {
+                throw new ModelInterpolationException(
+                    "Expression '" + wholeExpr + "' did not evaluate to anything in the model" );
+            }
+*/
+        }
+
+        return result;
     }
 
 }

Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java?rev=368108&r1=368107&r2=368108&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java Wed Jan 11 11:36:37 2006
@@ -24,6 +24,7 @@
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.Properties;
 
 /**
  * @author jdcasey
@@ -43,7 +44,7 @@
     }
 
     public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
-        throws ModelInterpolationException
+        throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -59,7 +60,7 @@
     }
 
     public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
-        throws ModelInterpolationException
+        throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -90,7 +91,7 @@
     }
 
     public void testTwoReferences()
-        throws ModelInterpolationException
+        throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -107,7 +108,7 @@
     }
 
     public void testBasedir()
-        throws ModelInterpolationException
+        throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -123,5 +124,65 @@
 
         assertEquals( "file://localhost/myBasedir/temp-repo",
                       ( (Repository) out.getRepositories().get( 0 ) ).getUrl() );
+    }
+
+    public void testEnvars()
+        throws Exception
+    {
+        Properties envars = new Properties();
+
+        envars.setProperty( "HOME", "/path/to/home" );
+
+        Model model = new Model();
+
+        Properties modelProperties = new Properties();
+
+        modelProperties.setProperty( "outputDirectory", "${env.HOME}" );
+
+        model.setProperties( modelProperties );
+
+        Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context );
+
+        assertEquals( out.getProperties().getProperty( "outputDirectory" ), "/path/to/home" );
+    }
+
+    public void testEnvarExpressionThatEvaluatesToNullReturnsTheLiteralString()
+        throws Exception
+    {
+        Properties envars = new Properties();
+
+        Model model = new Model();
+
+        Properties modelProperties = new Properties();
+
+        modelProperties.setProperty( "outputDirectory", "${env.DOES_NOT_EXIST}" );
+
+        model.setProperties( modelProperties );
+
+        Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context );
+
+        System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );        
+
+        assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
+    }
+
+
+
+    public void testExpressionThatEvaluatesToNullReturnsTheLiteralString()
+        throws Exception
+    {
+        Model model = new Model();
+
+        Properties modelProperties = new Properties();
+
+        modelProperties.setProperty( "outputDirectory", "${DOES_NOT_EXIST}" );
+
+        model.setProperties( modelProperties );
+
+        Model out = new RegexBasedModelInterpolator().interpolate( model, context );
+
+        System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
+
+        assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
     }
 }



Re: svn commit: r368108 - in /maven/components/trunk: integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ maven-core-it/ maven-core-it/it0088/ maven-core-it/it0090/ maven-core-it/it0090/src/ maven-core-it/it0090/src/main/ m...

Posted by Brett Porter <br...@apache.org>.
I had the problem too, but it looked like Windows pathing problems. (\
instead of \\ so that get omitted). Should be easily fixed.

- Brett

Emmanuel Venisse wrote:
> After investigation, it isn't this change that cause the pb.
> 
> Emmanuel
> 
> Emmanuel Venisse a écrit :
>>> Modified:
>>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
>>>
>>> URL:
>>> http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java?rev=368108&r1=368107&r2=368108&view=diff
>>>
>>> ==============================================================================
>>>
>>> ---
>>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
>>> (original)
>>> +++
>>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
>>> Wed Jan 11 11:36:37 2006
>>> @@ -22,7 +22,7 @@
>>>      private String basedir;
>>>  
>>>      /**
>>> -     * @parameter expression="${project.build.directory}"
>>> +     * @parameter expression="${projectBuildDirectory}"
>>>       */
>>>      private String projectBuildDirectory;
>>>  
>>
>>
>> Jason,
>>
>> Why do you don't use ${project.build.directory}?
>> With this change i have only "target" in mojo-generated.properties, so
>> it0088 fails now.
>>
>> Emmanuel
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

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


Re: svn commit: r368108 - in /maven/components/trunk: integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ maven-core-it/ maven-core-it/it0088/ maven-core-it/it0090/ maven-core-it/it0090/src/ maven-core-it/it0090/src/main/ m...

Posted by Emmanuel Venisse <em...@venisse.net>.
After investigation, it isn't this change that cause the pb.

Emmanuel

Emmanuel Venisse a écrit :
>> Modified: 
>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java 
>>
>> URL: 
>> http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java?rev=368108&r1=368107&r2=368108&view=diff 
>>
>> ============================================================================== 
>>
>> --- 
>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java 
>> (original)
>> +++ 
>> maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java 
>> Wed Jan 11 11:36:37 2006
>> @@ -22,7 +22,7 @@
>>      private String basedir;
>>  
>>      /**
>> -     * @parameter expression="${project.build.directory}"
>> +     * @parameter expression="${projectBuildDirectory}"
>>       */
>>      private String projectBuildDirectory;
>>  
> 
> 
> Jason,
> 
> Why do you don't use ${project.build.directory}?
> With this change i have only "target" in mojo-generated.properties, so 
> it0088 fails now.
> 
> Emmanuel
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 
> 
> 
> 


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


Re: svn commit: r368108 - in /maven/components/trunk: integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ maven-core-it/ maven-core-it/it0088/ maven-core-it/it0090/ maven-core-it/it0090/src/ maven-core-it/it0090/src/main/ m...

Posted by Emmanuel Venisse <em...@venisse.net>.
> Modified: maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java
> URL: http://svn.apache.org/viewcvs/maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java?rev=368108&r1=368107&r2=368108&view=diff
> ==============================================================================
> --- maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java (original)
> +++ maven/components/trunk/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java Wed Jan 11 11:36:37 2006
> @@ -22,7 +22,7 @@
>      private String basedir;
>  
>      /**
> -     * @parameter expression="${project.build.directory}"
> +     * @parameter expression="${projectBuildDirectory}"
>       */
>      private String projectBuildDirectory;
>  

Jason,

Why do you don't use ${project.build.directory}?
With this change i have only "target" in mojo-generated.properties, so it0088 fails now.

Emmanuel


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


Re: svn commit: r368108

Posted by Brett Porter <br...@apache.org>.
Should revs 368108 and 368118 be merged to the branch before tagging?

- Brett

jvanzyl@apache.org wrote:
> Author: jvanzyl
> Date: Wed Jan 11 11:36:37 2006
> New Revision: 368108
> 
> URL: http://svn.apache.org/viewcvs?rev=368108&view=rev
> Log:
> [MNG-1927] This adds the test mojos required to fix ${pom.build.*} expansion to full paths, the problem was the
>            new interpolator so the one from 2.0 was used and some envar handling was back ported. Unit tests
>            have been added for envar handling as well as an IT. The maven-core-it script will now set
>            an envar which is used in it0090.
> 
> 

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