diff --git a/liquibase-core/src/main/java/liquibase/diff/output/changelog/DiffToChangeLog.java b/liquibase-core/src/main/java/liquibase/diff/output/changelog/DiffToChangeLog.java index c48cb3b0cd7..8ff18856718 100644 --- a/liquibase-core/src/main/java/liquibase/diff/output/changelog/DiffToChangeLog.java +++ b/liquibase-core/src/main/java/liquibase/diff/output/changelog/DiffToChangeLog.java @@ -221,8 +221,7 @@ public void printNew(ChangeLogSerializer changeLogSerializer, File file) throws * Prints changeLog that would bring the target database to be the same as * the reference database */ - public void print(PrintStream out, ChangeLogSerializer changeLogSerializer) throws ParserConfigurationException, IOException, DatabaseException { - + public void print(final PrintStream out, final ChangeLogSerializer changeLogSerializer) throws ParserConfigurationException, IOException, DatabaseException { List changeSets = generateChangeSets(); changeLogSerializer.write(changeSets, out); diff --git a/liquibase-core/src/main/java/liquibase/license/LicenseService.java b/liquibase-core/src/main/java/liquibase/license/LicenseService.java index a3b0388453c..ca9a5454b53 100644 --- a/liquibase-core/src/main/java/liquibase/license/LicenseService.java +++ b/liquibase-core/src/main/java/liquibase/license/LicenseService.java @@ -49,6 +49,16 @@ public interface LicenseService { */ LicenseInstallResult installLicense(Location... locations); + /** + * + * Disable this LicenseService + * This can be used to turn off license checking + * after it has been determined that a license + * key is not valid + * + */ + void disable(); + /** * @return true if any installed license is valid but will expire within the next 30 days. */ diff --git a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java index 7f0d7d7c6e2..da2877b4d3f 100644 --- a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java +++ b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java @@ -264,6 +264,15 @@ public abstract class AbstractLiquibaseMojo extends AbstractMojo { */ private File driverPropertiesFile; + /** + * + * Liquibase PRO license key value + * + * @parameter property="liquibase.liquibaseProLicenseKey" + * + */ + protected String liquibaseProLicenseKey; + protected Writer getOutputWriter(final File outputFile) throws IOException { if (outputFileEncoding==null) { getLog().info("Char encoding not set! The created file will be system dependent!"); @@ -299,6 +308,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } + // + // Check for a LiquibasePro license + // + MavenUtils.checkProLicense(liquibaseProLicenseKey, getLog()); + ClassLoader artifactClassLoader = getMavenArtifactClassLoader(); ResourceAccessor fileOpener = getFileOpener(artifactClassLoader); configureFieldsAndValues(fileOpener); diff --git a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseGenerateChangeLogMojo.java b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseGenerateChangeLogMojo.java index ca823fd058c..1cfe7998f04 100644 --- a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseGenerateChangeLogMojo.java +++ b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseGenerateChangeLogMojo.java @@ -9,6 +9,7 @@ import liquibase.integration.commandline.CommandLineUtils; import liquibase.util.StringUtils; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; @@ -118,7 +119,22 @@ protected void performLiquibaseTask(Liquibase liquibase) } } - @Override + /** + * Performs some validation after the properties file has been loaded checking that all + * properties required have been specified. + * + * @throws MojoFailureException If any property that is required has not been + * specified. + */ + @Override + protected void checkRequiredParametersAreSpecified() throws MojoFailureException { + super.checkRequiredParametersAreSpecified(); + if (outputChangeLogFile == null) { + throw new MojoFailureException("The output changeLogFile must be specified."); + } + } + + @Override protected void printSettings(String indent) { super.printSettings(indent); getLog().info(indent + "defaultSchemaName: " + defaultSchemaName); diff --git a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/MavenUtils.java b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/MavenUtils.java index 5af9c2e28f6..060d065e1b1 100644 --- a/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/MavenUtils.java +++ b/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/MavenUtils.java @@ -3,6 +3,11 @@ package org.liquibase.maven.plugins; import liquibase.exception.LiquibaseException; +import liquibase.license.Location; +import liquibase.license.LocationType; +import liquibase.license.LicenseService; +import liquibase.license.LicenseServiceFactory; +import liquibase.license.LicenseInstallResult; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -86,6 +91,36 @@ public static ClassLoader getArtifactClassloader(MavenProject project, return new URLClassLoader(urlArray, clazz.getClassLoader()); } + public static void checkProLicense(String liquibaseProLicenseKey, Log log) { + LicenseService licenseService = LicenseServiceFactory.getInstance().getLicenseService(); + if (licenseService == null) { + return; + } + if (liquibaseProLicenseKey == null) { + log.info("No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line " + + "or in liquibase.properties to use Liquibase Pro features."); + } + else { + Location licenseKeyLocation = + new Location("property liquibaseProLicenseKey", LocationType.BASE64_STRING, liquibaseProLicenseKey); + LicenseInstallResult result = licenseService.installLicense(licenseKeyLocation); + if (result.code != 0) { + String allMessages = String.join("\n", result.messages); + log.warn(allMessages); + } + String licenseInfo = licenseService.getLicenseInfo(); + log.info(licenseInfo); + + // + // If the license has expired then just disable the service + // + if (licenseService.daysTilExpiration() < 0) { + licenseService.disable(); + } + } + log.info(licenseService.getLicenseInfo()); + } + /** * Adds the artifact file into the set of URLs so it can be used in a URLClassLoader. * @param urls The set to add the artifact file URL to.