From 77030a5e94a90cfae223acc477c216603cf3f149 Mon Sep 17 00:00:00 2001
From: Matthias Sohn
Date: Tue, 27 Jan 2015 16:06:38 +0100
Subject: [PATCH] Implement AutoClosable interface on classes that used
release()
Implement AutoClosable and deprecate the old release() method to give
JGit consumers some time to adapt.
Bug: 428039
Change-Id: Id664a91dc5a8cf2ac401e7d87ce2e3b89e221458
Signed-off-by: Matthias Sohn
---
.../eclipse/jgit/blame/BlameGenerator.java | 19 +++++++++++++++---
.../org/eclipse/jgit/diff/DiffFormatter.java | 19 +++++++++++++++---
.../internal/storage/pack/PackWriter.java | 19 +++++++++++++++---
.../org/eclipse/jgit/lib/ObjectInserter.java | 18 +++++++++++++++--
.../org/eclipse/jgit/lib/ObjectReader.java | 18 +++++++++++++++--
.../src/org/eclipse/jgit/revwalk/RevWalk.java | 20 ++++++++++++++++---
.../eclipse/jgit/submodule/SubmoduleWalk.java | 20 ++++++++++++++++---
.../org/eclipse/jgit/treewalk/TreeWalk.java | 20 ++++++++++++++++---
8 files changed, 131 insertions(+), 22 deletions(-)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
index e69cfa9d1..eb64425c6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
@@ -113,7 +113,7 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter;
* the ancestor, until there are no more lines to acquire information on, or the
* file's creation point is discovered in history.
*/
-public class BlameGenerator {
+public class BlameGenerator implements AutoCloseable {
private final Repository repository;
private final PathFilter resultPath;
@@ -937,9 +937,22 @@ public class BlameGenerator {
return queue != null ? queue.sourceText : null;
}
- /** Release the current blame session. */
+ /**
+ * Release the current blame session. Use {@link #close()} instead.
+ */
+ @Deprecated
public void release() {
- revPool.release();
+ close();
+ }
+
+ /**
+ * Release the current blame session.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ revPool.close();
queue = null;
outCandidate = null;
outRegion = null;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index d339d6a65..1aab51e9c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -104,7 +104,7 @@ import org.eclipse.jgit.util.io.DisabledOutputStream;
/**
* Format a Git style patch script.
*/
-public class DiffFormatter {
+public class DiffFormatter implements AutoCloseable {
private static final int DEFAULT_BINARY_FILE_THRESHOLD = PackConfig.DEFAULT_BIG_FILE_THRESHOLD;
private static final byte[] noNewLine = encodeASCII("\\ No newline at end of file\n"); //$NON-NLS-1$
@@ -380,10 +380,23 @@ public class DiffFormatter {
out.flush();
}
- /** Release the internal ObjectReader state. */
+ /**
+ * Release the internal ObjectReader state. Use {@link #close()} instead.
+ */
+ @Deprecated
public void release() {
+ close();
+ }
+
+ /**
+ * Release the internal ObjectReader state.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
if (reader != null)
- reader.release();
+ reader.close();
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index 164934704..510538d86 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
@@ -152,7 +152,7 @@ import org.eclipse.jgit.util.TemporaryBuffer;
* undefined behavior.
*
*/
-public class PackWriter {
+public class PackWriter implements AutoCloseable {
private static final int PACK_VERSION_GENERATED = 2;
/** A collection of object ids. */
@@ -1085,9 +1085,22 @@ public class PackWriter {
return state.snapshot();
}
- /** Release all resources used by this writer. */
+ /**
+ * Release all resources used by this writer. Use {@link #close()} instead.
+ */
+ @Deprecated
public void release() {
- reader.release();
+ close();
+ }
+
+ /**
+ * Release all resources used by this writer.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ reader.close();
if (myDeflater != null) {
myDeflater.end();
myDeflater = null;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
index 5c13ef354..f05326900 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
@@ -66,7 +66,7 @@ import org.eclipse.jgit.transport.PackParser;
* {@link #release()} or {@link #flush()} prior to updating references or
* otherwise making the returned ObjectIds visible to other code.
*/
-public abstract class ObjectInserter {
+public abstract class ObjectInserter implements AutoCloseable {
/** An inserter that can be used for formatting and id generation only. */
public static class Formatter extends ObjectInserter {
@Override
@@ -420,7 +420,21 @@ public abstract class ObjectInserter {
* Release any resources used by this inserter.
*
* An inserter that has been released can be used again, but may need to be
- * released after the subsequent usage.
+ * released after the subsequent usage. Use {@link #close()} instead
*/
+ @Deprecated
public abstract void release();
+
+ /**
+ * Release any resources used by this inserter.
+ *
+ * An inserter that has been released can be used again, but may need to be
+ * released after the subsequent usage.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ release();
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
index 58c141870..524dafb88 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
@@ -63,7 +63,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
* Readers that can support efficient reuse of pack encoded objects should also
* implement the companion interface {@link ObjectReuseAsIs}.
*/
-public abstract class ObjectReader {
+public abstract class ObjectReader implements AutoCloseable {
/** Type hint indicating the caller doesn't know the type. */
public static final int OBJ_ANY = -1;
@@ -466,9 +466,23 @@ public abstract class ObjectReader {
* Release any resources used by this reader.
*
* A reader that has been released can be used again, but may need to be
- * released after the subsequent usage.
+ * released after the subsequent usage. Use {@link #close()} instead.
*/
+ @Deprecated
public void release() {
+ close();
+ }
+
+ /**
+ * Release any resources used by this reader.
+ *
+ * A reader that has been released can be used again, but may need to be
+ * released after the subsequent usage.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
// Do nothing.
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index d19e467c1..55ffac7c5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -95,7 +95,7 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter;
* the same RevWalk at the same time. The Iterator may buffer RevCommits, while
* {@link #next()} does not.
*/
-public class RevWalk implements Iterable {
+public class RevWalk implements Iterable, AutoCloseable {
private static final int MB = 1 << 20;
/**
@@ -237,10 +237,24 @@ public class RevWalk implements Iterable {
* Release any resources used by this walker's reader.
*
* A walker that has been released can be used again, but may need to be
- * released after the subsequent usage.
+ * released after the subsequent usage. Use {@link #close()} instead.
*/
+ @Deprecated
public void release() {
- reader.release();
+ close();
+ }
+
+ /**
+ * Release any resources used by this walker's reader.
+ *
+ * A walker that has been released can be used again, but may need to be
+ * released after the subsequent usage.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ reader.close();
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
index 5db3378b7..a01f006c4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
@@ -76,7 +76,7 @@ import org.eclipse.jgit.util.FS;
/**
* Walker that visits all submodule entries found in a tree
*/
-public class SubmoduleWalk {
+public class SubmoduleWalk implements AutoCloseable {
/**
* The values for the config param submodule..ignore
@@ -729,8 +729,22 @@ public class SubmoduleWalk {
return url != null ? getSubmoduleRemoteUrl(repository, url) : null;
}
- /** Release any resources used by this walker's reader. */
+ /**
+ * Release any resources used by this walker's reader. Use {@link #close()}
+ * instead.
+ */
+ @Deprecated
public void release() {
- walk.release();
+ close();
+ }
+
+ /**
+ * Release any resources used by this walker's reader.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ walk.close();
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
index 94281fba1..577c9e303 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -82,7 +82,7 @@ import org.eclipse.jgit.util.RawParseUtils;
* Multiple simultaneous TreeWalk instances per {@link Repository} are
* permitted, even from concurrent threads.
*/
-public class TreeWalk {
+public class TreeWalk implements AutoCloseable {
private static final AbstractTreeIterator[] NO_TREES = {};
/**
@@ -247,10 +247,24 @@ public class TreeWalk {
* Release any resources used by this walker's reader.
*
* A walker that has been released can be used again, but may need to be
- * released after the subsequent usage.
+ * released after the subsequent usage. Use {@link #close()} instead.
*/
+ @Deprecated
public void release() {
- reader.release();
+ close();
+ }
+
+ /**
+ * Release any resources used by this walker's reader.
+ *
+ * A walker that has been released can be used again, but may need to be
+ * released after the subsequent usage.
+ *
+ * @since 4.0
+ */
+ @Override
+ public void close() {
+ reader.close();
}
/**