Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Java 8 features #5833

Merged
merged 11 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public CDILiquibaseConfig createCDILiquibaseConfig() {

final InputStream is = SchemesCDIConfigBuilder.class.getResourceAsStream(SCHEMA_NAME);
try {
return jvmLocked(id, new Callable<CDILiquibaseConfig>() {
public CDILiquibaseConfig call() throws Exception {
return createCDILiquibaseConfig(id, is);
}
});
return jvmLocked(id, () -> createCDILiquibaseConfig(id, is));
} catch (Exception ex) {
log.warning(String.format("[id = %s] Unable to initialize liquibase where '%s'.", id, ex.getMessage()), ex);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,10 +1359,9 @@ private void processSystemProperties() {
systemProperties = new Properties();
}
// Add all system properties configured by the user
Iterator<Object> iter = systemProperties.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = systemProperties.getProperty(key);
for (Map.Entry<?, ?> entry : systemProperties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
System.setProperty(key, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static ClassLoader getArtifactClassloader(MavenProject project,
// Find project dependencies, including the transitive ones.
Set<Artifact> dependencies = project.getArtifacts();
if ((dependencies != null) && !dependencies.isEmpty()) {
for (Iterator it = dependencies.iterator(); it.hasNext(); ) {
addArtifact(uris, (Artifact) it.next(), log, verbose);
for (Artifact dependency : dependencies) {
addArtifact(uris, dependency, log, verbose);
}
} else {
log.info("there are no resolved artifacts for the Maven project.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,65 +86,62 @@ public String toString() {
public void run(ChangeSetVisitor visitor, RuntimeEnvironment env) throws LiquibaseException {
databaseChangeLog.setRuntimeEnvironment(env);
try {
Scope.child(Scope.Attr.databaseChangeLog, databaseChangeLog, new Scope.ScopedRunner() {
@Override
public void run() throws Exception {
Scope.child(Scope.Attr.databaseChangeLog, databaseChangeLog, () -> {

List<ChangeSet> changeSetList = new ArrayList<>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
}
for (int i = 0; i < changeSetList.size(); i++) {
ChangeSet changeSet = changeSetList.get(i);
boolean shouldVisit = true;
Set<ChangeSetFilterResult> reasonsAccepted = new HashSet<>();
Set<ChangeSetFilterResult> reasonsDenied = new HashSet<>();
if (changeSetFilters != null) {
for (ChangeSetFilter filter : changeSetFilters) {
ChangeSetFilterResult acceptsResult = filter.accepts(changeSet);
if (acceptsResult.isAccepted()) {
reasonsAccepted.add(acceptsResult);
} else {
shouldVisit = false;
reasonsDenied.add(acceptsResult);
break;
}
List<ChangeSet> changeSetList = new ArrayList<>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
}
for (int i = 0; i < changeSetList.size(); i++) {
ChangeSet changeSet = changeSetList.get(i);
boolean shouldVisit = true;
Set<ChangeSetFilterResult> reasonsAccepted = new HashSet<>();
Set<ChangeSetFilterResult> reasonsDenied = new HashSet<>();
if (changeSetFilters != null) {
for (ChangeSetFilter filter : changeSetFilters) {
ChangeSetFilterResult acceptsResult = filter.accepts(changeSet);
if (acceptsResult.isAccepted()) {
reasonsAccepted.add(acceptsResult);
} else {
shouldVisit = false;
reasonsDenied.add(acceptsResult);
break;
}
}
}

boolean finalShouldVisit = shouldVisit;

Map<String, Object> scopeValues = new HashMap<>();
scopeValues.put(Scope.Attr.changeSet.name(), changeSet);
scopeValues.put(Scope.Attr.database.name(), env.getTargetDatabase());

int finalI = i;
Scope.child(scopeValues, () -> {
if (finalShouldVisit && !alreadySaw(changeSet)) {
//
// Go validate any changesets with an Executor if
// we are using a ValidatingVisitor
//
if (visitor instanceof ValidatingVisitor) {
validateChangeSetExecutor(changeSet, env);
}

try {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
} catch (Exception e) {
exceptionChangeSets.add(changeSet);
skippedDueToExceptionChangeSets.addAll(changeSetList.subList(finalI + 1, changeSetList.size()));

throw e;
}
markSeen(changeSet);
} else {
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
boolean finalShouldVisit = shouldVisit;

Map<String, Object> scopeValues = new HashMap<>();
scopeValues.put(Scope.Attr.changeSet.name(), changeSet);
scopeValues.put(Scope.Attr.database.name(), env.getTargetDatabase());

int finalI = i;
Scope.child(scopeValues, () -> {
if (finalShouldVisit && !alreadySaw(changeSet)) {
//
// Go validate any changesets with an Executor if
// we are using a ValidatingVisitor
//
if (visitor instanceof ValidatingVisitor) {
validateChangeSetExecutor(changeSet, env);
}
});
}

try {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
} catch (Exception e) {
exceptionChangeSets.add(changeSet);
skippedDueToExceptionChangeSets.addAll(changeSetList.subList(finalI + 1, changeSetList.size()));

throw e;
}
markSeen(changeSet);
} else {
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
}
});
}
});
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public boolean include(String fileName,
}
changeLog.setIncludeContextFilter(includeContextFilter);
changeLog.setIncludeLabels(labels);
changeLog.setIncludeIgnore(ignore != null ? ignore.booleanValue() : false);
changeLog.setIncludeIgnore(ignore != null && ignore);
} finally {
if (rootChangeLog == null) {
ROOT_CHANGE_LOG.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,25 @@ public StatusChangeLogIterator(DatabaseChangeLog databaseChangeLog, String tag,
public void run(ChangeSetVisitor visitor, RuntimeEnvironment env) throws LiquibaseException {
databaseChangeLog.setRuntimeEnvironment(env);
try {
Scope.child(Scope.Attr.databaseChangeLog, databaseChangeLog, new Scope.ScopedRunner() {
@Override
public void run() throws Exception {
List<ChangeSet> changeSetList = new ArrayList<>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
Scope.child(Scope.Attr.databaseChangeLog, databaseChangeLog, () -> {
List<ChangeSet> changeSetList = new ArrayList<>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
}
for (ChangeSet changeSet : changeSetList) {
AtomicBoolean shouldVisit = new AtomicBoolean(true);
Set<ChangeSetFilterResult> reasonsAccepted = new LinkedHashSet<>();
Set<ChangeSetFilterResult> reasonsDenied = new LinkedHashSet<>();
if (changeSetFilters != null) {
shouldVisit.set(iterateFilters(changeSet, reasonsAccepted, reasonsDenied));
}
for (ChangeSet changeSet : changeSetList) {
AtomicBoolean shouldVisit = new AtomicBoolean(true);
Set<ChangeSetFilterResult> reasonsAccepted = new LinkedHashSet<>();
Set<ChangeSetFilterResult> reasonsDenied = new LinkedHashSet<>();
if (changeSetFilters != null) {
shouldVisit.set(iterateFilters(changeSet, reasonsAccepted, reasonsDenied));
}

if (shouldVisit.get()) {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
markSeen(changeSet);
} else{
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
if (shouldVisit.get()) {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
markSeen(changeSet);
} else{
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void writeHTML(Resource rootOutputDir, ResourceAccessor resourceAccessor,

new ChangeLogListWriter(rootOutputDir).writeHTML(changeLogs);
SortedSet<Table> tables = new TreeSet<>(snapshot.get(Table.class));
tables.removeIf(table -> database.isLiquibaseObject(table));
tables.removeIf(database::isLiquibaseObject);

new TableListWriter(rootOutputDir).writeHTML(tables);
new AuthorListWriter(rootOutputDir).writeHTML(new TreeSet<Object>(changesByAuthor.keySet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
CommandScope commandScope = resultsBuilder.getCommandScope();
Database referenceDatabase = (Database) commandScope.getDependency(ReferenceDatabase.class);
DiffOutputControl diffOutputControl = (DiffOutputControl) resultsBuilder.getResult(DiffOutputControlCommandStep.DIFF_OUTPUT_CONTROL.getName());
if(commandScope.getArgumentValue(DiffChangelogCommandStep.USE_OR_REPLACE_OPTION).booleanValue()) {
if (commandScope.getArgumentValue(DiffChangelogCommandStep.USE_OR_REPLACE_OPTION)) {
diffOutputControl.setReplaceIfExistsSet(true);
}
referenceDatabase.setOutputDefaultSchema(diffOutputControl.getIncludeSchema());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
diffOutputControl.setDataDir(commandScope.getArgumentValue(DATA_OUTPUT_DIR_ARG));
referenceDatabase.setOutputDefaultSchema(diffOutputControl.getIncludeSchema());

if(commandScope.getArgumentValue(GenerateChangelogCommandStep.USE_OR_REPLACE_OPTION).booleanValue()) {
if (commandScope.getArgumentValue(GenerateChangelogCommandStep.USE_OR_REPLACE_OPTION)) {
diffOutputControl.setReplaceIfExistsSet(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public boolean isCaseSensitive() {
if (caseSensitive == null) {
return false;
} else {
return caseSensitive.booleanValue();
return caseSensitive;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean supportsBooleanDataType() {
throw new DatabaseException("Error getting fix pack number");

return getDatabaseMajorVersion() > 11
|| getDatabaseMajorVersion() == 11 && ( getDatabaseMinorVersion() == 1 && fixPack.intValue() >= 1 || getDatabaseMinorVersion() > 1 );
|| getDatabaseMajorVersion() == 11 && ( getDatabaseMinorVersion() == 1 && fixPack >= 1 || getDatabaseMinorVersion() > 1 );

} catch (final DatabaseException e) {
return false; // assume not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ public List<ChangeSet> generateChangeSets() {
}

private void setReplaceIfExistsTrueIfApplicable(Change[] changes) {
if(changes !=null && diffOutputControl.isReplaceIfExistsSet()) {
for(int i=0; i < changes.length; i++) {
if (changes[i] instanceof ReplaceIfExists) {
((ReplaceIfExists) changes[i]).setReplaceIfExists(true);
if (changes !=null && diffOutputControl.isReplaceIfExistsSet()) {
for (Change change : changes) {
if (change instanceof ReplaceIfExists) {
((ReplaceIfExists) change).setReplaceIfExists(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static void setParameterValueInternal(
if (sqlType == SqlTypeValue.TYPE_UNKNOWN) {
boolean useSetObject = false;
try {
useSetObject = (ps.getConnection().getMetaData().getDatabaseProductName().indexOf("Informix") != -1);
useSetObject = (ps.getConnection().getMetaData().getDatabaseProductName().contains("Informix"));
}
catch (Throwable ex) {
// logger.debug("Could not check database product name", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public Integer run() throws Exception {
try {
if ((args.length == 0) || ((args.length == 1) && ("--" + OPTIONS.HELP).equals(args[0]))) {
main.printHelp(outputStream);
return Integer.valueOf(0);
return 0;
} else if (("--" + OPTIONS.VERSION).equals(args[0])) {
main.command = "";
main.parseDefaultPropertyFiles();
Expand All @@ -260,7 +260,7 @@ public Integer run() throws Exception {
System.getProperties().getProperty("java.home"),
SystemUtil.getJavaVersion()
));
return Integer.valueOf(0);
return 0;
}

//
Expand All @@ -283,7 +283,7 @@ public Integer run() throws Exception {
main.parseOptions(args);
if (main.command == null) {
main.printHelp(outputStream);
return Integer.valueOf(0);
return 0;
}
Scope.getCurrentScope().addMdcValue(MdcKey.LIQUIBASE_COMMAND_NAME, main.command);
} catch (CommandLineParsingException e) {
Expand Down Expand Up @@ -373,14 +373,14 @@ public Integer run() throws Exception {
Scope.getCurrentScope().getUI().sendErrorMessage((
String.format(coreBundle.getString("did.not.run.because.param.was.set.to.false"),
LiquibaseCommandLineConfiguration.SHOULD_RUN.getCurrentConfiguredValue().getProvidedValue().getActualKey())));
return Integer.valueOf(0);
return 0;
}

if (setupNeeded(main)) {
List<String> setupMessages = main.checkSetup();
if (!setupMessages.isEmpty()) {
main.printHelp(setupMessages, isStandardOutputRequired(main.command) ? System.err : outputStream);
return Integer.valueOf(1);
return 1;
}
}

Expand Down Expand Up @@ -447,7 +447,7 @@ public Integer run() throws Exception {
}
}

return Integer.valueOf(0);
return 0;
}
});
}
Expand Down Expand Up @@ -1116,11 +1116,12 @@ protected void printHelp(PrintStream stream) {
protected static CodePointCheck checkArg(String arg) {
char[] chars = arg.toCharArray();
for (int i = 0; i < chars.length; i++) {
for (int j = 0; j < suspiciousCodePoints.length; j++) {
if (suspiciousCodePoints[j] == chars[i]) {
char ch = chars[i];
for (int suspiciousCodePoint : suspiciousCodePoints) {
if (suspiciousCodePoint == ch) {
CodePointCheck codePointCheck = new CodePointCheck();
codePointCheck.position = i;
codePointCheck.ch = chars[i];
codePointCheck.ch = ch;
return codePointCheck;
}
}
Expand Down