diff --git a/artifact/project.xml b/artifact/project.xml
index 9ebb0213..608fb397 100644
--- a/artifact/project.xml
+++ b/artifact/project.xml
@@ -63,68 +63,61 @@
MAVEN_ARTIFACT_1_4_1
-
maven
maven
1.0
- jar
plexus
plexus-utils
- 1.0-alpha-1
- jar
+ 1.0-alpha-3
+
+
+ commons-betwixt
+ commons-betwixt
+ 0.6
commons-net
commons-net
1.1.0
- jar
commons-httpclient
commons-httpclient
2.0
- jar
commons-lang
commons-lang
2.0
- jar
commons-logging
commons-logging
1.0.3
- jar
jsch
jsch
0.1.14
- jar
commons-jelly
commons-jelly
1.0-beta-4
- http://jakarta.apache.org/commons/jelly/
- jar
commons-jelly
commons-jelly-tags-velocity
1.0
- jar
velocity
velocity
1.4
- jar
org.apache.maven.wagon
@@ -156,5 +149,10 @@
wagon-file
1.0-alpha-3
+
+ maven
+ maven-model
+ 3.0.0-SNAPSHOT
+
diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
index a5302b7e..2bc059ea 100644
--- a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
+++ b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
@@ -17,11 +17,20 @@ package org.apache.maven.artifact.deployer;
* ====================================================================
*/
+import org.apache.commons.betwixt.XMLIntrospector;
+import org.apache.commons.betwixt.io.BeanWriter;
+import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.MavenConstants;
import org.apache.maven.MavenException;
+import org.apache.maven.MavenUtils;
+import org.apache.maven.jelly.MavenJellyContext;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.Project;
import org.apache.maven.repository.ArtifactTypeHandler;
import org.apache.maven.repository.DefaultArtifactTypeHandler;
@@ -41,8 +50,14 @@ import org.apache.maven.wagon.providers.ssh.SftpWagon;
import org.apache.maven.wagon.providers.sshext.ScpExternalWagon;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
@@ -100,7 +115,7 @@ public class DefaultArtifactDeployer
File file;
if ( POM_TYPE.equals( type ) )
{
- file = project.getFile();
+ file = getRewrittenPom( project );
}
else
{
@@ -110,12 +125,111 @@ public class DefaultArtifactDeployer
// do not deploy POM twice
if ( !POM_TYPE.equals( type ) )
{
- doDeploy( project.getFile(), project, POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
+ doDeploy( getRewrittenPom( project ), project, POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
}
doDeploy( file, project, handler, version, type );
}
+ private static File getRewrittenPom( Project project )
+ throws MavenException
+ {
+ Model model;
+ try
+ {
+ // Very gross, but in Maven 1.0 we can't get access, and we don't want initialize() called
+ // A future version should use use project.getModel() and serialize that
+ Method m = MavenUtils.class.getDeclaredMethod( "getNonJellyProject",
+ new Class[]{File.class, MavenJellyContext.class,
+ boolean.class} );
+ m.setAccessible( true );
+ Project p = (Project) m.invoke( null,
+ new Object[]{project.getFile(), project.getContext(), Boolean.TRUE} );
+ m.setAccessible( false );
+ m = MavenUtils.class.getDeclaredMethod( "getJellyProject", new Class[]{Project.class} );
+ m.setAccessible( true );
+ p = (Project) m.invoke( null, new Object[]{p} );
+ m.setAccessible( false );
+
+ // now sanitize
+ p.setContext( null );
+ p.setParent( null );
+ p.setArtifacts( null );
+ p.setDependencyVerifier( null );
+ p.setExtend( null );
+
+ ByteArrayOutputStream projectStream = new ByteArrayOutputStream();
+
+ BeanWriter beanWriter = new BeanWriter( projectStream );
+ beanWriter.setXMLIntrospector( createXMLIntrospector() );
+
+ beanWriter.enablePrettyPrint();
+ beanWriter.setWriteIDs( false );
+ beanWriter.write( p );
+
+ String asString = projectStream.toString( System.getProperty( "file.encoding" ) );
+
+ MavenXpp3Reader reader = new MavenXpp3Reader();
+ model = reader.read( new StringReader( asString ) );
+ model.setId( null );
+
+ for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
+ {
+ Dependency d = (Dependency) i.next();
+ d.setId( null );
+
+ if ( d.getUrl() != null && d.getUrl().length() == 0 )
+ {
+ d.setUrl( null );
+ }
+
+ if ( d.getType() != null && d.getType().length() == 0 )
+ {
+ d.setType( null );
+ }
+
+ if ( d.getJar() != null && d.getJar().length() == 0 )
+ {
+ d.setJar( null );
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new MavenException( "Error getting the project as a string", e );
+ }
+
+ FileWriter w = null;
+ try
+ {
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ File f = File.createTempFile( "maven-artifact-plugin.", null );
+ f.deleteOnExit();
+ w = new FileWriter( f );
+ writer.write( w, model );
+
+ return f;
+ }
+ catch ( IOException e )
+ {
+ throw new MavenException( "Error getting the project as a string", e );
+ }
+ finally
+ {
+ IOUtil.close( w );
+ }
+ }
+
+ private static XMLIntrospector createXMLIntrospector()
+ {
+ XMLIntrospector introspector = new XMLIntrospector();
+
+ introspector.setAttributesForPrimitives( false );
+ introspector.setElementNameMapper( new DecapitalizeNameMapper() );
+
+ return introspector;
+ }
+
/**
* @see ArtifactDeployer#install(String, String, Project, ArtifactTypeHandler)
*/
@@ -141,7 +255,7 @@ public class DefaultArtifactDeployer
File file;
if ( POM_TYPE.equals( type ) )
{
- file = project.getFile();
+ file = getRewrittenPom( project );
}
else
{
@@ -153,7 +267,7 @@ public class DefaultArtifactDeployer
// do not install twice
if ( !POM_TYPE.equals( type ) )
{
- doInstall( project.getFile(), POM_TYPE, project, version, POM_ARTIFACT_TYPE_HANDLER );
+ doInstall( getRewrittenPom( project ), POM_TYPE, project, version, POM_ARTIFACT_TYPE_HANDLER );
}
}
diff --git a/artifact/xdocs/changes.xml b/artifact/xdocs/changes.xml
index ed0d6ceb..9f707142 100644
--- a/artifact/xdocs/changes.xml
+++ b/artifact/xdocs/changes.xml
@@ -26,6 +26,7 @@
+ Wholly resolve the POM before deploying
Deploy anything with SNAPSHOT in the version as a snapshot
Deprecated install-snapshot and deploy-snapshot goals
Remove deprecated old deployment method