2010-01-03 19:29:48 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!--
|
|
|
|
|
|
|
|
|
2010-08-12 19:04:26 -04:00
|
|
|
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
2010-01-03 19:29:48 -05:00
|
|
|
|
|
|
|
====================================================================
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
====================================================================
|
|
|
|
|
|
|
|
-->
|
2010-08-12 19:04:26 -04:00
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
<project name="shrinkblob" default="shrinkblob" basedir="." xmlns:artifact="urn:maven-artifact-ant">
|
|
|
|
|
|
|
|
<!-- maven must be available before we use it -->
|
|
|
|
<get src="http://apache.imghat.com/maven/binaries/maven-ant-tasks-2.1.0.jar" dest="maven-ant-tasks-2.1.0.jar"/>
|
|
|
|
|
|
|
|
<!-- initialize maven tasks -->
|
|
|
|
<path id="maven-ant-tasks.classpath" path="maven-ant-tasks-2.1.0.jar" />
|
|
|
|
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant"
|
|
|
|
classpathref="maven-ant-tasks.classpath" />
|
|
|
|
|
|
|
|
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository" />
|
|
|
|
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots" />
|
2010-01-15 18:13:35 -05:00
|
|
|
<artifact:remoteRepository id="shrinkwrap.repository" url="http://repository.jboss.org/maven2" />
|
2010-01-03 19:29:48 -05:00
|
|
|
|
|
|
|
<!-- Setup maven so that we can get latest version of jclouds, shrinkwrap, and jruby -->
|
|
|
|
<artifact:dependencies pathId="shrinkwrap.classpath">
|
2010-04-30 14:20:23 -04:00
|
|
|
<dependency groupId="org.jboss.shrinkwrap" artifactId="shrinkwrap-impl-base" version="1.0.0-alpha-9" />
|
2010-01-03 19:29:48 -05:00
|
|
|
<dependency groupId="org.jruby" artifactId="jruby" version="1.4.0"/>
|
2010-04-30 14:20:23 -04:00
|
|
|
<dependency groupId="org.jclouds" artifactId="jclouds-aws" version="1.0-SNAPSHOT" />
|
|
|
|
<dependency groupId="org.jclouds" artifactId="jclouds-atmos" version="1.0-SNAPSHOT" />
|
|
|
|
<dependency groupId="org.jclouds" artifactId="jclouds-azure" version="1.0-SNAPSHOT" />
|
|
|
|
<dependency groupId="org.jclouds" artifactId="jclouds-rackspace" version="1.0-SNAPSHOT" />
|
2010-01-15 18:13:35 -05:00
|
|
|
<remoteRepository refid="shrinkwrap.repository" />
|
2010-01-03 19:29:48 -05:00
|
|
|
<remoteRepository refid="jclouds-snapshot.repository" />
|
|
|
|
<localRepository refid="local.repository" />
|
|
|
|
</artifact:dependencies>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="What is the directory you'd like to upload?"
|
|
|
|
addproperty="dir"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="What is the name of the zip you'd like ${dir} stored to?"
|
|
|
|
addproperty="zip"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="What is the container you wish to store ${zip} in?"
|
|
|
|
addproperty="container"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="Which service would you like to use (atmos,azureblob,cloudfiles,s3)?"
|
|
|
|
validargs="atmos,azureblob,cloudfiles,s3"
|
|
|
|
addproperty="service"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="What is your account on ${service}?"
|
|
|
|
addproperty="account"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
message="What is the key for ${account}?"
|
|
|
|
addproperty="key"
|
|
|
|
/>
|
|
|
|
|
2010-01-15 18:13:35 -05:00
|
|
|
<property name="location" value="default" />
|
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
<property name="urltoparse" value="blobstore://${account}:${key}@${service}/${container}" />
|
|
|
|
|
|
|
|
<target name="export">
|
|
|
|
<script language="jruby" classpathref="shrinkwrap.classpath"> <![CDATA[
|
|
|
|
require 'java'
|
|
|
|
require 'jruby/core_ext'
|
|
|
|
include_class 'org.apache.tools.ant.Task'
|
|
|
|
include_class 'org.jclouds.http.HttpUtils'
|
|
|
|
include_class 'org.jclouds.blobstore.BlobStoreContextFactory'
|
|
|
|
include_class 'org.jboss.shrinkwrap.api.Archives'
|
|
|
|
include_class 'org.jboss.shrinkwrap.api.exporter.ZipExporter'
|
|
|
|
include_class 'org.jboss.shrinkwrap.api.importer.ExplodedImporter'
|
|
|
|
include_class 'org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader'
|
|
|
|
|
|
|
|
# define a new ant task that uses ShrinkWrap to zip up things to a BlobStore
|
|
|
|
class ShrinkBlob < Task
|
|
|
|
def setBlobstore(blobstore)
|
|
|
|
@blobstore = blobstore
|
|
|
|
end
|
|
|
|
|
|
|
|
def setContainer(container)
|
|
|
|
@container = container
|
|
|
|
end
|
|
|
|
|
|
|
|
def setZip(zip)
|
|
|
|
@zip = zip
|
|
|
|
end
|
|
|
|
|
|
|
|
def setDir(dir)
|
|
|
|
@dir = dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2010-01-03 19:44:15 -05:00
|
|
|
# correct the ant classloader so that extensions can be found
|
2010-01-03 19:29:48 -05:00
|
|
|
java.lang.Thread.currentThread().setContextClassLoader(ServiceExtensionLoader.new().getClass().getClassLoader())
|
2010-01-03 19:44:15 -05:00
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
print "creating the archive from ",@dir,"\n"
|
2010-01-05 23:05:49 -05:00
|
|
|
zipStream = Archives.create(@zip, ExplodedImporter.java_class).importDirectory(@dir).as(ZipExporter.java_class).exportZip()
|
2010-01-03 19:44:15 -05:00
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
destination = HttpUtils.createUri(@blobstore)
|
|
|
|
print "connecting to service ",destination.getHost(),"/",@container,"\n"
|
2010-01-03 19:44:15 -05:00
|
|
|
|
|
|
|
# array thing is a weird hack since jruby doesn't understand varargs
|
2010-01-13 16:05:23 -05:00
|
|
|
context = BlobStoreContextFactory.new().createContext(destination)
|
2010-01-15 18:13:35 -05:00
|
|
|
context.getBlobStore().createContainerInLocation(@location, @container)
|
2010-01-03 19:44:15 -05:00
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
print "uploading to ",destination.getHost(),"/",@container,"/",@zip,"\n"
|
|
|
|
context.createInputStreamMap(@container).put(@zip,zipStream);
|
2010-01-03 19:44:15 -05:00
|
|
|
|
2010-01-03 19:29:48 -05:00
|
|
|
context.close();
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# make a real java class so that we can register it in ant
|
|
|
|
ShrinkBlob.add_method_signature("execute", [java.lang.Void::TYPE])
|
|
|
|
ShrinkBlob.add_method_signature("setBlobstore", [java.lang.Void::TYPE, java.lang.String.java_class])
|
|
|
|
ShrinkBlob.add_method_signature("setContainer", [java.lang.Void::TYPE, java.lang.String.java_class])
|
|
|
|
ShrinkBlob.add_method_signature("setZip", [java.lang.Void::TYPE, java.lang.String.java_class])
|
|
|
|
ShrinkBlob.add_method_signature("setDir", [java.lang.Void::TYPE, java.io.File.java_class])
|
|
|
|
clazz = ShrinkBlob.become_java!;
|
|
|
|
|
|
|
|
# register the ant task
|
|
|
|
$project.addTaskDefinition("shrinkblob", clazz)
|
|
|
|
]]></script>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<target name="shrinkblob" depends="export" >
|
|
|
|
<shrinkblob blobstore="${urltoparse}" container="${container}" dir="${dir}" zip="${zip}" />
|
|
|
|
</target>
|
|
|
|
|
|
|
|
</project>
|