Search in sources :

Example 1 with LicenseService

use of liquibase.license.LicenseService in project liquibase by liquibase.

the class LiquibaseCommandLine method execute.

public int execute(String[] args) {
    try {
        final String[] finalArgs = adjustLegacyArgs(args);
        configureLogging(Level.OFF, null);
        Main.runningFromNewCli = true;
        final List<ConfigurationValueProvider> valueProviders = registerValueProviders(finalArgs);
        try {
            return Scope.child(configureScope(), () -> {
                if (!LiquibaseCommandLineConfiguration.SHOULD_RUN.getCurrentValue()) {
                    Scope.getCurrentScope().getUI().sendErrorMessage((String.format(coreBundle.getString("did.not.run.because.param.was.set.to.false"), LiquibaseCommandLineConfiguration.SHOULD_RUN.getCurrentConfiguredValue().getProvidedValue().getActualKey())));
                    return 0;
                }
                configureVersionInfo();
                if (!wasHelpOrVersionRequested()) {
                    Scope.getCurrentScope().getUI().sendMessage(CommandLineUtils.getBanner());
                    Scope.getCurrentScope().getUI().sendMessage(String.format(coreBundle.getString("version.number"), LiquibaseUtil.getBuildVersionInfo()));
                    final LicenseService licenseService = Scope.getCurrentScope().getSingleton(LicenseServiceFactory.class).getLicenseService();
                    if (licenseService == null) {
                        Scope.getCurrentScope().getUI().sendMessage("WARNING: License service not loaded, cannot determine Liquibase Pro license status. Please consider re-installing Liquibase to include all dependencies. Continuing operation without Pro license.");
                    } else {
                        Scope.getCurrentScope().getUI().sendMessage(licenseService.getLicenseInfo());
                    }
                }
                CommandLine.ParseResult subcommandParseResult = commandLine.getParseResult();
                while (subcommandParseResult.hasSubcommand()) {
                    subcommandParseResult = subcommandParseResult.subcommand();
                }
                Map<String, String> changelogParameters = subcommandParseResult.matchedOptionValue("-D", new HashMap<>());
                if (changelogParameters.size() != 0) {
                    Main.newCliChangelogParameters = changelogParameters;
                }
                int response = commandLine.execute(finalArgs);
                if (!wasHelpOrVersionRequested()) {
                    final ConfiguredValue<File> logFile = LiquibaseCommandLineConfiguration.LOG_FILE.getCurrentConfiguredValue();
                    if (logFile.found()) {
                        Scope.getCurrentScope().getUI().sendMessage("Logs saved to " + logFile.getValue().getAbsolutePath());
                    }
                    final ConfiguredValue<File> outputFile = LiquibaseCommandLineConfiguration.OUTPUT_FILE.getCurrentConfiguredValue();
                    if (outputFile.found()) {
                        Scope.getCurrentScope().getUI().sendMessage("Output saved to " + outputFile.getValue().getAbsolutePath());
                    }
                    if (response == 0) {
                        final List<CommandLine> commandList = commandLine.getParseResult().asCommandLineList();
                        final String commandName = StringUtil.join(getCommandNames(commandList.get(commandList.size() - 1)), " ");
                        Scope.getCurrentScope().getUI().sendMessage("Liquibase command '" + commandName + "' was executed successfully.");
                    }
                }
                return response;
            });
        } finally {
            final LiquibaseConfiguration liquibaseConfiguration = Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class);
            for (ConfigurationValueProvider provider : valueProviders) {
                liquibaseConfiguration.unregisterProvider(provider);
            }
        }
    } catch (Throwable e) {
        handleException(e);
        return 1;
    } finally {
        cleanup();
    }
}
Also used : ConfigurationValueProvider(liquibase.configuration.ConfigurationValueProvider) CommandLine(picocli.CommandLine) LicenseService(liquibase.license.LicenseService) LicenseServiceFactory(liquibase.license.LicenseServiceFactory) LiquibaseConfiguration(liquibase.configuration.LiquibaseConfiguration)

Example 2 with LicenseService

use of liquibase.license.LicenseService in project liquibase by liquibase.

the class LiquibaseCommandLine method configureVersionInfo.

private void configureVersionInfo() {
    final LicenseService licenseService = Scope.getCurrentScope().getSingleton(LicenseServiceFactory.class).getLicenseService();
    String licenseInfo = "";
    if (licenseService == null) {
        licenseInfo = "WARNING: License service not loaded, cannot determine Liquibase Pro license status. Please consider re-installing Liquibase to include all dependencies. Continuing operation without Pro license.";
    } else {
        licenseInfo = licenseService.getLicenseInfo();
    }
    getRootCommand(this.commandLine).getCommandSpec().version(CommandLineUtils.getBanner(), String.format("Running Java under %s (Version %s)", System.getProperties().getProperty("java.home"), System.getProperty("java.version")), "", "Liquibase Version: " + LiquibaseUtil.getBuildVersionInfo(), licenseInfo);
}
Also used : LicenseService(liquibase.license.LicenseService) LicenseServiceFactory(liquibase.license.LicenseServiceFactory)

Aggregations

LicenseService (liquibase.license.LicenseService)2 LicenseServiceFactory (liquibase.license.LicenseServiceFactory)2 ConfigurationValueProvider (liquibase.configuration.ConfigurationValueProvider)1 LiquibaseConfiguration (liquibase.configuration.LiquibaseConfiguration)1 CommandLine (picocli.CommandLine)1