Examples of IO


Examples of org.sonatype.gshell.command.IO

        processor.setFlavor(CliProcessor.Flavor.GNU);
    }

    public Object execute(final CommandContext context) throws Exception {
        assert context != null;
        IO io = context.getIo();
        Variables vars = context.getVariables();
       
        if (version) {
            io.println(maven.getVersion());
            return Result.SUCCESS;
        }

        // HACK: support --encrypt-master-password and --encrypt-password
        if (encryptMasterPassword != null || encryptPassword != null) {
            return doEncryptPassword(context);
        }

        System.setProperty(MavenSystem.MAVEN_HOME, vars.get(SHELL_HOME, File.class).getAbsolutePath());

        MavenRuntimeConfiguration config = new MavenRuntimeConfiguration();

        config.setBaseDirectory(vars.get(SHELL_USER_DIR, File.class));

        if (file != null) {
            config.setPomFile(file);
        }
        if (profiles != null) {
            config.getProfiles().addAll(profiles);
        }
        if (quiet != null) {
            config.setQuiet(quiet);
        }
        if (debug != null) {
            config.setDebug(debug);
        }
        if (showVersion != null) {
            config.setShowVersion(showVersion);
        }
        if (props != null) {
            config.getProperties().putAll(props);
        }
        if (settingsFile != null) {
            config.setSettingsFile(settingsFile);
        }
        if (globalSettingsFile != null) {
            config.setGlobalSettingsFile(globalSettingsFile);
        }
        if (logFile != null) {
            config.setLogFile(logFile);
        }

        customize(config);

        MavenRuntime runtime = maven.create(config);
        MavenExecutionRequest request = runtime.create();

        if (offline != null) {
            request.setOffline(offline);
        }
        if (goals != null) {
            request.setGoals(goals);
        }
        if (batch != null) {
            request.setInteractiveMode(!batch);
        }
        if (resumeFrom != null) {
            request.setResumeFrom(resumeFrom);
        }
        if (toolChainsFile != null) {
            request.setUserToolchainsFile(toolChainsFile);
        }
        if (showErrors != null) {
            request.setShowErrors(showErrors);
        }
        if (nonRecursive != null) {
            request.setRecursive(!nonRecursive);
        }
        if (updateSnapshots != null) {
            request.setUpdateSnapshots(updateSnapshots);
        }
        if (noSnapshotUpdates != null) {
            request.setNoSnapshotUpdates(noSnapshotUpdates);
        }
        if (selectedProjects != null) {
            request.setSelectedProjects(selectedProjects);
        }

        if (strictChecksums) {
            request.setGlobalChecksumPolicy(CHECKSUM_POLICY_FAIL);
        }
        if (laxChecksums) {
            request.setGlobalChecksumPolicy(CHECKSUM_POLICY_WARN);
        }

        if (failFast) {
            request.setReactorFailureBehavior(REACTOR_FAIL_FAST);
        }
        else if (failAtEnd) {
            request.setReactorFailureBehavior(REACTOR_FAIL_AT_END);
        }
        else if (failNever) {
            request.setReactorFailureBehavior(REACTOR_FAIL_NEVER);
        }

        if (alsoMake && !alsoMakeDependents) {
            request.setMakeBehavior(REACTOR_MAKE_UPSTREAM);
        }
        else if (!alsoMake && alsoMakeDependents) {
            request.setMakeBehavior(REACTOR_MAKE_DOWNSTREAM);
        }
        else if (alsoMake && alsoMakeDependents) {
            request.setMakeBehavior(REACTOR_MAKE_BOTH);
        }

        // Customize the plugin groups
        request.addPluginGroup("org.apache.maven.plugins");
        request.addPluginGroup("org.codehaus.mojo");
        request.addPluginGroup("com.sonatype.maven.plugins");
        request.addPluginGroup("org.sonatype.maven.plugins");

        // Setup output colorization
        StreamSet current = StreamJack.current();
        StreamSet streams;
        if (color == null || color) {
            // Complain if the user asked for color and its not supported
            if (color != null && !io.getTerminal().isAnsiSupported()) {
                log.warn("ANSI color is not supported by the current terminal");
            }
            streams = new StreamSet(current.in, new ColorizingStream(current.out), new ColorizingStream(current.err));
        }
        else {
            streams = current;
        }
        config.setStreams(streams);

        StreamJack.register(streams);

        // Execute Maven
        int result = 0;
        try {
            result = runtime.execute(request);
        }
        finally {
            StreamJack.deregister();
            // HACK: Not sure why, but we need to reset the terminal after some mvn builds
            io.getTerminal().reset();
        }

        if (growl) {
            String cl = String.format("%s %s", getName(), Strings.join(context.getArguments(), " "));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.