Skip to content

Commit 096d699

Browse files
Enable building JNA on JDKs newer than 11
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.
1 parent 439e9f5 commit 096d699

9 files changed

+52
-21
lines changed

.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<classpathentry kind="src" output="build.eclipse/test-classes" path="test"/>
55
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
66
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
7-
<classpathentry kind="lib" path="lib/test/reflections-0.9.8.jar"/>
7+
<classpathentry kind="lib" path="lib/test/reflections-0.9.11.jar"/>
88
<classpathentry kind="output" path="build.eclipse/classes"/>
99
</classpath>

build.xml

+36-14
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,33 @@
9090
<condition property="test.compatibility" value="1.4">
9191
<equals arg1="${os.prefix}" arg2="w32ce-arm"/>
9292
</condition>
93-
<!-- Default compatibility, 1.6, or whatever version is running -->
94-
<condition property="compatibility" value="${ant.java.version}" else="1.6">
95-
<matches pattern="^1.[345]$" string="${ant.java.version}"/>
93+
94+
<!--
95+
Default compatibility, 1.6, or whatever version is running
96+
97+
Release builds of JNA target 1.6 and should be build on JDK 8, as JDK 9
98+
introduced changes in the ByteBuffer class, which result in classes, that
99+
can't be loaded on Java 6.
100+
101+
JDK 11 is the last JDK, that supports creation of Java 6 compatible class
102+
files.
103+
-->
104+
<condition property="compatibility" value="1.6" else="9">
105+
<matches pattern="^1\.\d+$" string="${ant.java.version}"/>
96106
</condition>
97-
<!-- Platform default compatibility, 1.5+ -->
98-
<condition property="platform.compatibility" value="1.5" else="${compatibility}">
99-
<equals arg1="${compatibility}" arg2="1.4"/>
107+
108+
<condition property="compatibility-check" value="true">
109+
<equals arg1="${compatility}" arg2="1.6" />
100110
</condition>
101-
<!-- Test default compatibility, 1.5+ -->
111+
112+
<property name="platform.compatibility" value="${compatibility}" />
113+
114+
<!-- JNA tests require at least 1.8 compatiblity -->
102115
<condition property="test.compatibility" value="1.8" else="${compatibility}">
103-
<equals arg1="${compatibility}" arg2="1.6"/>
116+
<or>
117+
<equals arg1="${compatibility}" arg2="1.6"/>
118+
<equals arg1="${compatibility}" arg2="1.7"/>
119+
</or>
104120
</condition>
105121
<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">
106122
<equals arg1="${os.prefix}" arg2="w32ce-arm"/>
@@ -1136,11 +1152,7 @@ cd ..
11361152
<property name="build-native" value="true"/>
11371153
</target>
11381154

1139-
<!-- When running tests from an IDE, be sure to set jna.library.path -->
1140-
<!-- to where the test library (testlib) is found. -->
1141-
<target name="test" depends="-enable-native,jar,compile-tests" unless="cross-compile"
1142-
description="Run all unit tests">
1143-
1155+
<target name="-check-java6-compatibility" depends="-enable-native,jar,compile-tests" if="compatibility-check">
11441156
<echo>Checking JDK compatibility 1.6</echo>
11451157

11461158
<echo></echo>
@@ -1150,10 +1162,20 @@ cd ..
11501162
</as:check-signature>
11511163

11521164
<echo></echo>
1165+
</target>
1166+
1167+
<target name="-warn-java6-compatiblity" depends="-enable-native,jar,compile-tests" unless="compatibility-check">
1168+
<echo level="warn">Build is not Java 6 compatible and NOT A PRODUCTION BUILD</echo>
1169+
</target>
1170+
1171+
<!-- When running tests from an IDE, be sure to set jna.library.path -->
1172+
<!-- to where the test library (testlib) is found. -->
1173+
<target name="test" depends="-enable-native,jar,compile-tests,-check-java6-compatibility,-warn-java6-compatiblity" unless="cross-compile"
1174+
description="Run all unit tests">
11531175

11541176
<property name="test.fork" value="yes"/>
11551177
<property name="test.forkmode" value="perTest"/>
1156-
1178+
11571179
<condition property="test.jdwp" value="-Xrunjdwp:transport=dt_socket,address=${test.debugport},server=y,suspend=y">
11581180
<isset property="test.debugport" />
11591181
</condition>

contrib/platform/build.xml

+12-3
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,27 @@ com.sun.jna.platform.wince;version=${osgi.version}
152152
</manifest>
153153
</target>
154154

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

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

159162
<echo></echo>
160163

161-
<as:check-signature signature="../../lib/java16-1.1.signature" classpath="${javac.classpath}">
162-
<path path="${build.classes.dir}"/>
164+
<as:check-signature signature="../../lib/java16-1.1.signature">
165+
<path path="${classes}"/>
163166
</as:check-signature>
164167

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

175+
<target name="test" depends="init,compile,compile-test,-pre-test-run,-check-java6-compatibility,-warn-java6-compatiblity" description="Run platform unit tests.">
167176
<echo>Running platform tests: ${test.src.dir}</echo>
168177
<property name="test.fork" value="yes"/>
169178
<property name="reports.junit" location="${build}/reports/junit/${os.prefix}"/>

contrib/platform/nbproject/project.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ run.modulepath=\
8585
${javac.modulepath}
8686
run.test.classpath=\
8787
${javac.test.classpath}:\
88-
../../lib/test/reflections-0.9.8.jar:\
89-
../../lib/test/guava-11.0.2.jar:\
88+
../../lib/test/reflections-0.9.11.jar:\
89+
../../lib/test/guava-27.1-jre.jar:\
9090
../../lib/test/javassist-3.12.1.GA.jar:\
9191
../../lib/test/slf4j-api-1.6.1.jar:\
9292
../../lib/test/dom4j-1.6.1.jar:\

lib/test/guava-11.0.2.jar

-1.57 MB
Binary file not shown.

lib/test/guava-27.1-jre.jar

2.62 MB
Binary file not shown.

lib/test/reflections-0.9.11.jar

128 KB
Binary file not shown.

lib/test/reflections-0.9.8.jar

-100 KB
Binary file not shown.

nbproject/project.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ auxiliary.show.customizer.message=<message>
9494
<compilation-unit>
9595
<package-root>test</package-root>
9696
<unit-tests/>
97-
<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>
97+
<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>
9898
<source-level>1.8</source-level>
9999
</compilation-unit>
100100
<compilation-unit>

0 commit comments

Comments
 (0)