maven-plugins/native/plugin.jelly
brett 1fedf1acfc MPNATIVE-7
Submitted By: Joachim Bader
Add support for native dependencies and Add support for optional include path (includepath/sysincludepath)


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@116138 13f79535-47bb-0310-9956-ffa450edef68
2004-10-15 10:10:17 +00:00

233 lines
11 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<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">
<path id="native.classpath">
<pathelement location="${plugin.getDependencyPath('ant-contrib:cpptasks')}" />
<pathelement location="${plugin.getDependencyPath('bcel:bcel')}" />
</path>
<taskdef name="cc" classname="net.sf.antcontrib.cpptasks.CCTask" classpathref="native.classpath"/>
<typedef name="linker" classname="net.sf.antcontrib.cpptasks.LinkerDef" classpathref="native.classpath"/>
<typedef name="compiler" classname="net.sf.antcontrib.cpptasks.CompilerDef" classpathref="native.classpath"/>
<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="${maven.native.link}" debug="${maven.native.debug}">
<compiler name="${maven.native.compiler.name}">
<compilerparam name="target" value="${maven.native.compiler.target}"/>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.compiler.arg.start}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<compilerarg location="start" value="${arg}"/>
</j:forEach>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.compiler.arg.mid}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<compilerarg location="mid" value="${arg}"/>
</j:forEach>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.compiler.arg.end}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<compilerarg location="end" value="${arg}"/>
</j:forEach>
</compiler>
<linker name="${maven.native.linker.name}">
<linkerparam name="target" value="${maven.native.linker.target}"/>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.linker.arg.start}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<linkerarg location="start" value="${arg}"/>
</j:forEach>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.linker.arg.mid}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<linkerarg location="mid" value="${arg}"/>
</j:forEach>
<util:tokenize var="argumentList" delim=" " trim="true">${maven.native.linker.arg.end}</util:tokenize>
<j:forEach var="arg" items="${argumentList}">
<linkerarg location="end" value="${arg}"/>
</j:forEach>
</linker>
<fileset dir="${maven.native.src}" includes="${maven.native.src.includes}" excludes="${maven.native.src.excludes}"/>
<j:if test="${jniFilesPresent == 'true'}">
<includepath location="${java.home}/../include"/>
<includepath location="${java.home}/../include/${maven.native.include.os}"/>
<includepath location="${maven.build.dir}/native/jni"/>
</j:if>
<util:tokenize var="includePathList" delim=" " trim="true">${maven.native.compile.includepath}</util:tokenize>
<j:forEach var="includePath" items="${includePathList}">
<includepath location="${includePath}"/>
</j:forEach>
<util:tokenize var="sysincludePathList" delim=" " trim="true">${maven.native.compile.sysincludepath}</util:tokenize>
<j:forEach var="sysincludePath" items="${sysincludePathList}">
<sysincludepath location="${sysincludePath}"/>
</j:forEach>
<!-- add depended libraries -->
<j:forEach var="lib" items="${pom.artifacts}">
<j:set var="dep" value="${lib.dependency}"/>
<!-- include sos-->
<j:if test="${dep.type=='so'}">
<j:set var="delim" value="lib"/>
<!-- replace ${delim} in the name -->
<util:tokenize var="libnameTokenizer" delim="${delim}" trim="true">${dep.artifactId}</util:tokenize>
<j:forEach var="libnamePart" items="${libnameTokenizer}" varStatus="index">
<j:if test="${index == 0}">
<j:set var="libname" value="${libnamePart}"/>
</j:if>
<j:if test="${index > 0}">
<j:set var="libname" value="${libname}${delim}${libnamePart}"/>
</j:if>
</j:forEach>
<!-- use syslibst or libset -->
<j:if test="${dep.getProperty('native.syslib') != 'true'}">
<libset dir="${lib.file.parent}" libs="${libname}-${dep.version}"/>
</j:if>
<j:if test="${dep.getProperty('native.syslib') == 'true'}">
<syslibset dir="${lib.file.parent}" libs="${libname}-${dep.version}"/>
</j:if>
</j:if>
</j:forEach>
</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}/sos"/>
<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"/>
<!-- need ANT 1.6
<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> -->
<!-- workaround -->
<property environment="env"/>
<exec executable="${env.JAVA_HOME}/bin/javah">
<arg line="-d ${maven.build.dir}/native/jni"/>
<arg line="-classpath ${maven.build.dest}"/>
<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'}">
<arg value="${clazz.className}"/>
</j:if>
</j:forEach>
</exec>
</j:if>
</goal>
</project>