Skip to content

Commit

Permalink
Merge branch 'master' into edb-check-too-broad
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Jan 19, 2022
2 parents fa7d512 + a9b2c81 commit 9cdf0f5
Show file tree
Hide file tree
Showing 69 changed files with 486 additions and 220 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -150,6 +150,32 @@ jobs:
path: |
*/target/*-0-SNAPSHOT.jar
sonar:
name: Sonar Scan
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v2
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn clean verify sonar:sonar -P sonar -Dsonar.login=$SONAR_TOKEN

integration-test:
name: Integration Test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -308,7 +334,7 @@ jobs:
finish:
name: Finish Build
runs-on: ubuntu-latest
needs: [ setup, build, integration-test, package ]
needs: [ setup, build, integration-test, package, sonar ]
if: ${{ always() }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# Liquibase [![Build and Test](https://github.com/liquibase/liquibase/actions/workflows/build.yml/badge.svg)](https://github.com/liquibase/liquibase/actions/workflows/build.yml)
# Liquibase [![Build and Test](https://github.com/liquibase/liquibase/actions/workflows/build.yml/badge.svg)](https://github.com/liquibase/liquibase/actions/workflows/build.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=liquibase&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=liquibase)
<p align="center"><img src="https://github.com/liquibase/liquibase/blob/master/Liquibase.png" width="30%" height="30%"></p>

Liquibase helps millions of teams track, version, and deploy database schema changes. It will help you to:
Expand Down
Expand Up @@ -2,6 +2,9 @@

import liquibase.command.CommandResults;
import liquibase.command.CommandScope;
import liquibase.command.CommonArgumentNames;
import liquibase.exception.CommandValidationException;
import liquibase.exception.MissingRequiredArgumentException;
import liquibase.util.StringUtil;
import picocli.CommandLine;

Expand All @@ -10,7 +13,10 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class CommandRunner implements Callable<CommandResults> {

Expand Down Expand Up @@ -43,6 +49,17 @@ public CommandResults call() throws Exception {
}

return commandScope.execute();
} catch (CommandValidationException cve) {
Throwable cause = cve.getCause();
if (cause instanceof MissingRequiredArgumentException) {
// This is a list of the arguments which the init project command supports. The thinking here is that if the user
// forgets to supply one of these arguments, we're going to remind them about the init project command, which
// can help them figure out what they should be providing here.
final Set<String> initProjectArguments = Stream.of(CommonArgumentNames.CHANGELOG_FILE, CommonArgumentNames.URL, CommonArgumentNames.USERNAME, CommonArgumentNames.PASSWORD).map(CommonArgumentNames::getArgumentName).collect(Collectors.toSet());
throw new CommandValidationException(cve.getMessage() + (initProjectArguments.contains(((MissingRequiredArgumentException) cause).getArgumentName()) ? ". If you need to configure new liquibase project files and arguments, run the 'liquibase init project' command." : ""));
} else {
throw cve;
}
} finally {
if (outputStream != null) {
outputStream.flush();
Expand Down
Expand Up @@ -971,7 +971,7 @@ private void configureHelp(CommandLine.Model.CommandSpec commandSpec, boolean in
"- Environment values (env variable listed above)\n" +
"- Defaults file (configuration key OR argument name)\n\n" +
"Full documentation is available at\n" +
"http://www.liquibase.org";
"https://docs.liquibase.com";


commandSpec.addOption(CommandLine.Model.OptionSpec.builder("--help", "-h")
Expand Down
3 changes: 2 additions & 1 deletion liquibase-core/src/main/java/liquibase/Liquibase.java
Expand Up @@ -1942,12 +1942,13 @@ public void reportLocks(PrintStream out) throws LiquibaseException {
+ "@" + getDatabase().getConnection().getURL());
if (locks.length == 0) {
out.println(" - No locks");
return;
}
for (DatabaseChangeLogLock lock : locks) {
out.println(" - " + lock.getLockedBy() + " at " +
DateFormat.getDateTimeInstance().format(lock.getLockGranted()));
}

out.println("NOTE: The lock time displayed is based on the database's configured time");
}

public void forceReleaseLocks() throws LiquibaseException {
Expand Down
Expand Up @@ -46,7 +46,7 @@ public Direction getDirection() {
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (! (executor instanceof LoggingExecutor)) {
Scope.getCurrentScope().getUI().sendMessage("Rolling Back Changeset:" + changeSet);
Scope.getCurrentScope().getUI().sendMessage("Rolling Back Changeset: " + changeSet);
}
sendRollbackWillRunEvent(changeSet, databaseChangeLog, database);
try {
Expand Down
Expand Up @@ -10,6 +10,9 @@
import liquibase.database.ObjectQuotingStrategy;
import liquibase.exception.LiquibaseException;
import liquibase.exception.MigrationFailedException;
import liquibase.executor.Executor;
import liquibase.executor.ExecutorService;
import liquibase.executor.LoggingExecutor;

import java.util.Set;

Expand Down Expand Up @@ -40,8 +43,12 @@ public Direction getDirection() {
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database,
Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (! (executor instanceof LoggingExecutor)) {
Scope.getCurrentScope().getUI().sendMessage("Running Changeset: " + changeSet);
}
ChangeSet.RunStatus runStatus = this.database.getRunStatus(changeSet);
Scope.getCurrentScope().getLog(getClass()).fine("Running Changeset:" + changeSet);
Scope.getCurrentScope().getLog(getClass()).fine("Running Changeset: " + changeSet);
fireWillRun(changeSet, databaseChangeLog, database, runStatus);
ExecType execType = null;
ObjectQuotingStrategy previousStr = this.database.getObjectQuotingStrategy();
Expand Down
Expand Up @@ -4,6 +4,7 @@
import liquibase.configuration.ConfigurationValueConverter;
import liquibase.configuration.ConfigurationValueObfuscator;
import liquibase.exception.CommandValidationException;
import liquibase.exception.MissingRequiredArgumentException;
import liquibase.integration.commandline.LiquibaseCommandLineConfiguration;
import liquibase.util.ObjectUtil;

Expand Down Expand Up @@ -113,7 +114,7 @@ public ConfigurationValueObfuscator<DataType> getValueObfuscator() {
public void validate(CommandScope commandScope) throws CommandValidationException {
final DataType currentValue = commandScope.getArgumentValue(this);
if (this.isRequired() && currentValue == null) {
throw new CommandValidationException(LiquibaseCommandLineConfiguration.ARGUMENT_CONVERTER.getCurrentValue().convert(this.getName()), "missing required argument");
throw new CommandValidationException(LiquibaseCommandLineConfiguration.ARGUMENT_CONVERTER.getCurrentValue().convert(this.getName()), "missing required argument", new MissingRequiredArgumentException(this.getName()));
}
}

Expand Down
Expand Up @@ -21,6 +21,13 @@ public <DataType> CommandArgumentDefinition.Building<DataType> argument(String n
return new CommandArgumentDefinition.Building<>(commandNames, new CommandArgumentDefinition<>(name, type));
}

/**
* Starts the building of a new {@link CommandArgumentDefinition}.
*/
public <DataType> CommandArgumentDefinition.Building<DataType> argument(CommonArgumentNames argument, Class<DataType> type) {
return new CommandArgumentDefinition.Building<>(commandNames, new CommandArgumentDefinition<>(argument.getArgumentName(), type));
}

/**
* Starts the building of a new {@link CommandResultDefinition}.
*/
Expand Down
@@ -0,0 +1,21 @@
package liquibase.command;

/**
* A common place to store commonly used command argument names.
*/
public enum CommonArgumentNames {
USERNAME("username"),
PASSWORD("password"),
URL("url"),
CHANGELOG_FILE("changelogFile");

private final String argumentName;

CommonArgumentNames(String argumentName) {
this.argumentName = argumentName;
}

public String getArgumentName() {
return argumentName;
}
}
Expand Up @@ -20,9 +20,9 @@ public class CalculateChecksumCommandStep extends AbstractCliWrapperCommandStep

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
CHANGELOG_FILE_ARG = builder.argument("changelogFile", String.class).required()
CHANGELOG_FILE_ARG = builder.argument(CommonArgumentNames.CHANGELOG_FILE, String.class).required()
.description("The root changelog file").build();
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -32,9 +32,9 @@ public class CalculateChecksumCommandStep extends AbstractCliWrapperCommandStep
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.description("The database password")
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.build();
Expand Down
Expand Up @@ -21,9 +21,9 @@ public class ChangelogSyncCommandStep extends AbstractCliWrapperCommandStep {

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
CHANGELOG_FILE_ARG = builder.argument("changelogFile", String.class).required()
CHANGELOG_FILE_ARG = builder.argument(CommonArgumentNames.CHANGELOG_FILE, String.class).required()
.description("The root changelog file").build();
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -33,9 +33,9 @@ public class ChangelogSyncCommandStep extends AbstractCliWrapperCommandStep {
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.description("The database password")
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.build();
Expand Down
Expand Up @@ -21,9 +21,9 @@ public class ChangelogSyncSqlCommandStep extends AbstractCliWrapperCommandStep {

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
CHANGELOG_FILE_ARG = builder.argument("changelogFile", String.class).required()
CHANGELOG_FILE_ARG = builder.argument(CommonArgumentNames.CHANGELOG_FILE, String.class).required()
.description("The root changelog file").build();
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -33,9 +33,9 @@ public class ChangelogSyncSqlCommandStep extends AbstractCliWrapperCommandStep {
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.description("The database password").build();
LABELS_ARG = builder.argument("labels", String.class)
Expand Down
Expand Up @@ -22,9 +22,9 @@ public class ChangelogSyncToTagCommandStep extends AbstractCliWrapperCommandStep

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
CHANGELOG_FILE_ARG = builder.argument("changelogFile", String.class).required()
CHANGELOG_FILE_ARG = builder.argument(CommonArgumentNames.CHANGELOG_FILE, String.class).required()
.description("The root changelog file").build();
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -34,9 +34,9 @@ public class ChangelogSyncToTagCommandStep extends AbstractCliWrapperCommandStep
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.description("The database password").build();
LABELS_ARG = builder.argument("labels", String.class)
Expand Down
Expand Up @@ -22,9 +22,9 @@ public class ChangelogSyncToTagSqlCommandStep extends AbstractCliWrapperCommandS

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
CHANGELOG_FILE_ARG = builder.argument("changelogFile", String.class).required()
CHANGELOG_FILE_ARG = builder.argument(CommonArgumentNames.CHANGELOG_FILE, String.class).required()
.description("The root changelog file").build();
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -34,9 +34,9 @@ public class ChangelogSyncToTagSqlCommandStep extends AbstractCliWrapperCommandS
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.description("The database password").build();
LABELS_ARG = builder.argument("labels", String.class)
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class ClearChecksumsCommandStep extends AbstractCliWrapperCommandStep {

static {
CommandBuilder builder = new CommandBuilder(COMMAND_NAME);
URL_ARG = builder.argument("url", String.class).required()
URL_ARG = builder.argument(CommonArgumentNames.URL, String.class).required()
.description("The JDBC database connection URL").build();
DEFAULT_SCHEMA_NAME_ARG = builder.argument("defaultSchemaName", String.class)
.description("The default schema name to use for the database connection").build();
Expand All @@ -28,9 +28,9 @@ public class ClearChecksumsCommandStep extends AbstractCliWrapperCommandStep {
.description("The JDBC driver class").build();
DRIVER_PROPERTIES_FILE_ARG = builder.argument("driverPropertiesFile", String.class)
.description("The JDBC driver properties file").build();
USERNAME_ARG = builder.argument("username", String.class)
USERNAME_ARG = builder.argument(CommonArgumentNames.USERNAME, String.class)
.description("The database username").build();
PASSWORD_ARG = builder.argument("password", String.class)
PASSWORD_ARG = builder.argument(CommonArgumentNames.PASSWORD, String.class)
.setValueObfuscator(ConfigurationValueObfuscator.STANDARD)
.description("The database password").build();
}
Expand Down

0 comments on commit 9cdf0f5

Please sign in to comment.