From df19c137b95f562df622849ca73a78b8017f89d2 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Thu, 11 Jun 2015 21:58:49 -0400 Subject: [PATCH] Made every variable final where possible. --- .../maven/plugins/mongodb/PortUtils.java | 6 ++-- .../maven/plugins/mongodb/StartMongoMojo.java | 28 +++++++++---------- .../maven/plugins/mongodb/StopMongoMojo.java | 2 +- .../log/FileOutputStreamProcessor.java | 10 +++---- .../maven/plugins/mongodb/log/Loggers.java | 6 ++-- .../mongodb/log/NoopStreamProcessor.java | 2 +- .../maven/plugins/mongodb/PortUtilsTest.java | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/PortUtils.java b/src/main/java/com/syncleus/maven/plugins/mongodb/PortUtils.java index e174b89..3939770 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/PortUtils.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/PortUtils.java @@ -26,11 +26,11 @@ public final class PortUtils { public static int allocateRandomPort() { try { - ServerSocket server = new ServerSocket(0); - int port = server.getLocalPort(); + final ServerSocket server = new ServerSocket(0); + final int port = server.getLocalPort(); server.close(); return port; - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException("Failed to acquire a random free port", e); } } diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java b/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java index 84cf476..292797a 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/StartMongoMojo.java @@ -224,7 +224,7 @@ public class StartMongoMojo extends AbstractMojo { this.addProxySelector(); } - MongodExecutable executable; + final MongodExecutable executable; try { final ICommandLinePostProcessor commandLinePostProcessor; @@ -241,7 +241,7 @@ public class StartMongoMojo extends AbstractMojo { commandLinePostProcessor = new ICommandLinePostProcessor.Noop(); } - IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder() + final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder() .defaults(Command.MongoD) .processOutput(getOutputConfig()) .artifactStore(getArtifactStore()) @@ -253,36 +253,36 @@ public class StartMongoMojo extends AbstractMojo { } savePortToProjectProperties(); - IMongodConfig config = new MongodConfigBuilder() + final IMongodConfig config = new MongodConfigBuilder() .version((getVersion() == null || getVersion().equals("") ? Version.Main.PRODUCTION : getVersion())) .net(new Net(bindIp, port, Network.localhostIsIPv6())) .replication(new Storage(getDataDirectory(), replSet, oplogSize)) .build(); executable = MongodStarter.getInstance(runtimeConfig).prepare(config); - } catch (UnknownHostException e) { + } catch (final UnknownHostException e) { throw new MojoExecutionException("Unable to determine if localhost is ipv6", e); - } catch (DistributionException e) { + } catch (final DistributionException e) { throw new MojoExecutionException("Failed to download MongoDB distribution: " + e.withDistribution(), e); - } catch (IOException e) { + } catch (final IOException e) { throw new MojoExecutionException("Unable to Config MongoDB: ", e); } try { - MongodProcess mongod = executable.start(); + final MongodProcess mongod = executable.start(); if (wait) { while (true) { try { TimeUnit.MINUTES.sleep(5); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { break; } } } getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod); - } catch (IOException e) { + } catch (final IOException e) { throw new MojoExecutionException("Unable to start the mongod", e); } } @@ -298,7 +298,7 @@ public class StartMongoMojo extends AbstractMojo { private ProcessOutput getOutputConfig() throws MojoFailureException { - LoggingStyle loggingStyle = LoggingStyle.valueOf(logging.toUpperCase()); + final LoggingStyle loggingStyle = LoggingStyle.valueOf(logging.toUpperCase()); switch (loggingStyle) { case CONSOLE: @@ -315,7 +315,7 @@ public class StartMongoMojo extends AbstractMojo { } private IArtifactStore getArtifactStore() { - IDownloadConfig downloadConfig = new DownloadConfigBuilder().defaultsForCommand(Command.MongoD).downloadPath(downloadPath).build(); + final IDownloadConfig downloadConfig = new DownloadConfigBuilder().defaultsForCommand(Command.MongoD).downloadPath(downloadPath).build(); return new ArtifactStoreBuilder().defaults(Command.MongoD).download(downloadConfig).build(); } @@ -334,7 +334,7 @@ public class StartMongoMojo extends AbstractMojo { final ProxySelector defaultProxySelector = ProxySelector.getDefault(); ProxySelector.setDefault(new ProxySelector() { @Override - public List<Proxy> select(URI uri) { + public List<Proxy> select(final URI uri) { if (uri.getHost().equals("fastdl.mongodb.org")) { return singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))); } else { @@ -343,7 +343,7 @@ public class StartMongoMojo extends AbstractMojo { } @Override - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + public void connectFailed(final URI uri, final SocketAddress sa, final IOException ioe) { } }); } @@ -357,7 +357,7 @@ public class StartMongoMojo extends AbstractMojo { try { return Version.valueOf(versionEnumName); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { getLog().warn("Unrecognised MongoDB version '" + this.version + "', this might be a new version that we don't yet know about. Attemping download anyway..."); return Versions.withFeatures(new IVersion() { @Override diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java b/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java index 4a40bed..427d280 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/StopMongoMojo.java @@ -41,7 +41,7 @@ public class StopMongoMojo extends AbstractMojo { return; } - MongodProcess mongod = (MongodProcess) getPluginContext().get(StartMongoMojo + final MongodProcess mongod = (MongodProcess) getPluginContext().get(StartMongoMojo .MONGOD_CONTEXT_PROPERTY_NAME); if (mongod != null) { diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/log/FileOutputStreamProcessor.java b/src/main/java/com/syncleus/maven/plugins/mongodb/log/FileOutputStreamProcessor.java index da58d1a..ca7cb7b 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/log/FileOutputStreamProcessor.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/log/FileOutputStreamProcessor.java @@ -29,13 +29,13 @@ public class FileOutputStreamProcessor implements IStreamProcessor { private String logFile; private String encoding; - public FileOutputStreamProcessor(String logFile, String encoding) { + public FileOutputStreamProcessor(final String logFile, final String encoding) { setLogFile(logFile); setEncoding(encoding); } @Override - public synchronized void process(String block) { + public synchronized void process(final String block) { try { if (stream == null) { @@ -45,7 +45,7 @@ public class FileOutputStreamProcessor implements IStreamProcessor { stream.write(block); stream.flush(); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } } @@ -55,14 +55,14 @@ public class FileOutputStreamProcessor implements IStreamProcessor { process("\n"); } - private void setLogFile(String logFile) { + private void setLogFile(final String logFile) { if (logFile == null || logFile.trim().length() == 0) { throw new IllegalArgumentException("no logFile given"); } this.logFile = logFile; } - private void setEncoding(String encoding) { + private void setEncoding(final String encoding) { if (encoding == null || encoding.trim().length() == 0) { throw new IllegalArgumentException("no encoding given"); } diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/log/Loggers.java b/src/main/java/com/syncleus/maven/plugins/mongodb/log/Loggers.java index a84a244..78b3b37 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/log/Loggers.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/log/Loggers.java @@ -23,8 +23,8 @@ import de.flapdoodle.embed.process.io.NamedOutputStreamProcessor; public class Loggers { - public static ProcessOutput file(String logFile, String encoding) { - FileOutputStreamProcessor file = new FileOutputStreamProcessor(logFile, encoding); + public static ProcessOutput file(final String logFile, final String encoding) { + final FileOutputStreamProcessor file = new FileOutputStreamProcessor(logFile, encoding); return new ProcessOutput( new NamedOutputStreamProcessor("[mongod output]", file), @@ -37,7 +37,7 @@ public class Loggers { } public static ProcessOutput none() { - NoopStreamProcessor noop = new NoopStreamProcessor(); + final NoopStreamProcessor noop = new NoopStreamProcessor(); return new ProcessOutput(noop, noop, noop); } diff --git a/src/main/java/com/syncleus/maven/plugins/mongodb/log/NoopStreamProcessor.java b/src/main/java/com/syncleus/maven/plugins/mongodb/log/NoopStreamProcessor.java index 7eb817d..5f8641b 100644 --- a/src/main/java/com/syncleus/maven/plugins/mongodb/log/NoopStreamProcessor.java +++ b/src/main/java/com/syncleus/maven/plugins/mongodb/log/NoopStreamProcessor.java @@ -21,7 +21,7 @@ import de.flapdoodle.embed.process.io.IStreamProcessor; public class NoopStreamProcessor implements IStreamProcessor { @Override - public void process(String block) { + public void process(final String block) { } @Override diff --git a/src/test/java/com/syncleus/maven/plugins/mongodb/PortUtilsTest.java b/src/test/java/com/syncleus/maven/plugins/mongodb/PortUtilsTest.java index fd63f1f..0f9e63f 100644 --- a/src/test/java/com/syncleus/maven/plugins/mongodb/PortUtilsTest.java +++ b/src/test/java/com/syncleus/maven/plugins/mongodb/PortUtilsTest.java @@ -55,7 +55,7 @@ public class PortUtilsTest { port = PortUtils.allocateRandomPort(); new ServerSocket(port); // port has been bound successfully - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException("Port " + port + " cannot be bind!"); } finally { allocationsCounter.countDown(); -- GitLab