Skip to content

Commit

Permalink
Merge pull request #339 from sk89q/feature/improved-travis-builds
Browse files Browse the repository at this point in the history
Improve Travis builds
  • Loading branch information
wizjany committed Feb 5, 2016
2 parents 03f8843 + 9824203 commit 3bd87cf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
21 changes: 16 additions & 5 deletions .travis.yml
Expand Up @@ -2,8 +2,19 @@ language: java
notifications:
email: false
before_install: chmod +x gradlew
install: ./gradlew setupCIWorkspace -S
matrix:
include:
- jdk: oraclejdk7
script: ./gradlew build -S
install: ./gradlew setupCIWorkspace -s
script: ./gradlew build -s
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/

# Faster builds without sudo.
sudo: false
Expand Up @@ -29,6 +29,7 @@
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;

Expand All @@ -55,6 +56,7 @@ public static Closer create() {

// only need space for 2 elements in most cases, so try to use the smallest array possible
private final Deque<Closeable> stack = new ArrayDeque<Closeable>(4);
private final Deque<ZipFile> zipStack = new ArrayDeque<ZipFile>(4);
private Throwable thrown;

@VisibleForTesting Closer(Suppressor suppressor) {
Expand All @@ -73,6 +75,17 @@ public <C extends Closeable> C register(C 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 extends ZipFile> 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
Expand Down Expand Up @@ -161,6 +174,18 @@ public void close() throws IOException {
}
}
}
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);
Expand All @@ -177,7 +202,7 @@ public void close() throws IOException {
* 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);
}

/**
Expand All @@ -188,7 +213,7 @@ public void close() throws IOException {
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);
}
Expand Down Expand Up @@ -217,7 +242,7 @@ private static Method getAddSuppressed() {
}

@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;
Expand Down

0 comments on commit 3bd87cf

Please sign in to comment.