From 1952c6f91acc144f1b435bc627c0b46845c1650c Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:23:51 -0800 Subject: [PATCH 1/5] Compile on JDK 6, 7, and 8 Ensure that all JDKs are supported. --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b43b6822..3c13ded18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ notifications: email: false before_install: chmod +x gradlew install: ./gradlew setupCIWorkspace -S -matrix: - include: - - jdk: oraclejdk7 - script: ./gradlew build -S \ No newline at end of file +script: ./gradlew build -S +jdk: + - oraclejdk8 + - oraclejdk7 + - openjdk6 From c14a3dfbde68f3bfd1debb8f51499715340cf11c Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:24:59 -0800 Subject: [PATCH 2/5] Add caching to Travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3c13ded18..f1f614733 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,10 @@ jdk: - oraclejdk8 - oraclejdk7 - openjdk6 +# Caching for Gradle files, prevents hitting Maven too much. +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ From 53b8f08e5eb0d42895eea77e5d5fb24919b6cf29 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:25:32 -0800 Subject: [PATCH 3/5] Have Travis give less verbose stack traces --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f1f614733..d7da99ae4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: java notifications: email: false before_install: chmod +x gradlew -install: ./gradlew setupCIWorkspace -S -script: ./gradlew build -S +install: ./gradlew setupCIWorkspace -s +script: ./gradlew build -s jdk: - oraclejdk8 - oraclejdk7 From 9dac0b30dbde2bc0c07541f609d2c6fda180c628 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:27:07 -0800 Subject: [PATCH 4/5] Speed up Travis by running on non-sudo containers See why at https://docs.travis-ci.com/user/workers/container-based-infrastructure/ --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d7da99ae4..e526c902f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,6 @@ cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ + +# Faster builds without sudo. +sudo: false From 982420369d7709c6732261708d1f075245d99286 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 22:26:30 -0800 Subject: [PATCH 5/5] Rewrite Closer to compile on Java 6 wrt Jar/ZipFile. --- .../com/sk89q/worldedit/util/io/Closer.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java index 2e733c6ab..6b5c37efe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java @@ -29,6 +29,7 @@ import java.util.ArrayDeque; import java.util.Deque; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.zip.ZipFile; import static com.google.common.base.Preconditions.checkNotNull; @@ -55,6 +56,7 @@ public final class Closer implements Closeable { // only need space for 2 elements in most cases, so try to use the smallest array possible private final Deque stack = new ArrayDeque(4); + private final Deque zipStack = new ArrayDeque(4); private Throwable thrown; @VisibleForTesting Closer(Suppressor suppressor) { @@ -73,6 +75,17 @@ public final class Closer implements Closeable { return closeable; } + /** + * Registers the given {@code zipFile} to be closed when this {@code Closer} is + * {@linkplain #close closed}. + * + * @return the given {@code closeable} + */ + public Z register(Z zipFile) { + zipStack.push(zipFile); + return zipFile; + } + /** * Stores the given throwable and rethrows it. It will be rethrown as is if it is an * {@code IOException}, {@code RuntimeException} or {@code Error}. Otherwise, it will be rethrown @@ -161,6 +174,18 @@ public final class Closer implements Closeable { } } } + while (!zipStack.isEmpty()) { + ZipFile zipFile = zipStack.pop(); + try { + zipFile.close(); + } catch (Throwable e) { + if (throwable == null) { + throwable = e; + } else { + suppressor.suppress(zipFile, throwable, e); + } + } + } if (thrown == null && throwable != null) { Throwables.propagateIfPossible(throwable, IOException.class); @@ -177,7 +202,7 @@ public final class Closer implements Closeable { * the given closeable. {@code thrown} is the exception that is actually being thrown from the * method. Implementations of this method should not throw under any circumstances. */ - void suppress(Closeable closeable, Throwable thrown, Throwable suppressed); + void suppress(Object closeable, Throwable thrown, Throwable suppressed); } /** @@ -188,7 +213,7 @@ public final class Closer implements Closeable { static final LoggingSuppressor INSTANCE = new LoggingSuppressor(); @Override - public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) { + public void suppress(Object closeable, Throwable thrown, Throwable suppressed) { // log to the same place as Closeables logger.log(Level.WARNING, "Suppressing exception thrown when closing " + closeable, suppressed); } @@ -217,7 +242,7 @@ public final class Closer implements Closeable { } @Override - public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) { + public void suppress(Object closeable, Throwable thrown, Throwable suppressed) { // ensure no exceptions from addSuppressed if (thrown == suppressed) { return;