Example usage for org.apache.maven.execution MavenExecutionRequest getUserToolchainsFile

List of usage examples for org.apache.maven.execution MavenExecutionRequest getUserToolchainsFile

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenExecutionRequest getUserToolchainsFile.

Prototype

File getUserToolchainsFile();

Source Link

Usage

From source file:org.hudsonci.maven.eventspy_30.handler.MavenExecutionRequestHandler.java

License:Open Source License

private void configureToolChains(final MavenExecutionRequest event) throws IOException {
    // If there is a toolchains document, then write its content to file and configure the request to use it
    DocumentReference document = getCallback().getToolChainsDocument();
    if (document == null)
        return;/*  w  w w.ja  va 2 s .c  o m*/

    if (event.getUserToolchainsFile() != DEFAULT_USER_TOOLCHAINS_FILE) {
        log.warn(
                "Custom tool-chains file configured via command-line as well as via document; document taking precedence");
    }

    log.info("Using tool-chains document ID: {}", document.getId());
    log.trace("Content:\n{}", document.getContent()); // FIXME: May contain sensitive data?

    File file = new File(getCallback().getMavenContextDirectory(), "toolchains.xml");
    File dir = file.getParentFile();
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            log.warn("Failed to create directory structure for: {}", file);
        }
    }

    // Document should not really contain sensitive details, so just leave it around
    Writer writer = new BufferedWriter(new FileWriter(file));
    try {
        writer.write(document.getContent());
    } finally {
        writer.close();
    }

    log.debug("Wrote toolchains.xml: {}", file);
    event.setUserToolchainsFile(file);
}