From 58e290864ef599592e70285637abf6a538400e5d Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 1 Oct 2015 17:29:36 +0900 Subject: [PATCH] ant: Open Repository and Git in try-with-resource To prevent potential resource leak. Change-Id: I3f4af9037c9d26ec575b529ab66066365ab918a5 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/ant/tasks/GitAddTask.java | 8 ++++---- .../src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java index c76ae2af8..b9a868826 100644 --- a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java +++ b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java @@ -117,10 +117,10 @@ public class GitAddTask extends Task { } AddCommand gitAdd; - try { - Repository repo = new FileRepositoryBuilder().readEnvironment() - .findGitDir(src).build(); - gitAdd = new Git(repo).add(); + try (Repository repo = new FileRepositoryBuilder().readEnvironment() + .findGitDir(src).build(); + Git git = new Git(repo);) { + gitAdd = git.add(); } catch (IOException e) { throw new BuildException("Could not access repository " + src, e); } diff --git a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java index 14c4bc570..9962472c9 100644 --- a/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java +++ b/org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java @@ -105,10 +105,10 @@ public class GitCheckoutTask extends Task { @Override public void execute() throws BuildException { CheckoutCommand checkout; - try { - Repository repo = new FileRepositoryBuilder().readEnvironment() - .findGitDir(src).build(); - checkout = new Git(repo).checkout(); + try (Repository repo = new FileRepositoryBuilder().readEnvironment() + .findGitDir(src).build(); + Git git = new Git(repo)) { + checkout = git.checkout(); } catch (IOException e) { throw new BuildException("Could not access repository " + src, e); }