Example usage for org.apache.maven.cli MavenCli doMain

List of usage examples for org.apache.maven.cli MavenCli doMain

Introduction

In this page you can find the example usage for org.apache.maven.cli MavenCli doMain.

Prototype

public int doMain(CliRequest cliRequest) 

Source Link

Usage

From source file:com.planet57.maven.shell.commands.maven.MavenCommand.java

License:Open Source License

public Object execute(final CommandContext context) throws Exception {
    assert context != null;

    IO io = context.getIo();//from  w ww  .  j a  va  2  s  . c o m
    Variables vars = context.getVariables();

    CliRequestBuilder request = new CliRequestBuilder();
    request.setArguments(strings(context.getArguments()));

    File baseDir = vars.get(SHELL_USER_DIR, File.class);
    request.setWorkingDirectory(baseDir);

    File projectDir = vars.get(MavenCli.MULTIMODULE_PROJECT_DIRECTORY, File.class, null);
    if (projectDir == null) {
        projectDir = findProjectDir(baseDir);
    }
    request.setProjectDirectory(projectDir);

    // 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;
    }
    StreamJack.register(streams);

    int result = -1;
    try {
        MavenCli cli = new MavenCli();
        result = cli.doMain(request.build());
    } finally {
        StreamJack.deregister();
    }

    return result;
}