Skip to content

Commit

Permalink
Fixed part of NAR-87
Browse files Browse the repository at this point in the history
  • Loading branch information
duns committed Dec 16, 2009
0 parents commit 1853f3b
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target

13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.archetypes</groupId>
<artifactId>maven-archetype-nar-jni</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Archetype - maven-archetype-nar-jni</name>
<url>http://maven.apache.org</url>

<build>
<defaultGoal>install</defaultGoal>
</build>
</project>
12 changes: 12 additions & 0 deletions src/main/resources/META-INF/maven/archetype.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<archetype>
<id>maven-archetype-nar-jni</id>
<resources>
<resource>src/main/c/NativeApp.c</resource>
</resources>
<sources>
<source>src/main/java/NativeApp.java</source>
</sources>
<testSources>
<source>src/test/java/NativeAppTest.java</source>
</testSources>
</archetype>
41 changes: 41 additions & 0 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>nar</packaging>
<version>${version}</version>

<name>Maven NAR JNI Project</name>

<properties>
<skipTests>true</skipTests>
</properties>

<build>
<defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-nar-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>${groupId}</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</project>
20 changes: 20 additions & 0 deletions src/main/resources/archetype-resources/src/main/c/NativeApp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#set($foo = "hello?")
#set($fr = "._")
#set($a = $fr.charAt(0))
#set($b = $fr.charAt(1))

\#include <stdio.h>
\#include "${groupId.replace($a, $b)}_NativeApp.h"

JNIEXPORT jstring JNICALL Java_${groupId.replace($a, $b)}_NativeApp_sayHello( JNIEnv *env, jobject obj ) {
jstring value; /* the return value */

char buf[40]; /* working buffer (really only need 20 ) */

sprintf ( buf, "%s", "Hello NAR World!" );

value = (*env)->NewStringUTF( env, buf );

return value;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ${groupId};

public class NativeApp
{
static
{
NarSystem.loadLibrary();
}

public final native String sayHello();

public static void main( String[] args )
{
NativeApp app = new NativeApp();
System.out.println( app.sayHello() );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ${groupId};

import ${groupId}.NativeApp;

import junit.framework.Assert;
import junit.framework.TestCase;

public class NativeAppTest extends TestCase
{
public final void testNativeApp()
throws Exception
{
NativeApp app = new NativeApp();
Assert.assertEquals( "Hello NAR World!", app.sayHello() );
}
}

0 comments on commit 1853f3b

Please sign in to comment.