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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, Inc.
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.queue;
25
26 import hudson.model.Queue.Executable;
27
28 import java.lang.reflect.InvocationTargetException;
29 import java.lang.reflect.Method;
30
31 /**
32 * Convenience methods around {@link Executable}.
33 *
34 * @author Kohsuke Kawaguchi
35 */
36 public class Executables {
37 /**
38 * Due to the return type change in {@link Executable}, the caller needs a special precaution now.
39 */
40 public static SubTask getParentOf(Executable e) {
41 try {
42 return _getParentOf(e);
43 } catch (AbstractMethodError _) {
44 try {
45 Method m = e.getClass().getMethod("getParent");
46 m.setAccessible(true);
47 return (SubTask) m.invoke(e);
48 } catch (IllegalAccessException x) {
49 throw (Error)new IllegalAccessError().initCause(x);
50 } catch (NoSuchMethodException x) {
51 throw (Error)new NoSuchMethodError().initCause(x);
52 } catch (InvocationTargetException x) {
53 Throwable y = x.getTargetException();
54 if (y instanceof Error) throw (Error)y;
55 if (y instanceof RuntimeException) throw (RuntimeException)y;
56 throw new Error(x);
57 }
58 }
59 }
60
61 /**
62 * A pointless function to work around what appears to be a HotSpot problem. See JENKINS-5756 and bug 6933067
63 * on BugParade for more details.
64 */
65 private static SubTask _getParentOf(Executable e) {
66 return e.getParent();
67 }
68
69 /**
70 * Returns the estimated duration for the executable.
71 * Protects against {@link AbstractMethodError}s if the {@link Executable} implementation
72 * was compiled against Hudson < 1.383
73 */
74 public static long getEstimatedDurationFor(Executable e) {
75 try {
76 return _getEstimatedDuration(e);
77 } catch (AbstractMethodError error) {
78 return e.getParent().getEstimatedDuration();
79 }
80 }
81
82 /**
83 * A pointless function to work around what appears to be a HotSpot problem. See JENKINS-5756 and bug 6933067
84 * on BugParade for more details.
85 */
86 private static long _getEstimatedDuration(Executable e) {
87 return e.getEstimatedDuration();
88 }
89 }
90