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. 6
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java
  2. 6
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java

6
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java

@ -117,10 +117,10 @@ public class GitAddTask extends Task {
} }
AddCommand gitAdd; AddCommand gitAdd;
try { try (Repository repo = new FileRepositoryBuilder().readEnvironment()
Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build(); .findGitDir(src).build();
gitAdd = new Git(repo).add(); Git git = new Git(repo);) {
gitAdd = git.add();
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Could not access repository " + src, e); throw new BuildException("Could not access repository " + src, e);
} }

6
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java

@ -105,10 +105,10 @@ public class GitCheckoutTask extends Task {
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
CheckoutCommand checkout; CheckoutCommand checkout;
try { try (Repository repo = new FileRepositoryBuilder().readEnvironment()
Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build(); .findGitDir(src).build();
checkout = new Git(repo).checkout(); Git git = new Git(repo)) {
checkout = git.checkout();
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Could not access repository " + src, e); throw new BuildException("Could not access repository " + src, e);
} }

Loading…
Cancel
Save