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>
This commit is contained in:
David Pursehouse 2015-10-01 17:29:36 +09:00
parent 3096ab6502
commit 58e290864e
2 changed files with 8 additions and 8 deletions

View File

@ -117,10 +117,10 @@ public void execute() throws BuildException {
} }
AddCommand gitAdd; AddCommand gitAdd;
try { try (Repository repo = new FileRepositoryBuilder().readEnvironment()
Repository repo = new FileRepositoryBuilder().readEnvironment() .findGitDir(src).build();
.findGitDir(src).build(); Git git = new Git(repo);) {
gitAdd = new Git(repo).add(); 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);
} }

View File

@ -105,10 +105,10 @@ public void setForce(boolean force) {
@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(); Git git = new Git(repo)) {
checkout = new Git(repo).checkout(); 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);
} }