Browse Source

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>
stable-4.1
David Pursehouse 9 years ago
parent
commit
58e290864e
  1. 8
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java
  2. 8
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java

8
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);
}

8
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);
}

Loading…
Cancel
Save