Skip to content

Commit

Permalink
[DAT-16135] add new scope flag for modifyChangeSet flow (#5707)
Browse files Browse the repository at this point in the history
* add new scope for modifyChangeSet flow

* reverted formatting changes

* added comment

* fixed regression with getting and normalizing path

---------

Co-authored-by: obovsunivskyii <baqaua@gmail.com>
  • Loading branch information
KushnirykOleh and obovsunivskyii committed Mar 22, 2024
1 parent f9e57fe commit d224b5b
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ public boolean include(String fileName,
throw new UnexpectedLiquibaseException(e);
}
}
final String normalizedFilePath = fileName;

DatabaseChangeLog changeLog;
try {
DatabaseChangeLog rootChangeLog = ROOT_CHANGE_LOG.get();
Expand All @@ -938,17 +940,24 @@ public boolean include(String fileName,
DatabaseChangeLog parentChangeLog = PARENT_CHANGE_LOG.get();
PARENT_CHANGE_LOG.set(this);
try {
if (!resourceAccessor.get(fileName).exists()) {
if (!resourceAccessor.get(normalizedFilePath).exists()) {
if (ChangeLogParserConfiguration.ON_MISSING_INCLUDE_CHANGELOG.getCurrentValue().equals(ChangeLogParserConfiguration.MissingIncludeConfiguration.WARN)
|| !errorIfMissing) {
Scope.getCurrentScope().getLog(getClass()).warning(FileUtil.getFileNotFoundMessage(fileName));
Scope.getCurrentScope().getLog(getClass()).warning(FileUtil.getFileNotFoundMessage(normalizedFilePath));
return false;
} else {
throw new ChangeLogParseException(FileUtil.getFileNotFoundMessage(fileName));
throw new ChangeLogParseException(FileUtil.getFileNotFoundMessage(normalizedFilePath));
}
}
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(fileName, resourceAccessor);
changeLog = parser.parse(fileName, changeLogParameters, resourceAccessor);
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(normalizedFilePath, resourceAccessor);

if (modifyChangeSets != null) {
// Some parser need to know it's not a top level changelog, in modifyChangeSets flow 'runWith' attributes are added later on
changeLog = Scope.child(Collections.singletonMap("modifyChangeSets", true),
() -> parser.parse(normalizedFilePath, changeLogParameters, resourceAccessor));
} else {
changeLog = parser.parse(normalizedFilePath, changeLogParameters, resourceAccessor);
}
changeLog.setIncludeContextFilter(includeContextFilter);
changeLog.setIncludeLabels(labels);
changeLog.setIncludeIgnore(ignore != null ? ignore.booleanValue() : false);
Expand All @@ -967,14 +976,14 @@ public boolean include(String fileName,
throw e;
}
// This matches only an extension, but filename can be a full path, too. Is it right?
boolean matchesFileExtension = StringUtil.trimToEmpty(fileName).matches("\\.\\w+$");
boolean matchesFileExtension = StringUtil.trimToEmpty(normalizedFilePath).matches("\\.\\w+$");
if (matchesFileExtension || onUnknownFileFormat == OnUnknownFileFormat.WARN) {
Scope.getCurrentScope().getLog(getClass()).warning(
"included file " + fileName + "/" + fileName + " is not a recognized file type"
"included file " + normalizedFilePath + "/" + normalizedFilePath + " is not a recognized file type"
);
}
return false;
} catch (IOException e) {
} catch (Exception e) {
throw new LiquibaseException(e.getMessage(), e);
}
PreconditionContainer preconditions = changeLog.getPreconditions();
Expand Down

0 comments on commit d224b5b

Please sign in to comment.