Skip to content

Commit

Permalink
Enable building JNA on JDKs newer than 11
Browse files Browse the repository at this point in the history
Building on JDK 8 is the recommend (and release) way for JNA. It results
in binaries, that are compatible with Java 6.

In theory JNA can be build with JDK 9-11 and target java 6, but that
results in binaries, that match the class format of java 6, but are
linked against methods, that were added/overriden in JDK 9 (ByteBuffer).

So any build with a JDK newer than 9 will not be binary compatible and
thus needs a major version bump.
  • Loading branch information
matthiasblaesing committed Mar 17, 2019
1 parent 439e9f5 commit 096d699
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<classpathentry kind="src" output="build.eclipse/test-classes" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
<classpathentry kind="lib" path="lib/test/reflections-0.9.8.jar"/>
<classpathentry kind="lib" path="lib/test/reflections-0.9.11.jar"/>
<classpathentry kind="output" path="build.eclipse/classes"/>
</classpath>
50 changes: 36 additions & 14 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,33 @@
<condition property="test.compatibility" value="1.4">
<equals arg1="${os.prefix}" arg2="w32ce-arm"/>
</condition>
<!-- Default compatibility, 1.6, or whatever version is running -->
<condition property="compatibility" value="${ant.java.version}" else="1.6">
<matches pattern="^1.[345]$" string="${ant.java.version}"/>

<!--
Default compatibility, 1.6, or whatever version is running
Release builds of JNA target 1.6 and should be build on JDK 8, as JDK 9
introduced changes in the ByteBuffer class, which result in classes, that
can't be loaded on Java 6.
JDK 11 is the last JDK, that supports creation of Java 6 compatible class
files.
-->
<condition property="compatibility" value="1.6" else="9">
<matches pattern="^1\.\d+$" string="${ant.java.version}"/>
</condition>
<!-- Platform default compatibility, 1.5+ -->
<condition property="platform.compatibility" value="1.5" else="${compatibility}">
<equals arg1="${compatibility}" arg2="1.4"/>

<condition property="compatibility-check" value="true">
<equals arg1="${compatility}" arg2="1.6" />
</condition>
<!-- Test default compatibility, 1.5+ -->

<property name="platform.compatibility" value="${compatibility}" />

<!-- JNA tests require at least 1.8 compatiblity -->
<condition property="test.compatibility" value="1.8" else="${compatibility}">
<equals arg1="${compatibility}" arg2="1.6"/>
<or>
<equals arg1="${compatibility}" arg2="1.6"/>
<equals arg1="${compatibility}" arg2="1.7"/>
</or>
</condition>
<condition property="tests.exclude-patterns" value="**/VarArgsTest.java,**/AnnotatedLibraryTest.java,**/WebStartTest.java,**/PointerBufferTest.java,**/HeadlessLoadLibraryTest.java,**/StructureBufferFieldTest.java,**/PerformanceTest.java,**/*BufferArgumentsMarshalTest.java" else="**/wince/*.java,**/WebStartTest.java">
<equals arg1="${os.prefix}" arg2="w32ce-arm"/>
Expand Down Expand Up @@ -1136,11 +1152,7 @@ cd ..
<property name="build-native" value="true"/>
</target>

<!-- When running tests from an IDE, be sure to set jna.library.path -->
<!-- to where the test library (testlib) is found. -->
<target name="test" depends="-enable-native,jar,compile-tests" unless="cross-compile"
description="Run all unit tests">

<target name="-check-java6-compatibility" depends="-enable-native,jar,compile-tests" if="compatibility-check">
<echo>Checking JDK compatibility 1.6</echo>

<echo></echo>
Expand All @@ -1150,10 +1162,20 @@ cd ..
</as:check-signature>

<echo></echo>
</target>

<target name="-warn-java6-compatiblity" depends="-enable-native,jar,compile-tests" unless="compatibility-check">
<echo level="warn">Build is not Java 6 compatible and NOT A PRODUCTION BUILD</echo>
</target>

<!-- When running tests from an IDE, be sure to set jna.library.path -->
<!-- to where the test library (testlib) is found. -->
<target name="test" depends="-enable-native,jar,compile-tests,-check-java6-compatibility,-warn-java6-compatiblity" unless="cross-compile"
description="Run all unit tests">

<property name="test.fork" value="yes"/>
<property name="test.forkmode" value="perTest"/>

<condition property="test.jdwp" value="-Xrunjdwp:transport=dt_socket,address=${test.debugport},server=y,suspend=y">
<isset property="test.debugport" />
</condition>
Expand Down
15 changes: 12 additions & 3 deletions contrib/platform/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,27 @@ com.sun.jna.platform.wince;version=${osgi.version}
</manifest>
</target>

<target name="test" depends="init,compile,compile-test,-pre-test-run" description="Run platform unit tests.">
<condition property="compatibility-check" value="true">
<equals arg1="${javac.target}" arg2="1.6" />
</condition>

<target name="-check-java6-compatibility" depends="init,compile,compile-test,-pre-test-run" if="compatibility-check">
<echo>Checking JDK compatibility 1.6</echo>

<echo></echo>

<as:check-signature signature="../../lib/java16-1.1.signature" classpath="${javac.classpath}">
<path path="${build.classes.dir}"/>
<as:check-signature signature="../../lib/java16-1.1.signature">
<path path="${classes}"/>
</as:check-signature>

<echo></echo>
</target>

<target name="-warn-java6-compatiblity" depends="init,compile,compile-test,-pre-test-run" unless="compatibility-check">
<echo level="warn">Build is not Java 6 compatible and NOT A PRODUCTION BUILD</echo>
</target>

<target name="test" depends="init,compile,compile-test,-pre-test-run,-check-java6-compatibility,-warn-java6-compatiblity" description="Run platform unit tests.">
<echo>Running platform tests: ${test.src.dir}</echo>
<property name="test.fork" value="yes"/>
<property name="reports.junit" location="${build}/reports/junit/${os.prefix}"/>
Expand Down
4 changes: 2 additions & 2 deletions contrib/platform/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
../../lib/test/reflections-0.9.8.jar:\
../../lib/test/guava-11.0.2.jar:\
../../lib/test/reflections-0.9.11.jar:\
../../lib/test/guava-27.1-jre.jar:\
../../lib/test/javassist-3.12.1.GA.jar:\
../../lib/test/slf4j-api-1.6.1.jar:\
../../lib/test/dom4j-1.6.1.jar:\
Expand Down
Binary file removed lib/test/guava-11.0.2.jar
Binary file not shown.
Binary file added lib/test/guava-27.1-jre.jar
Binary file not shown.
Binary file added lib/test/reflections-0.9.11.jar
Binary file not shown.
Binary file removed lib/test/reflections-0.9.8.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ auxiliary.show.customizer.message=<message>
<compilation-unit>
<package-root>test</package-root>
<unit-tests/>
<classpath mode="compile">lib/hamcrest-core-1.3.jar:lib/junit.jar:lib/test/dom4j-1.6.1.jar:lib/test/guava-11.0.2.jar:lib/test/javassist-3.12.1.GA.jar:lib/test/reflections-0.9.8.jar:lib/test/slf4j-api-1.6.1.jar:src</classpath>
<classpath mode="compile">lib/hamcrest-core-1.3.jar:lib/junit.jar:lib/test/dom4j-1.6.1.jar:lib/test/guava-11.0.2.jar:lib/test/javassist-3.12.1.GA.jar:lib/test/reflections-0.9.11.jar:lib/test/slf4j-api-1.6.1.jar:src</classpath>
<source-level>1.8</source-level>
</compilation-unit>
<compilation-unit>
Expand Down

0 comments on commit 096d699

Please sign in to comment.