Skip to content
Snippets Groups Projects
Commit df19c137 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Made every variable final where possible.

parent 3ae8ff6f
No related branches found
No related tags found
No related merge requests found
...@@ -26,11 +26,11 @@ public final class PortUtils { ...@@ -26,11 +26,11 @@ public final class PortUtils {
public static int allocateRandomPort() { public static int allocateRandomPort() {
try { try {
ServerSocket server = new ServerSocket(0); final ServerSocket server = new ServerSocket(0);
int port = server.getLocalPort(); final int port = server.getLocalPort();
server.close(); server.close();
return port; return port;
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException("Failed to acquire a random free port", e); throw new RuntimeException("Failed to acquire a random free port", e);
} }
} }
......
...@@ -224,7 +224,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -224,7 +224,7 @@ public class StartMongoMojo extends AbstractMojo {
this.addProxySelector(); this.addProxySelector();
} }
MongodExecutable executable; final MongodExecutable executable;
try { try {
final ICommandLinePostProcessor commandLinePostProcessor; final ICommandLinePostProcessor commandLinePostProcessor;
...@@ -241,7 +241,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -241,7 +241,7 @@ public class StartMongoMojo extends AbstractMojo {
commandLinePostProcessor = new ICommandLinePostProcessor.Noop(); commandLinePostProcessor = new ICommandLinePostProcessor.Noop();
} }
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder() final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(Command.MongoD) .defaults(Command.MongoD)
.processOutput(getOutputConfig()) .processOutput(getOutputConfig())
.artifactStore(getArtifactStore()) .artifactStore(getArtifactStore())
...@@ -253,36 +253,36 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -253,36 +253,36 @@ public class StartMongoMojo extends AbstractMojo {
} }
savePortToProjectProperties(); savePortToProjectProperties();
IMongodConfig config = new MongodConfigBuilder() final IMongodConfig config = new MongodConfigBuilder()
.version((getVersion() == null || getVersion().equals("") ? Version.Main.PRODUCTION : getVersion())) .version((getVersion() == null || getVersion().equals("") ? Version.Main.PRODUCTION : getVersion()))
.net(new Net(bindIp, port, Network.localhostIsIPv6())) .net(new Net(bindIp, port, Network.localhostIsIPv6()))
.replication(new Storage(getDataDirectory(), replSet, oplogSize)) .replication(new Storage(getDataDirectory(), replSet, oplogSize))
.build(); .build();
executable = MongodStarter.getInstance(runtimeConfig).prepare(config); executable = MongodStarter.getInstance(runtimeConfig).prepare(config);
} catch (UnknownHostException e) { } catch (final UnknownHostException e) {
throw new MojoExecutionException("Unable to determine if localhost is ipv6", 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); 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); throw new MojoExecutionException("Unable to Config MongoDB: ", e);
} }
try { try {
MongodProcess mongod = executable.start(); final MongodProcess mongod = executable.start();
if (wait) { if (wait) {
while (true) { while (true) {
try { try {
TimeUnit.MINUTES.sleep(5); TimeUnit.MINUTES.sleep(5);
} catch (InterruptedException e) { } catch (final InterruptedException e) {
break; break;
} }
} }
} }
getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod); getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod);
} catch (IOException e) { } catch (final IOException e) {
throw new MojoExecutionException("Unable to start the mongod", e); throw new MojoExecutionException("Unable to start the mongod", e);
} }
} }
...@@ -298,7 +298,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -298,7 +298,7 @@ public class StartMongoMojo extends AbstractMojo {
private ProcessOutput getOutputConfig() throws MojoFailureException { private ProcessOutput getOutputConfig() throws MojoFailureException {
LoggingStyle loggingStyle = LoggingStyle.valueOf(logging.toUpperCase()); final LoggingStyle loggingStyle = LoggingStyle.valueOf(logging.toUpperCase());
switch (loggingStyle) { switch (loggingStyle) {
case CONSOLE: case CONSOLE:
...@@ -315,7 +315,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -315,7 +315,7 @@ public class StartMongoMojo extends AbstractMojo {
} }
private IArtifactStore getArtifactStore() { 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(); return new ArtifactStoreBuilder().defaults(Command.MongoD).download(downloadConfig).build();
} }
...@@ -334,7 +334,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -334,7 +334,7 @@ public class StartMongoMojo extends AbstractMojo {
final ProxySelector defaultProxySelector = ProxySelector.getDefault(); final ProxySelector defaultProxySelector = ProxySelector.getDefault();
ProxySelector.setDefault(new ProxySelector() { ProxySelector.setDefault(new ProxySelector() {
@Override @Override
public List<Proxy> select(URI uri) { public List<Proxy> select(final URI uri) {
if (uri.getHost().equals("fastdl.mongodb.org")) { if (uri.getHost().equals("fastdl.mongodb.org")) {
return singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))); return singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
} else { } else {
...@@ -343,7 +343,7 @@ public class StartMongoMojo extends AbstractMojo { ...@@ -343,7 +343,7 @@ public class StartMongoMojo extends AbstractMojo {
} }
@Override @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 { ...@@ -357,7 +357,7 @@ public class StartMongoMojo extends AbstractMojo {
try { try {
return Version.valueOf(versionEnumName); 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..."); 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() { return Versions.withFeatures(new IVersion() {
@Override @Override
......
...@@ -41,7 +41,7 @@ public class StopMongoMojo extends AbstractMojo { ...@@ -41,7 +41,7 @@ public class StopMongoMojo extends AbstractMojo {
return; return;
} }
MongodProcess mongod = (MongodProcess) getPluginContext().get(StartMongoMojo final MongodProcess mongod = (MongodProcess) getPluginContext().get(StartMongoMojo
.MONGOD_CONTEXT_PROPERTY_NAME); .MONGOD_CONTEXT_PROPERTY_NAME);
if (mongod != null) { if (mongod != null) {
......
...@@ -29,13 +29,13 @@ public class FileOutputStreamProcessor implements IStreamProcessor { ...@@ -29,13 +29,13 @@ public class FileOutputStreamProcessor implements IStreamProcessor {
private String logFile; private String logFile;
private String encoding; private String encoding;
public FileOutputStreamProcessor(String logFile, String encoding) { public FileOutputStreamProcessor(final String logFile, final String encoding) {
setLogFile(logFile); setLogFile(logFile);
setEncoding(encoding); setEncoding(encoding);
} }
@Override @Override
public synchronized void process(String block) { public synchronized void process(final String block) {
try { try {
if (stream == null) { if (stream == null) {
...@@ -45,7 +45,7 @@ public class FileOutputStreamProcessor implements IStreamProcessor { ...@@ -45,7 +45,7 @@ public class FileOutputStreamProcessor implements IStreamProcessor {
stream.write(block); stream.write(block);
stream.flush(); stream.flush();
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
...@@ -55,14 +55,14 @@ public class FileOutputStreamProcessor implements IStreamProcessor { ...@@ -55,14 +55,14 @@ public class FileOutputStreamProcessor implements IStreamProcessor {
process("\n"); process("\n");
} }
private void setLogFile(String logFile) { private void setLogFile(final String logFile) {
if (logFile == null || logFile.trim().length() == 0) { if (logFile == null || logFile.trim().length() == 0) {
throw new IllegalArgumentException("no logFile given"); throw new IllegalArgumentException("no logFile given");
} }
this.logFile = logFile; this.logFile = logFile;
} }
private void setEncoding(String encoding) { private void setEncoding(final String encoding) {
if (encoding == null || encoding.trim().length() == 0) { if (encoding == null || encoding.trim().length() == 0) {
throw new IllegalArgumentException("no encoding given"); throw new IllegalArgumentException("no encoding given");
} }
......
...@@ -23,8 +23,8 @@ import de.flapdoodle.embed.process.io.NamedOutputStreamProcessor; ...@@ -23,8 +23,8 @@ import de.flapdoodle.embed.process.io.NamedOutputStreamProcessor;
public class Loggers { public class Loggers {
public static ProcessOutput file(String logFile, String encoding) { public static ProcessOutput file(final String logFile, final String encoding) {
FileOutputStreamProcessor file = new FileOutputStreamProcessor(logFile, encoding); final FileOutputStreamProcessor file = new FileOutputStreamProcessor(logFile, encoding);
return new ProcessOutput( return new ProcessOutput(
new NamedOutputStreamProcessor("[mongod output]", file), new NamedOutputStreamProcessor("[mongod output]", file),
...@@ -37,7 +37,7 @@ public class Loggers { ...@@ -37,7 +37,7 @@ public class Loggers {
} }
public static ProcessOutput none() { public static ProcessOutput none() {
NoopStreamProcessor noop = new NoopStreamProcessor(); final NoopStreamProcessor noop = new NoopStreamProcessor();
return new ProcessOutput(noop, noop, noop); return new ProcessOutput(noop, noop, noop);
} }
......
...@@ -21,7 +21,7 @@ import de.flapdoodle.embed.process.io.IStreamProcessor; ...@@ -21,7 +21,7 @@ import de.flapdoodle.embed.process.io.IStreamProcessor;
public class NoopStreamProcessor implements IStreamProcessor { public class NoopStreamProcessor implements IStreamProcessor {
@Override @Override
public void process(String block) { public void process(final String block) {
} }
@Override @Override
......
...@@ -55,7 +55,7 @@ public class PortUtilsTest { ...@@ -55,7 +55,7 @@ public class PortUtilsTest {
port = PortUtils.allocateRandomPort(); port = PortUtils.allocateRandomPort();
new ServerSocket(port); new ServerSocket(port);
// port has been bound successfully // port has been bound successfully
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException("Port " + port + " cannot be bind!"); throw new RuntimeException("Port " + port + " cannot be bind!");
} finally { } finally {
allocationsCounter.countDown(); allocationsCounter.countDown();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment