View Javadoc
1   /*
2    * The MIT License (MIT)
3    *
4    * Copyright (c) 2013-2026 The Coveralls Maven Plugin Project Contributors:
5    *     https://github.com/hazendaz/coveralls-maven-plugin/graphs/contributors
6    *
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   */
25  package org.eluder.coveralls.maven.plugin.source;
26  
27  import java.io.IOException;
28  
29  import org.eluder.coveralls.maven.plugin.ProcessingException;
30  import org.eluder.coveralls.maven.plugin.domain.Source;
31  
32  /**
33   * Source callback handler that allows chaining multiple callback handlers. Chained callback handler is executed after
34   * this callback.
35   */
36  public abstract class ChainingSourceCallback implements SourceCallback {
37  
38      /** The chained. */
39      private final SourceCallback chained;
40  
41      /**
42       * Instantiates a new chaining source callback.
43       *
44       * @param chained
45       *            the chained
46       */
47      protected ChainingSourceCallback(final SourceCallback chained) {
48          if (chained == null) {
49              throw new IllegalArgumentException("chained must be defined");
50          }
51          this.chained = chained;
52      }
53  
54      @Override
55      public final void onBegin() throws ProcessingException, IOException {
56          this.onBeginInternal();
57          this.chained.onBegin();
58      }
59  
60      @Override
61      public final void onSource(final Source source) throws ProcessingException, IOException {
62          this.onSourceInternal(source);
63          this.chained.onSource(source);
64      }
65  
66      @Override
67      public final void onComplete() throws ProcessingException, IOException {
68          this.onCompleteInternal();
69          this.chained.onComplete();
70      }
71  
72      /**
73       * Defaults to no-op implementation.
74       *
75       * @throws ProcessingException
76       *             if processing fails
77       * @throws IOException
78       *             if an I/O error occurs
79       *
80       * @see #onBegin()
81       */
82      protected void onBeginInternal() throws ProcessingException, IOException {
83  
84      }
85  
86      /**
87       * On source internal.
88       *
89       * @param source
90       *            the source file
91       *
92       * @throws ProcessingException
93       *             if further processing of the source fails
94       * @throws IOException
95       *             if an I/O error occurs
96       *
97       * @see #onSource(Source)
98       */
99      protected abstract void onSourceInternal(final Source source) throws ProcessingException, IOException;
100 
101     /**
102      * Defaults to no-op implementation.
103      *
104      * @throws ProcessingException
105      *             if processing fails
106      * @throws IOException
107      *             if an I/O error occurs
108      *
109      * @see #onComplete()
110      */
111     protected void onCompleteInternal() throws ProcessingException, IOException {
112 
113     }
114 }