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 2025/12/19 13:03:49 UTC

(maven-dependency-plugin) branch exc created (now a09fa5d0)

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

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


      at a09fa5d0 Better exception handling

This branch includes the following new commits:

     new a09fa5d0 Better exception handling

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-dependency-plugin) 01/01: Better exception handling

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

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

commit a09fa5d01a82617d131838bc2256e8b30da3f820
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Fri Dec 19 08:03:40 2025 -0500

    Better exception handling
---
 .../fromDependencies/RenderDependenciesMojo.java         | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/RenderDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/RenderDependenciesMojo.java
index 6a429148..00a78b09 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/RenderDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/RenderDependenciesMojo.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.io.UncheckedIOException;
 import java.io.Writer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -154,9 +155,10 @@ public class RenderDependenciesMojo extends AbstractDependencyFilterMojo {
     }
 
     /**
-     * Do render the template.
-     * @param artifacts input.
-     * @return the template rendered.
+     * Render the template.
+     *
+     * @param artifacts input
+     * @return the template rendered
      */
     private String render(final List<Artifact> artifacts) {
         final Path templatePath = getTemplatePath();
@@ -178,8 +180,7 @@ public class RenderDependenciesMojo extends AbstractDependencyFilterMojo {
         context.put("sorter", new CollectionTool());
 
         // Merge template + context
-        final StringWriter writer = new StringWriter();
-        try (StringWriter ignored = writer) {
+        try (StringWriter writer = new StringWriter()) {
             if (fromFile) {
                 final Template template =
                         ve.getTemplate(templatePath.getFileName().toString());
@@ -187,11 +188,10 @@ public class RenderDependenciesMojo extends AbstractDependencyFilterMojo {
             } else {
                 ve.evaluate(context, writer, "tpl-" + Math.abs(hashCode()), template);
             }
+            return writer.toString();
         } catch (final IOException e) {
-            // no-op, not possible
+            throw new UncheckedIOException("not possible", e);
         }
-
-        return writer.toString();
     }
 
     private Path getTemplatePath() {