/** * Parses an unnamespaced string representation of an artifact range. It is expected to be of the form: * {name}[{lower-version},{upper-version}]. Square brackets are inclusive, and parentheses are exclusive. * For example, my-functions[1.0.0,2.0.0) will correspond to an artifact name of my-functions with a * lower version of 1.0.0 and an upper version of 2.0.0. * * @param namespace the namespace of the artifact range * @param artifactRangeStr the string representation to parse * @return the ArtifactRange corresponding to the given string */ public static ArtifactRange parseArtifactRange(String namespace, String artifactRangeStr) throws InvalidArtifactRangeException { // search for the '[' or '(' between the artifact name and lower version int versionStartIndex = indexOf(artifactRangeStr, '[', '(', 0); if (versionStartIndex < 0) { throw new InvalidArtifactRangeException( String.format("Invalid artifact range %s. " + "Could not find '[' or '(' indicating start of artifact lower version.", artifactRangeStr)); } String name = artifactRangeStr.substring(0, versionStartIndex); if (!ArtifactId.isValidArtifactId(name)) { throw new InvalidArtifactRangeException( String.format("Invalid artifact range %s. Artifact name '%s' is invalid.", artifactRangeStr, name)); } return new ArtifactRange(namespace, name, ArtifactVersionRange.parse(artifactRangeStr.substring(versionStartIndex))); }
/** * Parses an unnamespaced string representation of an artifact range. It is expected to be of the form: * {name}[{lower-version},{upper-version}]. Square brackets are inclusive, and parentheses are exclusive. * For example, my-functions[1.0.0,2.0.0) will correspond to an artifact name of my-functions with a * lower version of 1.0.0 and an upper version of 2.0.0. * * @param namespace the namespace of the artifact range * @param artifactRangeStr the string representation to parse * @return the ArtifactRange corresponding to the given string */ public static ArtifactRange parseArtifactRange(String namespace, String artifactRangeStr) throws InvalidArtifactRangeException { // search for the '[' or '(' between the artifact name and lower version int versionStartIndex = indexOf(artifactRangeStr, '[', '(', 0); if (versionStartIndex < 0) { throw new InvalidArtifactRangeException( String.format("Invalid artifact range %s. " + "Could not find '[' or '(' indicating start of artifact lower version.", artifactRangeStr)); } String name = artifactRangeStr.substring(0, versionStartIndex); if (!ArtifactId.isValidArtifactId(name)) { throw new InvalidArtifactRangeException( String.format("Invalid artifact range %s. Artifact name '%s' is invalid.", artifactRangeStr, name)); } return new ArtifactRange(namespace, name, ArtifactVersionRange.parse(artifactRangeStr.substring(versionStartIndex))); }