maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r647287 - in /maven/components/trunk/maven-project/src: main/java/org/apache/maven/project/ main/java/org/apache/maven/project/interpolation/ test/java/org/apache/maven/project/interpolation/
Date Fri, 11 Apr 2008 19:53:06 GMT
Author: jdcasey
Date: Fri Apr 11 12:53:04 2008
New Revision: 647287

URL: http://svn.apache.org/viewvc?rev=647287&view=rev
Log:
Fixing interpolation for project.basedir and pom.basedir, by internalizing the basedir handling
into the interpolator (now that we're passing in projectDir, it's easier to handle there).

Modified:
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    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

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=647287&r1=647286&r2=647287&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Fri Apr 11 12:53:04 2008
@@ -973,8 +973,6 @@
         if ( pomFile != null )
         {
             projectDir = pomFile.getAbsoluteFile().getParentFile();
-
-            context.put( "basedir", projectDir.getAbsolutePath() );
         }
 
         Map overrideContext = new HashMap();

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java?rev=647287&r1=647286&r2=647287&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
Fri Apr 11 12:53:04 2008
@@ -181,7 +181,12 @@
      * @param overrideContext
      * @param outputDebugMessages
      */
-    private String interpolateInternal( String src, Model model, Map context, Map overrideContext,
File projectDir, boolean outputDebugMessages )
+    private String interpolateInternal( String src,
+                                        Model model,
+                                        Map context,
+                                        Map overrideContext,
+                                        final File projectDir,
+                                        boolean outputDebugMessages )
         throws ModelInterpolationException
     {
         Logger logger = getLogger();
@@ -196,9 +201,23 @@
                                                                        TRANSLATED_PATH_EXPRESSIONS,
                                                                        projectDir, pathTranslator
);
 
+        ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource(){
+            public Object getValue( String expression )
+            {
+                if ( projectDir != null && "basedir".equals( expression ) )
+                {
+                    return projectDir.getAbsolutePath();
+                }
+
+                return null;
+            }
+        },
+        PROJECT_PREFIXES, true );
+
         RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
 
         // NOTE: Order counts here!
+        interpolator.addValueSource( basedirValueSource );
         interpolator.addValueSource( new MapBasedValueSource( overrideContext ) );
         interpolator.addValueSource( modelValueSource1 );
         interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource(
model.getProperties() ), PROJECT_PREFIXES, true ) );

Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java?rev=647287&r1=647286&r2=647287&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
Fri Apr 11 12:53:04 2008
@@ -19,18 +19,23 @@
  * under the License.
  */
 
-import junit.framework.TestCase;
 import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DeploymentRepository;
+import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Organization;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.Scm;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
+import junit.framework.TestCase;
+
 /**
  * @author jdcasey
  * @version $Id$
@@ -46,6 +51,34 @@
         super.setUp();
 
         context = Collections.singletonMap( "basedir", "myBasedir" );
+    }
+
+    public void testShouldInterpolateProjectDotBasedirInDistributionManagement()
+        throws ModelInterpolationException, IOException
+    {
+        Model model = new Model();
+        DistributionManagement dm = new DistributionManagement();
+        DeploymentRepository repo = new DeploymentRepository();
+
+        // from IT0062...
+        repo.setUrl( "http://localhost/${project.basedir}/target/test-repo" );
+
+        dm.setRepository( repo );
+        model.setDistributionManagement( dm );
+
+        Map context = new HashMap();
+        String path = "path/to/project";
+
+        File basedir = new File( path ).getAbsoluteFile();
+
+        Model out = new RegexBasedModelInterpolator().interpolate( model,
+                                                                   context,
+                                                                   Collections.EMPTY_MAP,
+                                                                   basedir,
+                                                                   false );
+
+        assertEquals( "http://localhost/" + basedir.getAbsolutePath() + "/target/test-repo",
+                      out.getDistributionManagement().getRepository().getUrl() );
     }
 
     public void testShouldNotThrowExceptionOnReferenceToNonExistentValue()



Mime
View raw message