Example usage for org.apache.maven.toolchain.building ToolchainsBuildingResult getEffectiveToolchains

List of usage examples for org.apache.maven.toolchain.building ToolchainsBuildingResult getEffectiveToolchains

Introduction

In this page you can find the example usage for org.apache.maven.toolchain.building ToolchainsBuildingResult getEffectiveToolchains.

Prototype

PersistedToolchains getEffectiveToolchains();

Source Link

Document

Gets the assembled toolchains.

Usage

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFMavenCli.java

License:Apache License

@SuppressWarnings("checkstyle:methodlength")
protected void toolchains(AFCliRequest cliRequest) throws Exception {

    Path userToolchainsFile;/*  www .j a  va 2 s .  co m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) {
        userToolchainsFile = Paths
                .get(cliRequest.getCommandLine().getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS));
        userToolchainsFile = resolvePath(userToolchainsFile, cliRequest.getWorkingDirectory());

        if (!java.nio.file.Files.isRegularFile(userToolchainsFile)) {
            throw new FileNotFoundException(
                    "The specified user toolchains file does not exist: " + userToolchainsFile);
        }
    } else {
        userToolchainsFile = Paths.get(userMavenConfigurationHome.toString(), "toolchains.xml");
    }

    Path globalToolchainsFile;

    if (cliRequest.getCommandLine().hasOption(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS)) {
        globalToolchainsFile = Paths
                .get(cliRequest.getCommandLine().getOptionValue(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS));
        globalToolchainsFile = resolvePath(globalToolchainsFile, cliRequest.getWorkingDirectory());

        if (!java.nio.file.Files.isRegularFile(globalToolchainsFile)) {
            throw new FileNotFoundException(
                    "The specified global toolchains file does not exist: " + globalToolchainsFile);
        }
    } else {
        globalToolchainsFile = Paths.get(userMavenConfigurationHome.toString(), "toolchains.xml");
    }

    cliRequest.getRequest().setGlobalToolchainsFile(globalToolchainsFile.toFile());
    cliRequest.getRequest().setUserToolchainsFile(userToolchainsFile.toFile());

    DefaultToolchainsBuildingRequest toolchainsRequest = new DefaultToolchainsBuildingRequest();
    if (java.nio.file.Files.isRegularFile(globalToolchainsFile)) {
        toolchainsRequest.setGlobalToolchainsSource(new FileSource(globalToolchainsFile.toFile()));
    }
    if (java.nio.file.Files.isRegularFile(userToolchainsFile)) {
        toolchainsRequest.setUserToolchainsSource(new FileSource(userToolchainsFile.toFile()));
    }

    eventSpyDispatcher.onEvent(toolchainsRequest);

    slf4jLogger.debug("Reading global toolchains from "
            + getLocation(toolchainsRequest.getGlobalToolchainsSource(), globalToolchainsFile));
    slf4jLogger.debug("Reading user toolchains from "
            + getLocation(toolchainsRequest.getUserToolchainsSource(), userToolchainsFile));

    ToolchainsBuildingResult toolchainsResult = toolchainsBuilder.build(toolchainsRequest);

    eventSpyDispatcher.onEvent(toolchainsRequest);

    executionRequestPopulator.populateFromToolchains(cliRequest.getRequest(),
            toolchainsResult.getEffectiveToolchains());

    if (!toolchainsResult.getProblems().isEmpty() && slf4jLogger.isWarnEnabled()) {
        slf4jLogger.warn("");
        slf4jLogger.warn("Some problems were encountered while building the effective toolchains");

        for (Problem problem : toolchainsResult.getProblems()) {
            slf4jLogger.warn(problem.getMessage() + " @ " + problem.getLocation());
        }

        slf4jLogger.warn("");
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java

License:Apache License

@SuppressWarnings("checkstyle:methodlength")
protected void toolchains(AFCliRequest cliRequest) throws Exception {

    Path userToolchainsFile;/*from  w  w  w.ja  va2 s .c o m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) {
        userToolchainsFile = Paths
                .get(cliRequest.getCommandLine().getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS));
        userToolchainsFile = resolvePath(userToolchainsFile, cliRequest.getWorkingDirectory());

        if (!java.nio.file.Files.isRegularFile(userToolchainsFile)) {
            throw new FileNotFoundException(
                    "The specified user toolchains file does not exist: " + userToolchainsFile);
        }
    } else {
        userToolchainsFile = Paths.get(userMavenConfigurationHome.toString(), "toolchains.xml");
    }

    Path globalToolchainsFile;

    if (cliRequest.getCommandLine().hasOption(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS)) {
        globalToolchainsFile = Paths
                .get(cliRequest.getCommandLine().getOptionValue(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS));
        globalToolchainsFile = resolvePath(globalToolchainsFile, cliRequest.getWorkingDirectory());

        if (!java.nio.file.Files.isRegularFile(globalToolchainsFile)) {
            throw new FileNotFoundException(
                    "The specified global toolchains file does not exist: " + globalToolchainsFile);
        }
    } else {
        globalToolchainsFile = Paths.get(userMavenConfigurationHome.toString(), "toolchains.xml");
    }

    cliRequest.getRequest().setGlobalToolchainsFile(globalToolchainsFile.toFile());
    cliRequest.getRequest().setUserToolchainsFile(userToolchainsFile.toFile());

    DefaultToolchainsBuildingRequest toolchainsRequest = new DefaultToolchainsBuildingRequest();
    if (java.nio.file.Files.isRegularFile(globalToolchainsFile)) {
        toolchainsRequest.setGlobalToolchainsSource(new FileSource(globalToolchainsFile.toFile()));
    }
    if (java.nio.file.Files.isRegularFile(userToolchainsFile)) {
        toolchainsRequest.setUserToolchainsSource(new FileSource(userToolchainsFile.toFile()));
    }

    reusableEventSpyDispatcher.onEvent(toolchainsRequest);

    reusableSlf4jLogger.debug("Reading global toolchains from "
            + getLocation(toolchainsRequest.getGlobalToolchainsSource(), globalToolchainsFile));
    reusableSlf4jLogger.debug("Reading user toolchains from "
            + getLocation(toolchainsRequest.getUserToolchainsSource(), userToolchainsFile));

    ToolchainsBuildingResult toolchainsResult = reusableToolchainsBuilder.build(toolchainsRequest);

    reusableEventSpyDispatcher.onEvent(toolchainsRequest);

    reusableExecutionRequestPopulator.populateFromToolchains(cliRequest.getRequest(),
            toolchainsResult.getEffectiveToolchains());

    if (!toolchainsResult.getProblems().isEmpty() && reusableSlf4jLogger.isWarnEnabled()) {
        reusableSlf4jLogger.warn("");
        reusableSlf4jLogger.warn("Some problems were encountered while building the effective toolchains");

        for (Problem problem : toolchainsResult.getProblems()) {
            reusableSlf4jLogger.warn(problem.getMessage() + " @ " + problem.getLocation());
        }

        reusableSlf4jLogger.warn("");
    }
}