Hey John,

I can't see a problem one way or the other here, I just noticed you moved the caching - can you elaborate a bit on why that was necessary, and are you sure it won't cause any problems with caching resolved information? It looks like it is now after interpolation, and ISTR that giving me grief in the past.

Thanks,
Brett

On 15/03/2008, at 12:25 PM, [EMAIL PROTECTED] wrote:

Author: jdcasey
Date: Fri Mar 14 18:25:12 2008
New Revision: 637324

URL: http://svn.apache.org/viewvc?rev=637324&view=rev
Log:
[MNG-3355] Make expressions referencing build directories resolve and use translated paths when the project is local (NOT from a repository, where the project.getFile() returns null). Unit test included.

Added:
maven/components/branches/maven-2.0.x/maven-project/src/test/ resources/projects/build-path-expression-pom.xml (with props)
Modified:
maven/components/branches/maven-2.0.x/maven-project/src/main/java/ org/apache/maven/project/DefaultMavenProjectBuilder.java maven/components/branches/maven-2.0.x/maven-project/src/test/java/ org/apache/maven/project/DefaultMavenProjectBuilderTest.java

Modified: maven/components/branches/maven-2.0.x/maven-project/src/ main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=637324&r1=637323&r2=637324&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.x/maven-project/src/main/ java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original) +++ maven/components/branches/maven-2.0.x/maven-project/src/main/ java/org/apache/maven/project/DefaultMavenProjectBuilder.java Fri Mar 14 18:25:12 2008
@@ -862,14 +862,15 @@
        }

        processedProjectCache.put(
- createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project ); + createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );

-        // jvz:note
+          // jvz:note
        // this only happens if we are building from a source file
        if ( projectDescriptor != null )
        {
// Only translate the base directory for files in the source tree - pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() );
+            pathTranslator.alignToBaseDirectory( project.getModel(),
+                                                 projectDir );

            Build build = project.getBuild();

@@ -883,24 +884,9 @@
            project.setFile( projectDescriptor );
        }

-        MavenProject rawParent = project.getParent();
-
-        if ( rawParent != null )
-        {
-            String cacheKey =
- createCacheKey( rawParent.getGroupId(), rawParent.getArtifactId(), rawParent.getVersion() );
-
- MavenProject processedParent = (MavenProject) processedProjectCache.get( cacheKey );
-
- // yeah, this null check might be a bit paranoid, but better safe than sorry...
-            if ( processedParent != null )
-            {
-                project.setParent( processedParent );
-            }
-        }
-
-        project.setManagedVersionMap(
- createManagedVersionMap( projectId, project.getDependencyManagement(), project.getParent() ) ); + project.setManagedVersionMap( createManagedVersionMap( projectId, + project.getDependencyManagement(), + project.getParent() ) );

        return project;
    }
@@ -971,23 +957,26 @@
// We don't need all the project methods that are added over those in the model, but we do need basedir
        Map context = new HashMap();

+        Build build = model.getBuild();
+
        if ( projectDir != null )
        {
            context.put( "basedir", projectDir.getAbsolutePath() );
-        }

- // 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 );
+            // 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 ) );
+        }

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 );
@@ -1032,13 +1021,31 @@
            }
        }

-        project.setParent( parentProject );
-
        if ( parentProject != null )
        {
- Artifact parentArtifact = artifactFactory.createParentArtifact( parentProject.getGroupId(), - parentProject .getArtifactId(), - parentProject .getVersion() ); + String cacheKey = createCacheKey( parentProject.getGroupId(), + parentProject.getArtifactId(), + parentProject.getVersion() );
+
+ MavenProject processedParent = (MavenProject) processedProjectCache.get( cacheKey );
+            Artifact parentArtifact;
+
+ // yeah, this null check might be a bit paranoid, but better safe than sorry...
+            if ( processedParent != null )
+            {
+                project.setParent( processedParent );
+
+                parentArtifact = processedParent.getArtifact();
+            }
+            else
+            {
+                project.setParent( parentProject );
+
+ parentArtifact = artifactFactory.createParentArtifact( parentProject.getGroupId(), + parentProject .getArtifactId(), + parentProject .getVersion() );
+            }
+
            project.setParentArtifact( parentArtifact );
        }


Modified: maven/components/branches/maven-2.0.x/maven-project/src/ test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java?rev=637324&r1=637323&r2=637324&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.x/maven-project/src/test/ java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java (original) +++ maven/components/branches/maven-2.0.x/maven-project/src/test/ java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java Fri Mar 14 18:25:12 2008
@@ -19,22 +19,24 @@
 * under the License.
 */

-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
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.Profile;
import org.apache.maven.model.Repository;
+import org.apache.maven.model.Resource;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.codehaus.plexus.util.FileUtils;

+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
public class DefaultMavenProjectBuilderTest
    extends AbstractMavenProjectTestCase
{
@@ -148,7 +150,7 @@

    /**
* Check that we can build ok from the middle pom of a (parent,child,grandchild) heirarchy
-     * @throws Exception
+     * @throws Exception
     */
    public void testBuildFromMiddlePom() throws Exception
    {
@@ -156,23 +158,45 @@
File f2 = getTestFile( "src/test/resources/projects/ grandchild-check/child/grandchild/pom.xml");

        getProject( f1 );
-
+
// it's the building of the grandchild project, having already cached the child project
        // (but not the parent project), which causes the problem.
        getProject( f2 );
    }
-
+
     public void testDuplicatePluginDefinitionsMerged()
         throws Exception
     {
File f1 = getTestFile( "src/test/resources/projects/ duplicate-plugins-merged-pom.xml" );
-
+
         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()
        throws Exception
    {

Added: maven/components/branches/maven-2.0.x/maven-project/src/test/ resources/projects/build-path-expression-pom.xml
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/resources/projects/build-path-expression-pom.xml?rev=637324&view=auto
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.x/maven-project/src/test/ resources/projects/build-path-expression-pom.xml (added) +++ maven/components/branches/maven-2.0.x/maven-project/src/test/ resources/projects/build-path-expression-pom.xml Fri Mar 14 18:25:12 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/branches/maven-2.0.x/maven-project/src/ test/resources/projects/build-path-expression-pom.xml
------------------------------------------------------------------------------
   svn:eol-style = native

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



--
Brett Porter
[EMAIL PROTECTED]
http://blogs.exist.com/bporter/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to