001 package org.apache.maven.plugin;
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 import org.apache.maven.project.DuplicateArtifactAttachmentException;
023 import org.apache.maven.project.MavenProject;
024 import org.codehaus.plexus.util.StringUtils;
025
026 public class PluginExecutionException
027 extends PluginManagerException
028 {
029
030 private final MojoExecution mojoExecution;
031
032 public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message )
033 {
034 super( mojoExecution.getMojoDescriptor(), project, message );
035 this.mojoExecution = mojoExecution;
036 }
037
038 public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message, Throwable cause )
039 {
040 super( mojoExecution.getMojoDescriptor(), project, message, cause );
041 this.mojoExecution = mojoExecution;
042 }
043
044 public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, Exception cause )
045 {
046 super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
047 this.mojoExecution = mojoExecution;
048 }
049
050 public PluginExecutionException( MojoExecution mojoExecution, MavenProject project,
051 DuplicateArtifactAttachmentException cause )
052 {
053 super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
054 this.mojoExecution = mojoExecution;
055 }
056
057 public MojoExecution getMojoExecution()
058 {
059 return mojoExecution;
060 }
061
062 private static String constructMessage( MojoExecution mojoExecution, Throwable cause )
063 {
064 String message;
065
066 if ( mojoExecution != null )
067 {
068 message =
069 "Execution " + mojoExecution.getExecutionId() + " of goal " + mojoExecution.getMojoDescriptor().getId()
070 + " failed";
071 }
072 else
073 {
074 message = "Mojo execution failed";
075 }
076
077 if ( cause != null && StringUtils.isNotEmpty( cause.getMessage() ) )
078 {
079 message += ": " + cause.getMessage();
080 }
081 else
082 {
083 message += ".";
084 }
085
086 return message;
087 }
088
089 }