maven-plugins/native/plugin.jelly
knielsen 7239034b52 cleanup
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113244 13f79535-47bb-0310-9956-ffa450edef68
2003-04-01 12:28:12 +00:00

113 lines
5.1 KiB
XML

<?xml version="1.0"?>
<project xmlns:j="jelly:core" xmlns:util="jelly:util" xmlns:ant="jelly:ant">
<!--==================================================================-->
<!-- Compile all source code -->
<!--==================================================================-->
<goal name="native" description="Native compiler" prereqs="native:compile"/>
<!--==================================================================-->
<!-- Compile all source code -->
<!--==================================================================-->
<goal name="native:compile" description="Compile the native compiler" prereqs="native:jniheader">
<taskdef name="cc" classname="net.sf.antcontrib.cpptasks.CCTask"/>
<typedef name="linker" classname="net.sf.antcontrib.cpptasks.LinkerDef"/>
<typedef name="compiler" classname="net.sf.antcontrib.cpptasks.CompilerDef"/>
<ant:echo> Real Java Home = '${java.home}/..'
artifactId = '${pom.artifactId}' </ant:echo>
<mkdir dir="${maven.build.dir}/native"/>
<ant:available property="jniFilesPresent" file="${maven.build.dir}/native/jni"/>
<!-- for some reason '.' aren't allow as parameter for outfile-->
<cc outfile="${maven.build.dir}/native/_" link="shared" debug="true">
<compiler name="gcc"/>
<fileset dir="src/unix"/>
<j:if test="${jniFilesPresent == 'true'}">
<includepath location="${java.home}/../include"/>
<includepath location="${java.home}/../include/linux"/>
<includepath location="${maven.build.dir}/native/jni"/>
</j:if>
</cc>
<!-- just copy the file don't move because we don't want the compiler to compile if for no reason -->
<ant:available property="outputPresent" file="${maven.build.dir}/native/lib_.so"/>
<j:if test="${outputPresent == 'true'}">
<ant:copy file="${maven.build.dir}/native/lib_.so"
tofile="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.so" overwrite="true"/>
</j:if>
</goal>
<!-- ================================================================== -->
<!-- I N S T A L L L I B -->
<!-- ================================================================== -->
<goal name="native:install" prereqs="native:compile" description="Install the lib in the local repository">
<ant:echo>
id = '${pom.artifactId}'
groupId = '${pom.groupId}'
artifactDirectory = '${pom.artifactDirectory}'
</ant:echo>
<ant:property name="libdir__" value="${maven.repo.local}/${pom.artifactDirectory}/so"/>
<ant:mkdir dir="${libdir__}"/>
<ant:copy file="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.so" tofile="${libdir__}/lib${pom.artifactId}-${pom.currentVersion}.so" overwrite="true"/>
</goal>
<!-- ================================================================== -->
<!-- R U N J A V A H -->
<!-- ================================================================== -->
<goal name="native:jniheader" description="make jniheaders for classes" prereqs="java:compile">
<fileScanner var="classFiles">
<fileset dir="${maven.build.dest}">
<patternset>
<include name="**/*.class"/>
</patternset>
</fileset>
</fileScanner>
<!--do we need to run javah -->
<j:set var="compileJNI" value="false"/>
<j:useBean var="javaSourceTool" class="org.apache.maven.natives.util.JavaSourceTool"/>
<j:forEach var="file" items="${classFiles.iterator()}">
<j:set var="clazz" value="${javaSourceTool.getBcelClass(file.toString())}"/>
<j:forEach var="method" items="${clazz.getMethods()}">
<j:if test="${method.isNative() == 'true'}">
<j:set var="compileJNI" value="true"/>
</j:if>
</j:forEach>
</j:forEach>
<j:if test="${compileJNI == 'true'}">
<ant:echo>Running Javah on java classes</ant:echo>
<mkdir dir="${maven.build.dir}/native/jni"/>
<javah destdir="${maven.build.dir}/native/jni">
<classpath>
<pathelement location="${maven.build.dest}"/>
</classpath>
<j:forEach var="file" items="${classFiles.iterator()}">
<j:set var="isNative" value="false"/>
<j:set var="clazz" value="${javaSourceTool.getBcelClass(file.toString())}"/>
<j:forEach var="method" items="${clazz.getMethods()}">
<j:if test="${method.isNative() == 'true'}">
<j:set var="isNative" value="true"/>
</j:if>
</j:forEach>
<j:if test="${isNative == 'true'}">
<class name="${clazz.className}"/>
</j:if>
</j:forEach>
</javah>
</j:if>
</goal>
</project>