Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Features:
<?xml version="1.0" encoding="utf-8"?>
<project name="MyProjectName" basedir="." default="cdn-invalidation">

<!-- Other ant tasks -->
<!-- Other ant tasks -->

<target name="cdn-invalidation" description="Invalidation of static files">
<target name="cdn-invalidation" description="Invalidation of static files">
<taskdef name="cloudfront" classpath="aws-ant-task.jar" classname="it.corley.ant.CloudFront" />
<cloudfront key="your-key" secret="your-secret-key" distributionId="your-distribution-id">
<delete path="/js/folder/my-path.js"/>
<delete path="/css/folder/my-path.css"/>
<delete path="/direct-gen.txt"/>
<delete path="/js/folder/my-path.js"/>
<delete path="/css/folder/my-path.css"/>
<delete path="/direct-gen.txt"/>
</cloudfront>
</target>
</project>
Expand All @@ -29,7 +29,7 @@ Added a very simple S3 task that enable files upload

```xml
<taskdef name="s3" classpath="aws-ant-task.jar" classname="it.corley.ant.S3PutTask" />
<s3 key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
<s3 endpoint="s3-eu-west-1.amazonaws.com" key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
<fileset dir="my/dir" includes="**/*.html" />
</s3>
```
Expand All @@ -38,7 +38,7 @@ File upload using default [Ant fileset](http://ant.apache.org/manual/Types/files

```xml
<taskdef name="s3put" classpath="aws-ant-task.jar" classname="it.corley.ant.S3PutTask" />
<s3put key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
<s3put endpoint="s3-eu-west-1.amazonaws.com" key="your-key" secret="your-secret" bucket="your-bucket-name" dest="path/to/file">
<fileset dir="${public.src}" casesensitive="yes">
<patternset id="non.test.sources">
<include name="**/*.js"/>
Expand All @@ -55,6 +55,7 @@ by fileset directive. Your bucket rule is never touched.***

```xml
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand All @@ -70,6 +71,7 @@ Global Content-Type configuration:

```xml
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand All @@ -83,6 +85,7 @@ Content-Type mappers:
```xml
<typedef name="contenttypemapping" classname="it.corley.ant.ContentTypeMapping" classpathref="tasks.path"/>
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand All @@ -103,12 +106,13 @@ Global Cache-Control configuration:

```xml
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
dest="path/to/file"
contentType="application/x-whatever"
cacheControl="3600">
cacheControl="max-age=3600">
<!-- fileset structure -->
</s3put>
```
Expand All @@ -117,6 +121,7 @@ Cache-Control mappers:
```xml
<typedef name="cachecontrol.mapping" classname="it.corley.ant.CacheControlMapping" classpathref="tasks.path"/>
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand All @@ -136,6 +141,7 @@ Global Content-Encoding configuration:

```xml
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand All @@ -150,6 +156,7 @@ Content-Encoding mappers:
```xml
<typedef name="contentencoding.mapping" classname="it.corley.ant.ContentEncodingMapping" classpathref="tasks.path"/>
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="your-key"
secret="your-secret"
bucket="your-bucket-name"
Expand Down
16 changes: 12 additions & 4 deletions example_use_build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Task for setting up the aws-ant-tasks -->
<target name="awstasks.setup">
<path id="tasks.path">
<fileset dir="target/aws-ant-tasks-0.3-SNAPSHOT-bin" includes="*.jar"/>
<fileset dir="target/aws-ant-tasks-0.5-SNAPSHOT-bin" includes="*.jar"/>
</path>

<taskdef name="s3put" classpath="aws-ant-tasks-0.3-SNAPSHOT-bin" classname="it.corley.ant.S3PutTask"
Expand All @@ -21,11 +21,19 @@
<!--Actual use -->
<target name="use" description="Use the Task" depends="awstasks.setup">
<property file="test.properties"/>
<s3put key="${test.aws.access_key}" secret="${test.aws.secret_key}" bucket="${test.aws.bucket}"
dest="aws-task-tests" publicread="true" cacheControl="3600" contentType="application/x-readme">
<s3put
endpoint="s3-eu-west-1.amazonaws.com"
key="${test.aws.access_key}"
secret="${test.aws.secret_key}"
bucket="${test.aws.bucket}"
dest="aws-task-tests"
publicread="true"
cacheControl="3600"
contentType="application/x-readme">

<fileset dir="." includes="README.md"/>
<contenttypemapping extension="md" contenttype="text/plain"/>
<cachecontrolmapping extension="md" maxage="7200"/>
<cachecontrolmapping extension="md" cacheControl="max-age=7200"/>
<contentencodingmapping extension="md" encoding="UTF-8" />
</s3put>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>it.corley</groupId>
<artifactId>aws-ant-tasks</artifactId>
<version>0.4-SNAPSHOT</version>
<version>0.5-SNAPSHOT</version>
<name>Aws ant task</name>
<description>Simple AWS ANT Task</description>
<url>https://github.com/corley/aws-ant-task</url>
Expand Down
17 changes: 7 additions & 10 deletions src/main/it/corley/ant/CacheControlMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class CacheControlMapping {
private String extension;
private String maxAge;
private String cacheControl;

public CacheControlMapping() {}
public CacheControlMapping(String extension, String maxAge) {
public CacheControlMapping(String extension, String cacheControl) {
setExtension(extension);
setMaxAge(maxAge);
setCacheControl(cacheControl);
}

public void setExtension(String extension) {
Expand All @@ -21,17 +21,14 @@ public String getExtension()

/**
*
* @param maxAge
*
* throw NumberFormatException
* @param cacheControl The cache-control string eg. max-age=3600
*/
public void setMaxAge(String maxAge) {
int intMaxAge = Integer.valueOf(maxAge);
this.maxAge = String.valueOf(intMaxAge);
public void setCacheControl(String cacheControl) {
this.cacheControl = cacheControl;
}

public String getMaxAge()
{
return this.maxAge;
return this.cacheControl;
}
}
22 changes: 17 additions & 5 deletions src/main/it/corley/ant/S3PutTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.Upload;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;

import java.io.File;
Expand Down Expand Up @@ -44,6 +46,8 @@ public class S3PutTask extends AWSTask {
private String cacheControl;

private String contentEncoding;

private String endPoint = "s3-eu-west-1.amazonaws.com";

/**
* Filesets containing content to be uploaded
Expand Down Expand Up @@ -74,6 +78,8 @@ public void execute() {
validateConfiguration();
AWSCredentials credential = new BasicAWSCredentials(getKey(), getSecret());
final TransferManager transferManager = new TransferManager(credential);
log(String.format("Region %s provided", getEndPoint()), Project.MSG_INFO);
transferManager.getAmazonS3Client().setEndpoint(getEndPoint());

String path;
if (dest == null) {
Expand Down Expand Up @@ -145,14 +151,14 @@ private void applyMetadata(File file, PutObjectRequest por) {
boolean cacheControlMetadataSet = false;
for (CacheControlMapping mapping : cacheControlMappings) {
if (fileName.endsWith(mapping.getExtension())) {
metadata.setCacheControl("max-age=" + mapping.getMaxAge());
metadata.setCacheControl(mapping.getMaxAge());
cacheControlMetadataSet = true;
break;
}
}
//TODO: add single file metadata cache-control
if (cacheControl != null && !cacheControlMetadataSet) {
metadata.setCacheControl("max-age=" + cacheControl);
metadata.setCacheControl(cacheControl);
}

boolean contentEncodingMetadataSet = false;
Expand Down Expand Up @@ -211,11 +217,9 @@ public void setContentEncoding(String contentEncoding) {
* Set the cache control max-age=seconds
*
* @param cacheControl
* @throw NumberFormatException If cache control is not a number.
*/
public void setCacheControl(String cacheControl) {
int intCacheControl = Integer.valueOf(cacheControl);
this.cacheControl = String.valueOf(intCacheControl);
this.cacheControl = cacheControl;
}

public void addContentTypeMapping(ContentTypeMapping mapping) {
Expand All @@ -241,4 +245,12 @@ public void setReducedRedundancy(boolean reducedRedundancy) {
this.reducedRedundancy = reducedRedundancy;
}

public String getEndPoint() {
return endPoint;
}

public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}

}
15 changes: 0 additions & 15 deletions src/test/it/corley/ant/S3PutTaskTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
package it.corley.ant;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.*;
import junit.framework.Assert;
import junit.framework.TestCase;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.selectors.FileSelector;
import org.apache.tools.ant.types.selectors.FilenameSelector;

import java.io.*;
import java.util.Properties;

/**
* Unit test class for the S3PutTask class
* Created at 11:26 10.05.12
Expand Down