Coverage Report - org.kuali.maven.plugins.WaitMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
WaitMojo
0%
0/33
0%
0/4
1.417
 
 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  
  * Repeatedly contact the specified HTTP URL until a valid HTTP response code is returned or the maximum wait timeout is
 14  
  * exceeded, whichever comes first.
 15  
  *
 16  
  * @author Jeff Caddel
 17  
  * @goal wait
 18  
  * @execute phase="validate"
 19  
  * @since 1.0
 20  
  */
 21  0
 public class WaitMojo extends AbstractMojo {
 22  
 
 23  
     /**
 24  
      * The url to contact
 25  
      *
 26  
      * @parameter expression="${http.url}" default-value="http://localhost"
 27  
      */
 28  
     private String url;
 29  
 
 30  
     /**
 31  
      * The maximum number of seconds to wait for the url to respond correctly
 32  
      *
 33  
      * @parameter expression="${http.timeout}" default-value="180"
 34  
      */
 35  
     private int timeout;
 36  
 
 37  
     /**
 38  
      * The maximum number of milliseconds to wait for an individual HTTP request to complete
 39  
      *
 40  
      * @parameter expression="${http.requestTimeout}" default-value="3000"
 41  
      */
 42  
     private int requestTimeout;
 43  
 
 44  
     /**
 45  
      * The number of milliseconds to sleep in between HTTP requests
 46  
      *
 47  
      * @parameter expression="${http.sleepInterval}" default-value="3000"
 48  
      */
 49  
     private int sleepInterval;
 50  
 
 51  
     /**
 52  
      * Comma separated list of HTTP status codes that represent success
 53  
      *
 54  
      * @parameter expression="${http.successCodes}" default-value="200"
 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  
 }