blob: f528529b6c25c21e7f7a563fb654f69ef799c09f [file] [log] [blame]
<!--
Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<!--
This file should be included by all autodeployment build.xml files and
defines properties and tasks used by multiple auto-deploy tests.
-->
<property name="dateFormat" value="yyyy-MM-dd-HH:mm:ss"/>
<property name="autodeploy.dir" value="${env.S1AS_HOME}/domains/domain1/autodeploy"/>
<property name="autodeploy.util.build" value="${testsRoot}/build/autodeploy/util"/>
<path id="autodeploy.compile.classpath">
<pathelement location="${inst}/lib/javaee.jar"/>
<pathelement location="${java.home}/lib/tools.jar"/>
<pathelement location="${env.S1AS_HOME}/modules/deployment-autodeploy.jar"/>
<pathelement location="${autodeploy.util.build}"/>
</path>
<!--
This target runs a Java class that watches the app server's autodeploy directory and detects
when the app server has deployed or undeployed the app (or has reported a failure to do so) by observing
when the marker files appear in the directory.
The target records its results in a temporary properties file in the ${build} directory.
This provides a simple way (relatively simple, at least) to use the same target more than once
and store different result values in a way that can be retrieved and used from the main
target. (This basically works around the behavior of ant in which a called target's property
settings are NOT propagated out to the calling target. It also avoids the practice of creating
a set of marker files that, by their presence or absence, convey success or failure of a substep.)
-->
<target name="runAutoDeployMonitor">
<javaWithResult
fork="true"
failonerror="false"
jvm="${JAVA}"
classname="autodeploy.test.AutoDeployMonitor"
resultproperty="autodeployResult"
output="${build}/${log.id}.output.log"
>
<jvmarg value="-Dmonitor.debug=true"/>
<classpath refid="autodeploy.compile.classpath"/>
<!--
<classpath>
<path location="${inst}/lib/j2ee.jar"/>
<path location="${build}"/>
</classpath>
-->
<arg line="${arg.list}"/>
</javaWithResult>
<!--
The result property name used in the next task is an argument to the called target.
Note that the echo is a little oddly formatted. The </echo> is on a line by itself and left-justified so
that the output to the file being written will reside on a line by itself. The
left-justification is not really needed but the properties file looks a bit nicer
if you open it in an editor. This is because the next line in the properties file being
written is indented as far as the </echo> is indented here in the build.xml file.
-->
<echo file="${result.property.file}" append="true">${resultPropertyName}=${autodeployResult}
</echo>
</target>
<target name="deploy.autodeploy">
<!--
To monitor auto-deployment or auto-undeployment, we start by getting the current time.
Then we copy the archive file into the autodeploy directory (for auto-deploy) or delete
it (for auto-undeploy). All marker files created by the server during auto-deployment of
the newly-copied archive file will have later timestamps than the timestamp just created.
There could be earlier marker files for the same archive in the directory and the monitor
wants to ignore those, which is why we get the current time and pass it to the monitor.
The monitor will check for marker files for the copied archive file
and whose last modification time are after the current timestamp, returning 0 if the
auto-deployer creates a _deployed or _undeployed file, 1 if it creates a _deploy_failed
or _undeploy_failed file, and -1 if it recognized no marker file.
-->
<tstamp prefix="deploy">
<format property="NOW" pattern="${dateFormat}"/>
</tstamp>
<!-- Pause; some file systems record file rev date/time to 2-second precision -->
<sleep seconds="2"/>
<!--
Trigger the auto-deploy.
-->
<copy file="${archive.file}" todir="${autodeploy.dir}" overwrite="true"/>
<condition property="log.id" value="1">
<not>
<isset property="log.id"/>
</not>
</condition>
<!--
Use the monitor to detect when the auto-deploy has completed.
-->
<echo>Waiting for autodeployment to complete...</echo>
<antcall target="runAutoDeployMonitor">
<param name="arg.list" value="${archive.name} ${autodeploy.dir} ${dateFormat} ${deploy.NOW}"/>
<param name="resultPropertyName" value="${deployResultPropertyName}"/>
<param name="log.id" value="${log.id}"/>
</antcall>
</target>
<target name="deploy.autoundeploy">
<!--
This target works very much like the deploy.autodeploy target except that instead of
copying the archive into the autodeploy directory it deletes the previously copied
archive from that directory.
-->
<tstamp prefix="undeploy">
<format property="NOW" pattern="${dateFormat}"/>
</tstamp>
<!-- Pause; some file systems record file rev date/time to 2-second resolution -->
<sleep seconds="2"/>
<!--
Trigger auto-undeploy by deleting the file.
-->
<delete quiet="true">
<fileset dir="${autodeploy.dir}" includes="${archive.name}"/>
</delete>
<condition property="log.id" value="2">
<not>
<isset property="log.id"/>
</not>
</condition>
<echo>Waiting for autoundeployment to complete...</echo>
<antcall target="runAutoDeployMonitor">
<param name="arg.list" value="${archive.name} ${autodeploy.dir} ${dateFormat} ${undeploy.NOW}"/>
<param name="resultPropertyName" value="${undeployResultPropertyName}"/>
<param name="log.id" value="${log.id}"/>
</antcall>
</target>