001package org.apache.maven.repository;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023
024import org.apache.maven.artifact.ArtifactUtils;
025import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
026import org.apache.maven.model.Dependency;
027
028/**
029 * Thrown if a dependency has an invalid version.
030 *
031 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
032 */
033public class VersionNotFoundException
034    extends Exception
035{
036    private Dependency dependency;
037
038    private String projectId;
039    private File pomFile;
040    private InvalidVersionSpecificationException cause;
041
042    public VersionNotFoundException( String projectId, Dependency dependency, File pomFile,
043                                     InvalidVersionSpecificationException cause )
044    {
045        super( projectId + ", " + formatLocationInPom( dependency ) + " " + dependency.getVersion() + ", pom file "
046            + pomFile, cause );
047
048        this.projectId = projectId;
049
050        this.pomFile = pomFile;
051
052        this.cause = cause;
053
054        this.dependency = dependency;
055    }
056
057    private static String formatLocationInPom( Dependency dependency )
058    {
059        return "Dependency: " + ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
060    }
061
062    public Dependency getDependency()
063    {
064        return dependency;
065    }
066
067    public String getProjectId()
068    {
069        return projectId;
070    }
071
072    public File getPomFile()
073    {
074        return pomFile;
075    }
076
077    public InvalidVersionSpecificationException getCauseException()
078    {
079        return cause;
080    }
081
082
083}