diff --git a/artifact/project.xml b/artifact/project.xml index 1a2aaf10..438e8a80 100644 --- a/artifact/project.xml +++ b/artifact/project.xml @@ -83,7 +83,7 @@ commons-betwixt commons-betwixt - 0.6 + 1.0-beta-1.20030111.103454 commons-digester @@ -180,6 +180,28 @@ maven-model 3.0.0 + + + + maven + maven-jelly-tags + 1.0.1 + + + werkz + werkz + 20040426.222000 + + + commons-jelly + commons-jelly-tags-ant + 1.0 + + + commons-jexl + commons-jexl + 1.0-beta-1 + src/test/java diff --git a/artifact/src/main/org/apache/maven/artifact/PomRewriter.java b/artifact/src/main/org/apache/maven/artifact/PomRewriter.java index 0082777f..5ba00e64 100644 --- a/artifact/src/main/org/apache/maven/artifact/PomRewriter.java +++ b/artifact/src/main/org/apache/maven/artifact/PomRewriter.java @@ -29,6 +29,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.Project; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; import java.io.ByteArrayOutputStream; import java.io.File; @@ -36,6 +37,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Method; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -83,12 +85,11 @@ public class PomRewriter { // 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} ); + 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[]{file, context, Boolean.TRUE} ); + Project p = (Project) m.invoke( null, new Object[]{file, context, Boolean.TRUE} ); m.setAccessible( false ); m = MavenUtils.class.getDeclaredMethod( "getJellyProject", new Class[]{Project.class} ); m.setAccessible( true ); @@ -106,9 +107,20 @@ public class PomRewriter 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() ) + Map properties; + try { - depProperties.put( d.getId(), d.getProperties() ); + // Maven 1.0.2 + properties = (Map) d.getClass().getMethod( "resolvedProperties", new Class[] {} ).invoke( d, null ); + } + catch ( NoSuchMethodException e ) + { + // Maven 1.1 + properties = (Map) d.getClass().getMethod( "getProperties", new Class[] {} ).invoke( d, null ); + } + if ( properties != null && !properties.isEmpty() ) + { + depProperties.put( d.getId(), properties ); d.setProperties( null ); } } @@ -134,7 +146,7 @@ public class PomRewriter if ( depProperties.containsKey( d.getId() ) ) { - d.getProperties().putAll( (Properties) depProperties.get( d.getId() ) ); + d.getProperties().putAll( (Map) depProperties.get( d.getId() ) ); } d.setId( null ); @@ -154,7 +166,6 @@ public class PomRewriter d.setJar( null ); } - } } catch ( Exception e ) @@ -173,4 +184,5 @@ public class PomRewriter return introspector; } + } diff --git a/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java b/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java index e7205cfc..ec7d7da7 100644 --- a/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java +++ b/artifact/src/test/java/org/apache/maven/artifact/PomRewriterTest.java @@ -22,6 +22,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.Dependency; import org.apache.maven.MavenException; import org.apache.maven.MavenUtils; +import org.apache.maven.MavenConstants; import java.io.File; @@ -34,6 +35,15 @@ import java.io.File; public class PomRewriterTest extends TestCase { + protected void setUp() + throws Exception + { + if ( System.getProperty( MavenConstants.MAVEN_HOME ) == null ) + { + System.setProperty( MavenConstants.MAVEN_HOME, "target/maven-home" ); + } + } + public void testPropertiesRewriting() throws MavenException {