Skip to content

Commit e761481

Browse files
author
grishick
committed
update
1 parent b95efe3 commit e761481

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/org/citybot/ant/AzureBlobFileUpload.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
import java.io.IOException;
77
import java.net.URISyntaxException;
88
import java.security.InvalidKeyException;
9+
import java.util.Iterator;
10+
import java.util.Vector;
911

1012
import org.apache.tools.ant.BuildException;
13+
import org.apache.tools.ant.DirectoryScanner;
1114
import org.apache.tools.ant.Task;
15+
import org.apache.tools.ant.types.FileSet;
16+
import org.apache.tools.ant.types.selectors.FileSelector;
1217

1318
import com.microsoft.windowsazure.services.blob.client.BlobContainerPermissions;
1419
import com.microsoft.windowsazure.services.blob.client.BlobContainerPublicAccessType;
@@ -20,17 +25,13 @@
2025
import com.microsoft.windowsazure.services.core.storage.StorageException;
2126

2227
public class AzureBlobFileUpload extends Task {
23-
String blob;
2428
String container;
2529
String account;
2630
String key;
2731
String protocol = "http";
28-
String file;
32+
private Vector filesets = new Vector();
2933
Boolean create = true;
3034
Boolean list = false;
31-
public void setBlob(String blob) {
32-
this.blob = blob;
33-
}
3435
public void setContainer(String container) {
3536
this.container = container;
3637
}
@@ -46,17 +47,14 @@ public void setProtocol(String protocol) {
4647
public void setCreate(Boolean create) {
4748
this.create = create;
4849
}
49-
public void setFile(String file) {
50-
this.file = file;
51-
}
5250

5351
public void setList(Boolean list) {
5452
this.list = list;
5553
}
54+
public void addFileset(FileSet fileset) {
55+
filesets.add(fileset);
56+
}
5657
public void execute() {
57-
if (blob==null) {
58-
throw new BuildException("Property 'blob' is required");
59-
}
6058
if (container==null) {
6159
throw new BuildException("Property 'container' is required");
6260
}
@@ -66,8 +64,8 @@ public void execute() {
6664
if (key==null) {
6765
throw new BuildException("Property 'key' is required");
6866
}
69-
if(file == null) {
70-
throw new BuildException("Property 'file' is required");
67+
if(filesets.isEmpty()) {
68+
throw new BuildException("A nested 'fileset' is required");
7169
}
7270
try {
7371
String storageConnectionString = String.format("DefaultEndpointsProtocol=%s;AccountName=%s;AccountKey=%s", protocol, account, key);
@@ -85,13 +83,24 @@ public void execute() {
8583
}
8684

8785
// Create or overwrite the "myimage.jpg" blob with contents from a local file
88-
CloudBlockBlob blobHandle = blobContainer.getBlockBlobReference(blob);
89-
File source = new File(file);
90-
blobHandle.upload(new FileInputStream(source), source.length());
86+
87+
for(Iterator itFSets = filesets.iterator(); itFSets.hasNext(); ) {
88+
FileSet fs = (FileSet)itFSets.next();
89+
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
90+
String[] includedFiles = ds.getIncludedFiles();
91+
for(int i=0; i<includedFiles.length; i++) {
92+
String filename = includedFiles[i].replace('\\','/');
93+
File source = new File(ds.getBasedir() + "/" + filename);
94+
String blobname = filename.substring(filename.lastIndexOf("/")+1);
95+
CloudBlockBlob blobHandle = blobContainer.getBlockBlobReference(blobname);
96+
blobHandle.upload(new FileInputStream(source), source.length());
97+
}
98+
}
99+
91100
if(list) {
92101
// Loop over blobs within the container and output the URI to each of them
93102
for (ListBlobItem blobItem : blobContainer.listBlobs()) {
94-
project.log(blobItem.getUri().toString());
103+
getProject().log(blobItem.getUri().toString());
95104
}
96105
}
97106
} catch (InvalidKeyException e) {

0 commit comments

Comments
 (0)