Skip to content

Commit 0322dc5

Browse files
committed
fix: Make abrousseau001@ Homebrew contribution comply with Checkstyle rules of this project
1 parent aef27b8 commit 0322dc5

File tree

4 files changed

+80
-57
lines changed

4 files changed

+80
-57
lines changed

mariaDB4j-core/src/main/java/ch/vorburger/mariadb4j/DB.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public synchronized void start() throws ManagedProcessException {
162162
mysqldProcess.destroy();
163163
}
164164
throw new ManagedProcessException("Database does not seem to have started up correctly? Magic string not seen in "
165-
+ dbStartMaxWaitInMS + "ms: " + getReadyForConnectionsTag() + mysqldProcess.getLastConsoleLines());
165+
+ dbStartMaxWaitInMS + "ms: " + getReadyForConnectionsTag() + mysqldProcess.getLastConsoleLines());
166166
}
167167
logger.info("Database startup complete.");
168168
}
@@ -325,7 +325,7 @@ public void run(String command, String username, String password, String dbName,
325325
}
326326

327327
public void run(String command, String username, String password, String dbName, boolean force, boolean verbose)
328-
throws ManagedProcessException {
328+
throws ManagedProcessException {
329329
// If resource is created here, it should probably be released here also (as opposed to in protected run method)
330330
// Also move to try-with-resource syntax to remove closeQuietly deprecation errors.
331331
try (InputStream from = IOUtils.toInputStream(command, Charset.defaultCharset())) {
@@ -337,7 +337,7 @@ public void run(String command, String username, String password, String dbName,
337337
}
338338

339339
protected void run(String logInfoText, InputStream fromIS, String username, String password, String dbName, boolean force)
340-
throws ManagedProcessException {
340+
throws ManagedProcessException {
341341
logger.info("Running a " + logInfoText);
342342
try {
343343
ManagedProcessBuilder builder = new ManagedProcessBuilder(configuration.getExecutable(Client));
@@ -411,11 +411,9 @@ protected void unpackEmbeddedDb() {
411411
// Check for Homebrew, before doing anything else
412412
// If HomeBrew is not installed, then throw a runtime error, similar to how the below extraction method
413413
// does below for other operating systems
414-
if(configuration.isMacOs() && !Util.doesExecutableExistAndIsExecutable(new File(Util.homebrewInstallationPath)))
415-
{
414+
if (configuration.isMacOs() && !Util.doesExecutableExistAndIsExecutable(new File(Util.homebrewInstallationPath))) {
416415
throw new RuntimeException("Homebrew must be installed on the system before using this library");
417-
}
418-
else {
416+
} else {
419417
// All other OS except macOS needs to have a place where the binaries are to be extracted
420418
if (configuration.getBinariesClassPathLocation() == null) {
421419
logger.info("Not unpacking any embedded database (as BinariesClassPathLocation configuration is null)");
@@ -424,7 +422,7 @@ protected void unpackEmbeddedDb() {
424422
}
425423

426424
// Windows, Linux, and any other supported OS can have their binaries extracted as normal
427-
if(!configuration.isMacOs()) {
425+
if (!configuration.isMacOs()) {
428426
try {
429427
Util.extractFromClasspathToFile(configuration.getBinariesClassPathLocation(), baseDir);
430428
if (!configuration.isWindows()) {
@@ -437,9 +435,8 @@ protected void unpackEmbeddedDb() {
437435
} catch (IOException e) {
438436
throw new RuntimeException("Error unpacking embedded DB", e);
439437
}
440-
}
441-
else{
442-
if(!Util.installMariaDbFromHomebrew())
438+
} else {
439+
if (!Util.installMariaDbFromHomebrew())
443440
throw new RuntimeException("Error installing MariaDB from Homebrew");
444441
}
445442
}
@@ -485,17 +482,17 @@ protected void cleanupOnExit() {
485482
// unexpected deadlock).
486483

487484
public ManagedProcess dumpXML(File outputFile, String dbName, String user, String password)
488-
throws IOException, ManagedProcessException {
485+
throws IOException, ManagedProcessException {
489486
return dump(outputFile, Arrays.asList(dbName), true, true, true, user, password);
490487
}
491488

492489
public ManagedProcess dumpSQL(File outputFile, String dbName, String user, String password)
493-
throws IOException, ManagedProcessException {
490+
throws IOException, ManagedProcessException {
494491
return dump(outputFile, Arrays.asList(dbName), true, true, false, user, password);
495492
}
496493

497494
protected ManagedProcess dump(File outputFile, List<String> dbNamesToDump, boolean compactDump, boolean lockTables, boolean asXml,
498-
String user, String password) throws ManagedProcessException, IOException {
495+
String user, String password) throws ManagedProcessException, IOException {
499496

500497
ManagedProcessBuilder builder = new ManagedProcessBuilder(configuration.getExecutable(Dump));
501498

@@ -526,11 +523,13 @@ protected ManagedProcess dump(File outputFile, List<String> dbNamesToDump, boole
526523
builder.addArgument(StringUtils.join(dbNamesToDump, StringUtils.SPACE));
527524
builder.setDestroyOnShutdown(true);
528525
builder.setProcessListener(new ManagedProcessListener() {
529-
@Override public void onProcessComplete(int i) {
526+
@Override
527+
public void onProcessComplete(int i) {
530528
closeOutputStream();
531529
}
532530

533-
@Override public void onProcessFailed(int i, Throwable throwable) {
531+
@Override
532+
public void onProcessFailed(int i, Throwable throwable) {
534533
closeOutputStream();
535534
}
536535

mariaDB4j-core/src/main/java/ch/vorburger/mariadb4j/DBConfiguration.java

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public interface DBConfiguration {
9494
boolean isWindows();
9595

9696
/**
97-
* Whether running on macOS (this is used to determine whether or not to check for Homebrew)
97+
* Whether running on macOS (this is used to determine whether to check for Homebrew).
9898
*
9999
* @return returns boolean isMacOs
100100
*/
@@ -150,9 +150,9 @@ static class Impl implements DBConfiguration {
150150
private final Map<Executable, Supplier<File>> executables;
151151

152152
Impl(int port, String socket, String binariesClassPathLocation, String baseDir, String libDir, String dataDir, String tmpDir,
153-
boolean isWindows, boolean isMacOs, List<String> args, String osLibraryEnvironmentVarName, boolean isSecurityDisabled,
154-
boolean isDeletingTemporaryBaseAndDataDirsOnShutdown, Function<String, String> getURL, String defaultCharacterSet,
155-
Map<Executable, Supplier<File>> executables, ManagedProcessListener listener) {
153+
boolean isWindows, boolean isMacOs, List<String> args, String osLibraryEnvironmentVarName, boolean isSecurityDisabled,
154+
boolean isDeletingTemporaryBaseAndDataDirsOnShutdown, Function<String, String> getURL, String defaultCharacterSet,
155+
Map<Executable, Supplier<File>> executables, ManagedProcessListener listener) {
156156
this.port = port;
157157
this.socket = socket;
158158
this.binariesClassPathLocation = binariesClassPathLocation;
@@ -172,69 +172,90 @@ static class Impl implements DBConfiguration {
172172
this.executables = executables;
173173
}
174174

175-
@Override public int getPort() {
175+
@Override
176+
public int getPort() {
176177
return port;
177178
}
178179

179-
@Override public String getSocket() {
180+
@Override
181+
public String getSocket() {
180182
return socket;
181183
}
182184

183-
@Override public String getBinariesClassPathLocation() {
185+
@Override
186+
public String getBinariesClassPathLocation() {
184187
return binariesClassPathLocation;
185188
}
186189

187-
@Override public String getBaseDir() {
190+
@Override
191+
public String getBaseDir() {
188192
return baseDir;
189193
}
190194

191-
@Override public String getLibDir() {
195+
@Override
196+
public String getLibDir() {
192197
return libDir;
193198
}
194199

195-
@Override public String getDataDir() {
200+
@Override
201+
public String getDataDir() {
196202
return dataDir;
197203
}
198204

199-
@Override public String getTmpDir() {
205+
@Override
206+
public String getTmpDir() {
200207
return tmpDir;
201208
}
202209

203-
@Override public boolean isDeletingTemporaryBaseAndDataDirsOnShutdown() {
210+
@Override
211+
public boolean isDeletingTemporaryBaseAndDataDirsOnShutdown() {
204212
return isDeletingTemporaryBaseAndDataDirsOnShutdown;
205213
}
206214

207-
@Override public boolean isWindows() {
215+
@Override
216+
public boolean isWindows() {
208217
return isWindows;
209218
}
210219

211-
@Override public boolean isMacOs() { return isMacOs; };
220+
@Override
221+
public boolean isMacOs() {
222+
return isMacOs;
223+
}
224+
225+
;
212226

213-
@Override public List<String> getArgs() {
227+
@Override
228+
public List<String> getArgs() {
214229
return args;
215230
}
216231

217-
@Override public String getOSLibraryEnvironmentVarName() {
232+
@Override
233+
public String getOSLibraryEnvironmentVarName() {
218234
return osLibraryEnvironmentVarName;
219235
}
220236

221-
@Override public boolean isSecurityDisabled() {
237+
@Override
238+
public boolean isSecurityDisabled() {
222239
return isSecurityDisabled;
223240
}
224241

225-
@Override public String getURL(String dbName) {
242+
@Override
243+
public String getURL(String dbName) {
226244
return getURL.apply(dbName);
227245
}
228246

229-
@Override public ManagedProcessListener getProcessListener() {
247+
@Override
248+
public ManagedProcessListener getProcessListener() {
230249
return listener;
231250
}
232251

233-
@Override public String getDefaultCharacterSet() {
252+
@Override
253+
public String getDefaultCharacterSet() {
234254
return defaultCharacterSet;
235255
}
236256

237-
@Override public File getExecutable(Executable executable) {
257+
@Override
258+
public File getExecutable(Executable executable) {
238259
return executables.getOrDefault(executable, () -> {
239260
throw new IllegalArgumentException(executable.name());
240261
}).get();

mariaDB4j-core/src/main/java/ch/vorburger/mariadb4j/DBConfigurationBuilder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public DBConfigurationBuilder setSocket(String socket) {
206206
public DBConfiguration build() {
207207
frozen = true;
208208
return new DBConfiguration.Impl(_getPort(), _getSocket(), _getBinariesClassPathLocation(), getBaseDir(),
209-
getLibDir(), _getDataDir(), _getTmpDir(), isWindows(), isMacOs(), _getArgs(), _getOSLibraryEnvironmentVarName(),
210-
isSecurityDisabled(), isDeletingTemporaryBaseAndDataDirsOnShutdown(), this::getURL,
211-
getDefaultCharacterSet(), _getExecutables(), getProcessListener());
209+
getLibDir(), _getDataDir(), _getTmpDir(), isWindows(), isMacOs(), _getArgs(), _getOSLibraryEnvironmentVarName(),
210+
isSecurityDisabled(), isDeletingTemporaryBaseAndDataDirsOnShutdown(), this::getURL,
211+
getDefaultCharacterSet(), _getExecutables(), getProcessListener());
212212
}
213213

214214
/**
@@ -292,8 +292,8 @@ protected String _getDatabaseVersion() {
292292
if (databaseVersion == null) {
293293
if (!OSX.equals(getOS()) && !LINUX.equals(getOS()) && !WINX64.equals(getOS())) {
294294
throw new IllegalStateException(
295-
"OS not directly supported, please use setDatabaseVersion() to set the name "
296-
+ "of the package that the binaries are in, for: " + SystemUtils.OS_VERSION);
295+
"OS not directly supported, please use setDatabaseVersion() to set the name "
296+
+ "of the package that the binaries are in, for: " + SystemUtils.OS_VERSION);
297297
}
298298
// see https://github.com/MariaDB4j/MariaDB4j/pull/771 about why 10.11.5-fix1 on
299299
// Windows:
@@ -325,7 +325,7 @@ public String getOS() {
325325

326326
protected String _getOSLibraryEnvironmentVarName() {
327327
return SystemUtils.IS_OS_WINDOWS ? "PATH"
328-
: SystemUtils.IS_OS_MAC ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH";
328+
: SystemUtils.IS_OS_MAC ? "DYLD_FALLBACK_LIBRARY_PATH" : "LD_LIBRARY_PATH";
329329
}
330330

331331
protected String _getBinariesClassPathLocation() {
@@ -395,7 +395,7 @@ public boolean isWindows() {
395395
return WINX64.equals(getOS());
396396
}
397397

398-
public boolean isMacOs(){
398+
public boolean isMacOs() {
399399
return OSX.equals(getOS());
400400
}
401401

mariaDB4j-core/src/main/java/ch/vorburger/mariadb4j/Util.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.net.URL;
2525
import java.nio.charset.StandardCharsets;
2626
import java.util.concurrent.TimeUnit;
27-
2827
import org.apache.commons.io.FileUtils;
2928
import org.apache.commons.lang3.SystemUtils;
3029
import org.slf4j.Logger;
@@ -98,11 +97,12 @@ public static boolean isTemporaryDirectory(String directory) {
9897

9998
/**
10099
* Method to check for the existence of a prerequisite executable, like Homebrew on macOS,
101-
* and determine if it is executable
100+
* and determine if it is executable.
101+
*
102102
* @param executableFile file that is being checked for
103103
* @return boolean if the file exists and is executable
104104
*/
105-
public static boolean doesExecutableExistAndIsExecutable(File executableFile){
105+
public static boolean doesExecutableExistAndIsExecutable(File executableFile) {
106106
return executableFile.exists() && executableFile.canExecute();
107107
}
108108

@@ -112,7 +112,7 @@ public static void forceExecutable(File executableFile) throws IOException {
112112
boolean succeeded = executableFile.setExecutable(true);
113113
if (!succeeded) {
114114
throw new IOException("Failed to do chmod +x " + executableFile.toString()
115-
+ " using java.io.File.setExecutable, which will be a problem on *NIX...");
115+
+ " using java.io.File.setExecutable, which will be a problem on *NIX...");
116116
}
117117
logger.info("chmod +x {} (using java.io.File.setExecutable)", executableFile);
118118
}
@@ -155,17 +155,18 @@ public static int extractFromClasspathToFile(String packagePath, File toDir) thr
155155
}
156156
}
157157
if (counter > 0) {
158-
Object[] info = { counter, locationPattern, toDir };
158+
Object[] info = {counter, locationPattern, toDir};
159159
logger.info("Unpacked {} files from {} to {}", info);
160160
}
161161
return counter;
162162
}
163163

164164
/**
165-
* Method to check for the MariaDb installation on the system and then install if not installed
166-
* @return @{@link boolean} representing whether MariaDb has been installed on the system
165+
* Method to check for the MariaDB installation on the system and then install if not installed.
166+
*
167+
* @return @{@link boolean} representing whether MariaDB has been installed on the system
167168
*/
168-
public static boolean installMariaDbFromHomebrew(){
169+
public static boolean installMariaDbFromHomebrew() {
169170
boolean mariadbIsInstalled = false;
170171

171172
ProcessBuilder pb = new ProcessBuilder(homebrewInstallationPath + " list mariadb");
@@ -174,7 +175,7 @@ public static boolean installMariaDbFromHomebrew(){
174175
Process brewCheckMariadbIsInstalled = pb.start();
175176
String checkOutput = new String(brewCheckMariadbIsInstalled.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
176177

177-
if(checkOutput.contains(mariadbNotInstalledMessage)){
178+
if (checkOutput.contains(mariadbNotInstalledMessage)) {
178179
brewCheckMariadbIsInstalled.destroy();
179180

180181
ProcessBuilder brewInstallMariaDb = new ProcessBuilder(homebrewInstallationPath + " install mariadb");
@@ -185,19 +186,20 @@ public static boolean installMariaDbFromHomebrew(){
185186
// Wait until Homebrew installs the latest MariaDb
186187
do {
187188
brewInstall.waitFor(15, TimeUnit.SECONDS);
188-
} while (brewInstall.isAlive());
189+
}
190+
while (brewInstall.isAlive());
189191

190192
String checkInstallOutput = new String(brewInstall.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
191193

192-
if(checkInstallOutput.toLowerCase().contains("error")){
194+
if (checkInstallOutput.toLowerCase().contains("error")) {
193195
throw new IllegalStateException("Failed to install mariadb with Homebrew - see " + checkInstallOutput);
194196
}
195197

196198
// Cause it to clean up once it has installed
197199
brewInstall.destroy();
198200

199201
mariadbIsInstalled = true;
200-
} else{
202+
} else {
201203
mariadbIsInstalled = true;
202204
}
203205
} catch (IOException ioException) {
@@ -211,7 +213,8 @@ public static boolean installMariaDbFromHomebrew(){
211213
return mariadbIsInstalled;
212214
}
213215

214-
@SuppressWarnings("null") private static void tryN(int n, long msToWait, Procedure<IOException> procedure) throws IOException {
216+
@SuppressWarnings("null")
217+
private static void tryN(int n, long msToWait, Procedure<IOException> procedure) throws IOException {
215218
IOException lastIOException = null;
216219
int numAttempts = 0;
217220
while (numAttempts++ < n) {

0 commit comments

Comments
 (0)