From b462f0a345461aa653aee1d71ade66f925543807 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Tue, 26 Oct 2010 12:53:27 +0200 Subject: Added test for NAR-158 but decided it would not work. Left the test. Native tests will include javah generated directory --- src/it/it0003-jni/src/main/c/HelloWorldJNI.c | 5 +++++ src/it/it0003-jni/src/main/java/it0003/HelloWorldJNI.java | 3 +++ src/it/it0003-jni/src/test/java/it0003/test/HelloWorldJNITest.java | 7 +++++++ src/main/java/org/apache/maven/plugin/nar/NarTestCompileMojo.java | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/src/it/it0003-jni/src/main/c/HelloWorldJNI.c b/src/it/it0003-jni/src/main/c/HelloWorldJNI.c index f663a54..6126a9c 100644 --- a/src/it/it0003-jni/src/main/c/HelloWorldJNI.c +++ b/src/it/it0003-jni/src/main/c/HelloWorldJNI.c @@ -33,3 +33,8 @@ JNIEXPORT jstring JNICALL Java_it0003_HelloWorldJNI_sayHello( JNIEnv *env, jobje return value; } +JNIEXPORT jint JNICALL Java_it0003_HelloWorldJNI_timesHello + (JNIEnv *env, jobject obj, jint x, jint y) { + return x * y; +} + diff --git a/src/it/it0003-jni/src/main/java/it0003/HelloWorldJNI.java b/src/it/it0003-jni/src/main/java/it0003/HelloWorldJNI.java index 8a5284f..94a027b 100644 --- a/src/it/it0003-jni/src/main/java/it0003/HelloWorldJNI.java +++ b/src/it/it0003-jni/src/main/java/it0003/HelloWorldJNI.java @@ -27,10 +27,13 @@ public class HelloWorldJNI } public final native String sayHello(); + public final native int timesHello(int x, int y); public static void main( String[] args ) { HelloWorldJNI app = new HelloWorldJNI(); System.out.println( app.sayHello() ); + + System.out.println( app.timesHello(5, 7) ); } } diff --git a/src/it/it0003-jni/src/test/java/it0003/test/HelloWorldJNITest.java b/src/it/it0003-jni/src/test/java/it0003/test/HelloWorldJNITest.java index 15b85b5..b3cbc50 100644 --- a/src/it/it0003-jni/src/test/java/it0003/test/HelloWorldJNITest.java +++ b/src/it/it0003-jni/src/test/java/it0003/test/HelloWorldJNITest.java @@ -31,4 +31,11 @@ public class HelloWorldJNITest HelloWorldJNI app = new HelloWorldJNI(); Assert.assertEquals( "Hello NAR World!", app.sayHello() ); } + + @Test public final void testNativeTimesWorldJNI() + throws Exception + { + HelloWorldJNI app = new HelloWorldJNI(); + Assert.assertEquals( 35, app.timesHello(5, 7)); + } } diff --git a/src/main/java/org/apache/maven/plugin/nar/NarTestCompileMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarTestCompileMojo.java index 034e3ed..078f78e 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarTestCompileMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarTestCompileMojo.java @@ -159,6 +159,12 @@ public class NarTestCompileMojo task.createIncludePath().setPath( include.getPath() ); } } + + // add javah generated include path + File jniIncludeDir = getJavah().getJniDirectory(); + if (jniIncludeDir.exists()) { + task.createIncludePath().setPath(jniIncludeDir.getPath()); + } // add linker LinkerDef linkerDefinition = @@ -170,6 +176,7 @@ public class NarTestCompileMojo File includeDir = getLayout().getIncludeDirectory( getTargetDirectory(), getMavenProject().getArtifactId(), getMavenProject().getVersion() ); + File libDir = getLayout().getLibDirectory( getTargetDirectory(), getMavenProject().getArtifactId(), getMavenProject().getVersion(), getAOL().toString(), test.getLink() ); -- cgit v1.2.3