jclouds/demos/antjruby/build.xml

153 lines
5.8 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
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.
====================================================================
-->
<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" />
<artifact:remoteRepository id="shrinkwrap.repository" url="http://repository.jboss.org/maven2" />
<!-- Setup maven so that we can get latest version of jclouds, shrinkwrap, and jruby -->
<artifact:dependencies pathId="shrinkwrap.classpath">
<dependency groupId="org.jboss.shrinkwrap" artifactId="shrinkwrap-impl-base" version="1.0.0-alpha-9" />
<dependency groupId="org.jruby" artifactId="jruby" version="1.4.0"/>
<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" />
<remoteRepository refid="shrinkwrap.repository" />
<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"
/>
<property name="location" value="default" />
<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
# correct the ant classloader so that extensions can be found
java.lang.Thread.currentThread().setContextClassLoader(ServiceExtensionLoader.new().getClass().getClassLoader())
print "creating the archive from ",@dir,"\n"
zipStream = Archives.create(@zip, ExplodedImporter.java_class).importDirectory(@dir).as(ZipExporter.java_class).exportZip()
destination = HttpUtils.createUri(@blobstore)
print "connecting to service ",destination.getHost(),"/",@container,"\n"
# array thing is a weird hack since jruby doesn't understand varargs
context = BlobStoreContextFactory.new().createContext(destination)
context.getBlobStore().createContainerInLocation(@location, @container)
print "uploading to ",destination.getHost(),"/",@container,"/",@zip,"\n"
context.createInputStreamMap(@container).put(@zip,zipStream);
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>