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 2009/02/19 19:39:10 UTC

svn commit: r745955 - in /maven/components/branches/maven-2.1.x: ./ maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/ maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/ maven-artifact-manager/src/main/resou...

Author: jdcasey
Date: Thu Feb 19 18:39:09 2009
New Revision: 745955

URL: http://svn.apache.org/viewvc?rev=745955&view=rev
Log:
[MNG-3057] Interpolate versions in POMs before installing/deploying them. Leave other expressions alone.

Added:
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java   (with props)
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java   (with props)
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java   (with props)
    maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java   (with props)
Modified:
    maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
    maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
    maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml
    maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
    maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
    maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java
    maven/components/branches/maven-2.1.x/maven-project/src/main/resources/META-INF/plexus/components.xml
    maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
    maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml
    maven/components/branches/maven-2.1.x/pom.xml

Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java Thu Feb 19 18:39:09 2009
@@ -66,10 +66,39 @@
             throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." );
         }
 
+        // If we're installing the POM, we need to transform it first. The source file supplied for 
+        // installation here may be the POM, but that POM may not be set as the file of the supplied
+        // artifact. Since the transformation only has access to the artifact and not the supplied
+        // source file, we have to use the Artifact.setFile(..) and Artifact.getFile(..) methods
+        // to shunt the POM file into the transformation process.
+        // Here, we also set a flag indicating that the POM has been shunted through the Artifact,
+        // and to expect the transformed version to be available in the Artifact afterwards...
+        boolean useArtifactFile = false;
+        if ( "pom".equals( artifact.getType() ) )
+        {
+            if ( artifact.getFile() == null )
+            {
+                artifact.setFile( source );
+            }
+            
+            useArtifactFile = true;
+        }
+        
         try
         {
             transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );
 
+            // If we used the Artifact shunt to transform a POM source file, we need to install
+            // the transformed version, not the supplied version. Therefore, we need to replace
+            // the supplied source POM with the one from Artifact.getFile(..).
+            if ( useArtifactFile )
+            {
+                source = artifact.getFile();
+            }
+
+            // FIXME: Why oh why are we re-installing the artifact in the local repository? Isn't this
+            // the responsibility of the ArtifactInstaller??
+            
             // Copy the original file to the new one if it was transformed
             File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
             if ( !artifactFile.equals( source ) )

Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java Thu Feb 19 18:39:09 2009
@@ -55,9 +55,36 @@
     public void install( File source, Artifact artifact, ArtifactRepository localRepository )
         throws ArtifactInstallationException
     {
+        
+        // If we're installing the POM, we need to transform it first. The source file supplied for 
+        // installation here may be the POM, but that POM may not be set as the file of the supplied
+        // artifact. Since the transformation only has access to the artifact and not the supplied
+        // source file, we have to use the Artifact.setFile(..) and Artifact.getFile(..) methods
+        // to shunt the POM file into the transformation process.
+        // Here, we also set a flag indicating that the POM has been shunted through the Artifact,
+        // and to expect the transformed version to be available in the Artifact afterwards...
+        boolean useArtifactFile = false;
+        if ( "pom".equals( artifact.getType() ) )
+        {
+            if ( artifact.getFile() == null )
+            {
+                artifact.setFile( source );
+            }
+            
+            useArtifactFile = true;
+        }
+        
         try
         {
             transformationManager.transformForInstall( artifact, localRepository );
+            
+            // If we used the Artifact shunt to transform a POM source file, we need to install
+            // the transformed version, not the supplied version. Therefore, we need to replace
+            // the supplied source POM with the one from Artifact.getFile(..).
+            if ( useArtifactFile )
+            {
+                source = artifact.getFile();
+            }
 
             String localPath = localRepository.pathOf( artifact );
 
@@ -71,6 +98,13 @@
             getLogger().info( "Installing " + source.getPath() + " to " + destination );
 
             FileUtils.copyFile( source, destination );
+            
+            // Now, we'll set the artifact's file to the one installed in the local repository,
+            // to help avoid duplicate copy operations in the deployment step.
+            if ( useArtifactFile )
+            {
+                artifact.setFile( destination );
+            }
 
             // must be after the artifact is installed
             for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )

Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml Thu Feb 19 18:39:09 2009
@@ -174,11 +174,6 @@
       <role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
       <implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
     </component>
-
-    <component>
-      <role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
-      <implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
-    </component>
   </components>
 
 </component-set>

Modified: maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java Thu Feb 19 18:39:09 2009
@@ -104,6 +104,8 @@
     String getDependencyConflictId();
 
     void addMetadata( ArtifactMetadata metadata );
+    
+    ArtifactMetadata getMetadata( Class metadataClass );
 
     Collection getMetadataList();
 

Modified: maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java Thu Feb 19 18:39:09 2009
@@ -32,6 +32,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
@@ -264,6 +265,25 @@
         }
     }
 
+    public ArtifactMetadata getMetadata( Class metadataClass )
+    {
+        Collection metadata = getMetadataList();
+        
+        if ( metadata != null )
+        {
+            for ( Iterator it = metadata.iterator(); it.hasNext(); )
+            {
+                ArtifactMetadata m = (ArtifactMetadata) it.next();
+                if ( metadataClass.isAssignableFrom( m.getClass() ) )
+                {
+                    return m;
+                }
+            }
+        }
+        
+        return null;
+    }
+    
     public Collection getMetadataList()
     {
         return metadataMap == null ? Collections.EMPTY_LIST : metadataMap.values();

Modified: maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java Thu Feb 19 18:39:09 2009
@@ -158,4 +158,9 @@
         return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
                                     optional );
     }
+
+    protected ArtifactHandlerManager getArtifactHandlerManager()
+    {
+        return artifactHandlerManager;
+    }
 }

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Thu Feb 19 18:39:09 2009
@@ -78,7 +78,9 @@
 import org.apache.maven.profiles.ProfilesConversionUtils;
 import org.apache.maven.profiles.ProfilesRoot;
 import org.apache.maven.profiles.activation.ProfileActivationException;
+import org.apache.maven.project.artifact.ArtifactWithProject;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.artifact.ProjectArtifactFactory;
 import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
 import org.apache.maven.project.injection.ModelDefaultsInjector;
 import org.apache.maven.project.injection.ProfileInjector;
@@ -151,7 +153,7 @@
 
     protected ArtifactMetadataSource artifactMetadataSource;
 
-    private ArtifactFactory artifactFactory;
+    private ProjectArtifactFactory artifactFactory;
 
     private ModelInheritanceAssembler modelInheritanceAssembler;
 
@@ -1021,10 +1023,10 @@
         project.setActiveProfiles( activeProfiles );
 
         // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
-        Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
-                                                                        project.getVersion(), project.getPackaging() );
-
+        Artifact projectArtifact = artifactFactory.create( project );
+        
         project.setArtifact( projectArtifact );
+        project.setProjectBuilderConfiguration( config );
 
         project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),
                                                                                        artifactRepositoryFactory,

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/MavenProject.java Thu Feb 19 18:39:09 2009
@@ -155,6 +155,8 @@
     
     private Logger logger;
     
+    private ProjectBuilderConfiguration projectBuilderConfiguration;
+    
     public MavenProject()
     {
         Model model = new Model();
@@ -2094,4 +2096,21 @@
         this.logger = logger;
     }
 
+    /**
+     * Retrieve the {@link ProjectBuilderConfiguration} instance used to construct this MavenProject instance.
+     */
+    public ProjectBuilderConfiguration getProjectBuilderConfiguration()
+    {
+        return projectBuilderConfiguration;
+    }
+
+    /**
+     * Set the {@link ProjectBuilderConfiguration} instance used to construct this MavenProject instance.
+     * @param projectBuilderConfiguration
+     */
+    public void setProjectBuilderConfiguration( ProjectBuilderConfiguration projectBuilderConfiguration )
+    {
+        this.projectBuilderConfiguration = projectBuilderConfiguration;
+    }
+
 }

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java Thu Feb 19 18:39:09 2009
@@ -399,4 +399,9 @@
 
         return true;
     }
+
+    public ArtifactMetadata getMetadata( Class metadataClass )
+    {
+        return artifact.getMetadata( metadataClass );
+    }
 }

Added: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java?rev=745955&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java (added)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java Thu Feb 19 18:39:09 2009
@@ -0,0 +1,55 @@
+package org.apache.maven.project.artifact;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.project.MavenProject;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+public class ArtifactWithProject
+    extends DefaultArtifact
+{
+
+    private final MavenProject project;
+
+    public ArtifactWithProject( MavenProject project, String type, String classifier,
+                                ArtifactHandler artifactHandler, boolean optional )
+    {
+        super( project.getGroupId(), project.getArtifactId(), VersionRange.createFromVersion( project.getVersion() ),
+               null, type, classifier, artifactHandler, optional );
+        
+        this.project = project;
+    }
+
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+    public ProjectArtifactMetadata getProjectArtifactMetadata()
+    {
+        return getProjectArtifactMetadata( this );
+    }
+
+    public static ProjectArtifactMetadata getProjectArtifactMetadata( Artifact artifact )
+    {
+        Collection metadataList = artifact.getMetadataList();
+        if ( metadataList != null )
+        {
+            for ( Iterator it = metadataList.iterator(); it.hasNext(); )
+            {
+                Object metadata = it.next();
+                if ( metadata instanceof ProjectArtifactMetadata )
+                {
+                    return (ProjectArtifactMetadata) metadata;
+                }
+            }
+        }
+
+        return null;
+    }
+
+}

Propchange: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ArtifactWithProject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java?rev=745955&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java (added)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java Thu Feb 19 18:39:09 2009
@@ -0,0 +1,25 @@
+package org.apache.maven.project.artifact;
+
+import org.apache.maven.artifact.factory.DefaultArtifactFactory;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.project.MavenProject;
+
+public class ProjectArtifactFactory
+    extends DefaultArtifactFactory
+{
+    
+    public ArtifactWithProject create( MavenProject project )
+    {
+        ArtifactHandler handler = getArtifactHandlerManager().getArtifactHandler( project.getPackaging() );
+
+        return new ArtifactWithProject( project, project.getPackaging(), null, handler, false );
+    }
+
+    public ArtifactWithProject create( MavenProject project, String type, String classifier, boolean optional )
+    {
+        ArtifactHandler handler = getArtifactHandlerManager().getArtifactHandler( type );
+
+        return new ArtifactWithProject( project, type, classifier, handler, optional );
+    }
+
+}

Propchange: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java Thu Feb 19 18:39:09 2009
@@ -38,7 +38,11 @@
 public class ProjectArtifactMetadata
     extends AbstractArtifactMetadata
 {
-    private final File file;
+    private File originalFile;
+    
+    private File transformedFile;
+    
+    private boolean versionExpressionsResolved = false;
 
     public ProjectArtifactMetadata( Artifact artifact )
     {
@@ -49,7 +53,7 @@
                                     File file )
     {
         super( artifact );
-        this.file = file;
+        this.originalFile = file;
     }
 
     public String getRemoteFilename()
@@ -71,6 +75,12 @@
                                         ArtifactRepository remoteRepository )
         throws RepositoryMetadataStoreException
     {
+        File f = transformedFile == null ? originalFile : transformedFile;
+        if ( f == null )
+        {
+            return;
+        }
+        
         File destination = new File( localRepository.getBasedir(),
                                      localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
 
@@ -83,7 +93,7 @@
 
         try
         {
-            FileUtils.copyFile( file, destination );
+            FileUtils.copyFile( f, destination );
         }
         catch ( IOException e )
         {
@@ -114,9 +124,29 @@
     public void merge( ArtifactMetadata metadata )
     {
         ProjectArtifactMetadata m = (ProjectArtifactMetadata) metadata;
-        if ( !m.file.equals( file ) )
+        if ( !m.originalFile.equals( originalFile ) )
         {
             throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
         }
     }
+
+    public boolean isVersionExpressionsResolved()
+    {
+        return versionExpressionsResolved;
+    }
+
+    public void setVersionExpressionsResolved( boolean versionExpressionsResolved )
+    {
+        this.versionExpressionsResolved = versionExpressionsResolved;
+    }
+    
+    public void setFile( File file )
+    {
+        this.transformedFile = file;
+    }
+
+    public File getFile()
+    {
+        return transformedFile == null ? originalFile : transformedFile;
+    }
 }

Added: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java?rev=745955&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java (added)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java Thu Feb 19 18:39:09 2009
@@ -0,0 +1,396 @@
+package org.apache.maven.project.artifact;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.transform.ArtifactTransformation;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.project.DefaultProjectBuilderConfiguration;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.project.interpolation.ModelInterpolationException;
+import org.apache.maven.project.interpolation.StringSearchModelInterpolator;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.ValueSource;
+import org.codehaus.plexus.interpolation.object.FieldBasedObjectInterpolator;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+public class VersionExpressionTransformation
+    extends StringSearchModelInterpolator
+    implements Initializable, ArtifactTransformation
+{
+
+    private static Set BLACKLISTED_FIELD_NAMES;
+    
+    private static final Set WHITELISTED_FIELD_NAMES;
+    
+    static
+    {
+        Set whitelist = new HashSet();
+        
+        whitelist.add( "version" );
+        whitelist.add( "dependencies" );
+        whitelist.add( "build" );
+        whitelist.add( "plugins" );
+        whitelist.add( "reporting" );
+        whitelist.add( "parent" );
+        
+        WHITELISTED_FIELD_NAMES = whitelist;
+    }
+
+    public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
+                                        ArtifactRepository localRepository )
+        throws ArtifactDeploymentException
+    {
+        ProjectArtifactMetadata metadata = ArtifactWithProject.getProjectArtifactMetadata( artifact );
+        File pomFile;
+        boolean pomArtifact = false;
+        if ( "pom".equals( artifact.getType() ) )
+        {
+            System.out.println( "On Deploy: Using artifact file for POM: " + artifact );
+            pomFile = artifact.getFile();
+            pomArtifact = true;
+        }
+        // FIXME: We can't be this smart (yet) since the deployment step transforms from the 
+        // original POM once again and re-installs over the top of the install step.
+//        else if ( metadata == null || metadata.isVersionExpressionsResolved() )
+//        {
+//            return;
+//        }
+        else if ( metadata != null )
+        {
+            pomFile = metadata.getFile();
+        }
+        else
+        {
+            return;
+        }
+
+        try
+        {
+            File outFile = transformVersions( pomFile, artifact, localRepository );
+            
+            if ( pomArtifact )
+            {
+                // FIXME: We need a way to mark a POM artifact as resolved WRT version expressions, so we don't reprocess...
+                artifact.setFile( outFile );
+            }
+            else
+            {
+                metadata.setFile( outFile );
+                metadata.setVersionExpressionsResolved( true );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new ArtifactDeploymentException( "Failed to read or write POM for version transformation.", e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new ArtifactDeploymentException(
+                                                   "Failed to parse POM for version transformation. Error was in file: "
+                                                       + pomFile + ", at line: " + e.getLineNumber() + ", column: "
+                                                       + e.getColumnNumber(), e );
+        }
+        catch ( ModelInterpolationException e )
+        {
+            throw new ArtifactDeploymentException( "Failed to interpolate POM versions.", e );
+        }
+    }
+
+    public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
+        throws ArtifactInstallationException
+    {
+        ProjectArtifactMetadata metadata = (ProjectArtifactMetadata) artifact.getMetadata( ProjectArtifactMetadata.class );
+        File pomFile;
+        boolean pomArtifact = false;
+        if ( "pom".equals( artifact.getType() ) )
+        {
+            System.out.println( "On Install: Using artifact file for POM: " + artifact );
+            pomFile = artifact.getFile();
+            pomArtifact = true;
+        }
+        // FIXME: We can't be this smart (yet) since the deployment step transforms from the 
+        // original POM once again and re-installs over the top of the install step.
+//        else if ( metadata == null || metadata.isVersionExpressionsResolved() )
+//        {
+//            return;
+//        }
+        else if ( metadata != null )
+        {
+            pomFile = metadata.getFile();
+        }
+        else
+        {
+            return;
+        }
+
+        try
+        {
+            File outFile = transformVersions( pomFile, artifact, localRepository );
+            
+            if ( pomArtifact )
+            {
+                // FIXME: We need a way to mark a POM artifact as resolved WRT version expressions, so we don't reprocess...
+                artifact.setFile( outFile );
+            }
+            else
+            {
+                metadata.setFile( outFile );
+                metadata.setVersionExpressionsResolved( true );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new ArtifactInstallationException( "Failed to read or write POM for version transformation.", e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new ArtifactInstallationException(
+                                                     "Failed to parse POM for version transformation. Error was in file: "
+                                                         + pomFile + ", at line: " + e.getLineNumber() + ", column: "
+                                                         + e.getColumnNumber(), e );
+        }
+        catch ( ModelInterpolationException e )
+        {
+            throw new ArtifactInstallationException( "Failed to interpolate POM versions.", e );
+        }
+    }
+
+    public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
+        throws ArtifactResolutionException, ArtifactNotFoundException
+    {
+        return;
+    }
+
+    protected File transformVersions( File pomFile, Artifact artifact, ArtifactRepository localRepository )
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        ProjectBuilderConfiguration pbConfig;
+        File projectDir;
+        File outputFile;
+        if ( artifact instanceof ArtifactWithProject )
+        {
+            MavenProject project = ( (ArtifactWithProject) artifact ).getProject();
+
+            projectDir = project.getBasedir();
+            pbConfig = project.getProjectBuilderConfiguration();
+            outputFile = new File( project.getBuild().getDirectory(), "pom-transformed.xml" );
+        }
+        else
+        {
+            getLogger().info(
+                              "Artifact: " + artifact
+                                  + " does not have project-builder metadata (ProjectBuilderConfiguration) associated with it.\n"
+                                  + "Cannot access CLI properties for version transformation." );
+            
+            pbConfig = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
+            projectDir = pomFile.getAbsoluteFile().getParentFile();
+            outputFile = new File( projectDir, "target/pom-transformed.xml" );
+        }
+
+        Reader reader = null;
+        Model model;
+        try
+        {
+            reader = new FileReader( pomFile );
+            model = new MavenXpp3Reader().read( reader );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+        
+        interpolateVersions( model, projectDir, pbConfig );
+        
+        Writer writer = null;
+        try
+        {
+            outputFile.getParentFile().mkdirs();
+            
+            writer = new FileWriter( outputFile );
+            
+            new MavenXpp3Writer().write( writer, model );
+        }
+        finally
+        {
+            IOUtil.close( writer );
+        }
+        
+        return outputFile;
+    }
+
+    protected void interpolateVersions( Model model, File projectDir, ProjectBuilderConfiguration config )
+        throws ModelInterpolationException
+    {
+        boolean debugEnabled = getLogger().isDebugEnabled();
+
+        Interpolator interpolator = getInterpolator();
+
+        List valueSources = createValueSources( model, projectDir, config );
+        List postProcessors = createPostProcessors( model, projectDir, config );
+
+        synchronized ( this )
+        {
+            for ( Iterator it = valueSources.iterator(); it.hasNext(); )
+            {
+                ValueSource vs = (ValueSource) it.next();
+                interpolator.addValueSource( vs );
+            }
+
+            for ( Iterator it = postProcessors.iterator(); it.hasNext(); )
+            {
+                InterpolationPostProcessor postProcessor = (InterpolationPostProcessor) it.next();
+
+                interpolator.addPostProcessor( postProcessor );
+            }
+
+            try
+            {
+                FieldBasedObjectInterpolator objInterpolator =
+                    new FieldBasedObjectInterpolator( BLACKLISTED_FIELD_NAMES,
+                                                      FieldBasedObjectInterpolator.DEFAULT_BLACKLISTED_PACKAGE_PREFIXES );
+
+                try
+                {
+                    objInterpolator.interpolate( model, getInterpolator(), getRecursionInterceptor() );
+                }
+                catch ( InterpolationException e )
+                {
+                    throw new ModelInterpolationException( e.getMessage(), e );
+                }
+
+                if ( debugEnabled )
+                {
+                    List feedback = new ArrayList();
+                    if ( objInterpolator.hasWarnings() )
+                    {
+                        feedback.addAll( objInterpolator.getWarnings() );
+                    }
+
+                    List internalFeedback = interpolator.getFeedback();
+                    if ( internalFeedback != null && !internalFeedback.isEmpty() )
+                    {
+                        feedback.addAll( internalFeedback );
+                    }
+
+                    if ( feedback != null && !feedback.isEmpty() )
+                    {
+                        getLogger().debug( "Maven encountered the following problems while transforming POM versions:" );
+
+                        Object last = null;
+                        for ( Iterator it = feedback.iterator(); it.hasNext(); )
+                        {
+                            Object next = it.next();
+
+                            if ( next instanceof Throwable )
+                            {
+                                if ( last == null )
+                                {
+                                    getLogger().debug( "", ( (Throwable) next ) );
+                                }
+                                else
+                                {
+                                    getLogger().debug( String.valueOf( last ), ( (Throwable) next ) );
+                                }
+                            }
+                            else
+                            {
+                                if ( last != null )
+                                {
+                                    getLogger().debug( String.valueOf( last ) );
+                                }
+
+                                last = next;
+                            }
+                        }
+
+                        if ( last != null )
+                        {
+                            getLogger().debug( String.valueOf( last ) );
+                        }
+                    }
+                }
+
+                interpolator.clearFeedback();
+            }
+            finally
+            {
+                for ( Iterator iterator = valueSources.iterator(); iterator.hasNext(); )
+                {
+                    ValueSource vs = (ValueSource) iterator.next();
+                    interpolator.removeValuesSource( vs );
+                }
+
+                for ( Iterator iterator = postProcessors.iterator(); iterator.hasNext(); )
+                {
+                    InterpolationPostProcessor postProcessor = (InterpolationPostProcessor) iterator.next();
+                    interpolator.removePostProcessor( postProcessor );
+                }
+
+                getInterpolator().clearAnswers();
+            }
+        }
+
+        // if ( error != null )
+        // {
+        // throw error;
+        // }
+    }
+
+    public void initialize()
+        throws InitializationException
+    {
+        super.initialize();
+        
+        synchronized ( VersionExpressionTransformation.class )
+        {
+            if ( BLACKLISTED_FIELD_NAMES == null )
+            {
+                Set fieldNames = new HashSet();
+
+                Class[] classes = { Model.class, Dependency.class, Plugin.class, ReportPlugin.class };
+                for ( int i = 0; i < classes.length; i++ )
+                {
+                    Field[] fields = classes[i].getDeclaredFields();
+                    for ( int j = 0; j < fields.length; j++ )
+                    {
+                        if ( !WHITELISTED_FIELD_NAMES.contains( fields[j].getName() ) )
+                        {
+                            fieldNames.add( fields[j].getName() );
+                        }
+                    }
+                }
+
+                BLACKLISTED_FIELD_NAMES = fieldNames;
+            }
+        }
+    }
+
+}

Propchange: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/artifact/VersionExpressionTransformation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java Thu Feb 19 18:39:09 2009
@@ -378,9 +378,19 @@
         return result;
     }
     
+    protected RecursionInterceptor getRecursionInterceptor()
+    {
+        return recursionInterceptor;
+    }
+
+    protected void setRecursionInterceptor( RecursionInterceptor recursionInterceptor )
+    {
+        this.recursionInterceptor = recursionInterceptor;
+    }
+
     protected abstract Interpolator createInterpolator();
 
-    public final void initialize()
+    public void initialize()
         throws InitializationException
     {
         interpolator = createInterpolator();

Modified: maven/components/branches/maven-2.1.x/maven-project/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/resources/META-INF/plexus/components.xml?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/main/resources/META-INF/plexus/components.xml Thu Feb 19 18:39:09 2009
@@ -19,6 +19,16 @@
 
 <component-set>
   <components>
+    <component>
+      <role>org.apache.maven.project.artifact.ProjectArtifactFactory</role>
+      <role-hint>maven-project</role-hint>
+      <implementation>org.apache.maven.project.artifact.ProjectArtifactFactory</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
+        </requirement>
+      </requirements>
+    </component>
 <!--
      |
      |
@@ -39,6 +49,21 @@
      |
      -->
     <component>
+      <role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
+      <role-hint>version-expression</role-hint>
+      <implementation>org.apache.maven.project.artifact.VersionExpressionTransformation</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.project.path.PathTranslator</role>
+        </requirement>
+      </requirements>
+    </component>
+<!--
+     |
+     |
+     |
+     -->
+    <component>
       <role>org.apache.maven.project.interpolation.ModelInterpolator</role>
       <implementation>org.apache.maven.project.interpolation.StringSearchModelInterpolator</implementation>
       <requirements>
@@ -96,7 +121,8 @@
           <role>org.apache.maven.project.path.PathTranslator</role>
         </requirement>
         <requirement>
-          <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+          <role>org.apache.maven.project.artifact.ProjectArtifactFactory</role>
+	      <role-hint>maven-project</role-hint>
         </requirement>
         <requirement>
           <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>

Added: maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java?rev=745955&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java (added)
+++ maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java Thu Feb 19 18:39:09 2009
@@ -0,0 +1,661 @@
+package org.apache.maven.project.artifact;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.transform.ArtifactTransformation;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
+import org.apache.maven.model.Scm;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.project.DefaultProjectBuilderConfiguration;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.project.interpolation.ModelInterpolationException;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Properties;
+
+public class VersionExpressionTransformationTest
+    extends PlexusTestCase
+{
+
+    private static final String VERSION = "blah";
+
+    private VersionExpressionTransformation transformation;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        transformation =
+            (VersionExpressionTransformation) lookup( ArtifactTransformation.class.getName(), "version-expression" );
+    }
+
+    public void testTransformForResolve_DoNothing()
+        throws IOException, XmlPullParserException, ArtifactResolutionException, ArtifactNotFoundException
+    {
+        Model model = buildTestModel();
+
+        File pomDir = File.createTempFile( "VersionExpressionTransformationTest.", ".tmp.dir" );
+        pomDir.delete();
+        pomDir.mkdirs();
+        try
+        {
+            File pomFile = new File( pomDir, "pom.xml" );
+            pomFile.deleteOnExit();
+
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( pomFile );
+                new MavenXpp3Writer().write( writer, model );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+
+            Artifact a =
+                new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null,
+                                     new DefaultArtifactHandler( "jar" ), false );
+            ProjectArtifactMetadata pam = new ProjectArtifactMetadata( a, pomFile );
+
+            a.addMetadata( pam );
+
+            transformation.transformForResolve( a, Collections.EMPTY_LIST, null );
+
+            assertFalse( pam.isVersionExpressionsResolved() );
+            assertEquals( pomFile, pam.getFile() );
+
+            assertFalse( new File( pomDir, "target/pom-transformed.xml" ).exists() );
+
+            FileReader reader = null;
+            try
+            {
+                reader = new FileReader( pomFile );
+                model = new MavenXpp3Reader().read( reader );
+            }
+            finally
+            {
+                IOUtil.close( reader );
+            }
+
+            assertEquals( "${testVersion}", model.getVersion() );
+        }
+        finally
+        {
+            FileUtils.forceDelete( pomDir );
+        }
+    }
+
+    public void testTransformForInstall_TransformBasedOnModelProperties()
+        throws IOException, ArtifactInstallationException, XmlPullParserException
+    {
+        Model model = buildTestModel();
+
+        File pomDir = File.createTempFile( "VersionExpressionTransformationTest.", ".tmp.dir" );
+        pomDir.delete();
+        pomDir.mkdirs();
+        try
+        {
+            File pomFile = new File( pomDir, "pom.xml" );
+            pomFile.deleteOnExit();
+
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( pomFile );
+                new MavenXpp3Writer().write( writer, model );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+
+            Artifact a =
+                new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null,
+                                     new DefaultArtifactHandler( "jar" ), false );
+
+            ProjectArtifactMetadata pam = new ProjectArtifactMetadata( a, pomFile );
+
+            a.addMetadata( pam );
+
+            transformation.transformForInstall( a, null );
+
+            File transformedFile = new File( pomDir, "target/pom-transformed.xml" );
+
+            assertTrue( transformedFile.exists() );
+            assertEquals( transformedFile, pam.getFile() );
+
+            FileReader reader = null;
+            try
+            {
+                reader = new FileReader( pam.getFile() );
+                model = new MavenXpp3Reader().read( reader );
+            }
+            finally
+            {
+                IOUtil.close( reader );
+            }
+
+            assertTransformedVersions( model );
+        }
+        finally
+        {
+            FileUtils.forceDelete( pomDir );
+        }
+    }
+
+    public void testTransformForDeploy_TransformBasedOnModelProperties()
+        throws IOException, XmlPullParserException, ArtifactDeploymentException
+    {
+        Model model = buildTestModel();
+
+        File pomDir = File.createTempFile( "VersionExpressionTransformationTest.", ".tmp.dir" );
+        pomDir.delete();
+        pomDir.mkdirs();
+        try
+        {
+            File pomFile = new File( pomDir, "pom.xml" );
+            pomFile.deleteOnExit();
+
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( pomFile );
+                new MavenXpp3Writer().write( writer, model );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+
+            Artifact a =
+                new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null,
+                                     new DefaultArtifactHandler( "jar" ), false );
+
+            ProjectArtifactMetadata pam = new ProjectArtifactMetadata( a, pomFile );
+
+            a.addMetadata( pam );
+
+            transformation.transformForDeployment( a, null, null );
+
+            File transformedFile = new File( pomDir, "target/pom-transformed.xml" );
+
+            assertTrue( transformedFile.exists() );
+            assertEquals( transformedFile, pam.getFile() );
+
+            FileReader reader = null;
+            try
+            {
+                reader = new FileReader( pam.getFile() );
+                model = new MavenXpp3Reader().read( reader );
+            }
+            finally
+            {
+                IOUtil.close( reader );
+            }
+
+            assertTransformedVersions( model );
+        }
+        finally
+        {
+            FileUtils.forceDelete( pomDir );
+        }
+    }
+
+    // FIXME: We can't be this smart (yet) since the deployment step transforms from the 
+    // original POM once again and re-installs over the top of the install step.
+//    public void testTransformForInstall_SkipIfProjectArtifactMetadataResolvedFlagIsSet()
+//        throws IOException, ArtifactInstallationException, XmlPullParserException
+//    {
+//        Model model = buildTestModel();
+//
+//        File pomDir = File.createTempFile( "VersionExpressionTransformationTest.", ".tmp.dir" );
+//        pomDir.delete();
+//        pomDir.mkdirs();
+//        try
+//        {
+//            File pomFile = new File( pomDir, "pom.xml" );
+//            pomFile.deleteOnExit();
+//
+//            FileWriter writer = null;
+//            try
+//            {
+//                writer = new FileWriter( pomFile );
+//                new MavenXpp3Writer().write( writer, model );
+//            }
+//            finally
+//            {
+//                IOUtil.close( writer );
+//            }
+//
+//            Artifact a =
+//                new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null,
+//                                     new DefaultArtifactHandler( "jar" ), false );
+//            ProjectArtifactMetadata pam = new ProjectArtifactMetadata( a, pomFile );
+//            pam.setVersionExpressionsResolved( true );
+//
+//            a.addMetadata( pam );
+//
+//            transformation.transformForInstall( a, null );
+//
+//            assertEquals( pomFile, pam.getFile() );
+//
+//            assertFalse( new File( pomDir, "target/pom-transformed.xml" ).exists() );
+//
+//            FileReader reader = null;
+//            try
+//            {
+//                reader = new FileReader( pomFile );
+//                model = new MavenXpp3Reader().read( reader );
+//            }
+//            finally
+//            {
+//                IOUtil.close( reader );
+//            }
+//
+//            assertEquals( "${testVersion}", model.getVersion() );
+//        }
+//        finally
+//        {
+//            FileUtils.forceDelete( pomDir );
+//        }
+//    }
+
+    // FIXME: We can't be this smart (yet) since the deployment step transforms from the 
+    // original POM once again and re-installs over the top of the install step.
+//    public void testTransformForDeploy_SkipIfProjectArtifactMetadataResolvedFlagIsSet()
+//        throws IOException, XmlPullParserException, ArtifactDeploymentException
+//    {
+//        Model model = buildTestModel();
+//
+//        File pomDir = File.createTempFile( "VersionExpressionTransformationTest.", ".tmp.dir" );
+//        pomDir.delete();
+//        pomDir.mkdirs();
+//        try
+//        {
+//            File pomFile = new File( pomDir, "pom.xml" );
+//            pomFile.deleteOnExit();
+//
+//            FileWriter writer = null;
+//            try
+//            {
+//                writer = new FileWriter( pomFile );
+//                new MavenXpp3Writer().write( writer, model );
+//            }
+//            finally
+//            {
+//                IOUtil.close( writer );
+//            }
+//
+//            Artifact a =
+//                new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar", null,
+//                                     new DefaultArtifactHandler( "jar" ), false );
+//            ProjectArtifactMetadata pam = new ProjectArtifactMetadata( a, pomFile );
+//            pam.setVersionExpressionsResolved( true );
+//
+//            a.addMetadata( pam );
+//
+//            transformation.transformForDeployment( a, null, null );
+//
+//            assertEquals( pomFile, pam.getFile() );
+//
+//            assertFalse( new File( pomDir, "target/pom-transformed.xml" ).exists() );
+//
+//            FileReader reader = null;
+//            try
+//            {
+//                reader = new FileReader( pomFile );
+//                model = new MavenXpp3Reader().read( reader );
+//            }
+//            finally
+//            {
+//                IOUtil.close( reader );
+//            }
+//
+//            assertEquals( "${testVersion}", model.getVersion() );
+//        }
+//        finally
+//        {
+//            FileUtils.forceDelete( pomDir );
+//        }
+//    }
+
+    public void testTransformVersion_ShouldInterpolate_VanillaArtifact_ModelProperties()
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        Model model = buildTestModel();
+
+        model = runTransformVersion_VanillaArtifact( model );
+
+        assertTransformedVersions( model );
+    }
+
+    public void testTransformVersion_ShouldInterpolate_ArtifactWithProject_ModelProperties()
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        Model model = buildTestModel();
+
+        model = runTransformVersion_ArtifactWithProject( model, new DefaultProjectBuilderConfiguration() );
+
+        assertTransformedVersions( model );
+    }
+
+    public void testTransformVersion_ShouldInterpolate_ArtifactWithProject_CLIProperties()
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        Model model = buildTestModel();
+
+        Properties props = model.getProperties();
+        model.setProperties( new Properties() );
+
+        model =
+            runTransformVersion_ArtifactWithProject(
+                                                     model,
+                                                     new DefaultProjectBuilderConfiguration().setExecutionProperties( props ) );
+
+        assertTransformedVersions( model );
+    }
+
+    private Model runTransformVersion_VanillaArtifact( Model model )
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        File projectDir = File.createTempFile( "VersionExpressionTransformationTest.project.", ".tmp.dir" );
+        projectDir.delete();
+        projectDir.mkdirs();
+
+        File repoDir = File.createTempFile( "VersionExpressionTransformationTest.repo.", ".tmp.dir" );
+        repoDir.delete();
+        repoDir.mkdirs();
+
+        try
+        {
+            File pomFile = new File( projectDir, "pom.xml" );
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( pomFile );
+                new MavenXpp3Writer().write( writer, model );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+
+            model.getBuild().setOutputDirectory( new File( projectDir, "target" ).getAbsolutePath() );
+
+            Artifact a =
+                new DefaultArtifact( model.getGroupId(), model.getArtifactId(), VersionRange.createFromVersion( "1" ),
+                                     null, "jar", null, new DefaultArtifactHandler( "jar" ) );
+
+            ArtifactRepository localRepository =
+                new DefaultArtifactRepository( "local", repoDir.getAbsolutePath(), new DefaultRepositoryLayout() );
+
+            transformation.transformVersions( pomFile, a, localRepository );
+
+            FileReader reader = null;
+            try
+            {
+                reader = new FileReader( new File( projectDir, "target/pom-transformed.xml" ) );
+
+                model = new MavenXpp3Reader().read( reader );
+            }
+            finally
+            {
+                IOUtil.close( reader );
+            }
+        }
+        finally
+        {
+            FileUtils.forceDelete( projectDir );
+            FileUtils.forceDelete( repoDir );
+        }
+
+        return model;
+    }
+
+    private Model runTransformVersion_ArtifactWithProject( Model model, ProjectBuilderConfiguration pbConfig )
+        throws IOException, XmlPullParserException, ModelInterpolationException
+    {
+        File projectDir = File.createTempFile( "VersionExpressionTransformationTest.project.", ".tmp.dir" );
+        projectDir.delete();
+        projectDir.mkdirs();
+
+        File repoDir = File.createTempFile( "VersionExpressionTransformationTest.repo.", ".tmp.dir" );
+        repoDir.delete();
+        repoDir.mkdirs();
+
+        try
+        {
+            File pomFile = new File( projectDir, "pom.xml" );
+            FileWriter writer = null;
+            try
+            {
+                writer = new FileWriter( pomFile );
+                new MavenXpp3Writer().write( writer, model );
+            }
+            finally
+            {
+                IOUtil.close( writer );
+            }
+
+            model.getBuild().setDirectory( new File( projectDir, "target" ).getAbsolutePath() );
+
+            MavenProject project = new MavenProject( model );
+            project.setFile( pomFile );
+            project.setBasedir( projectDir );
+            project.setProjectBuilderConfiguration( pbConfig );
+
+            ArtifactWithProject a =
+                new ArtifactWithProject( project, "jar", null, new DefaultArtifactHandler( "jar" ), false );
+
+            ArtifactRepository localRepository =
+                new DefaultArtifactRepository( "local", repoDir.getAbsolutePath(), new DefaultRepositoryLayout() );
+
+            transformation.transformVersions( pomFile, a, localRepository );
+
+            FileReader reader = null;
+            try
+            {
+                reader = new FileReader( new File( project.getBuild().getDirectory(), "pom-transformed.xml" ) );
+
+                model = new MavenXpp3Reader().read( reader );
+            }
+            finally
+            {
+                IOUtil.close( reader );
+            }
+        }
+        finally
+        {
+            FileUtils.forceDelete( projectDir );
+            FileUtils.forceDelete( repoDir );
+        }
+
+        return model;
+    }
+
+    public void testInterpolate_ShouldNotInterpolateNonVersionFields()
+        throws ModelInterpolationException
+    {
+        Model model = buildTestModel();
+
+        Scm scm = new Scm();
+        scm.setUrl( "http://${testVersion}" );
+
+        model.setScm( scm );
+
+        File projectDir = new File( "." ).getAbsoluteFile();
+
+        transformation.interpolateVersions( model, projectDir, new DefaultProjectBuilderConfiguration() );
+
+        // /project/scm/url
+        assertFalse( model.getScm().getUrl().indexOf( VERSION ) > -1 );
+    }
+
+    public void testInterpolate_ShouldInterpolateAllVersionsUsingPOMProperties()
+        throws ModelInterpolationException
+    {
+        Model model = buildTestModel();
+        File projectDir = new File( "." ).getAbsoluteFile();
+
+        transformation.interpolateVersions( model, projectDir, new DefaultProjectBuilderConfiguration() );
+
+        assertTransformedVersions( model );
+    }
+
+    private void assertTransformedVersions( Model model )
+    {
+        // /project/version
+        assertEquals( VERSION, model.getVersion() );
+
+        // /project/dependenices/dependency/version
+        Dependency dep = (Dependency) model.getDependencies().get( 0 );
+        assertEquals( VERSION, dep.getVersion() );
+
+        // /project/dependencyManagement/dependenices/dependency/version
+        dep = (Dependency) model.getDependencyManagement().getDependencies().get( 0 );
+        assertEquals( VERSION, dep.getVersion() );
+
+        // /project/build/plugins/plugin/version
+        Plugin plugin = (Plugin) model.getBuild().getPlugins().get( 0 );
+        assertEquals( VERSION, plugin.getVersion() );
+
+        // /project/build/plugins/plugin/dependencies/dependency/version
+        dep = (Dependency) plugin.getDependencies().get( 0 );
+        assertEquals( VERSION, dep.getVersion() );
+
+        // /project/build/pluginManagement/plugins/plugin/version
+        plugin = (Plugin) model.getBuild().getPluginManagement().getPlugins().get( 0 );
+        assertEquals( VERSION, plugin.getVersion() );
+
+        // /project/build/pluginManagement/plugins/plugin/dependencies/dependency/version
+        dep = (Dependency) plugin.getDependencies().get( 0 );
+        assertEquals( VERSION, dep.getVersion() );
+
+        // /project/reporting/plugins/plugin/version
+        ReportPlugin rplugin = (ReportPlugin) model.getReporting().getPlugins().get( 0 );
+        assertEquals( VERSION, rplugin.getVersion() );
+    }
+
+    public void testInterpolate_ShouldInterpolateAllVersionsUsingCLIProperties()
+        throws ModelInterpolationException
+    {
+        Model model = buildTestModel();
+        File projectDir = new File( "." ).getAbsoluteFile();
+
+        Properties props = model.getProperties();
+        model.setProperties( new Properties() );
+
+        transformation.interpolateVersions( model, projectDir,
+                                            new DefaultProjectBuilderConfiguration().setExecutionProperties( props ) );
+
+        assertTransformedVersions( model );
+    }
+
+    public Model buildTestModel()
+    {
+        Model model = new Model();
+
+        model.setGroupId( "group.id" );
+        model.setArtifactId( "artifact-id" );
+        model.setPackaging( "jar" );
+
+        String expression = "${testVersion}";
+
+        Properties props = new Properties();
+        props.setProperty( "testVersion", VERSION );
+
+        model.setProperties( props );
+
+        model.setVersion( expression );
+
+        Dependency dep = new Dependency();
+        dep.setGroupId( "group.id" );
+        dep.setArtifactId( "artifact-id" );
+        dep.setVersion( expression );
+
+        model.addDependency( dep );
+
+        dep = new Dependency();
+        dep.setGroupId( "managed.group.id" );
+        dep.setArtifactId( "managed-artifact-id" );
+        dep.setVersion( expression );
+
+        DependencyManagement dmgmt = new DependencyManagement();
+        dmgmt.addDependency( dep );
+
+        model.setDependencyManagement( dmgmt );
+
+        Build build = new Build();
+        model.setBuild( build );
+
+        Plugin plugin = new Plugin();
+        plugin.setGroupId( "plugin.group" );
+        plugin.setArtifactId( "plugin-artifact" );
+        plugin.setVersion( expression );
+
+        dep = new Dependency();
+        dep.setGroupId( "plugin.dep.group" );
+        dep.setArtifactId( "plugin-dep-artifact" );
+        dep.setVersion( expression );
+        plugin.addDependency( dep );
+
+        build.addPlugin( plugin );
+
+        plugin = new Plugin();
+        plugin.setGroupId( "plugin.other.group" );
+        plugin.setArtifactId( "plugin-other-artifact" );
+        plugin.setVersion( expression );
+
+        dep = new Dependency();
+        dep.setGroupId( "plugin.dep.other.group" );
+        dep.setArtifactId( "plugin-dep-other-artifact" );
+        dep.setVersion( expression );
+        plugin.addDependency( dep );
+
+        PluginManagement pmgmt = new PluginManagement();
+        pmgmt.addPlugin( plugin );
+
+        build.setPluginManagement( pmgmt );
+
+        ReportPlugin rplugin = new ReportPlugin();
+        rplugin.setGroupId( "report.group" );
+        rplugin.setArtifactId( "report-artifact" );
+        rplugin.setVersion( expression );
+
+        Reporting reporting = new Reporting();
+        reporting.addPlugin( rplugin );
+
+        model.setReporting( reporting );
+
+        return model;
+    }
+
+}

Propchange: maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/project/artifact/VersionExpressionTransformationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml Thu Feb 19 18:39:09 2009
@@ -84,7 +84,8 @@
           <role>org.apache.maven.project.path.PathTranslator</role>
         </requirement>
         <requirement>
-          <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+          <role>org.apache.maven.project.artifact.ProjectArtifactFactory</role>
+          <role-hint>maven-project</role-hint>
         </requirement>
         <requirement>
           <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>

Modified: maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml Thu Feb 19 18:39:09 2009
@@ -84,7 +84,8 @@
           <role>org.apache.maven.project.path.PathTranslator</role>
         </requirement>
         <requirement>
-          <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+          <role>org.apache.maven.project.artifact.ProjectArtifactFactory</role>
+          <role-hint>maven-project</role-hint>
         </requirement>
         <requirement>
           <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>

Modified: maven/components/branches/maven-2.1.x/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/pom.xml?rev=745955&r1=745954&r2=745955&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/pom.xml (original)
+++ maven/components/branches/maven-2.1.x/pom.xml Thu Feb 19 18:39:09 2009
@@ -384,7 +384,7 @@
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-interpolation</artifactId>
-        <version>1.5</version>
+        <version>1.7</version>
       </dependency>
       <dependency>
         <groupId>org.codehaus.plexus</groupId>



Re: svn commit: r745955

Posted by Brett Porter <br...@apache.org>.
Sorry John, I sent a response before I went to sleep but when I came  
back found it hadn't gone through. The solution you put in place was  
right, it needs to set it regardless. I see you updated the IT too.

Thanks!

- Brett

On 25/02/2009, at 1:22 AM, John Casey wrote:

> I'm still hopeful that I can get the rewriting problems fixed.
>
> I don't really understand the details of what you're saying here,  
> though. If the artifact has no file, and it's packaging == "pom",  
> why is it a bad idea to set the POM as the artifact's file?
>
> I'll read up on that MCOMPILER issue today, I don't have time right  
> this moment, but if you could distill the issue WRT  
> Artifact.setFile() it might save me an hour or so...
>
> -john
>

--
Brett Porter
brett@apache.org
http://blogs.exist.com/bporter/


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


Re: svn commit: r745955

Posted by John Casey <jd...@commonjava.org>.
I'm still hopeful that I can get the rewriting problems fixed.

I don't really understand the details of what you're saying here, 
though. If the artifact has no file, and it's packaging == "pom", why is 
it a bad idea to set the POM as the artifact's file?

I'll read up on that MCOMPILER issue today, I don't have time right this 
moment, but if you could distill the issue WRT Artifact.setFile() it 
might save me an hour or so...

-john

Brett Porter wrote:
> Hi John,
> 
> I found another problem here:
> 
> On 20/02/2009, at 5:39 AM, jdcasey@apache.org wrote:
> 
>> Author: jdcasey
>> Date: Thu Feb 19 18:39:09 2009
>> New Revision: 745955
>>
>> URL: http://svn.apache.org/viewvc?rev=745955&view=rev
>> Log:
>> [MNG-3057] Interpolate versions in POMs before installing/deploying 
>> them. Leave other expressions alone.
>>
> [snip]
>>
>> Modified: 
>> maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java 
>>
>> URL: 
>> http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java?rev=745955&r1=745954&r2=745955&view=diff 
>>
>> ============================================================================== 
>>
>> --- 
>> maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java 
>> (original)
>> +++ 
>> maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java 
>> Thu Feb 19 18:39:09 2009
>> @@ -55,9 +55,36 @@
>>     public void install( File source, Artifact artifact, 
>> ArtifactRepository localRepository )
>>         throws ArtifactInstallationException
>>     {
>> +
>> +        // If we're installing the POM, we need to transform it 
>> first. The source file supplied for
>> +        // installation here may be the POM, but that POM may not be 
>> set as the file of the supplied
>> +        // artifact. Since the transformation only has access to the 
>> artifact and not the supplied
>> +        // source file, we have to use the Artifact.setFile(..) and 
>> Artifact.getFile(..) methods
>> +        // to shunt the POM file into the transformation process.
>> +        // Here, we also set a flag indicating that the POM has been 
>> shunted through the Artifact,
>> +        // and to expect the transformed version to be available in 
>> the Artifact afterwards...
>> +        boolean useArtifactFile = false;
>> +        if ( "pom".equals( artifact.getType() ) )
>> +        {
>> +            if ( artifact.getFile() == null )
>> +            {
>> +                artifact.setFile( source );
>> +            }
>> +
>> +            useArtifactFile = true;
>> +        }
>> +
> 
> This part of the change is tripping up projects that suffer from a 
> different bug I found: MCOMPILER-94. Take a look at the POM sample in 
> there - a project with something like that will succeed in 2.1.0-M1 and 
> fail in 2.1.0-SNAPSHOT. I think you would need to remove the 
> artifact.getFile() == null check to avoid it.
> 
> Even though this is really a bug in the compiler plugin, do you think we 
> should preserve behavior for plugins that abuse setFile for a POM by 
> adding an integration test, or should we just mandate a compiler plugin 
> upgrade for anyone that trips this (and get a release out)?
> 
> Or given the rewriting problems are you reconsidering this fix for 2.1.0?
> 
> Cheers,
> Brett
> 
> -- 
> Brett Porter
> brett@apache.org
> http://blogs.exist.com/bporter/
> 
> 
> ---------------------------------------------------------------------
> 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: r745955

Posted by Brett Porter <br...@apache.org>.
Hi John,

I found another problem here:

On 20/02/2009, at 5:39 AM, jdcasey@apache.org wrote:

> Author: jdcasey
> Date: Thu Feb 19 18:39:09 2009
> New Revision: 745955
>
> URL: http://svn.apache.org/viewvc?rev=745955&view=rev
> Log:
> [MNG-3057] Interpolate versions in POMs before installing/deploying  
> them. Leave other expressions alone.
>
[snip]
>
> Modified: maven/components/branches/maven-2.1.x/maven-artifact- 
> manager/src/main/java/org/apache/maven/artifact/installer/ 
> DefaultArtifactInstaller.java
> URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java?rev=745955&r1=745954&r2=745955&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/ 
> main/java/org/apache/maven/artifact/installer/ 
> DefaultArtifactInstaller.java (original)
> +++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/ 
> main/java/org/apache/maven/artifact/installer/ 
> DefaultArtifactInstaller.java Thu Feb 19 18:39:09 2009
> @@ -55,9 +55,36 @@
>     public void install( File source, Artifact artifact,  
> ArtifactRepository localRepository )
>         throws ArtifactInstallationException
>     {
> +
> +        // If we're installing the POM, we need to transform it  
> first. The source file supplied for
> +        // installation here may be the POM, but that POM may not  
> be set as the file of the supplied
> +        // artifact. Since the transformation only has access to  
> the artifact and not the supplied
> +        // source file, we have to use the Artifact.setFile(..) and  
> Artifact.getFile(..) methods
> +        // to shunt the POM file into the transformation process.
> +        // Here, we also set a flag indicating that the POM has  
> been shunted through the Artifact,
> +        // and to expect the transformed version to be available in  
> the Artifact afterwards...
> +        boolean useArtifactFile = false;
> +        if ( "pom".equals( artifact.getType() ) )
> +        {
> +            if ( artifact.getFile() == null )
> +            {
> +                artifact.setFile( source );
> +            }
> +
> +            useArtifactFile = true;
> +        }
> +

This part of the change is tripping up projects that suffer from a  
different bug I found: MCOMPILER-94. Take a look at the POM sample in  
there - a project with something like that will succeed in 2.1.0-M1  
and fail in 2.1.0-SNAPSHOT. I think you would need to remove the  
artifact.getFile() == null check to avoid it.

Even though this is really a bug in the compiler plugin, do you think  
we should preserve behavior for plugins that abuse setFile for a POM  
by adding an integration test, or should we just mandate a compiler  
plugin upgrade for anyone that trips this (and get a release out)?

Or given the rewriting problems are you reconsidering this fix for  
2.1.0?

Cheers,
Brett

--
Brett Porter
brett@apache.org
http://blogs.exist.com/bporter/


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