Skip to content

Commit

Permalink
Merge branch 'master' into github-action-DAT-10497
Browse files Browse the repository at this point in the history
# Conflicts:
#	liquibase-cli/src/main/java/liquibase/integration/commandline/LiquibaseLauncher.java
#	liquibase-dist/pom.xml
  • Loading branch information
nvoxland committed Jul 20, 2022
2 parents 1a9a005 + eb62560 commit 68556e4
Show file tree
Hide file tree
Showing 43 changed files with 490 additions and 508 deletions.
Expand Up @@ -24,6 +24,12 @@ public static void main(final String[] args) throws Exception {
debug("Debug mode enabled because LIQUIBASE_LAUNCHER_DEBUG is set to " + debugSetting);
}

String parentLoaderSetting = System.getenv("LIQUIBASE_LAUNCHER_PARENT_CLASSLOADER");
if (parentLoaderSetting == null) {
parentLoaderSetting = "system";
}
debug("LIQUIBASE_LAUNCHER_PARENT_CLASSLOADER is set to " + parentLoaderSetting);

final String liquibaseHomeEnv = System.getenv("LIQUIBASE_HOME");
debug("LIQUIBASE_HOME: " + liquibaseHomeEnv);
if (liquibaseHomeEnv == null || liquibaseHomeEnv.equals("")) {
Expand Down Expand Up @@ -80,10 +86,20 @@ public static void main(final String[] args) throws Exception {
}
}

//loading with the regular system classloader includes liquibase.jar in the parent.
//That causes the parent classloader to load LiqiuabaseCommandLine which makes it not able to access files in the child classloader
//The system classloader's parent is the boot classloader, which keeps the only classloader with liquibase-core.jar the same as the rest of the classes it needs to access.
final URLClassLoader classloader = new URLClassLoader(urls.toArray(new URL[0]), ClassLoader.getSystemClassLoader().getParent());
ClassLoader parentLoader;
if (parentLoaderSetting.equalsIgnoreCase("system")) {
//loading with the regular system classloader includes liquibase.jar in the parent.
//That causes the parent classloader to load LiquibaseCommandLine which makes it not able to access files in the child classloader
//The system classloader's parent is the boot classloader, which keeps the only classloader with liquibase-core.jar the same as the rest of the classes it needs to access.
parentLoader = ClassLoader.getSystemClassLoader().getParent();

} else if (parentLoaderSetting.equalsIgnoreCase("thread")) {
parentLoader = Thread.currentThread().getContextClassLoader();
} else {
throw new RuntimeException("Unknown LIQUIBASE_LAUNCHER_PARENT_CLASSLOADER value: "+parentLoaderSetting);
}

final URLClassLoader classloader = new URLClassLoader(urls.toArray(new URL[0]), parentLoader);
Thread.currentThread().setContextClassLoader(classloader);

final Class<?> cli = classloader.loadClass(LiquibaseCommandLine.class.getName());
Expand Down
53 changes: 27 additions & 26 deletions liquibase-core/src/main/java/liquibase/changelog/ChangeSet.java
@@ -1,6 +1,7 @@
package liquibase.changelog;

import liquibase.ContextExpression;
import liquibase.GlobalConfiguration;
import liquibase.Labels;
import liquibase.Scope;
import liquibase.change.*;
Expand All @@ -16,6 +17,7 @@
import liquibase.executor.ExecutorService;
import liquibase.executor.LoggingExecutor;
import liquibase.logging.Logger;
import liquibase.parser.ChangeLogParserConfiguration;
import liquibase.parser.core.ParsedNode;
import liquibase.parser.core.ParsedNodeException;
import liquibase.precondition.Conditional;
Expand Down Expand Up @@ -194,7 +196,7 @@ public String toString() {
*/
private PreconditionContainer preconditions;

/**
/**
* ChangeSet level attribute to specify an Executor
*/
private String runWith;
Expand Down Expand Up @@ -276,6 +278,7 @@ public String getFilePath() {

/**
* The logical file path defined directly on this node. Return null if not set.
*
* @return
*/
public String getLogicalFilePath() {
Expand Down Expand Up @@ -367,7 +370,7 @@ public void load(ParsedNode node, ResourceAccessor resourceAccessor) throws Pars
}
} else {
filePath = filePath.replaceAll("\\\\", "/")
.replaceFirst("^/", "");
.replaceFirst("^/", "");

}

Expand Down Expand Up @@ -440,11 +443,7 @@ protected void handleChildNode(ParsedNode child, ResourceAccessor resourceAccess
break;
case "preConditions":
this.preconditions = new PreconditionContainer();
try {
this.preconditions.load(child, resourceAccessor);
} catch (ParsedNodeException e) {
e.printStackTrace();
}
this.preconditions.load(child, resourceAccessor);
break;
case "changes":
for (ParsedNode changeNode : child.getChildren()) {
Expand Down Expand Up @@ -517,6 +516,14 @@ protected void handleRollbackNode(ParsedNode rollbackNode, ResourceAccessor reso
protected Change toChange(ParsedNode value, ResourceAccessor resourceAccessor) throws ParsedNodeException {
Change change = Scope.getCurrentScope().getSingleton(ChangeFactory.class).create(value.getName());
if (change == null) {
if (value.getChildren().size() > 0 && ChangeLogParserConfiguration.CHANGELOG_PARSE_MODE.getCurrentValue().equals(ChangeLogParserConfiguration.ChangelogParseMode.STRICT)) {
String message = "";
if (this.getChangeLog() != null && this.getChangeLog().getPhysicalFilePath() != null) {
message = "Error parsing " + this.getChangeLog().getPhysicalFilePath() + ": ";
}
message += "Unknown change type '" + value.getName() + "'. Check for spelling or capitalization errors and missing extensions such as liquibase-commercial.";
throw new ParsedNodeException(message);
}
return null;
} else {
change.load(value, resourceAccessor);
Expand Down Expand Up @@ -730,7 +737,7 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, customExecutor);
List<Change> changes = getChanges();
for (Change change : changes) {
if (! (change instanceof AbstractChange)) {
if (!(change instanceof AbstractChange)) {
continue;
}
final ResourceAccessor resourceAccessor = ((AbstractChange) change).getResourceAccessor();
Expand All @@ -743,21 +750,19 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
}

/**
*
* Look for a configuration property that matches liquibase.<executor name>.executor
* and if found, return its value as the executor name
*
* @param executorName The value from the input changeset runWith attribute
* @return String The mapped value
*
* @param executorName The value from the input changeset runWith attribute
* @return String The mapped value
*/
public static String lookupExecutor(String executorName) {
if (StringUtil.isEmpty(executorName)) {
return null;
}
String key = "liquibase." + executorName.toLowerCase() + ".executor";
String replacementExecutorName =
(String)Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getCurrentConfiguredValue(null, null, key).getValue();
(String) Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getCurrentConfiguredValue(null, null, key).getValue();
if (replacementExecutorName != null) {
Scope.getCurrentScope().getLog(ChangeSet.class).info("Mapped '" + executorName + "' to executor '" + replacementExecutorName + "'");
return replacementExecutorName;
Expand Down Expand Up @@ -906,7 +911,7 @@ public void setIgnore(boolean ignore) {
}

public boolean isInheritableIgnore() {
DatabaseChangeLog changeLog = getChangeLog();
DatabaseChangeLog changeLog = getChangeLog();
if (changeLog == null) {
return false;
}
Expand Down Expand Up @@ -945,11 +950,9 @@ public Collection<Labels> getInheritableLabels() {
}

/**
*
* Build and return a string which contains both the changeset and inherited context
*
* @return String
*
* @return String
*/
public String buildFullContext() {
StringBuilder contextExpression = new StringBuilder();
Expand All @@ -966,11 +969,9 @@ public String buildFullContext() {
}

/**
*
* Build and return a string which contains both the changeset and inherited labels
*
* @return String
*
* @return String
*/
public String buildFullLabels() {
StringBuilder labels = new StringBuilder();
Expand Down Expand Up @@ -1219,11 +1220,11 @@ public String getSerializedObjectName() {
@Override
public Set<String> getSerializableFields() {
return new LinkedHashSet<>(
Arrays.asList(
"id", "author", "runAlways", "runOnChange", "failOnError", "context", "labels", "dbms",
"objectQuotingStrategy", "comment", "preconditions", "changes", "rollback", "labels",
"logicalFilePath", "created", "runInTransaction", "runOrder", "ignore"
)
Arrays.asList(
"id", "author", "runAlways", "runOnChange", "failOnError", "context", "labels", "dbms",
"objectQuotingStrategy", "comment", "preconditions", "changes", "rollback", "labels",
"logicalFilePath", "created", "runInTransaction", "runOrder", "ignore"
)
);
}

Expand Down Expand Up @@ -1308,7 +1309,7 @@ public Object getSerializableFieldValue(String field) {
}

if ("logicalFilePath".equals(field)) {
return getLogicalFilePath();
return getLogicalFilePath();
}

if ("rollback".equals(field)) {
Expand Down
Expand Up @@ -426,13 +426,9 @@ protected void handleChildNode(ParsedNode node, ResourceAccessor resourceAccesso
}
case "preConditions": {
PreconditionContainer parsedContainer = new PreconditionContainer();
try {
parsedContainer.load(node, resourceAccessor);
this.preconditionContainer.addNestedPrecondition(parsedContainer);
parsedContainer.load(node, resourceAccessor);
this.preconditionContainer.addNestedPrecondition(parsedContainer);

} catch (ParsedNodeException e) {
e.printStackTrace();
}
break;
}
case "property": {
Expand Down

0 comments on commit 68556e4

Please sign in to comment.