| 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 | |
protected HttpInspector getHttpInspector() throws MojoExecutionException { |
| 59 | 0 | HttpInspector inspector = new HttpInspector(); |
| 60 | |
try { |
| 61 | 0 | BeanUtils.copyProperties(inspector, this); |
| 62 | 0 | } catch (Exception e) { |
| 63 | 0 | throw new MojoExecutionException("Error copying properties", e); |
| 64 | 0 | } |
| 65 | 0 | String[] successCodeStrings = StringUtils.splitByWholeSeparator(httpSuccessCodes, ","); |
| 66 | 0 | List<Integer> successCodeList = new ArrayList<Integer>(); |
| 67 | 0 | for (String successCodeString : successCodeStrings) { |
| 68 | 0 | successCodeList.add(new Integer(successCodeString)); |
| 69 | |
} |
| 70 | 0 | inspector.setSuccessCodes(successCodeList); |
| 71 | 0 | return inspector; |
| 72 | |
} |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 76 | 0 | HttpInspector inspector = getHttpInspector(); |
| 77 | 0 | Result result = inspector.wait(url); |
| 78 | 0 | boolean success = result.equals(Result.SUCCESS); |
| 79 | 0 | if (!success) { |
| 80 | 0 | throw new MojoExecutionException("Waiting for a response from '" + url + "' was not successful"); |
| 81 | |
} |
| 82 | 0 | } |
| 83 | |
|
| 84 | |
public String getUrl() { |
| 85 | 0 | return url; |
| 86 | |
} |
| 87 | |
|
| 88 | |
public void setUrl(String url) { |
| 89 | 0 | this.url = url; |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
public int getTimeout() { |
| 93 | 0 | return timeout; |
| 94 | |
} |
| 95 | |
|
| 96 | |
public void setTimeout(int timeout) { |
| 97 | 0 | this.timeout = timeout; |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
public int getRequestTimeout() { |
| 101 | 0 | return requestTimeout; |
| 102 | |
} |
| 103 | |
|
| 104 | |
public void setRequestTimeout(int requestTimeout) { |
| 105 | 0 | this.requestTimeout = requestTimeout; |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
public int getSleepInterval() { |
| 109 | 0 | return sleepInterval; |
| 110 | |
} |
| 111 | |
|
| 112 | |
public void setSleepInterval(int sleepInterval) { |
| 113 | 0 | this.sleepInterval = sleepInterval; |
| 114 | 0 | } |
| 115 | |
|
| 116 | |
public String getHttpSuccessCodes() { |
| 117 | 0 | return httpSuccessCodes; |
| 118 | |
} |
| 119 | |
|
| 120 | |
public void setHttpSuccessCodes(String httpSuccessCodes) { |
| 121 | 0 | this.httpSuccessCodes = httpSuccessCodes; |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
} |