You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/08/07 13:47:12 UTC

[commons-io] branch master updated: Restore binary compatibility in IOUtils with latest released version 2.7.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 5cbb4c7  Restore binary compatibility in IOUtils with latest released version 2.7.
5cbb4c7 is described below

commit 5cbb4c7c46be1e5b31a42745d84343e14b1f57db
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 7 09:47:06 2020 -0400

    Restore binary compatibility in IOUtils with latest released version
    2.7.
    
    - Refactor IOUtils to restore BC.
    - Make the GitHub build reuse the POM default goal.
    - Replace Apache CLIRR with JApiCmp since CLIRR is not Java 8 aware.
---
 .github/workflows/maven.yml                        |  2 +-
 pom.xml                                            |  3 ++-
 src/main/java/org/apache/commons/io/IOUtils.java   | 19 ++++++++++++++----
 .../org/apache/commons/io/IOUtilsTestCase.java     | 23 ++++++++++++++--------
 4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 7f2ed4d..63611cb 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -37,4 +37,4 @@ jobs:
       with:
         java-version: ${{ matrix.java }}
     - name: Build with Maven
-      run: mvn -V package --file pom.xml --no-transfer-progress
+      run: mvn -V --file pom.xml --no-transfer-progress
diff --git a/pom.xml b/pom.xml
index 40786b1..fce75b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -304,7 +304,8 @@ file comparators, endian transformation classes, and much more.
   </properties>
 
   <build>
-    <defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check javadoc:javadoc</defaultGoal>
+    <!-- japicmp:cmp needs package to work from a jar -->
+    <defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check javadoc:javadoc</defaultGoal>
     <pluginManagement>
       <plugins>
         <plugin>
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
index 73a2bb9..275c255 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -367,16 +367,27 @@ public class IOUtils {
     /**
      * Closes the given {@link Closeable} as a null-safe operation.
      *
-     * @param closeables The resource(s) to close, may be null.
+     * @param closeable The resource to close, may be null.
      * @throws IOException if an I/O error occurs.
      * @since 2.7
      */
+    public static void close(final Closeable closeable) throws IOException {
+        if (closeable != null) {
+            closeable.close();
+        }
+    }
+
+    /**
+     * Closes the given {@link Closeable} as a null-safe operation.
+     *
+     * @param closeables The resource(s) to close, may be null.
+     * @throws IOException if an I/O error occurs.
+     * @since 2.8.0
+     */
     public static void close(final Closeable... closeables) throws IOException {
         if (closeables != null) {
             for (Closeable closeable : closeables) {
-                if (closeable != null) {
-                    closeable.close();
-                }
+                close(closeable);
             }
         }
     }
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
index 82ae8f4..bfe96a2 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -146,16 +146,20 @@ public class IOUtilsTestCase {
         assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s"))));
     }
 
-    @Test public void testCloseMulti() {
+    @Test
+    public void testCloseMulti() {
         Closeable nulCloseable = null;
-        Closeable [] closeables = {null, null};
-        assertDoesNotThrow(() -> IOUtils.close(nulCloseable,nulCloseable));
+        Closeable[] closeables = {null, null};
+        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, nulCloseable));
         assertDoesNotThrow(() -> IOUtils.close(closeables));
-        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"),nulCloseable));
-        assertThrows(IOException.class, () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
+        assertDoesNotThrow(() -> IOUtils.close((Closeable[]) null));
+        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), nulCloseable));
+        assertThrows(IOException.class,
+            () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
     }
 
-    @Test public void testCloseConsumer() {
+    @Test
+    public void testCloseConsumer() {
         Closeable nulCloseable = null;
         assertDoesNotThrow(() -> IOUtils.close(nulCloseable, null)); // null consumer
         assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), null)); // null consumer
@@ -171,10 +175,13 @@ public class IOUtilsTestCase {
         assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), silentConsumer));
         assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), silentConsumer));
 
-        final IOConsumer<IOException> noisyConsumer = i -> {throw i;}; // consumer passes on the throw
+        final IOConsumer<IOException> noisyConsumer = i -> {
+            throw i;
+        }; // consumer passes on the throw
         assertDoesNotThrow(() -> IOUtils.close(nulCloseable, noisyConsumer)); // no throw
         assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), noisyConsumer)); // no throw
-        assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")),noisyConsumer)); // closeable throws
+        assertThrows(IOException.class,
+            () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), noisyConsumer)); // closeable throws
     }
 
     @Test public void testCloseQuietly_AllCloseableIOException() {


Re: [commons-io] branch master updated: Restore binary compatibility in IOUtils with latest released version 2.7.

Posted by sebb <se...@gmail.com>.
On Fri, 7 Aug 2020 at 14:47, <gg...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> ggregory pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-io.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
>      new 5cbb4c7  Restore binary compatibility in IOUtils with latest released version 2.7.
> 5cbb4c7 is described below
>
> commit 5cbb4c7c46be1e5b31a42745d84343e14b1f57db
> Author: Gary Gregory <ga...@gmail.com>
> AuthorDate: Fri Aug 7 09:47:06 2020 -0400
>
>     Restore binary compatibility in IOUtils with latest released version
>     2.7.
>
>     - Refactor IOUtils to restore BC.
>     - Make the GitHub build reuse the POM default goal.
>     - Replace Apache CLIRR with JApiCmp since CLIRR is not Java 8 aware.

These are unrelated changes and should please be committed as such.

> ---
>  .github/workflows/maven.yml                        |  2 +-
>  pom.xml                                            |  3 ++-
>  src/main/java/org/apache/commons/io/IOUtils.java   | 19 ++++++++++++++----
>  .../org/apache/commons/io/IOUtilsTestCase.java     | 23 ++++++++++++++--------
>  4 files changed, 33 insertions(+), 14 deletions(-)
>
> diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
> index 7f2ed4d..63611cb 100644
> --- a/.github/workflows/maven.yml
> +++ b/.github/workflows/maven.yml
> @@ -37,4 +37,4 @@ jobs:
>        with:
>          java-version: ${{ matrix.java }}
>      - name: Build with Maven
> -      run: mvn -V package --file pom.xml --no-transfer-progress
> +      run: mvn -V --file pom.xml --no-transfer-progress
> diff --git a/pom.xml b/pom.xml
> index 40786b1..fce75b7 100644
> --- a/pom.xml
> +++ b/pom.xml
> @@ -304,7 +304,8 @@ file comparators, endian transformation classes, and much more.
>    </properties>
>
>    <build>
> -    <defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check javadoc:javadoc</defaultGoal>
> +    <!-- japicmp:cmp needs package to work from a jar -->
> +    <defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check javadoc:javadoc</defaultGoal>
>      <pluginManagement>
>        <plugins>
>          <plugin>
> diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
> index 73a2bb9..275c255 100644
> --- a/src/main/java/org/apache/commons/io/IOUtils.java
> +++ b/src/main/java/org/apache/commons/io/IOUtils.java
> @@ -367,16 +367,27 @@ public class IOUtils {
>      /**
>       * Closes the given {@link Closeable} as a null-safe operation.
>       *
> -     * @param closeables The resource(s) to close, may be null.
> +     * @param closeable The resource to close, may be null.
>       * @throws IOException if an I/O error occurs.
>       * @since 2.7
>       */
> +    public static void close(final Closeable closeable) throws IOException {
> +        if (closeable != null) {
> +            closeable.close();
> +        }
> +    }
> +
> +    /**
> +     * Closes the given {@link Closeable} as a null-safe operation.
> +     *
> +     * @param closeables The resource(s) to close, may be null.
> +     * @throws IOException if an I/O error occurs.
> +     * @since 2.8.0
> +     */
>      public static void close(final Closeable... closeables) throws IOException {
>          if (closeables != null) {
>              for (Closeable closeable : closeables) {
> -                if (closeable != null) {
> -                    closeable.close();
> -                }
> +                close(closeable);
>              }
>          }
>      }
> diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
> index 82ae8f4..bfe96a2 100644
> --- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
> +++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
> @@ -146,16 +146,20 @@ public class IOUtilsTestCase {
>          assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s"))));
>      }
>
> -    @Test public void testCloseMulti() {
> +    @Test
> +    public void testCloseMulti() {
>          Closeable nulCloseable = null;
> -        Closeable [] closeables = {null, null};
> -        assertDoesNotThrow(() -> IOUtils.close(nulCloseable,nulCloseable));
> +        Closeable[] closeables = {null, null};
> +        assertDoesNotThrow(() -> IOUtils.close(nulCloseable, nulCloseable));
>          assertDoesNotThrow(() -> IOUtils.close(closeables));
> -        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"),nulCloseable));
> -        assertThrows(IOException.class, () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
> +        assertDoesNotThrow(() -> IOUtils.close((Closeable[]) null));
> +        assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), nulCloseable));
> +        assertThrows(IOException.class,
> +            () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
>      }
>
> -    @Test public void testCloseConsumer() {
> +    @Test
> +    public void testCloseConsumer() {
>          Closeable nulCloseable = null;
>          assertDoesNotThrow(() -> IOUtils.close(nulCloseable, null)); // null consumer
>          assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), null)); // null consumer
> @@ -171,10 +175,13 @@ public class IOUtilsTestCase {
>          assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), silentConsumer));
>          assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), silentConsumer));
>
> -        final IOConsumer<IOException> noisyConsumer = i -> {throw i;}; // consumer passes on the throw
> +        final IOConsumer<IOException> noisyConsumer = i -> {
> +            throw i;
> +        }; // consumer passes on the throw
>          assertDoesNotThrow(() -> IOUtils.close(nulCloseable, noisyConsumer)); // no throw
>          assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), noisyConsumer)); // no throw
> -        assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")),noisyConsumer)); // closeable throws
> +        assertThrows(IOException.class,
> +            () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), noisyConsumer)); // closeable throws
>      }
>
>      @Test public void testCloseQuietly_AllCloseableIOException() {
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org