001package org.apache.maven.artifact;
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
022/**
023 * Exception thrown when the identity of an artifact can not be established,
024 * eg. one of groupId, artifactId, version or type is null.
025 */
026public class InvalidArtifactRTException
027    extends RuntimeException
028{
029
030    private final String groupId;
031    private final String artifactId;
032    private final String version;
033    private final String type;
034    private final String baseMessage;
035
036    public InvalidArtifactRTException( String groupId,
037                                       String artifactId,
038                                       String version,
039                                       String type,
040                                       String message )
041    {
042        this.groupId = groupId;
043        this.artifactId = artifactId;
044        this.version = version;
045        this.type = type;
046        this.baseMessage = message;
047    }
048
049    public InvalidArtifactRTException( String groupId,
050                                       String artifactId,
051                                       String version,
052                                       String type,
053                                       String message,
054                                       Throwable cause )
055    {
056        super( cause );
057
058        this.groupId = groupId;
059        this.artifactId = artifactId;
060        this.version = version;
061        this.type = type;
062        this.baseMessage = message;
063    }
064
065    public String getMessage()
066    {
067        return "For artifact {" + getArtifactKey() + "}: " + getBaseMessage();
068    }
069
070    public String getBaseMessage()
071    {
072        return baseMessage;
073    }
074
075    public String getArtifactId()
076    {
077        return artifactId;
078    }
079
080    public String getGroupId()
081    {
082        return groupId;
083    }
084
085    public String getType()
086    {
087        return type;
088    }
089
090    public String getVersion()
091    {
092        return version;
093    }
094
095    public String getArtifactKey()
096    {
097        return groupId + ":" + artifactId + ":" + version + ":" + type;
098    }
099
100}