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

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver-ant-tasks.git

commit 448d0caed1c7758431b1346e6c24d9ac37a449ec
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Oct 31 13:04:07 2026 +0000

    Drop JUnit 4 and ant-testutil from the build
---
 build.xml                                          | 13 +--
 pom.xml                                            | 26 +++---
 .../maven/resolver/internal/ant/AntBuildFile.java  | 93 ++++++++++++++++++++--
 3 files changed, 110 insertions(+), 22 deletions(-)

diff --git a/build.xml b/build.xml
index c093e3f..6799c6d 100644
--- a/build.xml
+++ b/build.xml
@@ -95,19 +95,20 @@
   </target>
 
   <target name="test" depends="test-compile">
-    <junit haltonfailure="true" fork="true" forkmode="once" 
outputtoformatters="false">
+    <mkdir dir="${build.dir}/test-reports"/>
+    <junitlauncher haltOnFailure="true" printSummary="true">
       <classpath>
         <pathelement location="${build.dir}/test-classes"/>
         <pathelement location="${build.dir}/classes"/>
         <path refid="cp.runtime.test"/>
       </classpath>
 
-      <formatter type="brief" usefile="false"/>
-
-      <batchtest>
+      <testclasses outputdir="${build.dir}/test-reports">
+        <fork/>
         <fileset dir="${build.dir}/test-classes" includes="**/*Test.class" 
excludes="**/AntBuildsTest*"/>
-      </batchtest>
-    </junit>
+        <listener type="legacy-brief" sendSysOut="false"/>
+      </testclasses>
+    </junitlauncher>
   </target>
 
   <target name="package" depends="test">
diff --git a/pom.xml b/pom.xml
index 746003a..8591d05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,7 +62,6 @@
     <resolverVersion>2.0.24</resolverVersion>
     <antVersion>1.10.18</antVersion>
     <slf4jVersion>2.0.20</slf4jVersion>
-    <junitVersion>4.13.2</junitVersion>
     
<maven.site.path>resolver-archives/resolver-ant-tasks-LATEST</maven.site.path>
     
<checkstyle.violation.ignore>LineLength,MagicNumber</checkstyle.violation.ignore>
     
<project.build.outputTimestamp>2026-08-03T16:01:18Z</project.build.outputTimestamp>
@@ -204,9 +203,14 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.ant</groupId>
-      <artifactId>ant-testutil</artifactId>
-      <version>${antVersion}</version>
+      <!-- not needed by Surefire, which adds it; the Ant smoke test in 
build.xml runs the tests on the classpath -->
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.platform</groupId>
+      <artifactId>junit-platform-launcher</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -328,13 +332,15 @@
               </dependency>
               <dependency>
                 <groupId>org.apache.ant</groupId>
-                <artifactId>ant-junit</artifactId>
+                <artifactId>ant-junitlauncher</artifactId>
                 <version>${antVersion}</version>
-              </dependency>
-              <dependency>
-                <groupId>junit</groupId>
-                <artifactId>junit</artifactId>
-                <version>${junitVersion}</version>
+                <exclusions>
+                  <exclusion>
+                    <!-- an older launcher than the engine of the tests, which 
brings its own -->
+                    <groupId>org.junit.platform</groupId>
+                    <artifactId>*</artifactId>
+                  </exclusion>
+                </exclusions>
               </dependency>
             </dependencies>
             <executions>
diff --git 
a/src/test/java/org/apache/maven/resolver/internal/ant/AntBuildFile.java 
b/src/test/java/org/apache/maven/resolver/internal/ant/AntBuildFile.java
index 500d47e..282923a 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/AntBuildFile.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/AntBuildFile.java
@@ -18,18 +18,99 @@
  */
 package org.apache.maven.resolver.internal.ant;
 
-import org.apache.tools.ant.BuildFileRule;
+import java.io.File;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
 
 /**
- * Ant's {@link BuildFileRule} for JUnit 5 tests. The rule is a JUnit 4 {@code 
ExternalResource} whose cleanup is
- * protected, so this subclass exposes it to be called from an {@code 
@AfterEach} method.
+ * Loads an Ant build file into a {@link Project}, runs its targets and 
records the log. It stands in for Ant's own
+ * {@code BuildFileRule}, which is a JUnit 4 rule and would keep JUnit 4 on 
the test classpath.
  */
-public class AntBuildFile extends BuildFileRule {
+public class AntBuildFile {
+
+    private final StringBuffer log = new StringBuffer();
+
+    private Project project;
+
+    /**
+     * Configures the project from the given build file.
+     *
+     * @param filename the path of the build file
+     * @param logLevel the most verbose {@link Project} message level to record
+     * @throws BuildException if the build file cannot be parsed
+     */
+    public void configureProject(String filename, int logLevel) throws 
BuildException {
+        log.setLength(0);
+        project = new Project();
+        project.init();
+        project.addBuildListener(new BuildListener() {
+            @Override
+            public void buildStarted(BuildEvent event) {}
+
+            @Override
+            public void buildFinished(BuildEvent event) {}
+
+            @Override
+            public void targetStarted(BuildEvent event) {}
+
+            @Override
+            public void targetFinished(BuildEvent event) {}
+
+            @Override
+            public void taskStarted(BuildEvent event) {}
+
+            @Override
+            public void taskFinished(BuildEvent event) {}
+
+            @Override
+            public void messageLogged(BuildEvent event) {
+                int priority = event.getPriority();
+                if (priority <= logLevel && priority <= Project.MSG_INFO) {
+                    log.append(event.getMessage());
+                }
+            }
+        });
+        ProjectHelper.configureProject(project, new File(filename));
+    }
+
+    /**
+     * Runs a target of the configured project.
+     *
+     * @param targetName the target to run
+     */
+    public void executeTarget(String targetName) {
+        log.setLength(0);
+        project.executeTarget(targetName);
+    }
+
+    /**
+     * Returns the messages at info level or above that the last executed 
target logged.
+     *
+     * @return the log
+     */
+    public String getLog() {
+        return log.toString();
+    }
+
+    /**
+     * Returns the configured project.
+     *
+     * @return the project, or {@code null} before {@link 
#configureProject(String, int)}
+     */
+    public Project getProject() {
+        return project;
+    }
 
     /**
-     * Restores the standard streams the rule replaced while a build file was 
configured and executed.
+     * Runs the {@code tearDown} target when the build file has one.
      */
     public void release() {
-        after();
+        if (project != null && project.getTargets().containsKey("tearDown")) {
+            project.executeTarget("tearDown");
+        }
     }
 }

Reply via email to