1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.gmaven.plugin;
17
18 import javax.annotation.Nullable;
19
20 import com.google.common.annotations.VisibleForTesting;
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.codehaus.gmaven.adapter.ClosureTarget;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public class FailClosureTarget
67 implements ClosureTarget
68 {
69 @VisibleForTesting
70 static final String FAILED = "Failed";
71
72
73
74
75 public Object call(final @Nullable Object[] args) throws Exception {
76 if (args == null || args.length == 0) {
77 throw new MojoExecutionException(FAILED);
78 }
79 else if (args.length == 1) {
80 if (args[0] instanceof Throwable) {
81 Throwable cause = (Throwable) args[0];
82 throw new MojoExecutionException(cause.getMessage(), cause);
83 }
84 else {
85 throw new MojoExecutionException(String.valueOf(args[0]));
86 }
87 }
88 else if (args.length == 2) {
89 if (args[1] instanceof Throwable) {
90 throw new MojoExecutionException(String.valueOf(args[0]), (Throwable) args[1]);
91 }
92 else {
93 throw new Error("Invalid arguments to fail(Object, Throwable), second argument must be a Throwable");
94 }
95 }
96 else {
97 throw new Error("Too many arguments; expected one of: fail(), fail(Object) or fail(Object, Throwable)");
98 }
99 }
100 }