You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2026/09/28 12:14:52 UTC

(maven-antrun-plugin) branch deopre created (now f086e93)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch deopre
in repository https://gitbox.apache.org/repos/asf/maven-antrun-plugin.git


      at f086e93  Replace deprecated XMLReader class with JDK classes

This branch includes the following new commits:

     new f086e93  Replace deprecated XMLReader class with JDK classes

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-antrun-plugin) 01/01: Replace deprecated XMLReader class with JDK classes

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch deopre
in repository https://gitbox.apache.org/repos/asf/maven-antrun-plugin.git

commit f086e93dfb68d58fb5f5b3419ad688a7ef7358ad
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Mon Sep 28 08:14:08 2026 -0400

    Replace deprecated XMLReader class with JDK classes
---
 .../apache/maven/plugins/antrun/AntRunMojo.java    | 33 ++++++++++++++--------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java b/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
index 5ff1844..e12a9a7 100644
--- a/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
+++ b/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
@@ -19,10 +19,16 @@
 package org.apache.maven.plugins.antrun;
 
 import javax.inject.Inject;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Hashtable;
@@ -50,7 +56,6 @@ import org.apache.tools.ant.ProjectHelper;
 import org.apache.tools.ant.taskdefs.Typedef;
 import org.apache.tools.ant.types.Path;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.util.ReaderFactory;
 
 /**
  * <p>
@@ -525,8 +530,7 @@ public class AntRunMojo extends AbstractMojo {
 
     /**
      * @param buildException not null
-     * @return the fragment XML part where the buildException occurs.
-     * @since 1.7
+     * @return a fragment of XML from the place in the ant build.xml where the buildException occurs
      */
     private String findFragment(BuildException buildException) {
         if (buildException == null
@@ -540,16 +544,23 @@ public class AntRunMojo extends AbstractMojo {
             return null;
         }
 
-        try (LineNumberReader reader = new LineNumberReader(ReaderFactory.newXmlReader(antFile))) {
-            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
-                if (reader.getLineNumber() == buildException.getLocation().getLineNumber()) {
-                    return "around Ant part ..." + line.trim() + "... @ "
-                            + buildException.getLocation().getLineNumber() + ":"
-                            + buildException.getLocation().getColumnNumber() + " in " + antFile.getAbsolutePath();
+        XMLInputFactory factory = XMLInputFactory.newFactory();
+        try (InputStream in = Files.newInputStream(antFile.toPath())) {
+            XMLStreamReader xmlReader = factory.createXMLStreamReader(in);
+            String encoding = xmlReader.getEncoding();
+            xmlReader.close();
+            try (LineNumberReader reader =
+                    new LineNumberReader(new InputStreamReader(Files.newInputStream(antFile.toPath()), encoding))) {
+                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+                    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);
+        } catch (IOException | XMLStreamException ex) {
+            getLog().debug(ex.getMessage(), ex);
         }
 
         return null;