Make the code run properly under 1.0.2 and 1.1
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@190062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4d4f02f2e4
commit
42aec92c29
@ -83,7 +83,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-betwixt</groupId>
|
||||
<artifactId>commons-betwixt</artifactId>
|
||||
<version>0.6</version>
|
||||
<version>1.0-beta-1.20030111.103454</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-digester</groupId>
|
||||
@ -180,6 +180,28 @@
|
||||
<artifactId>maven-model</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- For Maven 1.0.2... -->
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-jelly-tags</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>werkz</groupId>
|
||||
<artifactId>werkz</artifactId>
|
||||
<version>20040426.222000</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-jelly</groupId>
|
||||
<artifactId>commons-jelly-tags-ant</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-jexl</groupId>
|
||||
<artifactId>commons-jexl</artifactId>
|
||||
<version>1.0-beta-1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user