maven-plugins/native/plugin.jelly
2005-01-18 09:11:01 +00:00

285 lines
14 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-->
<!-- 17 Dec 2004 - baleineca
Checking for runtime property and adding it. Default to "dynamic" if not present.
Seems like this is the only way at time of writing to get ccTask to pass something else than the default /MD arg to cl.
-->
<j:set var="runtime" value="${maven.native.runtime}"/>
<j:if test="${runtime} == ''">
<j:set var="runtime" value="dynamic"/>
</j:if>
<cc outfile="${maven.build.dir}/native/_" link="${maven.native.link}" debug="${maven.native.debug}" runtime="${runtime}" rtti="${rtti}">
<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' or dep.type=='dll'}">
<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 -->
<!-- so -->
<ant:available property="outputPresentSO" file="${maven.build.dir}/native/lib_.so"/>
<j:if test="${outputPresentSO == 'true'}">
<ant:copy file="${maven.build.dir}/native/lib_.so"
tofile="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.so" overwrite="true"/>
<!-- needed if cygwin gcc is used -->
<j:if test="${context.getVariable('maven.native.include.os')=='win32'}">
<ant:move file="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.so"
tofile="${maven.build.dir}/native/${pom.artifactId}-${pom.currentVersion}.dll"
overwrite="true"/>
</j:if>
</j:if>
<!-- dll -->
<ant:available property="outputPresentDLL" file="${maven.build.dir}/native/_.dll"/>
<j:if test="${outputPresentDLL == 'true'}">
<ant:copy file="${maven.build.dir}/native/_.dll"
tofile="${maven.build.dir}/native/${pom.artifactId}-${pom.currentVersion}.dll" overwrite="true"/>
</j:if>
<!-- dylib -->
<ant:available property="outputPresentDylib" file="${maven.build.dir}/native/lib_.dylib"/>
<j:if test="${outputPresentDylib == 'true'}">
<ant:copy file="${maven.build.dir}/native/lib_.dylib"
tofile="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.jnilib" 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>
<!-- so -->
<ant:available property="libPresentSO" file="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.so"/>
<j:if test="${libPresentSO == 'true'}">
<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"/>
</j:if>
<!-- dll -->
<ant:available property="libPresentDLL" file="${maven.build.dir}/native/${pom.artifactId}-${pom.currentVersion}.dll"/>
<j:if test="${libPresentDLL == 'true'}">
<ant:property name="libdir__" value="${maven.repo.local}/${pom.artifactDirectory}/dlls"/>
<ant:mkdir dir="${libdir__}"/>
<ant:copy file="${maven.build.dir}/native/${pom.artifactId}-${pom.currentVersion}.dll" tofile="${libdir__}/${pom.artifactId}-${pom.currentVersion}.dll" overwrite="true"/>
</j:if>
<!-- jnilib -->
<ant:available property="libPresentJnilib" file="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.jnilib"/>
<j:if test="${libPresentJnilib == 'true'}">
<ant:property name="libdir__" value="${maven.repo.local}/${pom.artifactDirectory}/jnilibs"/>
<ant:mkdir dir="${libdir__}"/>
<ant:copy file="${maven.build.dir}/native/lib${pom.artifactId}-${pom.currentVersion}.jnilib" tofile="${libdir__}/lib${pom.artifactId}-${pom.currentVersion}.jnilib" overwrite="true"/>
</j:if>
</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>