Skip to content

Commit

Permalink
Fix Java 1.6 compatibility and introduce animal-sniffer to prevent re…
Browse files Browse the repository at this point in the history
…gressions
  • Loading branch information
matthiasblaesing committed Oct 13, 2018
1 parent bb6d520 commit 36de803
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ pom-jna-platform.xml.asc
*.iml
/contrib/platform/${build.generated.sources.dir}/
/contrib/platform/${build}/
/contrib/platform/nbproject/private/
/contrib/platform/nbproject/private/
/nbproject/private/
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Features

Bug Fixes
---------

* [#1025](https://github.com/java-native-access/jna/pull/1025): Restore java 6 compatibility and introduce animal-sniffer to prevent regressions - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 5.0.0
=============
Expand Down
34 changes: 27 additions & 7 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="JNA" default="default" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" xmlns:if="ant:if">
<project name="JNA" default="default" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant"
xmlns:as="antlib:org.codehaus.mojo.animal_sniffer"
xmlns:if="ant:if">
<description>Builds and tests JNA</description>

<!-- Default build compiles all platform-independent stuff as well
Expand Down Expand Up @@ -136,6 +139,18 @@
<target name="compile-test-single" depends="compile-tests"/>
<target name="compile-single" depends="compile"/>

<!-- Prepare additional ant task -->
<path id="maven-ant-tasks.classpath">
<pathelement location="lib/animal-sniffer-ant-tasks-1.17.jar" />
<pathelement location="lib/maven-ant-tasks-2.1.3.jar" />
</path>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<typedef resource="org/codehaus/mojo/animal_sniffer/antlib.xml"
uri="antlib:org.codehaus.mojo.animal_sniffer"
classpathref="maven-ant-tasks.classpath" />

<target name="-prepare-anttools">
<mkdir dir="${build}/ant-tools" />
<javac classpath="lib/ant.jar"
Expand Down Expand Up @@ -1127,6 +1142,17 @@ cd ..
<!-- 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">

<echo>Checking JDK compatibility 1.6</echo>

<echo></echo>

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

<echo></echo>

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

Expand Down Expand Up @@ -1370,12 +1396,6 @@ cd ..
</artifact:mvn>
</target>


<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />

<!-- NOTE: The 'deploy' target works only if the version (jna.version in build.xml) ends in '-SNAPSHOT'. -->
<target name="deploy" depends="dist" description="deploy snapshot version to Maven snapshot repository">
<artifact:mvn failonerror="true">
Expand Down
29 changes: 26 additions & 3 deletions contrib/platform/build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="platform" default="default" basedir=".">
<project name="platform"
default="default"
basedir="."
xmlns:as="antlib:org.codehaus.mojo.animal_sniffer">
<description>Builds and tests platform-specific code.</description>
<import file="nbproject/build-impl.xml"/>
<!--
Expand Down Expand Up @@ -63,7 +66,16 @@
nbproject/build-impl.xml file.
-->


<!-- Prepare additional ant task -->
<path id="maven-ant-tasks.classpath">
<pathelement location="../../lib/animal-sniffer-ant-tasks-1.17.jar" />
<pathelement location="../../lib/maven-ant-tasks-2.1.3.jar" />
</path>
<typedef resource="org/codehaus/mojo/animal_sniffer/antlib.xml"
uri="antlib:org.codehaus.mojo.animal_sniffer"
classpathref="maven-ant-tasks.classpath" />

<!-- the -init-macrodef-copylibs target superseeds the target defined in
build-impl.xml. The classpath that the base copylibs target adds to the
MANIFEST.MF interferes with spring-boot and tomcat -->
Expand Down Expand Up @@ -98,7 +110,7 @@
</sequential>
</macrodef>
</target>

<target name="-pre-jar">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<manifest file="${tmp.manifest.file}" mode="replace">
Expand Down Expand Up @@ -140,6 +152,17 @@ com.sun.jna.platform.wince;version=${osgi.version}
</target>

<target name="test" depends="init,compile,compile-test,-pre-test-run" description="Run platform unit tests.">

<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>

<echo></echo>

<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
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ public static VARIANT toVariant(Object value) {
Constructor<VARIANT> constructor = null;
if (value != null) {
for (Constructor<VARIANT> m : (Constructor<VARIANT>[]) VARIANT.class.getConstructors()) {
if (m.getParameterCount() > 0
&& m.getParameterTypes()[0].isAssignableFrom(value.getClass())) {
Class<?>[] parameters = m.getParameterTypes();
if (parameters.length == 1
&& parameters[0].isAssignableFrom(value.getClass())) {
constructor = m;
}
}
Expand Down
Binary file added lib/animal-sniffer-ant-tasks-1.17.jar
Binary file not shown.
Binary file added lib/java16-1.1.signature
Binary file not shown.
9 changes: 2 additions & 7 deletions src/com/sun/jna/NativeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
*/
package com.sun.jna;

import java.nio.CharBuffer;


/** Provides a temporary allocation of an immutable C string
* (<code>const char*</code> or <code>const wchar_t*</code>) for use when
* converting a Java String into a native memory function argument.
Expand Down Expand Up @@ -111,9 +108,7 @@ public boolean equals(Object other) {
@Override
public String toString() {
boolean wide = WIDE_STRING.equals(encoding);
String s = wide ? "const wchar_t*" : "const char*";
s += "(" + (wide ? pointer.getWideString(0) : pointer.getString(0, encoding)) + ")";
return s;
return (wide ? pointer.getWideString(0) : pointer.getString(0, encoding));
}

public Pointer getPointer() {
Expand All @@ -132,7 +127,7 @@ public int length() {

@Override
public CharSequence subSequence(int start, int end) {
return CharBuffer.wrap(toString()).subSequence(start, end);
return toString().subSequence(start, end);
}

@Override
Expand Down

0 comments on commit 36de803

Please sign in to comment.