Coverage Report - org.kuali.maven.plugin.ksite.mojo.KualiSiteMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiSiteMojo
0%
0/82
0%
0/22
1.76
 
 1  
 package org.kuali.maven.plugin.ksite.mojo;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.apache.maven.model.DistributionManagement;
 5  
 import org.apache.maven.model.Site;
 6  
 import org.apache.maven.plugin.AbstractMojo;
 7  
 import org.apache.maven.plugin.MojoExecutionException;
 8  
 import org.apache.maven.plugin.MojoFailureException;
 9  
 import org.apache.maven.project.MavenProject;
 10  
 import org.kuali.maven.common.SiteContext;
 11  
 import org.kuali.maven.common.UrlBuilder;
 12  
 
 13  
 /**
 14  
  * This plugin organizes/standardizes the maven site publication process for the Kuali organization
 15  
  *
 16  
  * @goal updatesiteproperties
 17  
  * @phase pre-site
 18  
  */
 19  0
 public class KualiSiteMojo extends AbstractMojo implements SiteContext {
 20  
 
 21  
     /**
 22  
      * The prefix into the bucket when downloading a snapshot version
 23  
      *
 24  
      * @parameter expression="${downloadSnapshotPrefix}" default-value="snapshot"
 25  
      */
 26  
     private String downloadSnapshotPrefix;
 27  
 
 28  
     /**
 29  
      * The prefix into the bucket when downloading a release version
 30  
      *
 31  
      * @parameter expression="${downloadReleasePrefix}" default-value="release"
 32  
      */
 33  
     private String downloadReleasePrefix;
 34  
 
 35  
     /**
 36  
      * The protocol used when publishing the web site
 37  
      *
 38  
      * @parameter expression="${publishUrlProtocol}" default-value="s3"
 39  
      */
 40  
     private String publishUrlProtocol;
 41  
 
 42  
     /**
 43  
      * The protocol for the public facing website
 44  
      *
 45  
      * @parameter expression="${publicUrlProtocol}" default-value="http"
 46  
      */
 47  
     private String publicUrlProtocol;
 48  
 
 49  
     /**
 50  
      * The prefix for the location that artifacts can be downloaded from
 51  
      *
 52  
      * @parameter expression="${downloadPrefix}"
 53  
      * default-value="http://s3browse.springsource.com/browse/maven.kuali.org/"
 54  
      */
 55  
     private String downloadPrefix;
 56  
 
 57  
     /**
 58  
      * The groupId for the organization
 59  
      *
 60  
      * @parameter expression="${organizationGroupId}" default-value="org.kuali"
 61  
      */
 62  
     private String organizationGroupId;
 63  
 
 64  
     /**
 65  
      * The name of the AWS bucket the site gets published to
 66  
      *
 67  
      * @parameter expression="${bucket}" default-value="site.origin.kuali.org"
 68  
      * @required
 69  
      */
 70  
     private String bucket;
 71  
 
 72  
     /**
 73  
      * The public DNS name for the site
 74  
      *
 75  
      * @parameter expression="${hostname}" default-value="site.kuali.org"
 76  
      * @required
 77  
      */
 78  
     private String hostname;
 79  
 
 80  
     /**
 81  
      * The Maven project this plugin runs in.
 82  
      *
 83  
      * @parameter expression="${project}"
 84  
      * @required
 85  
      * @readonly
 86  
      */
 87  
     private MavenProject project;
 88  
 
 89  
     @Override
 90  
     public void execute() throws MojoExecutionException, MojoFailureException {
 91  0
         UrlBuilder builder = new UrlBuilder();
 92  
 
 93  
         // Generate our urls
 94  0
         String publicUrl = builder.getPublicUrl(getProject(), this);
 95  0
         String publishUrl = builder.getPublishUrl(getProject(), this);
 96  0
         String downloadUrl = builder.getDownloadUrl(getProject(), this);
 97  
 
 98  
         // Get a reference to the relevant model objects
 99  0
         MavenProject project = getProject();
 100  0
         DistributionManagement dm = project.getDistributionManagement();
 101  0
         Site site = dm.getSite();
 102  
 
 103  
         // Update the model with our generated urls as needed
 104  0
         handlePublicUrl(publicUrl, project);
 105  0
         handlePublishUrl(publishUrl, site);
 106  0
         handleDownloadUrl(downloadUrl, dm);
 107  
 
 108  0
     }
 109  
 
 110  
     /**
 111  
      * Return true if "s" is empty or contains "token"
 112  
      */
 113  
     protected boolean isReplace(final String s, final String token) {
 114  0
         if (StringUtils.isEmpty(s)) {
 115  0
             return true;
 116  
         }
 117  0
         int pos = s.indexOf(token);
 118  0
         if (pos != -1) {
 119  0
             return true;
 120  
         }
 121  0
         return false;
 122  
     }
 123  
 
 124  
     protected void warn(final String pomString, final String calculatedString, final String propertyDescription) {
 125  0
         getLog().warn("****************************************");
 126  0
         getLog().warn(propertyDescription + " mismatch");
 127  0
         getLog().warn("Value from the POM: " + pomString);
 128  0
         getLog().warn("  Calculated value: " + calculatedString);
 129  0
         getLog().warn("****************************************");
 130  0
     }
 131  
 
 132  
     /**
 133  
      * Return true if the 2 urls are exactly the same or if the only thing different about them is a trailing slash
 134  
      */
 135  
     protected boolean isUrlMatch(final String url1, final String url2) {
 136  0
         if (url1.equals(url2)) {
 137  0
             return true;
 138  
         }
 139  0
         if ((url1 + "/").equals(url2)) {
 140  0
             return true;
 141  
         }
 142  0
         if (url1.equals(url2 + "/")) {
 143  0
             return true;
 144  
         }
 145  0
         return false;
 146  
     }
 147  
 
 148  
     protected void handleDownloadUrl(final String downloadUrl, final DistributionManagement dm) {
 149  0
         if (isReplace(dm.getDownloadUrl(), "${kuali.site.download.url}")) {
 150  0
             getLog().info("Setting download url to " + downloadUrl + " (was " + dm.getDownloadUrl() + ")");
 151  0
             dm.setDownloadUrl(downloadUrl);
 152  0
             return;
 153  
         }
 154  0
         if (!isUrlMatch(downloadUrl, dm.getDownloadUrl())) {
 155  0
             warn(dm.getDownloadUrl(), downloadUrl, "Download url");
 156  
         }
 157  0
         getLog().info("Using download url from the POM " + dm.getDownloadUrl());
 158  0
     }
 159  
 
 160  
     protected void handlePublishUrl(final String publishUrl, final Site site) {
 161  0
         if (isReplace(site.getUrl(), "${kuali.site.publish.url}")) {
 162  0
             getLog().info("Setting site publication url to " + publishUrl + " (was " + site.getUrl() + ")");
 163  0
             site.setUrl(publishUrl);
 164  0
             return;
 165  
         }
 166  0
         if (!isUrlMatch(publishUrl, site.getUrl())) {
 167  0
             warn(site.getUrl(), publishUrl, "Site publication url");
 168  
         }
 169  0
         getLog().info("Using site publication url from the POM " + site.getUrl());
 170  0
     }
 171  
 
 172  
     protected void handlePublicUrl(final String publicUrl, final MavenProject project) {
 173  0
         if (isReplace(project.getUrl(), "${kuali.site.public.url}")) {
 174  0
             getLog().info("Setting public url to " + publicUrl + " (was " + project.getUrl() + ")");
 175  0
             project.setUrl(publicUrl);
 176  0
             return;
 177  
         }
 178  0
         if (!isUrlMatch(publicUrl, project.getUrl())) {
 179  0
             warn(project.getUrl(), publicUrl, "Public url");
 180  
         }
 181  0
         getLog().info("Using public url from the POM " + project.getUrl());
 182  0
     }
 183  
 
 184  
     /**
 185  
      * @return the project
 186  
      */
 187  
     public MavenProject getProject() {
 188  0
         return project;
 189  
     }
 190  
 
 191  
     /**
 192  
      * @param project
 193  
      * the project to set
 194  
      */
 195  
     public void setProject(final MavenProject project) {
 196  0
         this.project = project;
 197  0
     }
 198  
 
 199  
     /**
 200  
      * @return the bucket
 201  
      */
 202  
     @Override
 203  
     public String getBucket() {
 204  0
         return bucket;
 205  
     }
 206  
 
 207  
     /**
 208  
      * @param bucket
 209  
      * the bucket to set
 210  
      */
 211  
     public void setBucket(final String bucket) {
 212  0
         this.bucket = bucket;
 213  0
     }
 214  
 
 215  
     /**
 216  
      * @return the hostname
 217  
      */
 218  
     @Override
 219  
     public String getHostname() {
 220  0
         return hostname;
 221  
     }
 222  
 
 223  
     /**
 224  
      * @param hostname
 225  
      * the hostname to set
 226  
      */
 227  
     public void setHostname(final String hostname) {
 228  0
         this.hostname = hostname;
 229  0
     }
 230  
 
 231  
     /**
 232  
      * @return the downloadPrefix
 233  
      */
 234  
     @Override
 235  
     public String getDownloadPrefix() {
 236  0
         return downloadPrefix;
 237  
     }
 238  
 
 239  
     /**
 240  
      * @param downloadPrefix
 241  
      * the downloadPrefix to set
 242  
      */
 243  
     public void setDownloadPrefix(final String downloadPrefix) {
 244  0
         this.downloadPrefix = downloadPrefix;
 245  0
     }
 246  
 
 247  
     /**
 248  
      * @return the parentGroupId
 249  
      */
 250  
     @Override
 251  
     public String getOrganizationGroupId() {
 252  0
         return organizationGroupId;
 253  
     }
 254  
 
 255  
     /**
 256  
      * @param parentGroupId
 257  
      * the parentGroupId to set
 258  
      */
 259  
     public void setOrganizationGroupId(final String parentGroupId) {
 260  0
         this.organizationGroupId = parentGroupId;
 261  0
     }
 262  
 
 263  
     /**
 264  
      * @return the publishUrlProtocol
 265  
      */
 266  
     @Override
 267  
     public String getPublishUrlProtocol() {
 268  0
         return publishUrlProtocol;
 269  
     }
 270  
 
 271  
     /**
 272  
      * @param publishUrlProtocol
 273  
      * the publishUrlProtocol to set
 274  
      */
 275  
     public void setPublishUrlProtocol(final String publishUrlProtocol) {
 276  0
         this.publishUrlProtocol = publishUrlProtocol;
 277  0
     }
 278  
 
 279  
     /**
 280  
      * @return the publicUrlProtocol
 281  
      */
 282  
     @Override
 283  
     public String getPublicUrlProtocol() {
 284  0
         return publicUrlProtocol;
 285  
     }
 286  
 
 287  
     /**
 288  
      * @param publicUrlProtocol
 289  
      * the publicUrlProtocol to set
 290  
      */
 291  
     public void setPublicUrlProtocol(final String publicUrlProtocol) {
 292  0
         this.publicUrlProtocol = publicUrlProtocol;
 293  0
     }
 294  
 
 295  
     /**
 296  
      * @return the downloadSnapshotPrefix
 297  
      */
 298  
     @Override
 299  
     public String getDownloadSnapshotPrefix() {
 300  0
         return downloadSnapshotPrefix;
 301  
     }
 302  
 
 303  
     /**
 304  
      * @param downloadSnapshotPrefix
 305  
      * the downloadSnapshotPrefix to set
 306  
      */
 307  
     public void setDownloadSnapshotPrefix(final String downloadSnapshotPrefix) {
 308  0
         this.downloadSnapshotPrefix = downloadSnapshotPrefix;
 309  0
     }
 310  
 
 311  
     /**
 312  
      * @return the downloadReleasePrefix
 313  
      */
 314  
     @Override
 315  
     public String getDownloadReleasePrefix() {
 316  0
         return downloadReleasePrefix;
 317  
     }
 318  
 
 319  
     /**
 320  
      * @param downloadReleasePrefix
 321  
      * the downloadReleasePrefix to set
 322  
      */
 323  
     public void setDownloadReleasePrefix(final String downloadReleasePrefix) {
 324  0
         this.downloadReleasePrefix = downloadReleasePrefix;
 325  0
     }
 326  
 
 327  
 }