org.kuali.maven.mojo.s3
Class UpdateOriginBucketMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.kuali.maven.mojo.s3.BaseMojo
          extended by org.kuali.maven.mojo.s3.S3Mojo
              extended by org.kuali.maven.mojo.s3.UpdateOriginBucketMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

public class UpdateOriginBucketMojo
extends S3Mojo

This mojo updates a bucket serving as an origin for a Cloud Front distribution. It generates an html directory listing for each "directory" in the bucket and stores the html under a key in the bucket such that a regular http request for a directory returns html. What would happen otherwise is XML for "object does not exist" would be returned by Amazon.

For example: The url "http://www.mybucket.com/foo/bar" will return an html page containing a listing of all the files and directories under "foo/bar" in the bucket.

If a directory contains an object with a key that is the same as the default object, the plugin copies the object to a key representing the directory structure.

For example, the url "http://www.mybucket.com/foo/bar/index.html" represents an object in an S3 bucket under the key "foo/bar/index.html". This plugin will copy the object from the key "foo/bar/index.html" to the key "foo/bar/". This causes the url "http://www.mybucket.com/foo/bar/" to return the same content as the url "http://www.mybucket.com/foo/bar/index.html"

It also generates an html directory listing at the root of the bucket hierarchy and places that html into the bucket as the default object, unless a default object already exists.


Field Summary
 
Fields inherited from class org.kuali.maven.mojo.s3.BaseMojo
FS, SKIP_PACKAGING_TYPE
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
UpdateOriginBucketMojo()
           
 
Method Summary
 void executeMojo()
          This method is called after logging has been configured and only if mojo execution should not be skipped.
protected  String getAbout()
          Show some text about this plugin
 com.amazonaws.services.s3.model.CannedAccessControlList getAcl()
           
 String getBrowseKey()
           
 String getCacheControl()
           
protected  com.amazonaws.services.s3.model.CopyObjectRequest getCopyObjectRequest(String bucket, String sourceKey, String destKey)
          Create a CopyObjectRequest with an ACL set to PublicRead
 String getCss()
           
 String getDateFormat()
           
 String getDefaultObjectKey()
           
protected  String getDefaultPrefix(org.apache.maven.project.MavenProject project, String orgGroupId)
          Get a default prefix into the bucket from the project + groupId
 String getDirectoryImage()
           
 String getFileImage()
           
protected  SimpleDateFormat getLastModifiedDateFormatter()
          Return a SimpleDateFormat object initialized with the date format and timezone supplied to the mojo
protected  String getListMsg(int subDirectoryCount, long millis)
          Show some information about the current directory
protected  List<ListObjectsContext> getListObjectsContexts(S3BucketContext bucketContext, List<String> prefixes)
          Convert prefixes intl ListObjectContext objects
protected  com.amazonaws.services.s3.model.ListObjectsRequest getListObjectsRequest(S3BucketContext context, String prefix)
          Given a prefix and a bucket context return a ListObjectsRequest object
protected  com.amazonaws.services.s3.model.ObjectListing getObjectListing(S3BucketContext context, com.amazonaws.services.s3.model.ListObjectsRequest request)
          Get an object listing for the current directory
protected  List<com.amazonaws.services.s3.model.ObjectListing> getObjectListings(S3BucketContext context, List<String> prefixes, int maxThreads)
          Make a multi-threaded call to S3 to acquire ObjectListing objects for each of the prefixes
 String getOrganizationGroupId()
           
 List<String> getOrgPomGavs()
           
protected  List<String> getPathsToRoot(String delimiter, String startingPrefix)
          Split the string up and return a list of Strings representing the path from the starting prefix back to (and including) the root of the bucket.
protected  List<String> getPrefixes(com.amazonaws.services.s3.model.ObjectListing listing, String prefix, String delimiter)
          Return a listing of all the prefixes in this directory plus all the prefixes leading back to (and including) the root directory
protected  com.amazonaws.services.s3.model.PutObjectRequest getPutIndexObjectRequest(String html, String key)
          Create a PutObjectRequest for some html generated by this mojo.
protected  S3BucketContext getS3BucketContext()
          Get context information about the bucket we are operating on
protected  S3PrefixContext getS3PrefixContext(S3BucketContext context, com.amazonaws.services.s3.model.ObjectListing objectListing)
          Convert an ObjectListing into an S3PrefixContext
protected  List<S3PrefixContext> getS3PrefixContexts(S3BucketContext context, List<com.amazonaws.services.s3.model.ObjectListing> listings)
          Convert ObjectListing objects into S3PrefixContext objects
 int getThreads()
           
 String getTimezone()
           
protected  List<UpdateDirectoryContext> getUpdateDirContexts(List<S3PrefixContext> contexts)
          Convert S3PrefixContext objects into UpdateDirectoryContext objects.
 boolean isCopyDefaultObjectWithDelimiter()
           
 boolean isCopyDefaultObjectWithoutDelimiter()
           
protected  boolean isCreateOrUpdateDefaultObject(S3PrefixContext context)
          Return true if there is no object in the ObjectListing under defaultObjectKey.
Return true if the object in the ObjectListing was created by this plugin.
Return false otherwise.
protected  boolean isEmpty(Collection<?> c)
          Return true if the Collection is null or contains no entries, false otherwise
protected  boolean isExistingObject(com.amazonaws.services.s3.model.ObjectListing objectListing, String key)
          Return true if the ObjectListing contains an object under "key"
protected  boolean isOurObject(com.amazonaws.services.s3.model.S3Object s3Object)
          Return true if this S3Object was created by this plugin.
 void setAcl(com.amazonaws.services.s3.model.CannedAccessControlList acl)
           
 void setBrowseKey(String browseHtml)
           
 void setCacheControl(String cacheControl)
           
 void setCopyDefaultObjectWithDelimiter(boolean copyDefaultObjectWithDelimiter)
           
 void setCopyDefaultObjectWithoutDelimiter(boolean copyDefaultObjectWithoutDelimiter)
           
 void setCss(String css)
           
 void setDateFormat(String dateFormat)
           
 void setDefaultObjectKey(String defaultCloudFrontObject)
           
 void setDirectoryImage(String directoryImage)
           
 void setFileImage(String fileImage)
           
 void setOrganizationGroupId(String organizationGroupId)
           
 void setOrgPomGavs(List<String> orgPomGavs)
           
 void setThreads(int threadCount)
           
 void setTimezone(String timezone)
           
protected  void updateDirectory(S3PrefixContext context)
          Update this S3 "directory".
protected  void updateDirectory(S3PrefixContext context, boolean isCopyIfExists, String copyToKey)
          Create an object in the bucket under a key that lets a normal http request function correctly with CloudFront / S3.
Either use the client's object or upload some html created by this plugin
 void updateDirectory(UpdateDirectoryContext context)
           
protected  void updateMojoState()
          Update the state of this mojo from the project metadata
protected  void updatePrefix()
          If they supplied a prefix use it.
protected  void updateRoot(S3PrefixContext context)
          If this is the root of the bucket and the default object either does not exist or was created by this plugin, overwrite the default object with newly generated html.
 void updateRoot(UpdateDirectoryContext udc)
          If this is the root of the bucket and the default object either does not exist or was created by this plugin, overwrite the default object with newly generated html.
 
Methods inherited from class org.kuali.maven.mojo.s3.S3Mojo
getAccessKeyId, getAuthenticationErrorMessage, getBucket, getCredentials, getDelimiter, getMaxKeys, getObjectMetadata, getPrefix, getPutObjectRequest, getPutObjectRequest, getSecretAccessKey, getServerId, setAccessKeyId, setBucket, setDelimiter, setMaxKeys, setPrefix, setSecretAccessKey, setServerId, updateCredentials, validateCredentials
 
Methods inherited from class org.kuali.maven.mojo.s3.BaseMojo
execute, getEncoding, getMavenSession, getProject, getSettings, isForceMojoExecution, isSkip, setEncoding, setForceMojoExecution, setMavenSession, setProject, setSettings, setSkip, skipMojo
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UpdateOriginBucketMojo

public UpdateOriginBucketMojo()
Method Detail

getPrefixes

protected List<String> getPrefixes(com.amazonaws.services.s3.model.ObjectListing listing,
                                   String prefix,
                                   String delimiter)
Return a listing of all the prefixes in this directory plus all the prefixes leading back to (and including) the root directory

Parameters:
listing -
prefix -
delimiter -
Returns:

getObjectListing

protected com.amazonaws.services.s3.model.ObjectListing getObjectListing(S3BucketContext context,
                                                                         com.amazonaws.services.s3.model.ListObjectsRequest request)
Get an object listing for the current directory

Parameters:
context -
request -
Returns:

getListObjectsContexts

protected List<ListObjectsContext> getListObjectsContexts(S3BucketContext bucketContext,
                                                          List<String> prefixes)
Convert prefixes intl ListObjectContext objects

Parameters:
bucketContext -
prefixes -
Returns:

getListObjectsRequest

protected com.amazonaws.services.s3.model.ListObjectsRequest getListObjectsRequest(S3BucketContext context,
                                                                                   String prefix)
Given a prefix and a bucket context return a ListObjectsRequest object

Parameters:
context -
prefix -
Returns:

getListMsg

protected String getListMsg(int subDirectoryCount,
                            long millis)
Show some information about the current directory

Parameters:
subDirectoryCount -
millis -
Returns:

executeMojo

public void executeMojo()
                 throws org.apache.maven.plugin.MojoExecutionException,
                        org.apache.maven.plugin.MojoFailureException
Description copied from class: BaseMojo
This method is called after logging has been configured and only if mojo execution should not be skipped.

Specified by:
executeMojo in class BaseMojo
Throws:
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException

getObjectListings

protected List<com.amazonaws.services.s3.model.ObjectListing> getObjectListings(S3BucketContext context,
                                                                                List<String> prefixes,
                                                                                int maxThreads)
Make a multi-threaded call to S3 to acquire ObjectListing objects for each of the prefixes

Parameters:
context -
prefixes -
maxThreads -
Returns:

getUpdateDirContexts

protected List<UpdateDirectoryContext> getUpdateDirContexts(List<S3PrefixContext> contexts)
Convert S3PrefixContext objects into UpdateDirectoryContext objects. Each S3PrefixContext object generates two S3 calls. One for the prefix with the delimiter and one for the prefix without the delimiter.

Parameters:
contexts -
Returns:

getPathsToRoot

protected List<String> getPathsToRoot(String delimiter,
                                      String startingPrefix)
Split the string up and return a list of Strings representing the path from the starting prefix back to (and including) the root of the bucket.

Parameters:
delimiter -
startingPrefix -
Returns:

getDefaultPrefix

protected String getDefaultPrefix(org.apache.maven.project.MavenProject project,
                                  String orgGroupId)
Get a default prefix into the bucket from the project + groupId

Parameters:
project -
groupId -
Returns:

updatePrefix

protected void updatePrefix()
If they supplied a prefix use it. Otherwise generate one from the project metadata


updateMojoState

protected void updateMojoState()
                        throws org.apache.maven.plugin.MojoExecutionException
Update the state of this mojo from the project metadata

Throws:
org.apache.maven.plugin.MojoExecutionException

getS3BucketContext

protected S3BucketContext getS3BucketContext()
                                      throws org.apache.maven.plugin.MojoExecutionException
Get context information about the bucket we are operating on

Throws:
org.apache.maven.plugin.MojoExecutionException

getPutIndexObjectRequest

protected com.amazonaws.services.s3.model.PutObjectRequest getPutIndexObjectRequest(String html,
                                                                                    String key)
Create a PutObjectRequest for some html generated by this mojo. The PutObjectRequest sets the content type to S3_INDEX_CONTENT_TYPE, sets the ACL to PublicRead, and adds some custom metadata so we can positively identify it as an object created by this plugin


getLastModifiedDateFormatter

protected SimpleDateFormat getLastModifiedDateFormatter()
Return a SimpleDateFormat object initialized with the date format and timezone supplied to the mojo


isEmpty

protected boolean isEmpty(Collection<?> c)
Return true if the Collection is null or contains no entries, false otherwise


getAbout

protected String getAbout()
Show some text about this plugin


updateDirectory

public void updateDirectory(UpdateDirectoryContext context)
                     throws IOException
Throws:
IOException

updateDirectory

protected void updateDirectory(S3PrefixContext context,
                               boolean isCopyIfExists,
                               String copyToKey)
                        throws IOException
Create an object in the bucket under a key that lets a normal http request function correctly with CloudFront / S3.
Either use the client's object or upload some html created by this plugin

Throws:
IOException

updateDirectory

protected void updateDirectory(S3PrefixContext context)
                        throws IOException
Update this S3 "directory".

Throws:
IOException

updateRoot

public void updateRoot(UpdateDirectoryContext udc)
                throws IOException
If this is the root of the bucket and the default object either does not exist or was created by this plugin, overwrite the default object with newly generated html. Otherwise, do nothing.

Throws:
IOException

updateRoot

protected void updateRoot(S3PrefixContext context)
                   throws IOException
If this is the root of the bucket and the default object either does not exist or was created by this plugin, overwrite the default object with newly generated html. Otherwise, do nothing.

Throws:
IOException

getS3PrefixContexts

protected List<S3PrefixContext> getS3PrefixContexts(S3BucketContext context,
                                                    List<com.amazonaws.services.s3.model.ObjectListing> listings)
Convert ObjectListing objects into S3PrefixContext objects


getS3PrefixContext

protected S3PrefixContext getS3PrefixContext(S3BucketContext context,
                                             com.amazonaws.services.s3.model.ObjectListing objectListing)
Convert an ObjectListing into an S3PrefixContext


isExistingObject

protected boolean isExistingObject(com.amazonaws.services.s3.model.ObjectListing objectListing,
                                   String key)
Return true if the ObjectListing contains an object under "key"


isCreateOrUpdateDefaultObject

protected boolean isCreateOrUpdateDefaultObject(S3PrefixContext context)
Return true if there is no object in the ObjectListing under defaultObjectKey.
Return true if the object in the ObjectListing was created by this plugin.
Return false otherwise.


isOurObject

protected boolean isOurObject(com.amazonaws.services.s3.model.S3Object s3Object)
Return true if this S3Object was created by this plugin. This is is done by checking the metadata attached to this object for the presence of a custom value.


getCopyObjectRequest

protected com.amazonaws.services.s3.model.CopyObjectRequest getCopyObjectRequest(String bucket,
                                                                                 String sourceKey,
                                                                                 String destKey)
Create a CopyObjectRequest with an ACL set to PublicRead


getTimezone

public String getTimezone()

setTimezone

public void setTimezone(String timezone)

getDateFormat

public String getDateFormat()

setDateFormat

public void setDateFormat(String dateFormat)

getDefaultObjectKey

public String getDefaultObjectKey()

setDefaultObjectKey

public void setDefaultObjectKey(String defaultCloudFrontObject)

getFileImage

public String getFileImage()

setFileImage

public void setFileImage(String fileImage)

getDirectoryImage

public String getDirectoryImage()

setDirectoryImage

public void setDirectoryImage(String directoryImage)

getCss

public String getCss()

setCss

public void setCss(String css)

isCopyDefaultObjectWithDelimiter

public boolean isCopyDefaultObjectWithDelimiter()

setCopyDefaultObjectWithDelimiter

public void setCopyDefaultObjectWithDelimiter(boolean copyDefaultObjectWithDelimiter)

isCopyDefaultObjectWithoutDelimiter

public boolean isCopyDefaultObjectWithoutDelimiter()

setCopyDefaultObjectWithoutDelimiter

public void setCopyDefaultObjectWithoutDelimiter(boolean copyDefaultObjectWithoutDelimiter)

getCacheControl

public String getCacheControl()

setCacheControl

public void setCacheControl(String cacheControl)

getBrowseKey

public String getBrowseKey()

setBrowseKey

public void setBrowseKey(String browseHtml)

getOrganizationGroupId

public String getOrganizationGroupId()
Returns:
the organizationGroupId

setOrganizationGroupId

public void setOrganizationGroupId(String organizationGroupId)
Parameters:
organizationGroupId - the organizationGroupId to set

getThreads

public int getThreads()

setThreads

public void setThreads(int threadCount)

getAcl

public com.amazonaws.services.s3.model.CannedAccessControlList getAcl()

setAcl

public void setAcl(com.amazonaws.services.s3.model.CannedAccessControlList acl)

getOrgPomGavs

public List<String> getOrgPomGavs()

setOrgPomGavs

public void setOrgPomGavs(List<String> orgPomGavs)


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.