|
Added
Link Here
|
| 0 |
- |
1 |
<!--/******************************************************************************* |
|
|
2 |
* This program and the accompanying materials are made available under the |
| 3 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| 4 |
* which accompanies this distribution. |
| 5 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 6 |
* and the Eclipse Distribution License is available at |
| 7 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 8 |
* |
| 9 |
* Ant naming conventions: |
| 10 |
* - regardless of the actual OS platform,'/' is the directory separator |
| 11 |
* (Ant will convert as appropriate). |
| 12 |
* - multi-word properties use periods '.' |
| 13 |
* - properties ending in .jar define jarfile names only (no path) |
| 14 |
* - properties ending in .lib are fully qualified jars (path and filename) |
| 15 |
* - properties ending in .dir are directory paths |
| 16 |
* - properties ending in .path are path refid names (classpath fragments) |
| 17 |
* - multi-word targets use hyphens '-' |
| 18 |
* - targets beginning with test- are reserved for high level test targets, |
| 19 |
* and are used in test results parsing |
| 20 |
* - targets typically use the form <action>-<object>-<type> (ie. package-bundle-zip) |
| 21 |
* - multi-word macros use underscores '_' |
| 22 |
* - multi-word macro attributes are concatenated |
| 23 |
* e.g. 'runpathref' |
| 24 |
* - multi-word tasks (taskdef) names are concatenated |
| 25 |
* e.g. 'validateconnection' |
| 26 |
* - OS environment variables are in ALLCAPS and have 'env' as a prefix |
| 27 |
* e.g. ${env.XXX}. |
| 28 |
* - Ant properties are lower case. |
| 29 |
* |
| 30 |
* Contributors: |
| 31 |
* Lukas - initial API and implementation |
| 32 |
#******************************************************************************/--> |
| 33 |
|
| 34 |
<!-- This ant project includes the following tasks: |
| 35 |
- wildfly-install : install binary and drivers on the server |
| 36 |
- wildfly-setup : creates connection pools and prepares environment for tests |
| 37 |
- wildfly-reset : removes connection pool, cleans up installation |
| 38 |
- wildfly-start : starts server |
| 39 |
- wildfly-stop : stops server |
| 40 |
- wildfly-deploy : deploys ear |
| 41 |
- wildfly-undeploy : undeploys ear |
| 42 |
|
| 43 |
It requires some configuration of the wildfly.properties, it should be run through antbuild.xml, not directly. |
| 44 |
To connect to the wildfly admin console use http://localhost:9990/console/App.html, |
| 45 |
this may be useful for debugging deployment failures. |
| 46 |
Sometimes if a test or deployment fails, your server gets screwed up |
| 47 |
and you need to re-install your domain (ant -f antbuld.xml server-reset server-install server-setup). |
| 48 |
--> |
| 49 |
|
| 50 |
<project name="Eclipse Persistence Services JPA Wildfly Testing" basedir="."> |
| 51 |
|
| 52 |
<property name="env" environment="env" value="env"/> |
| 53 |
<!-- Allows a user to overide certain user specific properties. --> |
| 54 |
<property file="${user.home}/wildfly.properties"/> |
| 55 |
<property file="./wildfly.properties"/> |
| 56 |
|
| 57 |
<property name="jdbc.driver.lib" value="${jdbc.driver.jar}"/> |
| 58 |
<property name="w.jpa.api.jar" value="${persistence22.jar}"/> |
| 59 |
<path id="eclipselink.lib"> |
| 60 |
<fileset dir="${jpatest.basedir}/../../plugins/"> |
| 61 |
<include name="org.eclipse.persistence.*"/> |
| 62 |
<exclude name="*.source_*"/> |
| 63 |
</fileset> |
| 64 |
<pathelement location="${jpatest.2.sdo.plugins.dir}/${commonj.sdo.jar}"/> |
| 65 |
</path> |
| 66 |
|
| 67 |
<!-- Set db name by check db.driver --> |
| 68 |
<condition property="db.name" value="oracle"> |
| 69 |
<contains string="${db.driver}" substring="oracle"/> |
| 70 |
</condition> |
| 71 |
|
| 72 |
<condition property="db.name" value="mysql"> |
| 73 |
<contains string="${db.driver}" substring="mysql"/> |
| 74 |
</condition> |
| 75 |
|
| 76 |
<condition property="db.name" value="mssql"> |
| 77 |
<contains string="${db.driver}" substring="sqlserver"/> |
| 78 |
</condition> |
| 79 |
|
| 80 |
<condition property="db.name" value="db2"> |
| 81 |
<contains string="${db.driver}" substring="db2"/> |
| 82 |
</condition> |
| 83 |
|
| 84 |
<condition property="db.name" value="sybase"> |
| 85 |
<contains string="${db.driver}" substring="sybase"/> |
| 86 |
</condition> |
| 87 |
|
| 88 |
<condition property="is.eap"> |
| 89 |
<contains string="${server.version}" substring="eap"/> |
| 90 |
</condition> |
| 91 |
|
| 92 |
<!-- JVM used to run tests --> |
| 93 |
<property name="test.junit.jvm" value="${env.JAVA_HOME}"/> |
| 94 |
<property name="test.junit.jvm.exec" value="${test.junit.jvm}/bin/java"/> |
| 95 |
|
| 96 |
<property name="wildfly.modules.dir" location="${wildfly.home}/modules/system/layers/base"/> |
| 97 |
|
| 98 |
<target name="-backup-init"> |
| 99 |
<condition property="do.backup"> |
| 100 |
<not> |
| 101 |
<available file="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak"/> |
| 102 |
</not> |
| 103 |
</condition> |
| 104 |
</target> |
| 105 |
|
| 106 |
<target name="-do-backup" description="Backup org.eclipse.persistence module definition." depends="-backup-init" if="do.backup"> |
| 107 |
<move file="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml" tofile="${wildfly.modules.dir}/org/eclipse/persistence/main/module.xml.bak"/> |
| 108 |
<copy file="${wildfly.modules.dir}/javax/persistence/api/main/module.xml" tofile="${wildfly.modules.dir}/javax/persistence/api/main/module.xml.bak"/> |
| 109 |
</target> |
| 110 |
|
| 111 |
<target name="-wildfly-cli-init" description="Initialize 'cli' macro for jboss-cli."> |
| 112 |
<condition property="is.windows" value="true"> |
| 113 |
<os family="windows"/> |
| 114 |
</condition> |
| 115 |
<condition property="is.unix" value="true"> |
| 116 |
<os family="unix"/> |
| 117 |
</condition> |
| 118 |
<condition property="suffix" value="bat"> |
| 119 |
<isset property="is.windows"/> |
| 120 |
</condition> |
| 121 |
<condition property="suffix" value="sh"> |
| 122 |
<isset property="is.unix"/> |
| 123 |
</condition> |
| 124 |
|
| 125 |
<macrodef name="cli" description="Run ${wildfly.home}/bin/jboss-cli.${suffix}"> |
| 126 |
<attribute name="command"/> |
| 127 |
<sequential> |
| 128 |
<echo>Executing command: @{command}</echo> |
| 129 |
<exec executable="${wildfly.home}/bin/jboss-cli.${suffix}" dir="${basedir}" resultproperty="cli.result"> |
| 130 |
<env key="JAVA_HOME" value="${test.junit.jvm}"/> |
| 131 |
<env key="JBOSS_HOME" value="${wildfly.home}"/> |
| 132 |
<arg value="--connect"/> |
| 133 |
<arg value="command=@{command}"/> |
| 134 |
</exec> |
| 135 |
<echo> ==> Execution result: ${cli.result}</echo> |
| 136 |
</sequential> |
| 137 |
</macrodef> |
| 138 |
</target> |
| 139 |
|
| 140 |
<target name="wildfly-install" description="Install binaries on the server." depends="-do-backup,-wildfly-cli-init"> |
| 141 |
<pathconvert property="eclipselink.jars" refid="eclipselink.lib" pathsep=":"> |
| 142 |
<flattenmapper/> |
| 143 |
</pathconvert> |
| 144 |
<pathconvert property="junit.jars" pathsep=":"> |
| 145 |
<path path="${junit.lib}"/> |
| 146 |
<flattenmapper/> |
| 147 |
</pathconvert> |
| 148 |
<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"> |
| 149 |
<param name="resources" expression="${eclipselink.jars}"/> |
| 150 |
<param name="dependencies" expression="com.${db.name}:junit.junit"/> |
| 151 |
</xslt> |
| 152 |
<copy todir="${wildfly.modules.dir}/org/eclipse/persistence/main" flatten="true"> |
| 153 |
<path refid="eclipselink.lib"/> |
| 154 |
</copy> |
| 155 |
<replaceregexp file="${wildfly.modules.dir}/javax/persistence/api/main/module.xml" match="hibernate-.*jar" replace="${w.jpa.api.jar}" byline="true"/> |
| 156 |
<copy todir="${wildfly.modules.dir}/javax/persistence/api/main" file="${jpatest.2.jpa.plugins.dir}/${w.jpa.api.jar}" verbose="true"/> |
| 157 |
|
| 158 |
<antcall target="wildfly-start"/> |
| 159 |
<!-- JDBC Driver --> |
| 160 |
<cli command="module add --name=com.${db.name} --resources=${jdbc.driver.lib} --dependencies=javax.api,javax.transaction.api --module-root-dir=${wildfly.modules.dir}"/> |
| 161 |
<!-- JUnit --> |
| 162 |
<cli command="module add --name=junit.junit --resources=${junit.lib} --module-root-dir=${wildfly.modules.dir}"/> |
| 163 |
|
| 164 |
<cli command=":reload"/> |
| 165 |
</target> |
| 166 |
|
| 167 |
<target name="wildfly-setup" description="Create datasources and JDBC driver definition on the Wildfly server." depends="-wildfly-cli-init"> |
| 168 |
<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})"/> |
| 169 |
<cli command=":reload"/> |
| 170 |
|
| 171 |
<property name="w.ds.name" value="${wildfly.jtaDs.name}${db.name}Pool"/> |
| 172 |
<echo>Setting up ${w.ds.name}</echo> |
| 173 |
<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"/> |
| 174 |
<cli command="/subsystem=datasources/data-source=${w.ds.name}:write-attribute(name=password,value=${db.pwd})"/> |
| 175 |
|
| 176 |
<property name="w.nonjtads.name" value="${wildfly.nonJtaDs.name}${db.name}Pool"/> |
| 177 |
<echo>Setting up ${w.nonjtads.name}</echo> |
| 178 |
<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"/> |
| 179 |
<cli command="/subsystem=datasources/data-source=${w.nonjtads.name}:write-attribute(name=password,value=${db.pwd})"/> |
| 180 |
<cli command=":reload"/> |
| 181 |
|
| 182 |
<cli command="/system-property=eclipselink.archive.factory:add(value=org.jipijapa.eclipselink.JBossArchiveFactoryImpl)"/> |
| 183 |
<cli command=":reload"/> |
| 184 |
</target> |
| 185 |
|
| 186 |
<target name="wildfly-reset" description="Revert all modifications on the server done by install/setup." depends="-wildfly-cli-init,wildfly-start"> |
| 187 |
<!-- DataSources --> |
| 188 |
<cli command="data-source remove --name=${wildfly.jtaDs.name}${db.name}Pool"/> |
| 189 |
<cli command="data-source remove --name=${wildfly.nonJtaDs.name}${db.name}Pool"/> |
| 190 |
<cli command=":reload"/> |
| 191 |
|
| 192 |
<cli command="/subsystem=datasources/jdbc-driver=${db.name}Driver:remove"/> |
| 193 |
<cli command="/system-property=eclipselink.archive.factory:remove"/> |
| 194 |
<cli command=":reload"/> |
| 195 |
|
| 196 |
<!-- JDBC Driver --> |
| 197 |
<cli command="module remove --name=com.${db.name} --module-root-dir=${wildfly.modules.dir}"/> |
| 198 |
<!-- JUnit --> |
| 199 |
<cli command="module remove --name=junit.junit --module-root-dir=${wildfly.modules.dir}"/> |
| 200 |
|
| 201 |
<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"/> |
| 202 |
<delete file="${wildfly.modules.dir}/javax/persistence/api/main/${w.jpa.api.jar}" failonerror="false"/> |
| 203 |
|
| 204 |
<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"/> |
| 205 |
<pathconvert property="delete.eclipselink.jars" refid="eclipselink.lib" pathsep=","> |
| 206 |
<flattenmapper/> |
| 207 |
</pathconvert> |
| 208 |
<delete failonerror="false"> |
| 209 |
<fileset dir="${wildfly.modules.dir}/org/eclipse/persistence/main" includes="${delete.eclipselink.jars}"/> |
| 210 |
</delete> |
| 211 |
<cli command=":reload"/> |
| 212 |
</target> |
| 213 |
|
| 214 |
<target name="wildfly-start" description="Start the server." depends="-wildfly-cli-init"> |
| 215 |
<property name="additional.server.args" value=""/> |
| 216 |
<property name="additional.server.jvmOpts" value="-Xms64m -Xmx1g -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=2g -Djava.net.preferIPv4Stack=true"/> |
| 217 |
<property name="w.jvmOpts" value="-Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"/> |
| 218 |
<exec executable="${wildfly.home}/bin/standalone.${suffix}" spawn="true"> |
| 219 |
<env key="JAVA_HOME" value="${test.junit.jvm}"/> |
| 220 |
<env key="JBOSS_HOME" value="${wildfly.home}"/> |
| 221 |
<env key="JBOSS_MODULES_SYSTEM_PKGS" value="org.jboss.byteman"/> |
| 222 |
<env key="JAVA_OPTS" value="${additional.server.jvmOpts} ${w.jvmOpts}"/> |
| 223 |
<arg value="--server-config=${wildfly.config}"/> |
| 224 |
<arg value="-Ddb.user=${db.user}"/> |
| 225 |
<arg value="-Ddb.pwd=${db.pwd}"/> |
| 226 |
<arg line="${additional.server.args}"/> |
| 227 |
</exec> |
| 228 |
<waitfor maxwait="3" maxwaitunit="minute" checkevery="500" timeoutproperty="wildfly.not.running"> |
| 229 |
<http url="http://localhost:8080/index.html"/> |
| 230 |
</waitfor> |
| 231 |
<fail if="wildfly.not.running" message="Wildfly did not start within given time"/> |
| 232 |
<echo>Wildfly is runnig at http://localhost:8080/index.html</echo> |
| 233 |
</target> |
| 234 |
|
| 235 |
<target name="wildfly-stop" description="Stop the server." depends="-wildfly-cli-init"> |
| 236 |
<cli command=":shutdown"/> |
| 237 |
</target> |
| 238 |
|
| 239 |
<target name="wildfly-deploy" description="Deploy the application ear to the server." depends="-wildfly-cli-init"> |
| 240 |
<cli command="deploy ${ear.name} --force"/> |
| 241 |
</target> |
| 242 |
|
| 243 |
<target name="wildfly-undeploy" description="Undeploy the application ear frpm the server." depends="-wildfly-cli-init"> |
| 244 |
<cli command="undeploy ${application.name}.ear"/> |
| 245 |
</target> |
| 246 |
|
| 247 |
</project> |