001package org.apache.maven.lifecycle; 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.util.List; 023import java.util.concurrent.CopyOnWriteArrayList; 024 025import javax.inject.Named; 026import javax.inject.Singleton; 027 028import org.apache.maven.execution.MojoExecutionEvent; 029import org.apache.maven.execution.MojoExecutionListener; 030import org.apache.maven.plugin.MojoExecutionException; 031 032@Named 033@Singleton 034public class DelegatingMojoExecutionListener 035 implements MojoExecutionListener 036{ 037 private final List<MojoExecutionListener> listeners = new CopyOnWriteArrayList<MojoExecutionListener>(); 038 039 public void beforeMojoExecution( MojoExecutionEvent event ) 040 throws MojoExecutionException 041 { 042 for ( MojoExecutionListener listener : listeners ) 043 { 044 listener.beforeMojoExecution( event ); 045 } 046 } 047 048 public void afterMojoExecutionSuccess( MojoExecutionEvent event ) 049 throws MojoExecutionException 050 { 051 for ( MojoExecutionListener listener : listeners ) 052 { 053 listener.afterMojoExecutionSuccess( event ); 054 } 055 } 056 057 public void afterExecutionFailure( MojoExecutionEvent event ) 058 { 059 for ( MojoExecutionListener listener : listeners ) 060 { 061 listener.afterExecutionFailure( event ); 062 } 063 } 064 065 public void addMojoExecutionListener( MojoExecutionListener listener ) 066 { 067 this.listeners.add( listener ); 068 } 069 070 public void removeMojoExecutionListener( MojoExecutionListener listener ) 071 { 072 this.listeners.remove( listener ); 073 } 074 075}