Connector/J 5.1 supports both JDBC 3 and JDBC 4+ with a single code base. This requires JDBC 3 classes to be compiled with Java 5 and JDBC 4+ to be compiled
with Java 8.
The variables 'com.mysql.jdbc.jdk5' and 'com.mysql.jdbc.jdk8' are used to find the respective compilers when building the driver. Side by side
with these, the variable 'com.mysql.jdbc.extra.libs' must point to the location of third-party libraries that we don't distribute and are required for
compiling.
Compiling all JDBC 4+ code with Java 8 alone produces some warnings since JDBC 4.0 and JDBC 4.1 classes don't require a compliler higher than Java 6. To get
more precise results and avoid warnings use the property 'com.mysql.jdbc.jre6.rtjar' to point to the Java 6 'rt.jar' library (usually in 'jre/lib/rt.jar').
Further details can be found in http://dev.mysql.com/doc/connector-j/en/connector-j-installing-source.html.
Connector/J 5.1 ships with an extensive test suite that can be run simply by providing a MySQL JDBC URL in the variable 'com.mysql.jdbc.testsuite.url' and by
calling the target "test". If nothing more is set, these tests run with the JVMs referred in the variables 'com.mysql.jdbc.jdk5' and 'com.mysql.jdbc.jdk8' for
JDBC 3 and JDBC 4+ related tests respectively. Alternatively, all tests can be run with a single JVM, provided that it is pointed out in the variable
'com.mysql.jdbc.testsuite.jvm'.
Running the full test suite with different JVMs and different MySQL servers at once is also possible. The variables 'com.mysql.jdbc.testsuite.jvm' and
'com.mysql.jdbc.testsuite.url' can be suffixed with an index ".1" to ".9" to indicate the multiple alternatives which results in the matrix of all possible
combinations. The target "test-multijvm" must be called in this case.
Running only one test set is possible by setting the variable 'test' with the class' fully qualified name. If also a comma separated list of test names is
provided in the variable 'methods', then only these will be executed.
Targets: "test", "test-multijvm"
Compliance
==========
This file ships with targets for these matters. Further details can be found in the respective targets.
Coverage and instrumentation
============================
This file ships with target "test-coverage" for collecting coverage results and "report-coverage" for creating the HTML coverage report.
The JCov library needed to run these targets can be found at http://hg.openjdk.java.net/code-tools/jcov, it's JARs should be placed
into ${com.mysql.jdbc.extra.libs}/jcov directory.
The "test-coverage" target instruments classes using JCov, runs tests collecting coverage info into result file set as
Support for MySQL Fabric connections is seamlessly included in Connector/J, so when the driver is compiled it already includes all the required classes for it.
Testing MySQL Fabric support can be done by setting specific variables and running the respective targets. Further details can be found in the last targets in
this file.
Sample 'build.properties' that can be used to compile, build, test and test with multi JVMs
<!-- The following properties are needed for finding JDK5 and JDK8 needed for compile and can be passed on the command line to ant via -D switches. -->
<!-- The following property allows to point the location of third-party libraries we don't distribute. Default value points to src/lib so user could either
put these jars there or pass different location via ant -D switch. -->
<failmessage="Java 5 is required. Set the full path to this JDK home with the property 'com.mysql.jdbc.jdk5'. Default: '/usr/lib/jvm/jdk1.5').
Java 8 (for JDBC 4+ implementation) is also required. Set the full path to this JDK home with the property 'com.mysql.jdbc.jdk8'. Default: '/usr/lib/jvm/jdk1.8'.">
<condition>
<not>
<and>
<equalsarg1="${jdk5checkexitstatus}"arg2="0"/>
<containsstring="${com.mysql.jdbc.jdk5.version}"substring="java version "1.5"casesensitive="true"/>
</and>
</not>
</condition>
</fail>
</target>
<!-- Check for required JDK8 for compilation of JDBC 4+ implementation. -->
<failmessage="Java 8 (for JDBC 4+ implementation) is required. Set the full path to this JDK home with the property 'com.mysql.jdbc.jdk8'. Default: '/usr/lib/jvm/jdk1.8'.">
<condition>
<not>
<and>
<equalsarg1="${jdk8checkexitstatus}"arg2="0"/>
<containsstring="${com.mysql.jdbc.jdk8.version}"substring="java version "1.8"casesensitive="true"/>
</and>
</not>
</condition>
</fail>
</target>
<!-- Check for Java 6 runtime libraries for compilation of JDBC 4.0 and JDBC 4.1 implementations. Ignored if property is undefined. -->
<targetname="-jre6-rtjar-check">
<failmessage="Invalid or missing Java 6 runtime library pointed by 'com.mysql.jdbc.jre6.rtjar'. ">
<condition>
<and>
<issetproperty="com.mysql.jdbc.jre6.rtjar"/>
<not>
<availablefile="${com.mysql.jdbc.jre6.rtjar}"/>
</not>
</and>
</condition>
</fail>
</target>
<!-- Check provided URL for running unit tests. -->
<failmessage="Set the MySQL database connection string for the test suite in one of the properties, 'com.mysql.jdbc.testsuite.url' or 'com.mysql.jdbc.testsuite.url.N', according to desired target.">
<failmessage="Set the MySQL database connection string for the compliance tests in one of the properties, 'com.mysql.jdbc.compliance.url' or 'com.mysql.jdbc.compliance.url.N', according to desired target.">
<failmessage="Testing Connector/J requires a JVM 1.5 or higher. Set the path to this JVM (JRE or JDK) home with the property 'com.mysql.jdbc.testsuite.jvm'. Default: '${com.mysql.jdbc.jdk5}'.">
<condition>
<not>
<equalsarg1="${jvmcheckexitstatus}"arg2="0"/>
</not>
</condition>
</fail>
<!-- Run JDBC 4+(<4.2) tests with ${com.mysql.jdbc.jdk8.java} if chosen JVM for tests is JVM5 -->
<!-- Make MySQL GPL-licensed or commercially-licensed binaries package, that doesn't contain sources but contain docs. -->
<targetname="full-package-no-sources"
description="Builds driver, binary .jar file, docs and packages (.zip, .tar.gz) suitable for distribution that do _not_ contain sources but contain docs."
<!-- Run the full test suite, single test set or single test, and compliance test suite, against multiple JVMs and server configs. -->
<targetname="test-all-multi"
description="Runs the full test suite, single test set or single test, and compliance test suite, against multiple JVMs and server configs."
depends="compile">
<deletedir="${buildDir}/junit"/>
<antcalltarget="test-multijvm"/>
<antcalltarget="test-compliance-multijvm"/>
<failmessage="Tests failed. Check logs and/or reports in '${buildDir}/junit'."if="tests.compliance.failed"/>
</target>
<!-- Run the full test suite, single test set or named test against multiple JVMs and server configs. -->
<targetname="test-multijvm"
description="Runs the full test suite, single test set (variable 'test') or named tests (variables 'test' and 'methods') against multiple JVMs and server configs."
<!-- Run the full test suite, single test set or named tests against one JVM and one server config. -->
<targetname="test"
description="Runs the full test suite, single test set (variable 'test') or named tests (variables 'test' and 'methods') against one JVM and one server config."
value="Running JDBC 3 unit tests against '${com.mysql.jdbc.testsuite.url.final}' with jvm '${com.mysql.jdbc3.testsuite.jvm.java}'">
<not>
<issetproperty="test"/>
</not>
</condition>
<conditionproperty="test.message.jdbc3orcommon"
value="Running JDBC unit test '${test}', method(s) '${methods}' against '${com.mysql.jdbc.testsuite.url.final}' with jvm '${com.mysql.jdbc3.testsuite.jvm.java}'"
else="Running JDBC unit test '${test}' against '${com.mysql.jdbc.testsuite.url.final}' with jvm '${com.mysql.jdbc3.testsuite.jvm.java}'">
<targetname="report-coverage"depends="-jcov-merge, -set-report-coverage-detaults"description="Merges coverage results and creates HTML coverage report.">
<failmessage="The provided JVM reference is invalid '@{jvm}'. Set the path to a valid JVM(s) (JRE or JDK) home in the properties 'com.mysql.jdbc.testsuite.jvm.[1..8]'.">
<condition>
<not>
<and>
<equalsarg1="${jvmcheckexitstatus}"arg2="0"/>
<matchesstring="${jvm.version}"pattern="^java version "\d+\.\d+\.\d+_\d+".*$"casesensitive="true"multiline="true"/>