You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by pg...@apache.org on 2010/07/02 07:19:07 UTC
svn commit: r959858 - in
/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun:
AntRunMojo.java AntrunXmlPlexusConfigurationWriter.java
Author: pgier
Date: Fri Jul 2 05:19:07 2010
New Revision: 959858
URL: http://svn.apache.org/viewvc?rev=959858&view=rev
Log:
[MANTRUN-146] Use PlexusConfiguration instead of XmlPlexusConfiguration to maintain compatibility with Maven 3
Added:
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java (with props)
Modified:
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?rev=959858&r1=959857&r2=959858&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java Fri Jul 2 05:19:07 2010
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.antrun;
import java.io.File;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -43,7 +44,6 @@ import org.apache.tools.ant.taskdefs.Typ
import org.apache.tools.ant.types.Path;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
-import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
@@ -157,7 +157,7 @@ public class AntRunMojo
* @deprecated Use target instead
* @parameter
*/
- private XmlPlexusConfiguration tasks;
+ private PlexusConfiguration tasks;
/**
* The XML for the Ant target. You can add anything you can add between <target> and </target> in a
@@ -165,7 +165,7 @@ public class AntRunMojo
*
* @parameter
*/
- private XmlPlexusConfiguration target;
+ private PlexusConfiguration target;
/**
* This folder is added to the list of those folders containing source to be compiled. Use this if your ant script
@@ -422,7 +422,12 @@ public class AntRunMojo
private File writeTargetToProjectFile()
throws IOException, PlexusConfigurationException
{
- StringBuffer antProjectConfig = new StringBuffer( target.getXpp3Dom().toString() );
+ // Have to use an XML writer because in Maven 2.x the PlexusConfig toString() method loses XML attributes
+ StringWriter writer = new StringWriter();
+ AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
+ xmlWriter.write( writer, target );
+
+ StringBuffer antProjectConfig = writer.getBuffer();
// replace deprecated tasks tag with standard Ant target
stringReplace( antProjectConfig, "<tasks", "<target" );
Added: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java?rev=959858&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java Fri Jul 2 05:19:07 2010
@@ -0,0 +1,130 @@
+package org.apache.maven.plugin.antrun;
+
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+/**
+ * Write a plexus configuration to a stream
+ * Note: this is a copy of a class from plexus-container-default. It is duplicated here
+ * to maintain compatibility with both Maven 2.x and Maven 3.x.
+ *
+ */
+public class AntrunXmlPlexusConfigurationWriter
+{
+
+ public void write( OutputStream outputStream, PlexusConfiguration configuration )
+ throws IOException
+ {
+ write( new OutputStreamWriter( outputStream, "UTF-8" ), configuration );
+ }
+
+ public void write( Writer writer, PlexusConfiguration configuration )
+ throws IOException
+ {
+ int depth = 0;
+
+ display( configuration, writer, depth );
+ }
+
+ private void display( PlexusConfiguration c, Writer w, int depth )
+ throws IOException
+ {
+ int count = c.getChildCount();
+
+ if ( count == 0 )
+ {
+ displayTag( c, w, depth );
+ }
+ else
+ {
+ indent( depth, w );
+ w.write( '<' );
+ w.write( c.getName() );
+
+ attributes( c, w );
+
+ w.write( '>' );
+ w.write( '\n' );
+
+ for ( int i = 0; i < count; i++ )
+ {
+ PlexusConfiguration child = c.getChild( i );
+
+ display( child, w, depth + 1 );
+ }
+
+ indent( depth, w );
+ w.write( '<' );
+ w.write( '/' );
+ w.write( c.getName() );
+ w.write( '>' );
+ w.write( '\n' );
+ }
+ }
+
+ private void displayTag( PlexusConfiguration c, Writer w, int depth )
+ throws IOException
+ {
+ String value = c.getValue( null );
+
+ if ( value != null )
+ {
+ indent( depth, w );
+ w.write( '<' );
+ w.write( c.getName() );
+
+ attributes( c, w );
+
+ w.write( '>' );
+ w.write( c.getValue( null ) );
+ w.write( '<' );
+ w.write( '/' );
+ w.write( c.getName() );
+ w.write( '>' );
+ w.write( '\n' );
+ }
+ else
+ {
+ indent( depth, w );
+ w.write( '<' );
+ w.write( c.getName() );
+
+ attributes( c, w );
+
+ w.write( '/' );
+ w.write( '>' );
+ w.write( "\n" );
+ }
+ }
+
+ private void attributes( PlexusConfiguration c, Writer w )
+ throws IOException
+ {
+ String[] names = c.getAttributeNames();
+
+ for ( int i = 0; i < names.length; i++ )
+ {
+ w.write( ' ' );
+ w.write( names[i] );
+ w.write( '=' );
+ w.write( '"' );
+ w.write( c.getAttribute( names[i], null ) );
+ w.write( '"' );
+ }
+ }
+
+ private void indent( int depth, Writer w )
+ throws IOException
+ {
+ for ( int i = 0; i < depth; i++ )
+ {
+ w.write( ' ' );
+ }
+ }
+
+}
+
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntrunXmlPlexusConfigurationWriter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision