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:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user