blob: 5854908ff620ede74da45544ec47fe733635dbd4 [file] [log] [blame]
<!--
Copyright (c) 2018, 2020 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,
or the Eclipse Distribution License v. 1.0 which is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
-->
<!--
Contributors:
Lukas - initial API and implementation
-->
<!-- This ant project includes the following tasks:
- wildfly-install : install binary and drivers on the server
- wildfly-setup : creates connection pools and prepares environment for tests
- wildfly-reset : removes connection pool, cleans up installation
- wildfly-start : starts server
- wildfly-stop : stops server
- wildfly-deploy : deploys ear
- wildfly-undeploy : undeploys ear
It requires some configuration of the wildfly.properties, it should be run through antbuild.xml, not directly.
To connect to the wildfly admin console use http://localhost:9990/console/App.html,
this may be useful for debugging deployment failures.
Sometimes if a test or deployment fails, your server gets screwed up
and you need to re-install your domain (ant -f antbuld.xml server-reset server-install server-setup).
-->
<!--
* Ant naming conventions:
* - regardless of the actual OS platform,'/' is the directory separator
* (Ant will convert as appropriate).
* - multi-word properties use periods '.'
* - properties ending in .jar define jarfile names only (no path)
* - properties ending in .lib are fully qualified jars (path and filename)
* - properties ending in .dir are directory paths
* - properties ending in .path are path refid names (classpath fragments)
* - multi-word targets use hyphens '-'
* - targets beginning with test- are reserved for high level test targets,
* and are used in test results parsing
* - targets typically use the form <action>-<object>-<type> (ie. package-bundle-zip)
* - multi-word macros use underscores '_'
* - multi-word macro attributes are concatenated
* e.g. 'runpathref'
* - multi-word tasks (taskdef) names are concatenated
* e.g. 'validateconnection'
* - OS environment variables are in ALLCAPS and have 'env' as a prefix
* e.g. ${env.XXX}.
* - Ant properties are lower case.
-->
<project name="Eclipse Persistence Services JPA Wildfly Testing" basedir=".">
<property name="env" environment="env" value="env"/>
<!-- Allows a user to overide certain user specific properties. -->
<property file="${user.home}/wildfly.properties"/>
<property file="./wildfly.properties"/>
<property name="jdbc.driver.lib" value="${jdbc.driver.jar}"/>
<property name="jdbc2.driver.lib" value="${jdbc2.driver.jar}"/>
<property name="jdbc3.driver.lib" value="${jdbc3.driver.jar}"/>
<property name="w.jpa.api.jar" value="${persistence22.jar}"/>
<path id="eclipselink.lib">
<fileset dir="${jpatest.basedir}/../../plugins/">
<include name="org.eclipse.persistence.*"/>
<exclude name="*.source_*"/>
</fileset>
<pathelement location="${jpatest.2.sdo.plugins.dir}/${commonj.sdo.jar}"/>
</path>
<macrodef name="set-db-name">
<attribute name="property"/>
<attribute name="driver" />
<sequential>
<!-- Set db name by check db.driver -->
<condition property="@{property}" value="oracle">
<contains string="@{driver}" substring="oracle"/>
</condition>
<condition property="@{property}" value="mysql">
<contains string="@{driver}" substring="mysql"/>
</condition>
<condition property="@{property}" value="mssql">
<contains string="@{driver}" substring="sqlserver"/>
</condition>
<condition property="@{property}" value="db2">
<contains string="@{driver}" substring="db2"/>
</condition>
<condition property="@{property}" value="sybase">
<contains string="@{driver}" substring="sybase"/>
</condition>
</sequential>
</macrodef>
<set-db-name property="db.name" driver="${db.driver}"/>
<set-db-name property="db2.name" driver="${db2.driver}"/>
<set-db-name property="db3.name" driver="${db3.driver}"/>
<condition property="is.eap">
<contains string="${server.version}" substring="eap"/>
</condition>
<!-- JVM used to run tests -->
<property name="test.junit.jvm" value="${env.JAVA_HOME}"/>
<property name="test.junit.jvm.exec" value="${test.junit.jvm}/bin/java"/>
<property name="wildfly.modules.dir" location="${wildfly.home}/modules/system/layers/base"/>
<target name="-backup-init">
<condition property="do.backup">
<not>
<available file="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak"/>
</not>
</condition>
</target>
<target name="-do-backup" description="Backup org.eclipse.persistence module definition." depends="-backup-init" if="do.backup">
<move file="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml" tofile="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak"/>
<copy file="${wildfly.modules.dir}/javax/persistence/api/main/module.xml" tofile="${wildfly.modules.dir}/javax/persistence/api/main/module.xml.bak"/>
</target>
<target name="-wildfly-cli-init" description="Initialize 'cli' macro for jboss-cli.">
<condition property="suffix" value="bat" else="sh">
<os family="windows"/>
</condition>
<macrodef name="cli" description="Run ${wildfly.home}/bin/jboss-cli.${suffix}">
<attribute name="command"/>
<sequential>
<echo>Executing command: @{command}</echo>
<exec executable="${wildfly.home}/bin/jboss-cli.${suffix}" dir="${basedir}" resultproperty="cli.result">
<env key="JAVA_HOME" value="${test.junit.jvm}"/>
<env key="JBOSS_HOME" value="${wildfly.home}"/>
<arg value="--connect"/>
<arg value="command=@{command}"/>
</exec>
<echo> ==> Execution result: ${cli.result}</echo>
</sequential>
</macrodef>
</target>
<target name="wildfly-install" description="Install binaries on the server." depends="-do-backup,-wildfly-cli-init">
<pathconvert property="eclipselink.jars" refid="eclipselink.lib" pathsep=":">
<flattenmapper/>
</pathconvert>
<pathconvert property="junit.jars" pathsep=":">
<path path="${junit.lib}"/>
<flattenmapper/>
</pathconvert>
<xslt style="resource/wildfly/eclipselink-module-template.xsl" in="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak" out="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml" force="true">
<param name="resources" expression="${eclipselink.jars}"/>
<param name="dependencies" expression="com.${db.name}:junit.junit:jakarta.json.api"/>
</xslt>
<copy todir="${wildfly.modules.dir}/org/eclipse/persistence/main" flatten="true">
<path refid="eclipselink.lib"/>
</copy>
<replaceregexp file="${wildfly.modules.dir}/javax/persistence/api/main/module.xml" match="hibernate-.*jar" replace="${w.jpa.api.jar}" byline="true"/>
<copy todir="${wildfly.modules.dir}/javax/persistence/api/main" file="${jpatest.2.jpa.plugins.dir}/${w.jpa.api.jar}" verbose="true"/>
<antcall target="wildfly-start"/>
<!-- JDBC Driver -->
<cli command="module add --name=com.${db.name} --resources=${jdbc.driver.lib} --dependencies=javax.api,jakarta.transaction.api --module-root-dir=${wildfly.modules.dir}"/>
<cli command="module add --name=com.${db2.name} --resources=${jdbc2.driver.lib} --dependencies=javax.api,jakarta.transaction.api --module-root-dir=${wildfly.modules.dir}"/>
<cli command="module add --name=com.${db3.name} --resources=${jdbc3.driver.lib} --dependencies=javax.api,jakarta.transaction.api --module-root-dir=${wildfly.modules.dir}"/>
<!-- JUnit -->
<cli command="module add --name=junit.junit --resources=${junit.lib} --module-root-dir=${wildfly.modules.dir}"/>
<cli command=":reload"/>
</target>
<target name="wildfly-setup" description="Create datasources and JDBC driver definition on the Wildfly server." depends="-wildfly-cli-init">
<cli command="/subsystem=datasources/jdbc-driver=${db.name}Driver:add(driver-name=${db.name}Driver,driver-module-name=com.${db.name},driver-class-name=${db.driver})"/>
<cli command=":reload"/>
<cli command="/subsystem=datasources/jdbc-driver=${db2.name}Driver:add(driver-name=${db2.name}Driver,driver-module-name=com.${db2.name},driver-class-name=${db2.driver})"/>
<cli command=":reload"/>
<cli command="/subsystem=datasources/jdbc-driver=${db3.name}Driver:add(driver-name=${db3.name}Driver,driver-module-name=com.${db3.name},driver-class-name=${db3.driver})"/>
<cli command=":reload"/>
<property name="w.ds.name" value="${wildfly.jtaDs.name}${db.name}Pool"/>
<echo>Setting up ${w.ds.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.jtaDs.jndi} --name=${w.ds.name} --connection-url=${db.url} --driver-name=${db.name}Driver --user-name=${db.user} —-password=${db.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.ds.name}:write-attribute(name=password,value=${db.pwd})"/>
<property name="w.ds2.name" value="${wildfly.jtaDs2.name}${db2.name}Pool"/>
<echo>Setting up ${w.ds2.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.jtaDs2.jndi} --name=${w.ds2.name} --connection-url=${db2.url} --driver-name=${db2.name}Driver --user-name=${db2.user} —-password=${db2.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.ds2.name}:write-attribute(name=password,value=${db2.pwd})"/>
<property name="w.ds3.name" value="${wildfly.jtaDs3.name}${db3.name}Pool"/>
<echo>Setting up ${w.ds3.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.jtaDs3.jndi} --name=${w.ds3.name} --connection-url=${db3.url} --driver-name=${db3.name}Driver --user-name=${db3.user} —-password=${db3.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.ds3.name}:write-attribute(name=password,value=${db3.pwd})"/>
<property name="w.nonjtads.name" value="${wildfly.nonJtaDs.name}${db.name}Pool"/>
<echo>Setting up ${w.nonjtads.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.nonJtaDs.jndi} --name=${w.nonjtads.name} --connection-url=${db.url} --driver-name=${db.name}Driver --user-name=${db.user} —-password=${db.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.nonjtads.name}:write-attribute(name=password,value=${db.pwd})"/>
<cli command=":reload"/>
<property name="w.nonjtads2.name" value="${wildfly.nonJtaDs2.name}${db2.name}Pool"/>
<echo>Setting up ${w.nonjtads2.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.nonJtaDs2.jndi} --name=${w.nonjtads2.name} --connection-url=${db2.url} --driver-name=${db2.name}Driver --user-name=${db2.user} —-password=${db2.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.nonjtads2.name}:write-attribute(name=password,value=${db2.pwd})"/>
<cli command=":reload"/>
<property name="w.nonjtads3.name" value="${wildfly.nonJtaDs3.name}${db3.name}Pool"/>
<echo>Setting up ${w.nonjtads3.name}</echo>
<cli command="data-source add --jndi-name=${wildfly.nonJtaDs3.jndi} --name=${w.nonjtads3.name} --connection-url=${db3.url} --driver-name=${db3.name}Driver --user-name=${db3.user} —-password=${db3.pwd} --jta=true --enabled=true"/>
<cli command="/subsystem=datasources/data-source=${w.nonjtads3.name}:write-attribute(name=password,value=${db3.pwd})"/>
<cli command=":reload"/>
<cli command="/system-property=pa.connection.user:add(value=${pa.connection.user})"/>
<cli command="/system-property=pa.connection.password:add(value=${pa.connection.password})"/>
<cli command="/system-property=pa.proxyuser:add(value=${pa.proxyuser})"/>
<cli command="/system-property=pa.proxyuser.password:add(value=${pa.proxyuser.password})"/>
<cli command="/system-property=pa.proxyuser2:add(value=${pa.proxyuser2})"/>
<cli command="/system-property=pa.proxyuser2.password:add(value=${pa.proxyuser2.password})"/>
<cli command=":reload"/>
</target>
<target name="wildfly-reset" description="Revert all modifications on the server done by install/setup." depends="-wildfly-cli-init,wildfly-start">
<!-- DataSources -->
<cli command="data-source remove --name=${wildfly.jtaDs.name}${db.name}Pool"/>
<cli command="data-source remove --name=${wildfly.nonJtaDs.name}${db.name}Pool"/>
<cli command="data-source remove --name=${wildfly.jtaDs2.name}${db2.name}Pool"/>
<cli command="data-source remove --name=${wildfly.nonJtaDs2.name}${db2.name}Pool"/>
<cli command="data-source remove --name=${wildfly.jtaDs3.name}${db3.name}Pool"/>
<cli command="data-source remove --name=${wildfly.nonJtaDs3.name}${db3.name}Pool"/>
<cli command=":reload"/>
<cli command="/subsystem=datasources/jdbc-driver=${db.name}Driver:remove"/>
<cli command="/subsystem=datasources/jdbc-driver=${db2.name}Driver:remove"/>
<cli command="/subsystem=datasources/jdbc-driver=${db3.name}Driver:remove"/>
<cli command=":reload"/>
<!-- System properties -->
<cli command="/system-property=pa.connection.user:remove"/>
<cli command="/system-property=pa.connection.password:remove"/>
<cli command="/system-property=pa.proxyuser:remove"/>
<cli command="/system-property=pa.proxyuser.password:remove"/>
<cli command="/system-property=pa.proxyuser2:remove"/>
<cli command="/system-property=pa.proxyuser2.password:remove"/>
<cli command=":reload"/>
<!-- JDBC Driver -->
<cli command="module remove --name=com.${db.name} --module-root-dir=${wildfly.modules.dir}"/>
<cli command="module remove --name=com.${db2.name} --module-root-dir=${wildfly.modules.dir}"/>
<cli command="module remove --name=com.${db3.name} --module-root-dir=${wildfly.modules.dir}"/>
<!-- JUnit -->
<cli command="module remove --name=junit.junit --module-root-dir=${wildfly.modules.dir}"/>
<move file="${wildfly.modules.dir}/javax/persistence/api/main/module.xml.bak" tofile="${wildfly.modules.dir}/javax/persistence/api/main/module.xml" failonerror="false" verbose="true" overwrite="true"/>
<delete file="${wildfly.modules.dir}/javax/persistence/api/main/${w.jpa.api.jar}" failonerror="false"/>
<move file="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak" tofile="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml" failonerror="false" verbose="true" overwrite="true"/>
<pathconvert property="delete.eclipselink.jars" refid="eclipselink.lib" pathsep=",">
<flattenmapper/>
</pathconvert>
<delete failonerror="false">
<fileset dir="${wildfly.modules.dir}/org/eclipse/persistence/main" includes="${delete.eclipselink.jars}"/>
</delete>
<cli command=":reload"/>
</target>
<target name="wildfly-start" description="Start the server." depends="-wildfly-cli-init">
<property name="additional.server.args" value=""/>
<property name="additional.server.jvmOpts" value="-Xms64m -Xmx1g -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=2g -Djava.net.preferIPv4Stack=true"/>
<property name="w.jvmOpts" value="-Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"/>
<exec executable="${wildfly.home}/bin/standalone.${suffix}" spawn="true">
<env key="JAVA_HOME" value="${test.junit.jvm}"/>
<env key="JBOSS_HOME" value="${wildfly.home}"/>
<env key="JBOSS_MODULES_SYSTEM_PKGS" value="org.jboss.byteman"/>
<env key="JAVA_OPTS" value="${additional.server.jvmOpts} ${w.jvmOpts}"/>
<arg value="--server-config=${wildfly.config}"/>
<arg value="-Ddb.user=${db.user}"/>
<arg value="-Ddb.pwd=${db.pwd}"/>
<arg line="${additional.server.args}"/>
</exec>
<waitfor maxwait="3" maxwaitunit="minute" checkevery="500" timeoutproperty="wildfly.not.running">
<http url="http://localhost:8080/index.html"/>
</waitfor>
<fail if="wildfly.not.running" message="Wildfly did not start within given time"/>
<echo>Wildfly is running at http://localhost:8080/index.html</echo>
</target>
<target name="wildfly-stop" description="Stop the server." depends="-wildfly-cli-init">
<cli command=":shutdown"/>
</target>
<target name="wildfly-deploy" description="Deploy the application ear to the server." depends="-wildfly-cli-init">
<cli command="deploy ${ear.name} --force"/>
</target>
<target name="wildfly-undeploy" description="Undeploy the application ear from the server." depends="-wildfly-cli-init">
<cli command="undeploy ${application.name}.ear"/>
</target>
</project>