Return-Path: Delivered-To: apmail-maven-commits-archive@www.apache.org Received: (qmail 93001 invoked from network); 26 Oct 2010 12:42:12 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 Oct 2010 12:42:12 -0000 Received: (qmail 40407 invoked by uid 500); 26 Oct 2010 12:42:12 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 40147 invoked by uid 500); 26 Oct 2010 12:42:08 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 40140 invoked by uid 99); 26 Oct 2010 12:42:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Oct 2010 12:42:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Oct 2010 12:42:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0884823888EC; Tue, 26 Oct 2010 12:41:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1027516 - /maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java Date: Tue, 26 Oct 2010 12:41:10 -0000 To: commits@maven.apache.org From: vsiveton@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101026124111.0884823888EC@eris.apache.org> Author: vsiveton Date: Tue Oct 26 12:41:10 2010 New Revision: 1027516 URL: http://svn.apache.org/viewvc?rev=1027516&view=rev Log: MANTRUN-127: provide more tracking info when a task fails o extract the Ant xml part from the BuildException 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=1027516&r1=1027515&r2=1027516&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 Tue Oct 26 12:41:10 2010 @@ -21,6 +21,7 @@ package org.apache.maven.plugin.antrun; import java.io.File; import java.io.IOException; +import java.io.LineNumberReader; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; @@ -46,6 +47,8 @@ import org.apache.tools.ant.types.Path; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; /** @@ -305,9 +308,16 @@ public class AntRunMojo } catch ( BuildException e ) { - throw new MojoExecutionException( "An Ant BuildException has occured: " + e.getMessage(), e ); + StringBuffer sb = new StringBuffer(); + sb.append( "An Ant BuildException has occured: " + e.getMessage() ); + String fragment = findFragment( e ); + if ( fragment != null ) + { + sb.append( "\n" ).append( fragment ); + } + throw new MojoExecutionException( sb.toString(), e ); } - catch ( Exception e ) + catch ( Throwable e ) { throw new MojoExecutionException( "Error executing ant tasks: " + e.getMessage(), e ); } @@ -445,6 +455,7 @@ public class AntRunMojo getLog().debug( "Propagated Ant properties to Maven properties" ); Hashtable antProps = antProject.getProperties(); + Iterator iter = antProps.keySet().iterator(); while ( iter.hasNext() ) { @@ -585,4 +596,49 @@ public class AntRunMojo return targetName; } + /** + * @param buildException not null + * @return the fragment XML part where the buildException occurs. + * @since 1.7 + */ + private String findFragment( BuildException buildException ) + { + if ( buildException == null || buildException.getLocation() == null + || buildException.getLocation().getFileName() == null ) + { + return null; + } + + File antFile = new File( buildException.getLocation().getFileName() ); + if ( !antFile.exists() ) + { + return null; + } + + LineNumberReader reader = null; + try + { + reader = new LineNumberReader( ReaderFactory.newXmlReader( antFile ) ); + String line = ""; + while ( ( line = reader.readLine() ) != null ) + { + if ( reader.getLineNumber() == buildException.getLocation().getLineNumber() ) + { + return "around Ant part ..." + line.trim() + "... @ " + buildException.getLocation().getLineNumber() + ":" + + buildException.getLocation().getColumnNumber() + " in " + antFile.getAbsolutePath(); + } + } + } + catch ( Exception e ) + { + getLog().debug( e.getMessage(), e ); + return null; + } + finally + { + IOUtil.close( reader ); + } + + return null; + } }