Coverage Report - org.kuali.maven.plugins.WaitMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
WaitMojo
0%
0/35
0%
0/4
1.357
 
 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,302,304"
 55  
          */
 56  
         private String httpSuccessCodes;
 57  
 
 58  
         /**
 59  
          * The format to use when displaying dates in the log messages
 60  
          * 
 61  
          * @parameter expression="${http.dateFormat}" default-value="yyyy-MM-dd HH:mm:ss z"
 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  
 }