Search in sources :

Example 1 with RequirementMatcher

use of org.apache.maven.toolchain.RequirementMatcher 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)

Aggregations

File (java.io.File)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MisconfiguredToolchainException (org.apache.maven.toolchain.MisconfiguredToolchainException)1 RequirementMatcher (org.apache.maven.toolchain.RequirementMatcher)1