Example usage for org.apache.maven.artifact.versioning Restriction containsVersion

List of usage examples for org.apache.maven.artifact.versioning Restriction containsVersion

Introduction

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

Prototype

public boolean containsVersion(ArtifactVersion version) 

Source Link

Usage

From source file:com.naughtyzombie.calypso.maven.mojo.BuildClasspathMojo.java

License:Apache License

/**
 * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default
 * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" ==
 * "[2.0.4,)"/*from ww  w .  j av a2s  .  c o  m*/
 *
 * @param allowedRange range of allowed versions.
 * @param theVersion   the version to be checked.
 * @return true if the version is contained by the range.
 */
public static boolean containsVersion(VersionRange allowedRange, ArtifactVersion theVersion) {
    ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion();
    if (recommendedVersion == null) {
        @SuppressWarnings("unchecked")
        List<Restriction> restrictions = allowedRange.getRestrictions();
        for (Restriction restriction : restrictions) {
            if (restriction.containsVersion(theVersion)) {
                return true;
            }
        }
    }

    // only singular versions ever have a recommendedVersion
    return recommendedVersion.compareTo(theVersion) <= 0;
}

From source file:de.mytoys.maven.plugins.debug.AbstractDebugMojo.java

License:Apache License

/**
 * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default
 * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" ==
 * "[2.0.4,)"//from  www  .  j  av  a 2  s. co  m
 *
 * @param allowedRange range of allowed versions.
 * @param theVersion the version to be checked.
 * @return true if the version is contained by the range.
 */
public static boolean containsVersion(VersionRange allowedRange, ArtifactVersion theVersion) {
    ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion();
    if (recommendedVersion == null) {
        List<Restriction> restrictions = allowedRange.getRestrictions();
        for (Restriction restriction : restrictions) {
            if (restriction.containsVersion(theVersion)) {
                return true;
            }
        }
    }

    // only singular versions ever have a recommendedVersion
    return recommendedVersion.compareTo(theVersion) <= 0;
}

From source file:fr.synchrotron.soleil.ica.ci.maven.plugins.soleildependency.mojo.TreeMojo.java

License:Apache License

/**
 * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default
 * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" ==
 * "[2.0.4,)"// w  w  w .  j a  va 2  s  .co m
 *
 * @param allowedRange range of allowed versions.
 * @param theVersion   the version to be checked.
 * @return true if the version is contained by the range.
 */
public static boolean containsVersion(VersionRange allowedRange, ArtifactVersion theVersion) {
    boolean matched = false;
    ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion();
    if (recommendedVersion == null) {

        for (Iterator i = allowedRange.getRestrictions().iterator(); i.hasNext() && !matched;) {
            Restriction restriction = (Restriction) i.next();
            if (restriction.containsVersion(theVersion)) {
                matched = true;
            }
        }
    } else {
        // only singular versions ever have a recommendedVersion
        int compareTo = recommendedVersion.compareTo(theVersion);
        matched = (compareTo <= 0);
    }
    return matched;
}

From source file:org.codehaus.mojo.versions.api.ArtifactVersions.java

License:Apache License

/**
 * Checks if the version is in the range (and ensures that the range respects the <code>-!</code> syntax
 * to rule out any qualifiers from range boundaries).
 *
 * @param version the version to check./*w  w w  . j  a  v a  2 s. c o  m*/
 * @param range   the range to check.
 * @return <code>true</code> if and only if the version is in the range.
 * @since 1.3
 */
public static boolean isVersionInRange(ArtifactVersion version, VersionRange range) {
    if (!range.containsVersion(version)) {
        return false;
    }
    for (Restriction r : ((List<Restriction>) range.getRestrictions())) {
        if (r.containsVersion(version)) {
            // check for the -! syntax
            if (!r.isLowerBoundInclusive() && r.getLowerBound() != null) {
                String s = r.getLowerBound().toString();
                if (s.endsWith("-!") && version.toString().startsWith(s.substring(0, s.length() - 2))) {
                    return false;
                }
            }
            if (!r.isUpperBoundInclusive() && r.getUpperBound() != null) {
                String s = r.getUpperBound().toString();
                if (s.endsWith("-!") && version.toString().startsWith(s.substring(0, s.length() - 2))) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:org.commonjava.emb.component.vscheme.SchemeAwareVersionRange.java

License:Apache License

/**
 * Creates and returns a new <code>VersionRange</code> that is a restriction of this version range and the specified
 * version range./*from   w w w . jav  a  2 s.co m*/
 * <p>
 * Note: Precedence is given to the recommended version from this version range over the recommended version from
 * the specified version range.
 * </p>
 * 
 * @param restriction
 *            the <code>VersionRange</code> that will be used to restrict this version range.
 * @return the <code>VersionRange</code> that is a restriction of this version range and the specified version
 *         range.
 *         <p>
 *         The restrictions of the returned version range will be an intersection of the restrictions of this
 *         version range and the specified version range if both version ranges have restrictions. Otherwise, the
 *         restrictions on the returned range will be empty.
 *         </p>
 *         <p>
 *         The recommended version of the returned version range will be the recommended version of this version
 *         range, provided that ranges falls within the intersected restrictions. If the restrictions are empty,
 *         this version range's recommended version is used if it is not <code>null</code>. If it is
 *         <code>null</code>, the specified version range's recommended version is used (provided it is non-
 *         <code>null</code>). If no recommended version can be obtained, the returned version range's recommended
 *         version is set to <code>null</code>.
 *         </p>
 * @throws NullPointerException
 *             if the specified <code>VersionRange</code> is <code>null</code>.
 */
public SchemeAwareVersionRange restrict(final SchemeAwareVersionRange restriction) {
    final List<Restriction> r1 = getRestrictions();
    final List<Restriction> r2 = restriction.getRestrictions();
    List<Restriction> restrictions;

    if (r1.isEmpty() || r2.isEmpty()) {
        restrictions = Collections.emptyList();
    } else {
        restrictions = intersection(r1, r2);
    }

    ArtifactVersion version = null;
    if (restrictions.size() > 0) {
        for (final Restriction r : restrictions) {
            if (getRecommendedVersion() != null && r.containsVersion(getRecommendedVersion())) {
                // if we find the original, use that
                version = getRecommendedVersion();
                break;
            } else if (version == null && restriction.getRecommendedVersion() != null
                    && r.containsVersion(restriction.getRecommendedVersion())) {
                // use this if we can, but prefer the original if possible
                version = restriction.getRecommendedVersion();
            }
        }
    }
    // Either the original or the specified version ranges have no restrictions
    else if (getRecommendedVersion() != null) {
        // Use the original recommended version since it exists
        version = getRecommendedVersion();
    } else if (restriction.getRecommendedVersion() != null) {
        // Use the recommended version from the specified VersionRange since there is no
        // original recommended version
        version = restriction.getRecommendedVersion();
    }
    /*
     * TODO: should throw this immediately, but need artifact else { throw new OverConstrainedVersionException(
     * "Restricting incompatible version ranges" ); }
     */

    return new SchemeAwareVersionRange(version, restrictions, restriction.getVersionScheme());
}

From source file:org.commonjava.emb.component.vscheme.SchemeAwareVersionRange.java

License:Apache License

public boolean containsVersion(final ArtifactVersion version) {
    for (final Restriction restriction : getRestrictions()) {
        if (restriction.containsVersion(version)) {
            return true;
        }//from  w  ww  . j ava 2  s.c  o  m
    }
    return false;
}