Example usage for org.apache.maven.toolchain RequirementMatcherFactory createExactMatcher

List of usage examples for org.apache.maven.toolchain RequirementMatcherFactory createExactMatcher

Introduction

In this page you can find the example usage for org.apache.maven.toolchain RequirementMatcherFactory createExactMatcher.

Prototype

public static RequirementMatcher createExactMatcher(String provideValue) 

Source Link

Usage

From source file:org.codehaus.mojo.exec.PathsToolchainFactory.java

License:Apache License

public ToolchainPrivate createToolchain(final ToolchainModel model) throws MisconfiguredToolchainException {
    if (model == null)
        return null;

    final PathsToolchain pathsToolchain = new PathsToolchain(model, this.logger);
    final Properties provides = this.getProvidesProperties(model);
    for (final Map.Entry<Object, Object> provide : provides.entrySet()) {
        final String key = (String) provide.getKey();
        final String value = (String) provide.getValue();
        if (value == null)
            throw new MisconfiguredToolchainException(
                    "Provides token '" + key + "' doesn't have any value configured.");

        pathsToolchain.addProvideToken(key, RequirementMatcherFactory.createExactMatcher(value));
    }//from   w w w . j ava 2  s  .com

    final Xpp3Dom config = (Xpp3Dom) model.getConfiguration();
    if (config == null)
        return pathsToolchain;

    final Xpp3Dom pathDom = config.getChild("paths");
    if (pathDom == null)
        return pathsToolchain;

    final Xpp3Dom[] pathDoms = pathDom.getChildren("path");
    if (pathDoms == null || pathDoms.length == 0)
        return pathsToolchain;

    final List<String> paths = new ArrayList<String>(pathDoms.length);
    for (final Xpp3Dom pathdom : pathDoms) {
        final String pathString = pathdom.getValue();

        if (pathString == null)
            throw new MisconfiguredToolchainException("path element is empty");

        final String normalizedPath = FileUtils.normalize(pathString);
        final File file = new File(normalizedPath);
        if (!file.exists())
            throw new MisconfiguredToolchainException("Non-existing path '" + file.getAbsolutePath() + "'");

        paths.add(normalizedPath);
    }

    pathsToolchain.setPaths(paths);

    return pathsToolchain;
}

From source file:org.xolstice.maven.toolchain.protobuf.DefaultProtobufToolchainFactory.java

License:Open Source License

@Override
public ToolchainPrivate createToolchain(final ToolchainModel model) throws MisconfiguredToolchainException {
    if (model == null) {
        return null;
    }/*from w w w . j a  va 2s  .co  m*/
    final DefaultProtobufToolchain toolchain = new DefaultProtobufToolchain(model, logger);

    // populate the configuration section
    final Properties configuration = toProperties((Xpp3Dom) model.getConfiguration());
    final String protocExecutable = configuration.getProperty(DefaultProtobufToolchain.KEY_PROTOC_EXECUTABLE);
    if (protocExecutable == null) {
        throw new MisconfiguredToolchainException("Protobuf toolchain without the "
                + DefaultProtobufToolchain.KEY_PROTOC_EXECUTABLE + " configuration element.");
    }
    final String normalizedProtocExecutablePath = FileUtils.normalize(protocExecutable);
    final File protocExecutableFile = new File(normalizedProtocExecutablePath);
    if (protocExecutableFile.exists()) {
        toolchain.setProtocExecutable(normalizedProtocExecutablePath);
    } else {
        throw new MisconfiguredToolchainException(
                "Non-existing protoc executable at " + protocExecutableFile.getAbsolutePath());
    }

    // populate the provides section
    final Properties provides = getProvidesProperties(model);
    for (final Map.Entry<Object, Object> provide : provides.entrySet()) {
        final String key = (String) provide.getKey();
        final String value = (String) provide.getValue();

        if (value == null) {
            throw new MisconfiguredToolchainException(
                    "Provides token '" + key + "' doesn't have any value configured.");
        }

        final RequirementMatcher matcher;
        if ("version".equals(key)) {
            matcher = RequirementMatcherFactory.createVersionMatcher(value);
        } else {
            matcher = RequirementMatcherFactory.createExactMatcher(value);
        }
        toolchain.addProvideToken(key, matcher);
    }

    return toolchain;
}