Author: brett
Date: Fri Jun 10 17:29:27 2005
New Revision: 190044

URL: http://svn.apache.org/viewcvs?rev=190044&view=rev
Log:
PR: MPARTIFACT-51
correct POM rewriting for dependency properties, add test
also add other missing dependencies, required in Maven 1.1

Added:
    
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
   (with props)
    maven/maven-1/plugins/trunk/artifact/src/test/
    maven/maven-1/plugins/trunk/artifact/src/test/java/
    maven/maven-1/plugins/trunk/artifact/src/test/java/org/
    maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/
    maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/
    
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/
    
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
   (with props)
    maven/maven-1/plugins/trunk/artifact/src/test/resources/
    
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml 
  (with props)
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=190044&r1=190043&r2=190044&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/project.xml (original)
+++ maven/maven-1/plugins/trunk/artifact/project.xml Fri Jun 10 17:29:27 2005
@@ -18,7 +18,8 @@
  */
  -->
 
-<project>
+<project xmlns="http://maven.apache.org/POM/3.0.0"; 
xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 
http://maven.apache.org/maven-v3_0_0.xsd";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <extend>../plugin-parent/project.xml</extend>
   <pomVersion>3</pomVersion>
   <id>maven-artifact-plugin</id>
@@ -90,6 +91,21 @@
       <version>1.4.1</version>
     </dependency>
     <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils</artifactId>
+      <version>1.6.1</version>
+    </dependency>
+    <dependency>
+      <groupId>dom4j</groupId>
+      <artifactId>dom4j</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>
       <version>1.1.0</version>
@@ -165,4 +181,14 @@
       <version>3.0.0</version>
     </dependency>
   </dependencies>
+  <build>
+    <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
+    <unitTest>
+      <resources>
+        <resource>
+          <directory>src/test/resources</directory>
+        </resource>
+      </resources>
+    </unitTest>
+  </build>
 </project>

Added: 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java?rev=190044&view=auto
==============================================================================
--- 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
 (added)
+++ 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
 Fri Jun 10 17:29:27 2005
@@ -0,0 +1,176 @@
+package org.apache.maven.artifact;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.project.Project;
+import org.apache.maven.MavenException;
+import org.apache.maven.MavenUtils;
+import org.apache.maven.jelly.MavenJellyContext;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.commons.betwixt.io.BeanWriter;
+import org.apache.commons.betwixt.XMLIntrospector;
+import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
+import org.apache.oro.text.perl.Perl5Util;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Rewrite a full model for publishing. Inheritence and expression will have 
been resolved.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ * @version $Id$
+ */
+public class PomRewriter
+{
+    public static File getRewrittenPom( Project project )
+        throws MavenException
+    {
+        Model model = getRewrittenModel( project );
+
+        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 );
+        }
+    }
+
+    static Model getRewrittenModel( 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 );
+
+            Map depProperties = new HashMap();
+            for ( Iterator i = p.getDependencies().iterator(); i.hasNext(); )
+            {
+                org.apache.maven.project.Dependency d = 
(org.apache.maven.project.Dependency) i.next();
+                if ( d.getProperties() != null && !d.getProperties().isEmpty() 
)
+                {
+                    depProperties.put( d.getId(), d.getProperties() );
+                    d.setProperties( 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();
+
+                if ( depProperties.containsKey( d.getId() ) )
+                {
+                    d.getProperties().putAll( (Properties) depProperties.get( 
d.getId() ) );
+                }
+
+                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 );
+        }
+        return model;
+    }
+
+    private static XMLIntrospector createXMLIntrospector()
+    {
+        XMLIntrospector introspector = new XMLIntrospector();
+
+        introspector.setAttributesForPrimitives( false );
+        introspector.setElementNameMapper( new DecapitalizeNameMapper() );
+
+        return introspector;
+    }
+}

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/PomRewriter.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=190044&r1=190043&r2=190044&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
 Fri Jun 10 17:29:27 2005
@@ -1,20 +1,19 @@
 package org.apache.maven.artifact.deployer;
 
-/* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 import org.apache.commons.betwixt.XMLIntrospector;
@@ -26,6 +25,7 @@
 import org.apache.maven.MavenConstants;
 import org.apache.maven.MavenException;
 import org.apache.maven.MavenUtils;
+import org.apache.maven.artifact.PomRewriter;
 import org.apache.maven.jelly.MavenJellyContext;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
@@ -118,7 +118,7 @@
         File file;
         if ( POM_TYPE.equals( type ) )
         {
-            file = getRewrittenPom( project );
+            file = PomRewriter.getRewrittenPom( project );
         }
         else
         {
@@ -128,111 +128,12 @@
         // do not deploy POM twice
         if ( !POM_TYPE.equals( type ) )
         {
-            doDeploy( getRewrittenPom( project ), project, 
POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
+            doDeploy( PomRewriter.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)
      */
@@ -258,7 +159,7 @@
         File file;
         if ( POM_TYPE.equals( type ) )
         {
-            file = getRewrittenPom( project );
+            file = PomRewriter.getRewrittenPom( project );
         }
         else
         {
@@ -270,7 +171,7 @@
         // do not install twice
         if ( !POM_TYPE.equals( type ) )
         {
-            doInstall( getRewrittenPom( project ), POM_TYPE, project, version, 
POM_ARTIFACT_TYPE_HANDLER );
+            doInstall( PomRewriter.getRewrittenPom( project ), POM_TYPE, 
project, version, POM_ARTIFACT_TYPE_HANDLER );
         }
     }
 

Added: 
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java?rev=190044&view=auto
==============================================================================
--- 
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
 (added)
+++ 
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
 Fri Jun 10 17:29:27 2005
@@ -0,0 +1,60 @@
+package org.apache.maven.artifact;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.project.Project;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.MavenException;
+import org.apache.maven.MavenUtils;
+
+import java.io.File;
+
+/**
+ * Test the POM rewriter.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ * @version $Id$
+ */
+public class PomRewriterTest
+    extends TestCase
+{
+    public void testPropertiesRewriting()
+        throws MavenException
+    {
+        Project project = getProject( "pom-with-properties.xml" );
+
+        Model model = PomRewriter.getRewrittenModel( project );
+
+        Dependency dep = (Dependency) model.getDependencies().get( 0 );
+        assertEquals( "check property war.bundle", "true", dep.getProperty( 
"war.bundle" ) );
+        assertEquals( "check num properties", 1, dep.getProperties().size() );
+
+        dep = (Dependency) model.getDependencies().get( 1 );
+        assertEquals( "check property gump.project", 
"jakarta-taglibs-standard", dep.getProperty( "gump.project" ) );
+        assertEquals( "check property gump.id", "jstl", dep.getProperty( 
"gump.id" ) );
+        assertEquals( "check num properties", 2, dep.getProperties().size() );
+    }
+
+    private static Project getProject( String resourceName )
+        throws MavenException
+    {
+        // TODO: use a resource if MavenUtils supported it
+        return MavenUtils.getProject( new File( System.getProperty( 
"basedir"), "src/test/resources/" + resourceName ) );
+    }
+}

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml
URL: 
http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml?rev=190044&view=auto
==============================================================================
--- 
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml 
(added)
+++ 
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml 
Fri Jun 10 17:29:27 2005
@@ -0,0 +1,27 @@
+<project xmlns="http://maven.apache.org/POM/3.0.0"; 
xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 
http://maven.apache.org/maven-v3_0_0.xsd";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <pomVersion>3</pomVersion>
+  <artifactId>artifactId</artifactId>
+  <groupId>groupId</groupId>
+  <currentVersion>1.0-SNAPSHOT</currentVersion>
+  <dependencies>
+    <dependency>
+      <artifactId>a1</artifactId>
+      <groupId>g1</groupId>
+      <version>v1</version>
+      <properties>
+        <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <groupId>jstl</groupId>
+      <artifactId>jstl</artifactId>
+      <version>1.0.6</version>
+      
<url>http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/intro.html</url>
+      <properties>
+        <gump.project>jakarta-taglibs-standard</gump.project>
+        <gump.id>jstl</gump.id>
+      </properties>
+    </dependency>
+  </dependencies>
+</project>

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-1/plugins/trunk/artifact/src/test/resources/pom-with-properties.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=190044&r1=190043&r2=190044&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml (original)
+++ maven/maven-1/plugins/trunk/artifact/xdocs/changes.xml Fri Jun 10 17:29:27 
2005
@@ -26,6 +26,7 @@
   </properties>
   <body>
     <release version="1.5.2-SNAPSHOT" date="in SVN">
+      <action dev="brett" type="fix" issue="MPARTIFACT-51">Correct the 
translation of dependency properties on deployment of the POM</action>
       <action dev="brett" type="fix" issue="MPARTIFACT-52">Upgrade Wagon SSH 
External provider to correct issues</action>
     </release>
     <release version="1.5.1" date="2005-06-05">



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

Reply via email to