Browse Source

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 <matthias.sohn@sap.com>
tags/v4.0.0.201503231230-m1
Matthias Sohn 9 years ago
parent
commit
77030a5e94

+ 16
- 3
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java View File

* the ancestor, until there are no more lines to acquire information on, or the * the ancestor, until there are no more lines to acquire information on, or the
* file's creation point is discovered in history. * file's creation point is discovered in history.
*/ */
public class BlameGenerator {
public class BlameGenerator implements AutoCloseable {
private final Repository repository; private final Repository repository;


private final PathFilter resultPath; private final PathFilter resultPath;
return queue != null ? queue.sourceText : null; return queue != null ? queue.sourceText : null;
} }


/** Release the current blame session. */
/**
* Release the current blame session. Use {@link #close()} instead.
*/
@Deprecated
public void release() { public void release() {
revPool.release();
close();
}

/**
* Release the current blame session.
*
* @since 4.0
*/
@Override
public void close() {
revPool.close();
queue = null; queue = null;
outCandidate = null; outCandidate = null;
outRegion = null; outRegion = null;

+ 16
- 3
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java View File

/** /**
* Format a Git style patch script. * 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 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$ private static final byte[] noNewLine = encodeASCII("\\ No newline at end of file\n"); //$NON-NLS-1$
out.flush(); out.flush();
} }


/** Release the internal ObjectReader state. */
/**
* Release the internal ObjectReader state. Use {@link #close()} instead.
*/
@Deprecated
public void release() { public void release() {
close();
}

/**
* Release the internal ObjectReader state.
*
* @since 4.0
*/
@Override
public void close() {
if (reader != null) if (reader != null)
reader.release();
reader.close();
} }


/** /**

+ 16
- 3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java View File

* undefined behavior. * undefined behavior.
* </p> * </p>
*/ */
public class PackWriter {
public class PackWriter implements AutoCloseable {
private static final int PACK_VERSION_GENERATED = 2; private static final int PACK_VERSION_GENERATED = 2;


/** A collection of object ids. */ /** A collection of object ids. */
return state.snapshot(); 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() { 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) { if (myDeflater != null) {
myDeflater.end(); myDeflater.end();
myDeflater = null; myDeflater = null;

+ 16
- 2
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java View File

* {@link #release()} or {@link #flush()} prior to updating references or * {@link #release()} or {@link #flush()} prior to updating references or
* otherwise making the returned ObjectIds visible to other code. * 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. */ /** An inserter that can be used for formatting and id generation only. */
public static class Formatter extends ObjectInserter { public static class Formatter extends ObjectInserter {
@Override @Override
* Release any resources used by this inserter. * Release any resources used by this inserter.
* <p> * <p>
* An inserter that has been released can be used again, but may need to be * 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(); public abstract void release();

/**
* Release any resources used by this inserter.
* <p>
* 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();
}
} }

+ 16
- 2
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java View File

* Readers that can support efficient reuse of pack encoded objects should also * Readers that can support efficient reuse of pack encoded objects should also
* implement the companion interface {@link ObjectReuseAsIs}. * 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. */ /** Type hint indicating the caller doesn't know the type. */
public static final int OBJ_ANY = -1; public static final int OBJ_ANY = -1;


* Release any resources used by this reader. * Release any resources used by this reader.
* <p> * <p>
* A reader that has been released can be used again, but may need to be * 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() { public void release() {
close();
}

/**
* Release any resources used by this reader.
* <p>
* 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. // Do nothing.
} }
} }

+ 17
- 3
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java View File

* the same RevWalk at the same time. The Iterator may buffer RevCommits, while * the same RevWalk at the same time. The Iterator may buffer RevCommits, while
* {@link #next()} does not. * {@link #next()} does not.
*/ */
public class RevWalk implements Iterable<RevCommit> {
public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
private static final int MB = 1 << 20; private static final int MB = 1 << 20;


/** /**
* Release any resources used by this walker's reader. * Release any resources used by this walker's reader.
* <p> * <p>
* A walker that has been released can be used again, but may need to be * 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() { public void release() {
reader.release();
close();
}

/**
* Release any resources used by this walker's reader.
* <p>
* 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();
} }


/** /**

+ 17
- 3
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java View File

/** /**
* Walker that visits all submodule entries found in a tree * 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.<name>.ignore * The values for the config param submodule.<name>.ignore
return url != null ? getSubmoduleRemoteUrl(repository, url) : null; 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() { public void release() {
walk.release();
close();
}

/**
* Release any resources used by this walker's reader.
*
* @since 4.0
*/
@Override
public void close() {
walk.close();
} }
} }

+ 17
- 3
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java View File

* Multiple simultaneous TreeWalk instances per {@link Repository} are * Multiple simultaneous TreeWalk instances per {@link Repository} are
* permitted, even from concurrent threads. * permitted, even from concurrent threads.
*/ */
public class TreeWalk {
public class TreeWalk implements AutoCloseable {
private static final AbstractTreeIterator[] NO_TREES = {}; private static final AbstractTreeIterator[] NO_TREES = {};


/** /**
* Release any resources used by this walker's reader. * Release any resources used by this walker's reader.
* <p> * <p>
* A walker that has been released can be used again, but may need to be * 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() { public void release() {
reader.release();
close();
}

/**
* Release any resources used by this walker's reader.
* <p>
* 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();
} }


/** /**

Loading…
Cancel
Save