<property file="${user.home}/build.properties" />
<fail unless="play.path" message="Property play.path not set in build.properties file"/>
<fail unless="project.version" message="Property project.version not set"/>
<fail unless="project.path" message="Property project.path not set in build.properties file"/>
<property name="play.cache.repository" value="${play.path}/repository/cache/my.group.com" />
<property name="play.stage.dir" value="/target/staged" />
<tstamp/>
<property name="project.version.timestamp" value="${project.version}-${DSTAMP}${TSTAMP}"/>
<!-- On deploy we don't need to send all the files in the stage folder, but only the ones specific to our project -->
<patternset id="project.files.pattern">
<include name="**/foo-*.jar"/>
<include name="**/bar-*.jar"/>
<include name="**/api-*.jar"/>
<include name="**/joda-time*.jar"/>
</patternset>
<!-- This is what we'll call from Jenkins -->
<target name="jenkins-play-build" description="Specific target for jenkins">
<antcall target="play-stage"/>
<antcall target="deploy"/>
</target>
<target name="play-stage" description="Does a full build and stage of our Play apps">
<!-- We have some maven projects which we want to update by deleting this folder-->
<delete dir="${play.cache.repository}"/>
<exec executable="${play.path}/play" dir="${my.repository.path}/foo">
<arg value="clean"/>
<arg value="compile"/>
<arg value="stage"/>
</exec>
<exec executable="${play.path}/play" dir="${my.repository.path}/bar">
<arg value="clean"/>
<arg value="compile"/>
<arg value="stage"/>
</exec>
<exec executable="${play.path}/play" dir="${my.repository.path}/api">
<arg value="clean"/>
<arg value="compile"/>
<arg value="stage"/>
</exec>
</target>
<target name="play-deploy" description="Deploys the given project">
<fail unless="project.version.timestamp" message="Property version.timestamp needed to continue"/>
<fail unless="deploy.server" message="Property needed to continue"/>
<fail unless="webapp" message="Property webapp needed to continue"/>
<property name="scp.path" value="${remote.user}@${remote.server}:${remote.dir}/webapps/${webapp}" />
<sshexec
host="${remote.server}"
username="${remote.user}"
keyfile="${user.home}/.ssh/id_rsa" trust="true"
command="mkdir ${remote.dir}/webapps/${webapp}/${project.version.timestamp}" failonerror="false"/>
<scp toDir="${scp.path}/${project.version.timestamp}" keyfile="${user.home}/.ssh/id_rsa" trust="true">
<fileset dir="${project.path}/${webapp}/${play.stage.dir}" casesensitive="yes">
<patternset refid="project.files.pattern"/>
</fileset>
</scp>
</target>
<!-- Deploy each of the projects separately. Repeat for each project. -->
<target name="play-deploy-foo" depends="check-play-foo-staged" if="project.foo.staged">
<antcall target="play-deploy">
<param name="webapp" value="foo"/>
</antcall>
</target>
<target name="check-play-foo-staged">
<echo message="Check path ${project.path}/foo$/{play.stage.dir} exists"/>
<available file="${project.path}/foo/${play.stage.dir}" type="dir" property="project.foo.staged"/>
</target>
<!-- This is the target which binds everything together for the deploy -->
<target name="deploy" description="Deploy all applications">
<antcall target="play-deploy-foo"/>
<antcall target="play-deploy-api"/>
<antcall target="play-deploy-bar"/>
<sshexec
host="${remote.server}"
username="${remote.user}"
keyfile="${user.home}/.ssh/id_rsa" trust="true"
command="/home/play/bin/deploy ${project.version.timestamp}"/>
</target>