groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_2_5_X updated: minor refactor - reduce duplicated code
Date Sat, 16 Mar 2019 03:47:56 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 16c34e1  minor refactor - reduce duplicated code
16c34e1 is described below

commit 16c34e1dab60acaff5cdea7ac2746ac00ea772f8
Author: Paul King <paulk@asert.com.au>
AuthorDate: Sat Mar 16 13:47:44 2019 +1000

    minor refactor - reduce duplicated code
---
 src/main/groovy/groovy/grape/GrapeIvy.groovy | 42 +++++-----------------------
 1 file changed, 7 insertions(+), 35 deletions(-)

diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index 3912e54..f0785e5 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -59,6 +59,8 @@ import java.util.zip.ZipEntry
 import java.util.zip.ZipException
 import java.util.zip.ZipFile
 
+import static org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport.closeQuietly
+
 /**
  * Implementation supporting {@code @Grape} and {@code @Grab} annotations based on Ivy.
  */
@@ -329,13 +331,7 @@ class GrapeIvy implements GrapeEngine {
                             is = jar.getInputStream(entry)
                             props.load(is)
                         } finally {
-                            if (null != is) {
-                                try {
-                                    is.close()
-                                } catch (e) {
-                                    // ignore
-                                }
-                            }
+                            closeQuietly(is)
                         }
 
                         Map<CachedClass, List<MetaMethod>> metaMethods = new
HashMap<CachedClass, List<MetaMethod>>()
@@ -356,13 +352,7 @@ class GrapeIvy implements GrapeEngine {
                 } catch(ZipException zipException) {
                     throw new RuntimeException("Grape could not load jar '$file'", zipException)
                 } finally {
-                    if (null != jar) {
-                        try {
-                            jar.close()
-                        } catch (e) {
-                            // ignore
-                        }
-                    }
+                    closeQuietly(jar)
                 }
             }
         }
@@ -397,13 +387,7 @@ class GrapeIvy implements GrapeEngine {
                     is = zf.getInputStream(serializedCategoryMethods)
                     processSerializedCategoryMethods(is)
                 } finally {
-                    if (null != is) {
-                        try {
-                            is.close()
-                        } catch (e) {
-                            // ignore
-                        }
-                    }
+                    closeQuietly(is)
                 }
 
             }
@@ -418,13 +402,7 @@ class GrapeIvy implements GrapeEngine {
                     is = zf.getInputStream(pluginRunners)
                     processRunners(is, f.getName(), loader)
                 } finally {
-                    if (null != is) {
-                        try {
-                            is.close()
-                        } catch (e) {
-                            // ignore
-                        }
-                    }
+                    closeQuietly(is)
                 }
             }
             // GroovyRunners are loaded per ClassLoader using a ServiceLoader so here
@@ -436,13 +414,7 @@ class GrapeIvy implements GrapeEngine {
             // ignore files we can't process, e.g. non-jar/zip artifacts
             // TODO log a warning
         } finally {
-            if (null != zf) {
-                try {
-                    zf.close()
-                } catch (e) {
-                    // ignore
-                }
-            }
+            closeQuietly(zf)
         }
         return services
     }


Mime
View raw message