001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.version;
020
021import org.eclipse.aether.RepositoryException;
022
023/**
024 * Thrown when a version or version range could not be parsed.
025 */
026public class InvalidVersionSpecificationException extends RepositoryException {
027
028    private final String version;
029
030    /**
031     * Creates a new exception with the specified version and detail message.
032     *
033     * @param version The invalid version specification, may be {@code null}.
034     * @param message The detail message, may be {@code null}.
035     */
036    public InvalidVersionSpecificationException(String version, String message) {
037        super(message);
038        this.version = version;
039    }
040
041    /**
042     * Creates a new exception with the specified version and cause.
043     *
044     * @param version The invalid version specification, may be {@code null}.
045     * @param cause The exception that caused this one, may be {@code null}.
046     */
047    public InvalidVersionSpecificationException(String version, Throwable cause) {
048        super("Could not parse version specification " + version + getMessage(": ", cause), cause);
049        this.version = version;
050    }
051
052    /**
053     * Creates a new exception with the specified version, detail message and cause.
054     *
055     * @param version The invalid version specification, may be {@code null}.
056     * @param message The detail message, may be {@code null}.
057     * @param cause The exception that caused this one, may be {@code null}.
058     */
059    public InvalidVersionSpecificationException(String version, String message, Throwable cause) {
060        super(message, cause);
061        this.version = version;
062    }
063
064    /**
065     * Gets the version or version range that could not be parsed.
066     *
067     * @return The invalid version specification or {@code null} if unknown.
068     */
069    public String getVersion() {
070        return version;
071    }
072}