List of usage examples for org.apache.maven.artifact.versioning InvalidVersionSpecificationException InvalidVersionSpecificationException
public InvalidVersionSpecificationException(String message)
From source file:org.commonjava.emb.component.vscheme.SchemeAwareVersionRange.java
License:Apache License
@SuppressWarnings("unchecked") public static SchemeAwareVersionRange createFromVersionSpec(final String spec, final VersionScheme scheme) throws InvalidVersionSpecificationException { if (spec == null) { return null; }/* ww w . jav a 2s. c o m*/ final List<Restriction> restrictions = new ArrayList<Restriction>(); String process = spec; ArtifactVersion version = null; ArtifactVersion upperBound = null; ArtifactVersion lowerBound = null; while (process.startsWith("[") || process.startsWith("(")) { final int index1 = process.indexOf(")"); final int index2 = process.indexOf("]"); int index = index2; if (index2 < 0 || index1 < index2) { if (index1 >= 0) { index = index1; } } if (index < 0) { throw new InvalidVersionSpecificationException("Unbounded range: " + spec); } final Restriction restriction = parseRestriction(process.substring(0, index + 1), scheme); if (lowerBound == null) { lowerBound = restriction.getLowerBound(); } if (upperBound != null) { if (restriction.getLowerBound() == null || restriction.getLowerBound().compareTo(upperBound) < 0) { throw new InvalidVersionSpecificationException("Ranges overlap: " + spec); } } restrictions.add(restriction); upperBound = restriction.getUpperBound(); process = process.substring(index + 1).trim(); if (process.length() > 0 && process.startsWith(",")) { process = process.substring(1).trim(); } } if (process.length() > 0) { if (restrictions.size() > 0) { throw new InvalidVersionSpecificationException( "Only fully-qualified sets allowed in multiple set scenario: " + spec); } else { version = new SchemeAwareArtifactVersion(process, scheme); restrictions.add(Restriction.EVERYTHING); } } return new SchemeAwareVersionRange(version, restrictions, scheme); }
From source file:org.commonjava.emb.component.vscheme.SchemeAwareVersionRange.java
License:Apache License
@SuppressWarnings({ "unchecked" }) private static Restriction parseRestriction(final String spec, final VersionScheme scheme) throws InvalidVersionSpecificationException { final boolean lowerBoundInclusive = spec.startsWith("["); final boolean upperBoundInclusive = spec.endsWith("]"); final String process = spec.substring(1, spec.length() - 1).trim(); Restriction restriction;//from w ww .j av a 2 s. c o m final int index = process.indexOf(","); if (index < 0) { if (!lowerBoundInclusive || !upperBoundInclusive) { throw new InvalidVersionSpecificationException("Single version must be surrounded by []: " + spec); } final ArtifactVersion version = new SchemeAwareArtifactVersion(process, scheme); restriction = new Restriction(version, lowerBoundInclusive, version, upperBoundInclusive); } else { final String lowerBound = process.substring(0, index).trim(); final String upperBound = process.substring(index + 1).trim(); if (lowerBound.equals(upperBound)) { throw new InvalidVersionSpecificationException("Range cannot have identical boundaries: " + spec); } ArtifactVersion lowerVersion = null; if (lowerBound.length() > 0) { lowerVersion = new SchemeAwareArtifactVersion(lowerBound, scheme); } ArtifactVersion upperVersion = null; if (upperBound.length() > 0) { upperVersion = new SchemeAwareArtifactVersion(upperBound, scheme); } if (upperVersion != null && lowerVersion != null && upperVersion.compareTo(lowerVersion) < 0) { throw new InvalidVersionSpecificationException("Range defies version ordering: " + spec); } restriction = new Restriction(lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive); } return restriction; }