Polish "Use try-with-resources to close resources automatically"

- Apply code formatting
- Use try-with-resources in many other places that were missed in the
  pull request

Closes gh-8045
This commit is contained in:
Andy Wilkinson
2017-05-23 17:24:01 +01:00
parent 3e797c326a
commit d5438c299c
78 changed files with 284 additions and 703 deletions

View File

@@ -205,21 +205,18 @@ public class StartMojo extends AbstractRunMojo {
throws IOException, MojoFailureException, MojoExecutionException {
try {
getLog().debug("Connecting to local MBeanServer at port " + this.jmxPort);
JMXConnector connector = execute(this.wait, this.maxAttempts,
new CreateJmxConnector(this.jmxPort));
if (connector == null) {
throw new MojoExecutionException(
"JMX MBean server was not reachable before the configured "
+ "timeout (" + (this.wait * this.maxAttempts) + "ms");
}
getLog().debug("Connected to local MBeanServer at port " + this.jmxPort);
try {
try (JMXConnector connector = execute(this.wait, this.maxAttempts,
new CreateJmxConnector(this.jmxPort))) {
if (connector == null) {
throw new MojoExecutionException(
"JMX MBean server was not reachable before the configured "
+ "timeout (" + (this.wait * this.maxAttempts)
+ "ms");
}
getLog().debug("Connected to local MBeanServer at port " + this.jmxPort);
MBeanServerConnection connection = connector.getMBeanServerConnection();
doWaitForSpringApplication(connection);
}
finally {
connector.close();
}
}
catch (IOException ex) {
throw ex;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,14 +110,11 @@ public class StopMojo extends AbstractMojo {
private void stopForkedProcess()
throws IOException, MojoFailureException, MojoExecutionException {
JMXConnector connector = SpringApplicationAdminClient.connect(this.jmxPort);
try {
try (JMXConnector connector = SpringApplicationAdminClient
.connect(this.jmxPort)) {
MBeanServerConnection connection = connector.getMBeanServerConnection();
doStop(connection);
}
finally {
connector.close();
}
}
private void stop() throws IOException, MojoFailureException, MojoExecutionException {

View File

@@ -198,14 +198,10 @@ public final class Verify {
.startsWith(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }));
}
ZipFile zipFile = new ZipFile(this.file);
try {
try (ZipFile zipFile = new ZipFile(this.file)) {
ArchiveVerifier verifier = new ArchiveVerifier(zipFile);
verifyZipEntries(verifier);
}
finally {
zipFile.close();
}
}
protected void verifyZipEntries(ArchiveVerifier verifier) throws Exception {