You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2008/03/15 02:28:01 UTC

svn commit: r637326 - in /maven/components/trunk/maven-project/src: main/java/org/apache/maven/project/ test/java/org/apache/maven/project/ test/resources/projects/

Author: jdcasey
Date: Fri Mar 14 18:28:01 2008
New Revision: 637326

URL: http://svn.apache.org/viewvc?rev=637326&view=rev
Log:
[MNG-3355] Use translated paths to resolve expressions referencing build directories in the model during interpolation, if the project-descriptor is known (if the project is from the local filesystem, not from the repository system).

Also, merge repositories and pluginRepositories when creating their ArtifactRepository analogs, to restore the pluginRepository functionality. I've added a deprecation warning in these cases, but it may need to be made more prominent.

Added:
    maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml   (with props)
Modified:
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.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=637326&r1=637325&r2=637326&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 Mar 14 18:28:01 2008
@@ -945,19 +945,29 @@
 
         if ( pomFile != null )
         {
+            File projectDir = pomFile.getAbsoluteFile().getParentFile();
+
             context.put( "basedir", pomFile.getParentFile().getAbsolutePath() );
+            context.put( "basedir", projectDir.getAbsolutePath() );
+
+            Build build = model.getBuild();
+
+            // MNG-1927, MNG-2124, MNG-3355:
+            // If the build section is present and the project directory is non-null, we should make
+            // sure interpolation of the directories below uses translated paths.
+            // Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
+            // code below...
+            context.put( "build.directory", pathTranslator.alignToBaseDirectory( build.getDirectory(), projectDir ) );
+            context.put( "build.outputDirectory", pathTranslator.alignToBaseDirectory( build.getOutputDirectory(), projectDir ) );
+            context.put( "build.testOutputDirectory", pathTranslator.alignToBaseDirectory( build.getTestOutputDirectory(), projectDir ) );
+            context.put( "build.sourceDirectory", pathTranslator.alignToBaseDirectory( build.getSourceDirectory(), projectDir ) );
+            context.put( "build.testSourceDirectory", pathTranslator.alignToBaseDirectory( build.getTestSourceDirectory(), projectDir ) );
         }
 
-        // TODO: this is a hack to ensure MNG-2124 can be satisfied without triggering MNG-1927
-        //  MNG-1927 relies on the false assumption that ${project.build.*} evaluates to null, which occurs before
-        //  MNG-2124 is fixed. The null value would leave it uninterpolated, to be handled after path translation.
-        //  Until these steps are correctly sequenced, we guarantee these fields remain uninterpolated.
-        context.put( "build.directory", null );
-        context.put( "build.outputDirectory", null );
-        context.put( "build.testOutputDirectory", null );
-        context.put( "build.sourceDirectory", null );
-        context.put( "build.testSourceDirectory", null );
+        model = modelInterpolator.interpolate( model, context, strict );
 
+        // [MNG-2339] ensure the system properties are still interpolated for backwards compat, but the model values must win
+        context.putAll( System.getProperties() );
         model = modelInterpolator.interpolate( model, context, strict );
 
         // interpolation is before injection, because interpolation is off-limits in the injected variables
@@ -1009,8 +1019,20 @@
 
         try
         {
+            LinkedHashSet repoSet = new LinkedHashSet();
+            if ( ( model.getRepositories() != null ) && !model.getRepositories().isEmpty() )
+            {
+                repoSet.addAll( model.getRepositories() );
+            }
+
+            if ( ( model.getPluginRepositories() != null ) && !model.getPluginRepositories().isEmpty() )
+            {
+                getLogger().warn( "The <pluginRepositories/> section of the POM has been deprecated. Please update your POMs." );
+                repoSet.addAll( model.getPluginRepositories() );
+            }
+
             project.setRemoteArtifactRepositories(
-                                                  mavenTools.buildArtifactRepositories( model.getRepositories() ) );
+                                                  mavenTools.buildArtifactRepositories( new ArrayList( repoSet ) ) );
         }
         catch( Exception e )
         {

Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java?rev=637326&r1=637325&r2=637326&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java Fri Mar 14 18:28:01 2008
@@ -22,7 +22,9 @@
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.model.Build;
 import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Resource;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
@@ -103,6 +105,31 @@
         MavenProject project = getProject( f1 );
 
         assertEquals( 2, ( (Plugin) project.getBuildPlugins().get( 0 ) ).getDependencies().size() );
+    }
+
+    public void testBuildDirectoryExpressionInterpolatedWithTranslatedValue()
+        throws Exception
+    {
+        File pom = getTestFile( "src/test/resources/projects/build-path-expression-pom.xml" );
+
+        MavenProject project = getProject( pom );
+
+        Build build = project.getBuild();
+        assertNotNull( "Project should have a build section containing the test resource.", build );
+
+        String sourceDirectory = build.getSourceDirectory();
+        assertNotNull( "Project build should contain a valid source directory.", sourceDirectory );
+
+        List resources = build.getResources();
+        assertNotNull( "Project should contain a build resource.", resources );
+        assertEquals( "Project should contain exactly one build resource.", 1, resources.size() );
+
+        Resource res = (Resource) resources.get( 0 );
+        assertEquals( "Project resource should be the same directory as the source directory.",
+                      sourceDirectory,
+                      res.getDirectory() );
+
+        System.out.println( "Interpolated, translated resource directory is: " + res.getDirectory() );
     }
 
     protected ArtifactRepository getLocalRepository()

Added: maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml?rev=637326&view=auto
==============================================================================
--- maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml (added)
+++ maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml Fri Mar 14 18:28:01 2008
@@ -0,0 +1,14 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.project.tests</groupId>
+  <artifactId>build-path-expression</artifactId>
+  <version>1</version>
+  <build>
+    <sourceDirectory>sources</sourceDirectory>
+    <resources>
+      <resource>
+        <directory>${project.build.sourceDirectory}</directory>
+      </resource>
+    </resources>
+  </build>
+</project>
\ No newline at end of file

Propchange: maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-project/src/test/resources/projects/build-path-expression-pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"