Example usage for org.apache.maven.artifact.versioning VersionRange getSelectedVersion

List of usage examples for org.apache.maven.artifact.versioning VersionRange getSelectedVersion

Introduction

In this page you can find the example usage for org.apache.maven.artifact.versioning VersionRange getSelectedVersion.

Prototype

public ArtifactVersion getSelectedVersion(Artifact artifact) throws OverConstrainedVersionException 

Source Link

Usage

From source file:org.automagic.deps.doctor.spy.PomSpyImpl.java

License:Apache License

@SuppressWarnings("unchecked")
private boolean isLowerThanCurrent(TransitiveDependency newDependency, Optional<Node> currentVersionNode)
        throws InvalidVersionSpecificationException, OverConstrainedVersionException {
    String version = currentVersionNode.get().getTextContent().trim();
    Optional<String> propertyName = getVersionPropertyName(version);
    if (propertyName.isPresent()) {
        Optional<Node> propertyNode = Utils.getNode("/project/properties/" + propertyName.get(), document);
        if (!propertyNode.isPresent()) {
            return false;
        }// w w w.  j  ava2  s . c  o m
        version = propertyNode.get().getTextContent().trim();
    }
    VersionRange versionRange = VersionRange.createFromVersionSpec(version);
    ArtifactVersion currentVersion = versionRange.getSelectedVersion(newDependency.getArtifact());
    int result = newDependency.getVersion().compareTo(currentVersion);
    return result < 0;
}