Skip to content

Commit

Permalink
Merge branch 'liquibase:master' into 2974_Database_Closeable
Browse files Browse the repository at this point in the history
  • Loading branch information
zorglube committed Jul 7, 2022
2 parents 2666234 + 4fb56c5 commit bf49ebe
Show file tree
Hide file tree
Showing 62 changed files with 2,676 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download release assets
uses: robinraju/release-downloader@v1.3
uses: robinraju/release-downloader@v1.4
with:
repository: "liquibase/liquibase"
tag: "${{ needs.setup.outputs.tag }}"
Expand Down
34 changes: 34 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
Liquibase Core Changelog
===========================================

Changes in version 4.13.0 (2022.07.07)

## Enhancements
* Added new liquibase.duplicateFileMode setting by @nvoxland in https://github.com/liquibase/liquibase/pull/3006
* Add additional info in CLI's --version output by @nvoxland in https://github.com/liquibase/liquibase/pull/2942
* Added support for new "searchPath" global configuration by @nvoxland in https://github.com/liquibase/liquibase/pull/2917

## Fixes
* Hide CommandFailedException stacktrace when thrown to set exit code (DAT-9608) by @StevenMassaro in https://github.com/liquibase/liquibase/pull/2938
* Update copyright year in txt files; also update links in txt files (DAT-10261) by @StevenMassaro in https://github.com/liquibase/liquibase/pull/2955
* add support for default-catalog-name in SQL Server (DAT-10484) by @StevenMassaro in https://github.com/liquibase/liquibase/pull/2940
* Make additional query for more column information for MariaDB DAT-8693 by @wwillard7800 in https://github.com/liquibase/liquibase/pull/2898
* Include should fail if a parser cannot be found for the specified file by @nvoxland in https://github.com/liquibase/liquibase/pull/2972
* Improved postgresql prepared statement performance by @nvoxland in https://github.com/liquibase/liquibase/pull/2914
* Cleanup relative paths preventing sql files being found by the class loader by @marcsowen in https://github.com/liquibase/liquibase/pull/2932
* Fix missing attributes in serialization by @tms-91 in https://github.com/liquibase/liquibase/pull/2585
* Improved parsing of single-quoted strings by @nvoxland in https://github.com/liquibase/liquibase/pull/2949
* DAT-10260: add outputFile argument in maven plugin for checks.run target by @StevenMassaro in https://github.com/liquibase/liquibase/pull/2975
* Formatted SQL files with uppercase in the liquibase attributes (DAT-10531) by @abrackx in https://github.com/liquibase/liquibase/pull/2985
* handle empty or null input to stripComments method (DAT-10296) by @StevenMassaro in https://github.com/liquibase/liquibase/pull/2970
* Fixed issue with parameter expression parsing by @nvoxland in https://github.com/liquibase/liquibase/pull/2984
* Fixed before/after/at column arguments in addColumn by @nvoxland in https://github.com/liquibase/liquibase/pull/2943
* Adds liquibase.psql.conf example (DAT-10303) by @abrackx in https://github.com/liquibase/liquibase/pull/2939
* [DAT-10093] added schema escaping to getColumns call to jdbc metadata classes by @KushnirykOleh in https://github.com/liquibase/liquibase/pull/2895
* Use "numeric" (without parameters) data type in PostgreSQL by @LonwoLonwo in https://github.com/liquibase/liquibase/pull/1906
* Force "json" resultset formats in Snowflake when running Java 17+ by @nvoxland in https://github.com/liquibase/liquibase/pull/3019

## JDBC Driver and Third-Party Library Updates
* Upgraded jaxb-core from 2.3.0.1 to 4.0.0 by @dependabot in https://github.com/liquibase/liquibase/pull/2962
* Upgraded snowflake-jdbc from 3.13.19 to 3.13.20 by @dependabot in https://github.com/liquibase/liquibase/pull/3001
* Upgraded mariadb-java-client from 3.0.4 to 3.0.5 by @dependabot in https://github.com/liquibase/liquibase/pull/2881
* Upgraded ojdbc8 from 21.5.0.0 to 21.6.0.0.1 by @dependabot in https://github.com/liquibase/liquibase/pull/2987
* Upgraded h2 from 2.1.212 to 2.1.214 by @dependabot in https://github.com/liquibase/liquibase/pull/2944

Changes in version 4.12.0 (2022.06.16)

## Enhancements
Expand Down
2 changes: 1 addition & 1 deletion liquibase-cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP4</version>
<version>2.0</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
import liquibase.license.LicenseServiceFactory;
import liquibase.logging.LogService;
import liquibase.logging.core.JavaLogService;
import liquibase.resource.CompositeResourceAccessor;
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.*;
import liquibase.ui.ConsoleUIService;
import liquibase.ui.UIService;
import liquibase.util.ISODateFormat;
import liquibase.util.LiquibaseUtil;
import liquibase.util.ObjectUtil;
import liquibase.util.StringUtil;
import liquibase.util.*;
import picocli.CommandLine;

import java.io.*;
Expand Down Expand Up @@ -383,10 +379,8 @@ protected void enableMonitoring() {
return;
}

final String version = System.getProperty("java.version");
final String[] splitVersion = version.split("\\.", 2);
if (Integer.parseInt(splitVersion[0]) < 11) {
Scope.getCurrentScope().getUI().sendMessage("Performance monitoring requires Java 11 or greater. Version " + version + " is not supported.");
if (SystemUtil.getJavaMajorVersion() < 11) {
Scope.getCurrentScope().getUI().sendMessage("Performance monitoring requires Java 11 or greater. Version " + SystemUtil.getJavaVersion() + " is not supported.");
return;
}

Expand Down Expand Up @@ -675,7 +669,9 @@ private CommandLine getRootCommand(CommandLine commandLine) {
private Map<String, Object> configureResourceAccessor(ClassLoader classLoader) {
Map<String, Object> returnMap = new HashMap<>();

returnMap.put(Scope.Attr.resourceAccessor.name(), new CompositeResourceAccessor(new FileSystemResourceAccessor(Paths.get(".").toAbsolutePath().toFile()), new CommandLineResourceAccessor(classLoader)));
returnMap.put(Scope.Attr.resourceAccessor.name(), new SearchPathResourceAccessor(
new FileSystemResourceAccessor(Paths.get(".").toAbsolutePath().toFile()),
new CommandLineResourceAccessor(classLoader)));

return returnMap;
}
Expand All @@ -695,7 +691,7 @@ protected ClassLoader configureClassLoader() throws IllegalArgumentException {
for (String classpathEntry : classpathSoFar) {
File classPathFile = new File(classpathEntry);
if (!classPathFile.exists()) {
throw new IllegalArgumentException(classPathFile.getAbsolutePath() + " does.not.exist");
throw new IllegalArgumentException(classPathFile.getAbsolutePath() + " does not exist");
}

try {
Expand Down
8 changes: 4 additions & 4 deletions liquibase-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
<version>5.0.0</version>
</dependency>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
17 changes: 17 additions & 0 deletions liquibase-core/src/main/java/liquibase/GlobalConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class GlobalConfiguration implements AutoloadedConfigurations {
public static final ConfigurationDefinition<Boolean> PRESERVE_SCHEMA_CASE;
public static final ConfigurationDefinition<Boolean> SHOW_BANNER;

public static final ConfigurationDefinition<DuplicateFileMode> DUPLICATE_FILE_MODE;

/**
* @deprecated No longer used
*/
Expand All @@ -41,6 +43,7 @@ public class GlobalConfiguration implements AutoloadedConfigurations {
public static final ConfigurationDefinition<Boolean> STRICT;
public static final ConfigurationDefinition<Integer> DDL_LOCK_TIMEOUT;
public static final ConfigurationDefinition<Boolean> SECURE_PARSING;
public static final ConfigurationDefinition<String> SEARCH_PATH;

static {
ConfigurationDefinition.Builder builder = new ConfigurationDefinition.Builder("liquibase");
Expand Down Expand Up @@ -198,5 +201,19 @@ public class GlobalConfiguration implements AutoloadedConfigurations {
.setDescription("If true, show a Liquibase banner on startup.")
.setDefaultValue(true)
.build();

DUPLICATE_FILE_MODE = builder.define("duplicateFileMode", DuplicateFileMode.class)
.setDescription("How to handle multiple files being found in the search path that have duplicate paths. Options are WARN (log warning and choose one at random) or ERROR (fail current operation)")
.setDefaultValue(DuplicateFileMode.ERROR)
.build();

SEARCH_PATH = builder.define("searchPath", String.class)
.setDescription("Complete list of Location(s) to search for files such as changelog files in. Multiple paths can be specified by separating them with commas.")
.build();
}

public enum DuplicateFileMode {
WARN,
ERROR,
}
}
13 changes: 4 additions & 9 deletions liquibase-core/src/main/java/liquibase/Liquibase.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
import liquibase.util.StringUtil;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Writer;
import java.io.*;
import java.text.DateFormat;
import java.util.*;
import java.util.function.Supplier;
Expand Down Expand Up @@ -972,13 +969,11 @@ protected void removeRunStatus(List<ChangeSet> changeSets, Contexts contexts, La
protected void executeRollbackScript(String rollbackScript, List<ChangeSet> changeSets, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
final Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
String rollbackScriptContents;
try (InputStreamList streams = resourceAccessor.openStreams(null, rollbackScript)) {
if ((streams == null) || streams.isEmpty()) {
try (InputStream stream = resourceAccessor.openStream(null, rollbackScript)) {
if (stream == null) {
throw new LiquibaseException("WARNING: The rollback script '" + rollbackScript + "' was not located. Please check your parameters. No rollback was performed");
} else if (streams.size() > 1) {
throw new LiquibaseException("Found multiple rollbackScripts named " + rollbackScript);
}
rollbackScriptContents = StreamUtil.readStreamAsString(streams.iterator().next());
rollbackScriptContents = StreamUtil.readStreamAsString(stream);
} catch (IOException e) {
throw new LiquibaseException("Error reading rollbackScript " + executor + ": " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,9 @@ public SqlStatement[] generateStatements(Database database) {
addColumnStatement.setDefaultValueConstraintName(column.getDefaultValueConstraintName());
addColumnStatement.setComputed(column.getComputed());

if ((database instanceof MySQLDatabase) && (column.getAfterColumn() != null)) {
addColumnStatement.setAddAfterColumn(column.getAfterColumn());
} else if (((database instanceof HsqlDatabase) || (database instanceof H2Database))
&& (column.getBeforeColumn() != null)) {
addColumnStatement.setAddBeforeColumn(column.getBeforeColumn());
} else if ((database instanceof FirebirdDatabase) && (column.getPosition() != null)) {
addColumnStatement.setAddAtPosition(column.getPosition());
}
addColumnStatement.setAddAfterColumn(column.getAfterColumn());
addColumnStatement.setAddBeforeColumn(column.getBeforeColumn());
addColumnStatement.setAddAtPosition(column.getPosition());

addColumnStatements.add(addColumnStatement);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ private String expandExpressions(StringReader reader, DatabaseChangeLog changeLo
if (nextChar == '$') {
reader.mark(1);
if (reader.read() == '{') {
reader.mark(1);
if (enableEscaping && reader.read() == ':') {
stringBuilder.append("${");
stringBuilder.append(expandExpressions(reader, changeLog, true).trim());
stringBuilder.append("}");
String paramExpression = expandExpressions(reader, changeLog, true);

Object paramValue;
if (paramExpression.startsWith("${")) {
paramValue = paramExpression; //was not actually a valid expression
} else if (paramExpression.startsWith(":") && enableEscaping) {
paramValue = "${" + paramExpression.substring(1).trim() + "}";
} else {
inExpression = true;
reader.reset();
String paramExpression = expandExpressions(reader, changeLog, true);
Object paramValue = parameters.getValue(paramExpression.trim(), changeLog);
paramValue = parameters.getValue(paramExpression.trim(), changeLog);

if (paramValue == null) {
final ChangeLogParserConfiguration.MissingPropertyMode missingPropertyMode = ChangeLogParserConfiguration.MISSING_PROPERTY_MODE.getCurrentValue();
Expand All @@ -62,11 +61,14 @@ private String expandExpressions(StringReader reader, DatabaseChangeLog changeLo
paramValue = expandExpressions((String) paramValue, changeLog);
}
}
stringBuilder.append(paramValue);
}

stringBuilder.append(paramValue);
} else {
reader.reset();
stringBuilder.append("$");
reader.reset();
nextChar = reader.read();
continue;
}
} else {
if (nextChar == '}' && inExpression) {
Expand All @@ -82,6 +84,11 @@ private String expandExpressions(StringReader reader, DatabaseChangeLog changeLo
// Unreachable as we initialize the StringReader with a non-null string
}

return stringBuilder.toString();
if (inExpression) {
//never got to the trailing `}`, return the string as-is
return "${"+stringBuilder;
} else {
return stringBuilder.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ public DatabaseDataType toDatabaseDataType(Database database) {
return new DatabaseDataType("NUMBER", getParameters());
}
} else if (database instanceof PostgresDatabase) {
if ((getParameters().length > 0) && (Integer.parseInt(getParameters()[0].toString()) > 1000)) {
return new DatabaseDataType("numeric");
if ((getParameters().length > 0)) {
try {
if ((Integer.parseInt(getParameters()[0].toString()) > 1000)) {
return new DatabaseDataType("numeric");
}
} catch (NumberFormatException e) {
return new DatabaseDataType("numeric", getParameters());
}
}
return new DatabaseDataType("numeric", getParameters());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ private void addToChangeSets(Change[] changes, List<ChangeSet> changeSets, Objec
if (useSeparateChangeSets(changes)) {
for (Change change : changes) {
ChangeSet changeSet = new ChangeSet(generateId(changes), getChangeSetAuthor(), false, false, this.changeSetPath, changeSetContext,
null, false, quotingStrategy, null);
null, true, quotingStrategy, null);
changeSet.setCreated(created);
if (diffOutputControl.getLabels() != null) {
changeSet.setLabels(diffOutputControl.getLabels());
Expand All @@ -782,7 +782,7 @@ private void addToChangeSets(Change[] changes, List<ChangeSet> changeSets, Objec
}
} else {
ChangeSet changeSet = new ChangeSet(generateId(changes), getChangeSetAuthor(), false, false, this.changeSetPath, csContext,
null, false, quotingStrategy, null);
null, true, quotingStrategy, null);
changeSet.setCreated(created);
if (diffOutputControl.getLabels() != null) {
changeSet.setLabels(diffOutputControl.getLabels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.io.Writer;

public abstract class AbstractChangeLogBasedTask extends BaseLiquibaseTask {

private String searchPath;
private String changeLogDirectory;
private String changeLogFile;
private String contexts;
Expand Down Expand Up @@ -42,7 +44,20 @@ public String getChangeLogDirectory() {
public void setChangeLogDirectory(String changeLogDirectory) {
this.changeLogDirectory = changeLogDirectory;
}


/**
* Gets the change log directory set from Ant.
* @return The change log directory resource.
*/
@Override
public String getSearchPath() {
return searchPath;
}

public void setSearchPath(String searchPath) {
this.searchPath = searchPath;
}

/**
* Gets the change log file set from Ant.
* @return The change log file resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.CompositeResourceAccessor;
import liquibase.resource.ResourceAccessor;
import liquibase.resource.SearchPathResourceAccessor;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
Expand Down Expand Up @@ -118,6 +119,15 @@ public String getChangeLogDirectory() {
return null;
}

/**
* This method is designed to be overridden by subclasses when a change log is needed. By default it returns null.
*
* @return Returns null in this implementation. Subclasses that need a change log should implement.
*/
public String getSearchPath() {
return null;
}

/**
* This method is designed to be overridden by subclasses when a change log is needed. By default it returns null.
*
Expand Down Expand Up @@ -156,7 +166,7 @@ protected void validateParameters() {
* @return A ResourceAccessor.
*/
private ResourceAccessor createResourceAccessor(AntClassLoader classLoader) {
return new CompositeResourceAccessor(
return new SearchPathResourceAccessor(getSearchPath(),
new AntResourceAccessor(classLoader, getChangeLogDirectory()),
new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ResourceAccessor;
import liquibase.ui.ConsoleUIService;
import liquibase.util.BooleanUtil;
import liquibase.util.ISODateFormat;
import liquibase.util.LiquibaseUtil;
import liquibase.util.StringUtil;
import liquibase.util.*;

import java.io.*;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -250,7 +247,7 @@ public Integer run() throws Exception {

Scope.getCurrentScope().getUI().sendMessage(String.format("Running Java under %s (Version %s)",
System.getProperties().getProperty("java.home"),
System.getProperty("java.version")
SystemUtil.getJavaVersion()
));
return Integer.valueOf(0);
}
Expand Down

0 comments on commit bf49ebe

Please sign in to comment.