1 | |
package org.kuali.maven.plugins; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.apache.commons.beanutils.BeanUtils; |
7 | |
import org.apache.commons.lang.StringUtils; |
8 | |
import org.apache.maven.plugin.AbstractMojo; |
9 | |
import org.apache.maven.plugin.MojoExecutionException; |
10 | |
import org.apache.maven.plugin.MojoFailureException; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | 0 | public class WaitMojo extends AbstractMojo { |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
private String url; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
private int timeout; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
private int requestTimeout; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private int sleepInterval; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private String httpSuccessCodes; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
private String dateFormat; |
64 | |
|
65 | |
protected HttpInspector getHttpInspector() throws MojoExecutionException { |
66 | 0 | HttpInspector inspector = new HttpInspector(); |
67 | |
try { |
68 | 0 | BeanUtils.copyProperties(inspector, this); |
69 | 0 | } catch (Exception e) { |
70 | 0 | throw new MojoExecutionException("Error copying properties", e); |
71 | 0 | } |
72 | 0 | String[] successCodeStrings = StringUtils.splitByWholeSeparator(httpSuccessCodes, ","); |
73 | 0 | List<Integer> successCodeList = new ArrayList<Integer>(); |
74 | 0 | for (String successCodeString : successCodeStrings) { |
75 | 0 | successCodeList.add(new Integer(successCodeString)); |
76 | |
} |
77 | 0 | inspector.setSuccessCodes(successCodeList); |
78 | 0 | return inspector; |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
83 | 0 | HttpInspector inspector = getHttpInspector(); |
84 | 0 | boolean success = inspector.wait(url); |
85 | 0 | if (!success) { |
86 | 0 | throw new MojoExecutionException("Waiting for a response from '" + url + "' was not successful"); |
87 | |
} |
88 | 0 | } |
89 | |
|
90 | |
public String getUrl() { |
91 | 0 | return url; |
92 | |
} |
93 | |
|
94 | |
public void setUrl(String url) { |
95 | 0 | this.url = url; |
96 | 0 | } |
97 | |
|
98 | |
public int getTimeout() { |
99 | 0 | return timeout; |
100 | |
} |
101 | |
|
102 | |
public void setTimeout(int timeout) { |
103 | 0 | this.timeout = timeout; |
104 | 0 | } |
105 | |
|
106 | |
public int getRequestTimeout() { |
107 | 0 | return requestTimeout; |
108 | |
} |
109 | |
|
110 | |
public void setRequestTimeout(int requestTimeout) { |
111 | 0 | this.requestTimeout = requestTimeout; |
112 | 0 | } |
113 | |
|
114 | |
public int getSleepInterval() { |
115 | 0 | return sleepInterval; |
116 | |
} |
117 | |
|
118 | |
public void setSleepInterval(int sleepInterval) { |
119 | 0 | this.sleepInterval = sleepInterval; |
120 | 0 | } |
121 | |
|
122 | |
public String getDateFormat() { |
123 | 0 | return dateFormat; |
124 | |
} |
125 | |
|
126 | |
public void setDateFormat(String dateFormat) { |
127 | 0 | this.dateFormat = dateFormat; |
128 | 0 | } |
129 | |
|
130 | |
public String getHttpSuccessCodes() { |
131 | 0 | return httpSuccessCodes; |
132 | |
} |
133 | |
|
134 | |
public void setHttpSuccessCodes(String httpSuccessCodes) { |
135 | 0 | this.httpSuccessCodes = httpSuccessCodes; |
136 | 0 | } |
137 | |
|
138 | |
} |