Skip to content

Commit

Permalink
Merge pull request #295 from hazendaz/develop
Browse files Browse the repository at this point in the history
Run overall code cleanup using Eclipse
  • Loading branch information
hazendaz committed May 6, 2023
2 parents 7b6f14a + eb960c1 commit 127012a
Show file tree
Hide file tree
Showing 44 changed files with 268 additions and 220 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/apache/ibatis/migration/Change.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -90,7 +90,7 @@ public boolean equals(Object o) {

Change change = (Change) o;

return (id.equals(change.getId()));
return id.equals(change.getId());
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/apache/ibatis/migration/CommandLine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -42,7 +42,8 @@ public void execute() {
if (selectedOptions.needsHelp()) {
printUsage();
return;
} else if (selectedOptions.getCommand() == null) {
}
if (selectedOptions.getCommand() == null) {
console.printf("No command specified.%n");
printUsage();
return;
Expand Down Expand Up @@ -85,20 +86,19 @@ private void runCommand(Command command, SelectedOptions selectedOptions) {
exceptionCaught = true;
if (t instanceof MigrationException) {
throw (MigrationException) t;
} else {
throw new MigrationException(t);
}
throw new MigrationException(t);
} finally {
console.printf("------------------------------------------------------------------------%n");

if (hasColor(selectedOptions)) {
console.printf("-- MyBatis Migrations %s%s%s%n", (exceptionCaught) ? ConsoleColors.RED : ConsoleColors.GREEN,
(exceptionCaught) ? "FAILURE" : "SUCCESS", ConsoleColors.RESET);
console.printf("-- MyBatis Migrations %s%s%s%n", exceptionCaught ? ConsoleColors.RED : ConsoleColors.GREEN,
exceptionCaught ? "FAILURE" : "SUCCESS", ConsoleColors.RESET);
} else {
console.printf("-- MyBatis Migrations %s%n", (exceptionCaught) ? "FAILURE" : "SUCCESS");
console.printf("-- MyBatis Migrations %s%n", exceptionCaught ? "FAILURE" : "SUCCESS");
}

console.printf("-- Total time: %ss%n", ((System.currentTimeMillis() - start) / 1000));
console.printf("-- Total time: %ss%n", (System.currentTimeMillis() - start) / 1000);
console.printf("-- Finished at: %s%n", new Date());
printMemoryUsage();
console.printf("------------------------------------------------------------------------%n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand All @@ -25,7 +25,6 @@ public class DataSourceConnectionProvider implements ConnectionProvider {
private DataSource dataSource;

public DataSourceConnectionProvider(DataSource dataSource) {
super();
this.dataSource = dataSource;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/apache/ibatis/migration/Environment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -146,11 +146,11 @@ public Environment(File file) {
this.timeZone = readProperty(prop, SETTING_KEY.time_zone.name(), "GMT+0:00");
this.delimiter = readProperty(prop, SETTING_KEY.delimiter.name(), ";");
this.scriptCharset = readProperty(prop, SETTING_KEY.script_char_set.name(), Charset.defaultCharset().name());
this.fullLineDelimiter = Boolean.valueOf(readProperty(prop, SETTING_KEY.full_line_delimiter.name()));
this.sendFullScript = Boolean.valueOf(readProperty(prop, SETTING_KEY.send_full_script.name()));
this.autoCommit = Boolean.valueOf(readProperty(prop, SETTING_KEY.auto_commit.name()));
this.removeCrs = Boolean.valueOf(readProperty(prop, SETTING_KEY.remove_crs.name()));
this.ignoreWarnings = Boolean.valueOf(readProperty(prop, SETTING_KEY.ignore_warnings.name(), "true"));
this.fullLineDelimiter = Boolean.parseBoolean(readProperty(prop, SETTING_KEY.full_line_delimiter.name()));
this.sendFullScript = Boolean.parseBoolean(readProperty(prop, SETTING_KEY.send_full_script.name()));
this.autoCommit = Boolean.parseBoolean(readProperty(prop, SETTING_KEY.auto_commit.name()));
this.removeCrs = Boolean.parseBoolean(readProperty(prop, SETTING_KEY.remove_crs.name()));
this.ignoreWarnings = Boolean.parseBoolean(readProperty(prop, SETTING_KEY.ignore_warnings.name(), "true"));

this.driverPath = readProperty(prop, SETTING_KEY.driver_path.name());
this.driver = readProperty(prop, SETTING_KEY.driver.name());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -34,7 +34,6 @@ public class FileMigrationLoader implements MigrationLoader {
protected final Properties variables;

public FileMigrationLoader(File scriptsDir, String charset, Properties variables) {
super();
this.scriptsDir = scriptsDir;
this.charset = charset;
this.variables = variables;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand All @@ -23,7 +23,6 @@
import java.util.Set;

import org.apache.ibatis.migration.io.ResolverUtil;
import org.apache.ibatis.migration.io.ResolverUtil.Test;

public class JavaMigrationLoader implements MigrationLoader {

Expand All @@ -36,7 +35,6 @@ public JavaMigrationLoader(String... packageNames) {
}

public JavaMigrationLoader(ClassLoader classLoader, String... packageNames) {
super();
this.classLoader = classLoader;
this.packageNames = packageNames;
}
Expand Down Expand Up @@ -74,12 +72,9 @@ public Reader getScriptReader(Change change, boolean undo) {
ResolverUtil<MigrationScript> resolver = getResolver();
final String className = change.getFilename();
for (String pkg : packageNames) {
resolver.find(new Test() {
@Override
public boolean matches(Class<?> type) {
return type != null && MigrationScript.class.isAssignableFrom(type) && type.getName().equals(className);
}
}, pkg);
resolver.find(
type -> type != null && MigrationScript.class.isAssignableFrom(type) && type.getName().equals(className),
pkg);
}
Reader reader = null;
Set<Class<? extends MigrationScript>> classes = resolver.getClasses();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand All @@ -20,7 +20,6 @@ public class MigrationException extends RuntimeException {
private static final long serialVersionUID = 491769430730827896L;

public MigrationException() {
super();
}

public MigrationException(String message) {
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/apache/ibatis/migration/MigrationReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -122,23 +122,21 @@ public int read(char[] cbuf, int off, int len) throws IOException {
determinePart(c);
searchVariable(c);

if (c == '\r' || (c == '\n' && previousChar != '\r')) {
if (c == '\r' || c == '\n' && previousChar != '\r') {
switch (part) {
case AFTER_UNDO_TAG:
if (undo) {
addToBuffer(lineBuffer.delete(afterCommentPrefixIndex, afterDoubleSlashIndex)
.insert(afterCommentPrefixIndex, ' '));
inUndo = true;
} else {
if (!undo) {
// Won't read from the file anymore.
lineBuffer.setLength(0);
int bufferLen = buffer.length();
if (bufferLen == 0) {
return -1;
} else {
return readFromBuffer(cbuf, off, len);
}
return readFromBuffer(cbuf, off, len);
}
addToBuffer(lineBuffer.delete(afterCommentPrefixIndex, afterDoubleSlashIndex)
.insert(afterCommentPrefixIndex, ' '));
inUndo = true;
break;
case NOT_UNDO_LINE:
if (!undo || inUndo) {
Expand Down Expand Up @@ -281,8 +279,7 @@ public int read() throws IOException {
protected static Reader scriptFileReader(InputStream inputStream, String charset) {
if (charset == null || charset.length() == 0) {
return new InputStreamReader(inputStream);
} else {
return new InputStreamReader(inputStream, Charset.forName(charset));
}
return new InputStreamReader(inputStream, Charset.forName(charset));
}
}
13 changes: 6 additions & 7 deletions src/main/java/org/apache/ibatis/migration/VariableReplacer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -69,15 +69,14 @@ public String replace(String text) {
offset = start + openToken.length();
int end = text.indexOf(closeToken, offset);
while (end > -1) {
if (end > offset && src[end - 1] == '\\') {
// this close token is escaped. remove the backslash and continue.
expression.append(src, offset, end - offset - 1).append(closeToken);
offset = end + closeToken.length();
end = text.indexOf(closeToken, offset);
} else {
if (end <= offset || src[end - 1] != '\\') {
expression.append(src, offset, end - offset);
break;
}
// this close token is escaped. remove the backslash and continue.
expression.append(src, offset, end - offset - 1).append(closeToken);
offset = end + closeToken.length();
end = text.indexOf(closeToken, offset);
}
if (end == -1) {
// close token was not found.
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -116,9 +116,8 @@ protected String getNextIDAsString() {
}
if (idPattern != null && !idPattern.isEmpty()) {
return generatePatternedId(idPattern);
} else {
return generateTimestampId();
}
return generateTimestampId();
}

private String generatePatternedId(String pattern) {
Expand All @@ -130,7 +129,8 @@ private String generatePatternedId(String pattern) {
Change lastChange = migrations.get(migrations.size() - 1);
try {
long lastId = (Long) fmt.parse(lastChange.getId().toString());
return fmt.format(++lastId);
lastId++;
return fmt.format(lastId);
} catch (ParseException e) {
throw new MigrationException(
"Failed to parse last id '" + lastChange.getId() + "' using the specified idPattern '" + pattern + "'");
Expand Down Expand Up @@ -210,12 +210,11 @@ protected int getStepCountParameter(int defaultSteps, String... params) {
final String stringParam = params.length > 0 ? params[0] : null;
if (stringParam == null || "".equals(stringParam)) {
return defaultSteps;
} else {
try {
return Integer.parseInt(stringParam);
} catch (NumberFormatException e) {
throw new MigrationException("Invalid parameter passed to command: " + params[0]);
}
}
try {
return Integer.parseInt(stringParam);
} catch (NumberFormatException e) {
throw new MigrationException("Invalid parameter passed to command: " + params[0]);
}
}

Expand All @@ -232,7 +231,8 @@ private ClassLoader getDriverClassLoader() {
File localDriverPath = getCustomDriverPath();
if (driverClassLoader != null) {
return driverClassLoader;
} else if (localDriverPath.exists()) {
}
if (localDriverPath.exists()) {
try {
List<URL> urlList = new ArrayList<>();
File[] files = localDriverPath.listFiles();
Expand All @@ -259,9 +259,8 @@ private File getCustomDriverPath() {
String customDriverPath = environment().getDriverPath();
if (customDriverPath != null && customDriverPath.length() > 0) {
return new File(customDriverPath);
} else {
return options.getPaths().getDriverPath();
}
return options.getPaths().getDriverPath();
}

protected MigrationLoader getMigrationLoader() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
Expand Down Expand Up @@ -77,12 +77,7 @@ private static Command createCommand(Commands aResolvedCommand, SelectedOptions
case REDO:
return new RedoCommand(selectedOptions);
default:
return new Command() {
@Override
public void execute(String... params) {
System.out.println("unknown command");
}
};
return params -> System.out.println("unknown command");
}
}
}
Loading

0 comments on commit 127012a

Please sign in to comment.