Search in sources :

Example 1 with UIService

use of liquibase.ui.UIService in project liquibase by liquibase.

the class RegisterChangelogCommandStep method readProjectFromConsole.

private String readProjectFromConsole(List<Project> projects, String changeLogFile) throws CommandLineParsingException {
    final UIService ui = Scope.getCurrentScope().getUI();
    StringBuilder prompt = new StringBuilder("Registering a changelog connects Liquibase operations to a Project for monitoring and reporting.\n");
    prompt.append("Register changelog " + changeLogFile + " to an existing Project, or create a new one.\n");
    prompt.append("Please make a selection:\n");
    prompt.append("[c] Create new Project\n");
    String projFormat = "[%d]";
    if (projects.size() >= 10 && projects.size() < 100) {
        projFormat = "[%2d]";
    } else if (projects.size() >= 100 && projects.size() < 1000) {
        projFormat = "[%3d]";
    } else if (projects.size() >= 1000 && projects.size() < 10000) {
        projFormat = "[%4d]";
    }
    int maxLen = 40;
    for (Project project : projects) {
        if (project.getName() != null && project.getName().length() > maxLen) {
            maxLen = project.getName().length();
        }
    }
    for (int i = 0; i < projects.size(); i++) {
        Project project = projects.get(i);
        prompt.append(String.format(projFormat + " %-" + maxLen + "s (Project ID:%s) %s\n", i + 1, project.getName(), projects.get(i).getId(), projects.get(i).getCreateDate()));
    }
    prompt.append("[N] to not register this changelog right now.\n" + "You can still run Liquibase commands, but no data will be saved in your Liquibase Hub account for monitoring or reports.\n" + " Learn more at https://hub.liquibase.com.\n?");
    return StringUtil.trimToEmpty(ui.prompt(prompt.toString(), "N", null, String.class));
}
Also used : Project(liquibase.hub.model.Project) UIService(liquibase.ui.UIService)

Example 2 with UIService

use of liquibase.ui.UIService in project liquibase by liquibase.

the class RegisterChangelogCommandStep method readProjectNameFromConsole.

private String readProjectNameFromConsole() throws CommandLineParsingException {
    final UIService ui = Scope.getCurrentScope().getUI();
    String hubUrl = HubConfiguration.LIQUIBASE_HUB_URL.getCurrentValue();
    String input = ui.prompt("Please enter your Project name and press [enter].  This is editable in your Liquibase Hub account at " + hubUrl, null, null, String.class);
    return StringUtil.trimToEmpty(input);
}
Also used : UIService(liquibase.ui.UIService)

Example 3 with UIService

use of liquibase.ui.UIService in project liquibase by liquibase.

the class LiquibaseCommandLine method configureScope.

/**
 * Configures the system, and returns values to add to Scope.
 *
 * @return values to set in the scope
 */
private Map<String, Object> configureScope() throws Exception {
    Map<String, Object> returnMap = new HashMap<>();
    final ClassLoader classLoader = configureClassLoader();
    returnMap.putAll(configureLogging());
    returnMap.putAll(configureResourceAccessor(classLoader));
    ConsoleUIService ui = null;
    List<UIService> uiServices = Scope.getCurrentScope().getServiceLocator().findInstances(UIService.class);
    for (UIService uiService : uiServices) {
        if (uiService instanceof ConsoleUIService) {
            ui = (ConsoleUIService) uiService;
            break;
        }
    }
    if (ui == null) {
        ui = new ConsoleUIService();
    }
    ui.setAllowPrompt(true);
    ui.setOutputStream(System.err);
    returnMap.put(Scope.Attr.ui.name(), ui);
    returnMap.put(LiquibaseCommandLineConfiguration.ARGUMENT_CONVERTER.getKey(), (LiquibaseCommandLineConfiguration.ArgumentConverter) argument -> "--" + StringUtil.toKabobCase(argument));
    return returnMap;
}
Also used : LicenseService(liquibase.license.LicenseService) java.util.logging(java.util.logging) CommandLineParsingException(liquibase.exception.CommandLineParsingException) java.util(java.util) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) SystemUtil.isWindows(liquibase.util.SystemUtil.isWindows) LicenseServiceFactory(liquibase.license.LicenseServiceFactory) URL(java.net.URL) ConfiguredValue(liquibase.configuration.ConfiguredValue) LogService(liquibase.logging.LogService) ConfigurationValueProvider(liquibase.configuration.ConfigurationValueProvider) URLClassLoader(java.net.URLClassLoader) ConsoleUIService(liquibase.ui.ConsoleUIService) LogMessageFilter(liquibase.logging.LogMessageFilter) Scope(liquibase.Scope) JavaLogService(liquibase.logging.core.JavaLogService) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) CommandLine(picocli.CommandLine) ResourceBundle.getBundle(java.util.ResourceBundle.getBundle) liquibase.command(liquibase.command) liquibase.command.core(liquibase.command.core) MalformedURLException(java.net.MalformedURLException) PrivilegedAction(java.security.PrivilegedAction) LiquibaseUtil(liquibase.util.LiquibaseUtil) StringUtil(liquibase.util.StringUtil) Collectors(java.util.stream.Collectors) ConfigurationDefinition(liquibase.configuration.ConfigurationDefinition) UIService(liquibase.ui.UIService) Stream(java.util.stream.Stream) java.io(java.io) Paths(java.nio.file.Paths) CommandValidationException(liquibase.exception.CommandValidationException) LiquibaseConfiguration(liquibase.configuration.LiquibaseConfiguration) AccessController(java.security.AccessController) DefaultsFileValueProvider(liquibase.configuration.core.DefaultsFileValueProvider) HubConfiguration(liquibase.hub.HubConfiguration) ConsoleUIService(liquibase.ui.ConsoleUIService) URLClassLoader(java.net.URLClassLoader) ConsoleUIService(liquibase.ui.ConsoleUIService) UIService(liquibase.ui.UIService)

Example 4 with UIService

use of liquibase.ui.UIService in project liquibase by liquibase.

the class RegisterChangelogCommandStep method retrieveOrCreateProject.

private Project retrieveOrCreateProject(HubService service, String changeLogFile, boolean skipPromptIfOneProject) throws CommandLineParsingException, LiquibaseException, LiquibaseHubException {
    final UIService ui = Scope.getCurrentScope().getUI();
    Project project = null;
    List<Project> projects = getProjectsFromHub();
    if (skipPromptIfOneProject && projects.size() == 1) {
        return projects.get(0);
    }
    boolean done = false;
    String input = null;
    while (!done) {
        input = readProjectFromConsole(projects, changeLogFile);
        try {
            if (input.equalsIgnoreCase("C")) {
                String projectName = readProjectNameFromConsole();
                if (StringUtil.isEmpty(projectName)) {
                    ui.sendMessage("\nNo project created\n");
                    continue;
                } else if (projectName.length() > 255) {
                    ui.sendMessage("\nThe project name you entered is longer than 255 characters\n");
                    continue;
                }
                project = service.createProject(new Project().setName(projectName));
                if (project == null) {
                    throw new CommandExecutionException("Unable to create project '" + projectName + "'.\n\n");
                }
                ui.sendMessage("\nProject '" + project.getName() + "' created with project ID '" + project.getId() + "'.\n");
                projects = getProjectsFromHub();
                done = true;
                continue;
            } else if (input.equalsIgnoreCase("N")) {
                throw new CommandExecutionException("Your changelog " + changeLogFile + " was not registered to any Liquibase Hub project. You can still run Liquibase commands, but no data will be saved in your Liquibase Hub account for monitoring or reports.  Learn more at https://hub.liquibase.com.");
            }
            int projectIdx = Integer.parseInt(input);
            if (projectIdx > 0 && projectIdx <= projects.size()) {
                project = projects.get(projectIdx - 1);
                if (project != null) {
                    done = true;
                }
            } else {
                ui.sendMessage("\nInvalid project '" + projectIdx + "' selected\n");
            }
        } catch (NumberFormatException nfe) {
            ui.sendMessage("\nInvalid selection '" + input + "'\n");
        }
    }
    return project;
}
Also used : Project(liquibase.hub.model.Project) UIService(liquibase.ui.UIService) CommandExecutionException(liquibase.exception.CommandExecutionException)

Aggregations

UIService (liquibase.ui.UIService)4 Project (liquibase.hub.model.Project)2 java.io (java.io)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Paths (java.nio.file.Paths)1 AccessController (java.security.AccessController)1 PrivilegedAction (java.security.PrivilegedAction)1 java.util (java.util)1 ResourceBundle.getBundle (java.util.ResourceBundle.getBundle)1 java.util.logging (java.util.logging)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Scope (liquibase.Scope)1 liquibase.command (liquibase.command)1 liquibase.command.core (liquibase.command.core)1 ConfigurationDefinition (liquibase.configuration.ConfigurationDefinition)1 ConfigurationValueProvider (liquibase.configuration.ConfigurationValueProvider)1 ConfiguredValue (liquibase.configuration.ConfiguredValue)1