Search in sources :

Example 1 with ParentBuilder

use of com.mulesoft.tools.migration.project.model.pom.Parent.ParentBuilder in project mule-migration-assistant by mulesoft.

the class MigrationRunner method initializeOptions.

/**
 * Initialises the console options with Apache Command Line
 *
 * @param args
 * @return
 */
private boolean initializeOptions(String[] args) {
    Options options = new Options();
    options.addOption(HELP, false, "Shows the help");
    options.addOption(PROJECT_BASE_PATH, true, "Base directory of the project to be migrated");
    options.addOption(PARENT_DOMAIN_BASE_PATH, true, "Base directory of the parent domain of the project to be migrated, if any");
    options.addOption(DESTINATION_PROJECT_BASE_PATH, true, "Base directory of the migrated project");
    options.addOption(MULE_VERSION, true, "Mule version where to migrate project");
    options.addOption(CANCEL_ON_ERROR, true, "Use cancelOnError to stop the migration. Default is false");
    options.addOption(PROJECT_PARENT_GAV, true, "Use projectParentGAV to migration parent in your pom.xml");
    options.addOption(PROJECT_GAV, true, "Use projectGAV to override default GAV coordinates when a pom.xml is not provided");
    options.addOption(JSON_REPORT, false, "Generate migration report in JSON format");
    options.addOption("userId", true, "The userId to send for the usage statistics");
    options.addOption("sessionId", true, "The sessionId to send for the usage statistics");
    options.addOption("proxyHost", true, "The host of the proxy to use when sending usage statistics");
    options.addOption("proxyPort", true, "The port of the proxy to use when sending usage statistics");
    options.addOption("proxyUser", true, "The username of the proxy to use when sending usage statistics");
    options.addOption("proxyPass", true, "The password of the proxy to use when sending usage statistics");
    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);
        if (line.hasOption(PROJECT_BASE_PATH)) {
            this.projectBasePath = line.getOptionValue(PROJECT_BASE_PATH);
        } else {
            throw new ConsoleOptionsException("You must specify a project base path of the files to be migrated");
        }
        if (line.hasOption(PARENT_DOMAIN_BASE_PATH)) {
            this.parentDomainProjectBasePath = line.getOptionValue(PARENT_DOMAIN_BASE_PATH);
        }
        if (line.hasOption(DESTINATION_PROJECT_BASE_PATH)) {
            this.destinationProjectBasePath = line.getOptionValue(DESTINATION_PROJECT_BASE_PATH);
        } else {
            throw new ConsoleOptionsException("You must specify a destination project base path");
        }
        if (line.hasOption(MULE_VERSION)) {
            this.muleVersion = line.getOptionValue(MULE_VERSION);
        } else {
            throw new ConsoleOptionsException("You must specify a target mule version");
        }
        if (line.hasOption(CANCEL_ON_ERROR)) {
            final String value = line.getOptionValue(CANCEL_ON_ERROR);
            if ("true".equals(value) || "false".equals(value)) {
                this.cancelOnError = Boolean.getBoolean(value);
            } else {
                throw new ConsoleOptionsException("You must specify a boolean value (true or false) for the 'cancelOnError' option");
            }
        }
        if (line.hasOption(PROJECT_PARENT_GAV)) {
            final String value = line.getOptionValue(PROJECT_PARENT_GAV);
            if (StringUtils.isNotEmpty(value) && value.split(":").length == 3) {
                String[] gav = value.split(":");
                this.projectParentGAV = new ParentBuilder().withGroupId(gav[0]).withArtifactId(gav[1]).withVersion(gav[2]).build();
            } else {
                throw new ConsoleOptionsException("You must specify the GAV (groupId, artifactId and version) for the 'projectParentGAV' option");
            }
        }
        if (line.hasOption(PROJECT_GAV)) {
            final String value = line.getOptionValue(PROJECT_GAV);
            if (StringUtils.isNotEmpty(value) && value.matches(".*:.*:.*")) {
                this.projectGAV = value;
            } else {
                throw new ConsoleOptionsException("You must specify the GAV (groupId:artifactId:version) for the 'projectGAV' option");
            }
        }
        if (line.hasOption(JSON_REPORT)) {
            jsonReport = true;
        }
        if (line.hasOption(HELP)) {
            printHelp(options);
        }
        if (line.hasOption("userId")) {
            this.userId = line.getOptionValue("userId");
        } else {
            this.userId = randomUUID().toString();
        }
        if (line.hasOption("sessionId")) {
            this.sessionId = line.getOptionValue("sessionId");
        } else {
            this.sessionId = "111111111";
        }
        if (line.hasOption("proxyHost")) {
            this.proxyHost = line.getOptionValue("proxyHost");
        }
        if (line.hasOption("proxyPort")) {
            this.proxyPort = parseInt(line.getOptionValue("proxyPort"));
        }
        if (line.hasOption("proxyUser")) {
            this.proxyUser = line.getOptionValue("proxyUser");
        }
        if (line.hasOption("proxyPass")) {
            this.proxyPass = line.getOptionValue("proxyPass");
        }
    } catch (ParseException | ConsoleOptionsException e) {
        System.err.println("[ERROR] " + e.getMessage());
        printHelp(options);
        return false;
    }
    return true;
}
Also used : ConsoleOptionsException(com.mulesoft.tools.migration.exception.ConsoleOptionsException) ParentBuilder(com.mulesoft.tools.migration.project.model.pom.Parent.ParentBuilder)

Aggregations

ConsoleOptionsException (com.mulesoft.tools.migration.exception.ConsoleOptionsException)1 ParentBuilder (com.mulesoft.tools.migration.project.model.pom.Parent.ParentBuilder)1