View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.checkstyle;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
25  import com.puppycrawl.tools.checkstyle.api.AuditListener;
26  
27  /**
28   * AuditListener that forwards events to a list of other AuditListeners
29   */
30  public class CompositeAuditListener implements AuditListener {
31  
32      private final List<AuditListener> delegates = new ArrayList<>();
33  
34      public void addListener(AuditListener listener) {
35          delegates.add(listener);
36      }
37  
38      @Override
39      public void auditStarted(AuditEvent event) {
40          for (AuditListener listener : delegates) {
41              listener.auditStarted(event);
42          }
43      }
44  
45      @Override
46      public void auditFinished(AuditEvent event) {
47          for (AuditListener listener : delegates) {
48              listener.auditFinished(event);
49          }
50      }
51  
52      @Override
53      public void fileStarted(AuditEvent event) {
54          for (AuditListener listener : delegates) {
55              listener.fileStarted(event);
56          }
57      }
58  
59      @Override
60      public void fileFinished(AuditEvent event) {
61          for (AuditListener listener : delegates) {
62              listener.fileFinished(event);
63          }
64      }
65  
66      @Override
67      public void addError(AuditEvent event) {
68          for (AuditListener listener : delegates) {
69              listener.addError(event);
70          }
71      }
72  
73      @Override
74      public void addException(AuditEvent event, Throwable throwable) {
75          for (AuditListener listener : delegates) {
76              listener.addException(event, throwable);
77          }
78      }
79  }