Skip to content

Commit

Permalink
Merge pull request #152 from Datical/DAT-3147
Browse files Browse the repository at this point in the history
Dat 3147
  • Loading branch information
nvoxland committed Dec 16, 2019
2 parents ca34d65 + 3a8600a commit 2e785de
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
Expand Up @@ -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<ChangeSet> changeSets = generateChangeSets();

changeLogSerializer.write(changeSets, out);
Expand Down
10 changes: 10 additions & 0 deletions liquibase-core/src/main/java/liquibase/license/LicenseService.java
Expand Up @@ -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.
*/
Expand Down
Expand Up @@ -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!");
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2e785de

Please sign in to comment.