blob: bcd818be5802888825bf3e6f18ef785c46a7e71e [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<project name="javaws">
<!--
This project defines targets useful for integrating Java Web Start-based
app client testing into both the SQE and the devtest test frameworks.
The enclosing ant environment must define the property ${javaws.lib.jar}
to point to the ant-extras.jar containing the JavaWSURLBuilder class.
@Author: Tim Quinn
-->
<target name="javaws.init" >
<prepare-javaws-security/>
</target>
<target name="javaws.cleanup" >
<restore-javaws-security/>
</target>
<!--
Security-related targets
GlassFish signs the GlassFish system JARs needed by the ACC and the application
JARs needed by the client. By default it uses the self-signed cert
that is generated when the domain is created (or during the GlassFish
build in the case of the default domain, domain1.) Java Web Start
verifies signed JARs it downloads, and if the cert used to sign a JAR
does not have a certificate chain to a trusted certificate authority
then Java Web Start displays a dialog box, asking the user if s/he wants
to trust the content.
For automated testing we need to prevent Java Web Start from prompting
the user. We do this by telling Java Web Start to trust the self-signed
cert which GlassFish used to sign the JARs. And we do that by setting
a property in the current user's deployment.properties config file so
that Java Web Start will use the GlassFish domain's keystore (which
contains the domain's self-signed cert) as the Java Web Start truststore.
Because Java Web Start then sees that it should trust the self-signed
cert, it will not prompt the user.
To accomplish this, as part of initialization we make a safe copy of the existing
deployment.properties file (if one exists), then we append a line to
the deployment.properties file (creating it if it does not already
exist). Later, as part of clean-up, we restore the safe copy (if there
was a pre-existing deployment.properties).
-->
<macrodef name="prepare-javaws-security">
<sequential>
<find-deployment-properties/>
<choose-new-deployment-properties/>
<!--
Make the safe copy of any existing deployment.properties file.
-->
<property name="savedDeploymentPropertiesFilePath" value="${user.home}/deployment-saved.properties"/>
<property name="trustedCertsPath" value="${admin.domain.dir}/${admin.domain}/config/keystore.jks"/>
<copy file="${originalDeploymentPropertiesFilePath}"
tofile="${savedDeploymentPropertiesFilePath}"
overwrite="false"
failonerror="false"/>
<!--
Add the line to the existing file (or create a new one) pointing to
the domain's keystore as the Java Web Start user-level truststore.
-->
<echo append="true"
file="${originalDeploymentPropertiesFilePath}">
# Generated by GlassFish test framework for Java Web Start testing
deployment.user.security.trusted.certs=${trustedCertsPath}
</echo>
</sequential>
</macrodef>
<macrodef name="restore-javaws-security">
<sequential>
<move
file="${savedDeploymentPropertiesFilePath}"
tofile="${originalDeploymentPropertiesFilePath}"
overwrite="true"
failonerror="false"/>
</sequential>
</macrodef>
<!--
The deployment.properties file - if it exists - could be in a number of
different places depending on which OS this is.
-->
<macrodef name="find-deployment-properties">
<sequential>
<condition property="originalDeploymentPropertiesFilePath"
value="${user.home}/Application Data/Sun/Java/deployment.properties"
>
<os family="windows"/>
</condition>
<condition property="originalDeploymentPropertiesFilePath"
value="${user.home}/Library/Caches/Java/deployment.properties"
>
<os family="mac"/>
</condition>
<condition property="originalDeploymentPropertiesFilePath"
value="${user.home}/.java/deployment/deployment.properties">
<os family="unix"/>
</condition>
</sequential>
</macrodef>
<macrodef name="choose-new-deployment-properties">
<sequential>
<property name="newDeploymentPropertiesFilePath" value="${user.home}/tempDeployment.properties"/>
</sequential>
</macrodef>
<!--
For the SQE framework, launches the app client using Java Web Start.
-->
<target name="launch-appclient-javaws" if="use.javaws">
<echo message="Launching app client using Java Web Start"/>
<tempfile property="clientOutputFile" prefix="appclient" suffix=".txt"/>
<prepare-javaws-security/>
<!--
Choose the output file.
-->
<tempfile property="javaws.report.file" prefix="javaws" suffix=".txt"/>
<property name="javaws.status.file" value="${javaws.report.file}.status"/>
<property name="javaws.protocol" value="http"/>
<property name="javaws.report.timeout" value="1500000"/>
<!--
Compose the URL to use for launching the app client via Java Web Start.
-->
<java classname="org.glassfish.ant.extras.JavaWSURLBuilder"
classpath="${ant-extras.lib.jar}"
outputproperty="jnlp.url"
logError="true"
fork="true">
<arg line="-client" />
<arg line="${assemble.dir}/${appname}AppClient.jar"/>
<arg line="-name" />
<arg line="${appname}Client"/>
<arg line="-textauth"/>
<arg line="-user ${acc.user}"/>
<arg line="-password ${acc.password}"/>
<arg line="-xml &quot;${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml&quot;"/>
<arg line="${appclient.application.args}"/>
<env key="APPCPATH" value="${appclient.classpath}"/>
<env key="VMARGS" value="${appclient.vmargs}"/>
<arg value="-testOutput"/>
<arg value="${javaws.report.file}"/>
<sysproperty key="javaws.protocol" value="${javaws.protocol}"/>
<sysproperty key="http.host" value="${http.host}"/>
<sysproperty key="http.port" value="${http.port}"/>
<sysproperty key="appname" value="${appname}"/>
<sysproperty key="clientname" value="${clientname}"/>
</java>
<!--
Now launch the client.
-->
<echo>Launching with ${JAVAWS} -Xnosplash ${jnlp.url}</echo>
<exec executable="${JAVAWS}"
failonerror="false"
timeout="${javaws.report.timeout}"
>
<arg value="-Xnosplash"/>
<arg value="${jnlp.url}"/>
</exec>
<!--
The Java Web Start launch runs outside this VM, so wait
for the status file to appear
-->
<echo>Waiting for Java Web Start launch to complete....</echo>
<waitfor maxwaitunit="second" maxwait="${javaws.report.timeout}">
<available file="${javaws.status.file}"/>
</waitfor>
<echo>Java Web Start launch finished</echo>
<!--
Read the output file into a property, echo the output to the
output so any human watching can see it, and then check the
status for success or failure.
-->
<loadresource property="launchOutput">
<file file="${javaws.report.file}"/>
</loadresource>
<echo file="${clientOutputFile}" message="${launchOutput}"/>
<echo message="${launchOutput}"/>
<antcall target="checkReporting-common">
<param name="test.name" value="${appname}"/>
<param name="test.description" value="${test.description}"/>
<param name="test.count" value="${test.count}"/>
</antcall>
<delete file="${javaws.report.file}"/>
<delete file="${javaws.status.file}"/>
<restore-javaws-security/>
</target>
</project>