diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2015-10-01 17:29:36 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2015-10-01 17:44:06 +0900 |
commit | 58e290864ef599592e70285637abf6a538400e5d (patch) | |
tree | 88c2e7e542d7e8b0575244f4258b24190294d5aa /org.eclipse.jgit.ant/src/org/eclipse/jgit | |
parent | 3096ab6502471ec2f2f76040f72d31680e2b61ca (diff) | |
download | jgit-58e290864ef599592e70285637abf6a538400e5d.tar.gz jgit-58e290864ef599592e70285637abf6a538400e5d.zip |
ant: Open Repository and Git in try-with-resource
To prevent potential resource leak.
Change-Id: I3f4af9037c9d26ec575b529ab66066365ab918a5
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.ant/src/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java | 8 | ||||
-rw-r--r-- | org.eclipse.jgit.ant/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 c76ae2af8c..b9a868826e 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 14c4bc5700..9962472c9e 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); } |