File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\matrix\listeners\MatrixBuildListener.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.matrix.listeners;
25
26 import hudson.ExtensionList;
27 import hudson.ExtensionPoint;
28 import hudson.matrix.MatrixConfiguration;
29 import hudson.matrix.MatrixBuild;
30 import hudson.matrix.MatrixRun;
31 import hudson.model.Action;
32 import jenkins.model.Jenkins;
33 import hudson.model.Queue;
34 import hudson.model.Queue.Task;
35
36 import java.util.List;
37
38 /**
39 * Controls which subset of {@link MatrixRun}s to rebuild.
40 *
41 * <p>
42 * Plugins can implement this extension point to filter out the subset of matrix project to build.
43 * Most typically, such a plugin would add a custom {@link Action} to a build when it goes to the queue
44 * ({@link Queue#schedule(Task, int, List)}, then access this from {@link MatrixBuild} to drive
45 * the filtering logic.
46 *
47 * <p>
48 * See the matrix reloaded plugin for an example.
49 *
50 * @author Christian Wolfgang
51 * @since 1.413
52 */
53 public abstract class MatrixBuildListener implements ExtensionPoint {
54 /**
55 * Determine whether to build a given configuration or not
56 *
57 * @param b
58 * Never null. The umbrella build.
59 * @param c
60 * The configuration whose build is being considered. If any of the {@link MatrixBuildListener}
61 * returns false, then the build for this configuration is skipped, and the previous build
62 * of this configuration will be taken as the default result.
63 * @return
64 * True to let the build happen, false to skip it.
65 */
66 public abstract boolean doBuildConfiguration(MatrixBuild b, MatrixConfiguration c);
67
68 public static boolean buildConfiguration(MatrixBuild b, MatrixConfiguration c) {
69 for (MatrixBuildListener l : all()) {
70 if(!l.doBuildConfiguration(b, c)) {
71 return false;
72 }
73 }
74
75 return true;
76 }
77
78 /**
79 * Returns all the registered {@link MatrixBuildListener} descriptors.
80 */
81 public static ExtensionList<MatrixBuildListener> all() {
82 return Jenkins.getInstance().getExtensionList(MatrixBuildListener.class);
83 }
84 }
85