File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\listeners\SCMPollListener.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2011, Christian Wolfgang
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model.listeners;
25
26 import hudson.ExtensionList;
27 import hudson.ExtensionPoint;
28 import hudson.scm.PollingResult;
29 import jenkins.model.Jenkins;
30 import hudson.model.AbstractProject;
31 import hudson.model.TaskListener;
32
33 import java.io.IOException;
34
35 /**
36 * A hook for listening to polling activities in Jenkins.
37 *
38 * @author Christian Wolfgang
39 * @author Kohsuke Kawaguchi
40 * @since 1.474
41 */
42 public abstract class SCMPollListener implements ExtensionPoint {
43 /**
44 * Called before the polling execution.
45 *
46 * @param project
47 * Project that's about to run polling.
48 * @param listener
49 * Connected to the polling log.
50 */
51 public void onBeforePolling( AbstractProject<?, ?> project, TaskListener listener ) {}
52
53 /**
54 * Called when the polling successfully concluded.
55 *
56 * @param result
57 * The result of the polling.
58 */
59 public void onPollingSuccess( AbstractProject<?, ?> project, TaskListener listener, PollingResult result) {}
60
61 /**
62 * Called when the polling concluded with an error.
63 *
64 * @param exception
65 * The problem reported. This can include {@link InterruptedException} (that corresponds to the user cancelling it),
66 * some anticipated problems like {@link IOException}, or bug in the code ({@link RuntimeException})
67 */
68 public void onPollingFailed( AbstractProject<?, ?> project, TaskListener listener, Throwable exception) {}
69
70 public static void fireBeforePolling( AbstractProject<?, ?> project, TaskListener listener ) {
71 for (SCMPollListener l : all()) {
72 try {
73 l.onBeforePolling(project, listener);
74 } catch (Exception e) {
75 /* Make sure, that the listeners do not have any impact on the actual poll */
76 }
77 }
78 }
79
80 public static void firePollingSuccess( AbstractProject<?, ?> project, TaskListener listener, PollingResult result ) {
81 for( SCMPollListener l : all() ) {
82 try {
83 l.onPollingSuccess(project, listener, result);
84 } catch (Exception e) {
85 /* Make sure, that the listeners do not have any impact on the actual poll */
86 }
87 }
88 }
89
90 public static void firePollingFailed( AbstractProject<?, ?> project, TaskListener listener, Throwable exception ) {
91 for( SCMPollListener l : all() ) {
92 try {
93 l.onPollingFailed(project, listener, exception);
94 } catch (Exception e) {
95 /* Make sure, that the listeners do not have any impact on the actual poll */
96 }
97 }
98 }
99
100 /**
101 * Returns all the registered {@link SCMPollListener}s.
102 */
103 public static ExtensionList<SCMPollListener> all() {
104 return Jenkins.getInstance().getExtensionList( SCMPollListener.class );
105 }
106 }
107