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

lukaszlenart pushed a commit to branch feat/WW-5864-struts-maven-plugin-watch
in repository https://gitbox.apache.org/repos/asf/struts.git

commit d75f44ee19eaa2aa19dbb0be6732b8b8ba659733
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sat Nov 14 08:52:20 2026 +0100

    WW-5864 fix(tools): report stale-push failures and keep going
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 .../org/apache/struts2/maven/watch/WatchMojo.java  |  8 ++++--
 .../apache/struts2/maven/watch/WatchMojoTest.java  | 33 +++++++++++++++++++++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git 
a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchMojo.java
 
b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchMojo.java
index 4dbaae7fd..9d0b94407 100644
--- 
a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchMojo.java
+++ 
b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchMojo.java
@@ -34,6 +34,7 @@ import java.nio.file.Path;
 import java.time.Duration;
 import java.util.List;
 import java.util.Map;
+import java.util.function.BiConsumer;
 import java.util.function.BooleanSupplier;
 import java.util.function.Function;
 
@@ -102,7 +103,8 @@ public class WatchMojo extends AbstractMojo {
                 new FilteringResourcePusher(resourcesFiltering, project, 
session, settings, outputDirectory);
         ResourcePusher pusher = loggingPusher(filteringPusher, basedir);
 
-        pushStaleOutputs(scanner.scan(), filteringPusher::outputPathOf, 
pusher);
+        pushStaleOutputs(scanner.scan(), filteringPusher::outputPathOf, pusher,
+                (message, e) -> getLog().error(message, e));
 
         List<Path> filterFiles = project.getBuild().getFilters().stream()
                 .map(filter -> basedir.resolve(filter))
@@ -136,14 +138,14 @@ public class WatchMojo extends AbstractMojo {
     }
 
     static void pushStaleOutputs(Map<SourceFile, FileStamp> scan, 
Function<SourceFile, Path> outputPathOf,
-                                 ResourcePusher pusher) {
+                                 ResourcePusher pusher, BiConsumer<String, 
Exception> error) {
         for (Map.Entry<SourceFile, FileStamp> entry : scan.entrySet()) {
             File output = outputPathOf.apply(entry.getKey()).toFile();
             if (!output.isFile() || output.lastModified() < 
entry.getValue().lastModified()) {
                 try {
                     pusher.push(entry.getKey());
                 } catch (IOException | RuntimeException e) {
-                    throw new IllegalStateException("Cannot push " + 
entry.getKey().relativePath(), e);
+                    error.accept("Failed to push " + 
entry.getKey().relativePath(), e);
                 }
             }
         }
diff --git 
a/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/WatchMojoTest.java
 
b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/WatchMojoTest.java
index 799d672e8..5523c8408 100644
--- 
a/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/WatchMojoTest.java
+++ 
b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/WatchMojoTest.java
@@ -103,11 +103,42 @@ public class WatchMojoTest {
             }
         };
 
-        WatchMojo.pushStaleOutputs(scan, file -> 
out.resolve(file.relativePath()), pusher);
+        WatchMojo.pushStaleOutputs(scan, file -> 
out.resolve(file.relativePath()), pusher, (m, e) -> { });
 
         assertThat(pushed).containsExactlyInAnyOrder("stale.txt", 
"missing.txt");
     }
 
+    @Test
+    public void stalePushFailureIsReportedAndRemainingFilesArePushed() throws 
Exception {
+        Path src = temp.newFolder("src2").toPath();
+        Path out = temp.newFolder("out2").toPath();
+        WatchedRoot root = new WatchedRoot(src, List.of(), List.of(), null, 
false);
+        Map<SourceFile, FileStamp> scan = new LinkedHashMap<>();
+        for (String name : List.of("bad.txt", "good.txt")) {
+            File f = write(src.resolve(name), 1000);
+            scan.put(new SourceFile(root, name), new 
FileStamp(f.lastModified(), f.length()));
+        }
+        List<String> pushed = new ArrayList<>();
+        List<String> errors = new ArrayList<>();
+        ResourcePusher pusher = new ResourcePusher() {
+            public void push(SourceFile file) throws java.io.IOException {
+                if (file.relativePath().equals("bad.txt")) {
+                    throw new java.io.IOException("locked");
+                }
+                pushed.add(file.relativePath());
+            }
+
+            public void delete(SourceFile file) {
+            }
+        };
+
+        WatchMojo.pushStaleOutputs(scan, file -> 
out.resolve(file.relativePath()), pusher,
+                (message, e) -> errors.add(message));
+
+        assertThat(pushed).containsExactly("good.txt");
+        assertThat(errors).containsExactly("Failed to push bad.txt");
+    }
+
     private File write(Path path, long lastModified) throws Exception {
         Files.writeString(path, "x");
         File file = path.toFile();

Reply via email to