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

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

commit d9226230851e69c44ae228ef83771c2fe630d937
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Fri Nov 22 06:52:14 2024 -0500

    Modernize I/O
---
 .../maven/plugins/jira/ClassicJiraDownloader.java  | 48 +++++++---------------
 1 file changed, 14 insertions(+), 34 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/jira/ClassicJiraDownloader.java 
b/src/main/java/org/apache/maven/plugins/jira/ClassicJiraDownloader.java
index a291ae3..763f05c 100644
--- a/src/main/java/org/apache/maven/plugins/jira/ClassicJiraDownloader.java
+++ b/src/main/java/org/apache/maven/plugins/jira/ClassicJiraDownloader.java
@@ -31,7 +31,6 @@ import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.StatusLine;
@@ -57,7 +56,6 @@ public final class ClassicJiraDownloader extends 
AbstractJiraDownloader {
 
     /**
      * Execute the query on the JIRA server.
-     *
      */
     public void doExecute() {
         try {
@@ -306,22 +304,17 @@ public final class ClassicJiraDownloader extends 
AbstractJiraDownloader {
      * @param link the URL to JIRA
      */
     private void download(final HttpClient cl, final String link) {
-        InputStream in = null;
-        OutputStream out = null;
-        try {
-            GetMethod gm = new GetMethod(link);
-
-            getLog().info("Downloading from JIRA at: " + link);
-
-            gm.setFollowRedirects(true);
 
+        GetMethod gm = new GetMethod(link);
+        getLog().info("Downloading from JIRA at: " + link);
+        gm.setFollowRedirects(true);
+        try {
             cl.executeMethod(gm);
 
             StatusLine sl = gm.getStatusLine();
 
             if (sl == null) {
                 getLog().error("Unknown error validating link: " + link);
-
                 return;
             }
 
@@ -333,47 +326,34 @@ public final class ClassicJiraDownloader extends 
AbstractJiraDownloader {
                     getLog().warn("Site sent redirect, but did not set 
Location header");
                 } else {
                     String newLink = locationHeader.getValue();
-
                     getLog().debug("Following redirect to " + newLink);
-
                     download(cl, newLink);
                 }
             }
 
             if (gm.getStatusCode() == HttpStatus.SC_OK) {
-                in = gm.getResponseBodyAsStream();
-
                 if (!output.getParentFile().exists()) {
-                    output.getParentFile().mkdirs();
+                    if (!output.getParentFile().mkdirs()) {
+                        getLog().error("Downloading issues from JIRA failed. 
Could not create "
+                                + output.getParentFile());
+                        return;
+                    }
                 }
 
-                // write the response to file
-                out = new FileOutputStream(output);
-                IOUtil.copy(in, out);
-                out.close();
-                out = null;
-                in.close();
-                in = null;
-
-                getLog().debug("Downloading from JIRA was successful");
+                try (InputStream in = gm.getResponseBodyAsStream();
+                        OutputStream out = new FileOutputStream(output)) {
+                    IOUtil.copy(in, out);
+                    getLog().debug("Downloading from JIRA was successful");
+                }
             } else {
                 getLog().warn("Downloading from JIRA failed. Received: [" + 
gm.getStatusCode() + "]");
             }
-        } catch (HttpException e) {
-            if (getLog().isDebugEnabled()) {
-                getLog().error("Error downloading issues from JIRA:", e);
-            } else {
-                getLog().error("Error downloading issues from JIRA url: " + 
e.getLocalizedMessage());
-            }
         } catch (IOException e) {
             if (getLog().isDebugEnabled()) {
                 getLog().error("Error downloading issues from JIRA:", e);
             } else {
                 getLog().error("Error downloading issues from JIRA. Cause is " 
+ e.getLocalizedMessage());
             }
-        } finally {
-            IOUtil.close(out);
-            IOUtil.close(in);
         }
     }
 

Reply via email to