001package org.apache.maven.project;
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 org.apache.maven.artifact.Artifact;
023
024/**
025 * This exception is thrown if an application attempts to attach
026 * two of the same artifacts to a single project.
027 *
028 * @author pgier
029 * @author jdcasey
030 * @todo Make this a checked exception, and modify the API of MavenProjectHelper.
031 * Currently, this modification would create compatibility problems for existing plugins.
032 */
033public class DuplicateArtifactAttachmentException
034    extends RuntimeException
035{
036
037    private static final String DEFAULT_MESSAGE = "Duplicate artifact attachment detected.";
038
039    private Artifact artifact;
040
041    private final MavenProject project;
042
043    public DuplicateArtifactAttachmentException( MavenProject project, Artifact artifact )
044    {
045        super( constructMessage( project, artifact ) );
046        this.project = project;
047        this.artifact = artifact;
048    }
049
050    private static String constructMessage( MavenProject project, Artifact artifact )
051    {
052        return DEFAULT_MESSAGE + " (project: " + project.getId() + "; illegal attachment: " + artifact.getId() + ")";
053    }
054
055    public MavenProject getProject()
056    {
057        return project;
058    }
059
060    public Artifact getArtifact()
061    {
062        return artifact;
063    }
064}