Search in sources :

Example 1 with MisconfiguredToolchainException

use of org.apache.maven.toolchain.MisconfiguredToolchainException in project maven-plugins by apache.

the class ToolchainMojo method selectToolchain.

protected boolean selectToolchain(String type, Map<String, String> params) throws MojoExecutionException {
    getLog().info("Required toolchain: " + getToolchainRequirementAsString(type, params));
    int typeFound = 0;
    try {
        ToolchainPrivate[] tcs = getToolchains(type);
        for (ToolchainPrivate tc : tcs) {
            if (!type.equals(tc.getType())) {
                // useful because of MNG-5716
                continue;
            }
            typeFound++;
            if (tc.matchesRequirements(params)) {
                getLog().info("Found matching toolchain for type " + type + ": " + tc);
                // store matching toolchain to build context
                toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
                return true;
            }
        }
    } catch (MisconfiguredToolchainException ex) {
        throw new MojoExecutionException("Misconfigured toolchains.", ex);
    }
    getLog().error("No toolchain " + ((typeFound == 0) ? "found" : ("matched from " + typeFound + " found")) + " for type " + type);
    return false;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ToolchainPrivate(org.apache.maven.toolchain.ToolchainPrivate) MisconfiguredToolchainException(org.apache.maven.toolchain.MisconfiguredToolchainException)

Example 2 with MisconfiguredToolchainException

use of org.apache.maven.toolchain.MisconfiguredToolchainException in project maven-plugins by apache.

the class CustomToolchainFactory method createToolchain.

public ToolchainPrivate createToolchain(ToolchainModel model) throws MisconfiguredToolchainException {
    if (model == null) {
        return null;
    }
    CustomToolchainImpl customToolchain = new CustomToolchainImpl(model, logger);
    // populate the provides section
    Properties provides = getProvidesProperties(model);
    for (Map.Entry<Object, Object> provide : provides.entrySet()) {
        String key = (String) provide.getKey();
        String value = (String) provide.getValue();
        if (value == null) {
            throw new MisconfiguredToolchainException("Provides token '" + key + "' doesn't have any value configured.");
        }
        RequirementMatcher matcher;
        if ("version".equals(key)) {
            matcher = RequirementMatcherFactory.createVersionMatcher(value);
        } else {
            matcher = RequirementMatcherFactory.createExactMatcher(value);
        }
        customToolchain.addProvideToken(key, matcher);
    }
    // populate the configuration section
    Properties configuration = toProperties((Xpp3Dom) model.getConfiguration());
    String toolHome = configuration.getProperty(CustomToolchainImpl.KEY_TOOLHOME);
    if (toolHome == null) {
        throw new MisconfiguredToolchainException("Custom toolchain without the " + CustomToolchainImpl.KEY_TOOLHOME + " configuration element.");
    }
    toolHome = FileUtils.normalize(toolHome);
    customToolchain.setToolHome(toolHome);
    if (!new File(toolHome).exists()) {
        throw new MisconfiguredToolchainException("Non-existing tool home configuration at " + new File(toolHome).getAbsolutePath());
    }
    return customToolchain;
}
Also used : Properties(java.util.Properties) Map(java.util.Map) File(java.io.File) MisconfiguredToolchainException(org.apache.maven.toolchain.MisconfiguredToolchainException) RequirementMatcher(org.apache.maven.toolchain.RequirementMatcher)

Example 3 with MisconfiguredToolchainException

use of org.apache.maven.toolchain.MisconfiguredToolchainException in project maven-plugins by apache.

the class ToolchainMojo method selectToolchain.

protected boolean selectToolchain(String type, Map<String, String> params) throws MojoExecutionException {
    getLog().info("Required toolchain: " + getToolchainRequirementAsString(type, params));
    int typeFound = 0;
    try {
        ToolchainPrivate[] tcs = getToolchains(type);
        for (ToolchainPrivate tc : tcs) {
            if (!type.equals(tc.getType())) {
                // useful because of MNG-5716
                continue;
            }
            typeFound++;
            if (tc.matchesRequirements(params)) {
                getLog().info("Found matching toolchain for type " + type + ": " + tc);
                // store matching toolchain to build context
                toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
                return true;
            }
        }
    } catch (MisconfiguredToolchainException ex) {
        throw new MojoExecutionException("Misconfigured toolchains.", ex);
    }
    getLog().error("No toolchain " + ((typeFound == 0) ? "found" : ("matched from " + typeFound + " found")) + " for type " + type);
    return false;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ToolchainPrivate(org.apache.maven.toolchain.ToolchainPrivate) MisconfiguredToolchainException(org.apache.maven.toolchain.MisconfiguredToolchainException)

Aggregations

MisconfiguredToolchainException (org.apache.maven.toolchain.MisconfiguredToolchainException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ToolchainPrivate (org.apache.maven.toolchain.ToolchainPrivate)2 File (java.io.File)1 Map (java.util.Map)1 Properties (java.util.Properties)1 RequirementMatcher (org.apache.maven.toolchain.RequirementMatcher)1