Author: brett
Date: Thu Jun  2 00:13:57 2005
New Revision: 179539

URL: http://svn.apache.org/viewcvs?rev=179539&view=rev
Log:
PR: MPARTIFACT-49
resolve the POM before deploying

Modified:
    maven/maven-1/plugins/trunk/artifact/project.xml
    
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
    maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml

Modified: maven/maven-1/plugins/trunk/artifact/project.xml
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/project.xml?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/project.xml (original)
+++ maven/maven-1/plugins/trunk/artifact/project.xml Thu Jun  2 00:13:57 2005
@@ -63,68 +63,61 @@
       <tag>MAVEN_ARTIFACT_1_4_1</tag>
     </version>
   </versions>
-  <developers/>
   <dependencies>
     <dependency>
       <groupId>maven</groupId>
       <artifactId>maven</artifactId>
       <version>1.0</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.0-alpha-1</version>
-      <type>jar</type>
+      <version>1.0-alpha-3</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-betwixt</groupId>
+      <artifactId>commons-betwixt</artifactId>
+      <version>0.6</version>
     </dependency>
     <dependency>
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>
       <version>1.1.0</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>2.0</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>2.0</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <version>1.0.3</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>jsch</groupId>
       <artifactId>jsch</artifactId>
       <version>0.1.14</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>commons-jelly</groupId>
       <artifactId>commons-jelly</artifactId>
       <version>1.0-beta-4</version>
-      <url>http://jakarta.apache.org/commons/jelly/</url>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>commons-jelly</groupId>
       <artifactId>commons-jelly-tags-velocity</artifactId>
       <version>1.0</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>velocity</groupId>
       <artifactId>velocity</artifactId>
       <version>1.4</version>
-      <type>jar</type>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
@@ -155,6 +148,11 @@
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-file</artifactId>
       <version>1.0-alpha-3</version>
+    </dependency>
+    <dependency>
+      <groupId>maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>3.0.0-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
 (original)
+++ 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
 Thu Jun  2 00:13:57 2005
@@ -17,11 +17,20 @@
  * ====================================================================
  */
 
+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.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 @@
         File file;
         if ( POM_TYPE.equals( type ) )
         {
-            file = project.getFile();
+            file = getRewrittenPom( project );
         }
         else
         {
@@ -110,12 +125,111 @@
         // 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 @@
         File file;
         if ( POM_TYPE.equals( type ) )
         {
-            file = project.getFile();
+            file = getRewrittenPom( project );
         }
         else
         {
@@ -153,7 +267,7 @@
         // 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 );
         }
     }
 

Modified: maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml?rev=179539&r1=179538&r2=179539&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml (original)
+++ maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml Thu Jun  2 00:13:57 
2005
@@ -26,6 +26,7 @@
   </properties>
   <body>
     <release version="1.5-SNAPSHOT" date="in SVN">
+      <action dev="brett" type="update" issue="MPARTIFACT-49">Wholly resolve 
the POM before deploying</action>
       <action dev="brett" type="update" issue="MPARTIFACT-19">Deploy anything 
with SNAPSHOT in the version as a snapshot</action>
       <action dev="brett" type="update">Deprecated install-snapshot and 
deploy-snapshot goals</action>
       <action dev="brett" type="remove">Remove deprecated old deployment 
method</action>



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

Reply via email to