diff options
Diffstat (limited to 'auto/modules/java')
-rw-r--r-- | auto/modules/java | 458 |
1 files changed, 458 insertions, 0 deletions
diff --git a/auto/modules/java b/auto/modules/java new file mode 100644 index 00000000..27030da1 --- /dev/null +++ b/auto/modules/java @@ -0,0 +1,458 @@ + +# Copyright (C) NGINX, Inc. + + +shift + +NXT_JAVA_HOME=${JAVA_HOME-} +NXT_JAR_REPO=http://central.maven.org/maven2/ +NXT_JAR_LOCAL_REPO=$HOME/.m2/repository/ + +for nxt_option; do + + case "$nxt_option" in + -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) value="" ;; + esac + + case "$nxt_option" in + + --module=*) NXT_JAVA_MODULE="$value" ;; + --home=*) NXT_JAVA_HOME="$value" ;; + --lib-path=*) NXT_JAVA_LIB_PATH="$value" ;; + --repo=*) NXT_JAR_REPO="$value" ;; + --local-repo=*) NXT_JAR_LOCAL_REPO="$value" ;; + --jars=*) NXT_JARS="$value" ;; + + --help) + cat << END + + --module=NAME set unit Java module name + --home=DIR set Java home directory + --lib-path=DIRECTORY set directory path to libjvm.so library + --repo=URL set Maven remote repository URL + default: "$NXT_JAR_REPO" + --local-repo=DIR set local repository directory + default: "$NXT_JAR_LOCAL_REPO" + --jars=DIR set jars install/search directory + +END + exit 0 + ;; + + *) + echo + echo $0: error: invalid Java option \"$nxt_option\" + echo + exit 1 + ;; + esac + +done + + +if [ ! -f $NXT_AUTOCONF_DATA ]; then + echo + echo Please run common $0 before configuring module \"$nxt_module\". + echo + exit 1 +fi + +. $NXT_AUTOCONF_DATA + + +NXT_JARS=${NXT_JARS=$NXT_MODULES} +NXT_JAVA_MODULE=${NXT_JAVA_MODULE=java} +NXT_JAVA_LIB_PATH=${NXT_JAVA_LIB_PATH=} + +$echo "configuring Java module" +$echo "configuring Java module ..." >> $NXT_AUTOCONF_ERR + +if [ -n "${NXT_JAVA_HOME}" ]; then + $echo "using java.home ${NXT_JAVA_HOME}" + $echo "using java.home ${NXT_JAVA_HOME}" >> $NXT_AUTOCONF_ERR + + if [ ! -d "${NXT_JAVA_HOME}" ]; then + $echo + $echo $0: error: Java home directory not found. + $echo + exit 1 + fi + + NXT_JAVA="${NXT_JAVA_HOME}/bin/java" + +else + $echo -n "checking for java executable" + $echo "checking for java executable ..." >> $NXT_AUTOCONF_ERR + + NXT_JAVA=`which java || :` + if [ -z "$NXT_JAVA" -o ! -x "$NXT_JAVA" ]; then + $echo + $echo $0: error: java executable not found. + $echo + exit 1 + fi + + $echo " found $NXT_JAVA" + $echo "found $NXT_JAVA" >> $NXT_AUTOCONF_ERR + + "$NXT_JAVA" -version + + $echo -n "checking java.home" + $echo "checking java.home ..." >> $NXT_AUTOCONF_ERR + + NXT_JAVA_HOME=`$NXT_JAVA -XshowSettings 2>&1 | grep -F -e java.home | sed -e 's/^.*= //'` + if [ -z "$NXT_JAVA_HOME" ]; then + $echo + $echo $0: error: java.home not found. + $echo + exit 1 + fi + + $echo " $NXT_JAVA_HOME" + $echo "got java.home $NXT_JAVA_HOME" >> $NXT_AUTOCONF_ERR + + if [ ! -x "${NXT_JAVA_HOME}/bin/javac" ]; then + NXT_JAVA_HOME_=${NXT_JAVA_HOME%/jre} + if [ -x "${NXT_JAVA_HOME_}/bin/javac" ]; then + $echo "adjust java.home $NXT_JAVA_HOME_" + $echo "adjust java.home $NXT_JAVA_HOME_" >> $NXT_AUTOCONF_ERR + + NXT_JAVA_HOME="$NXT_JAVA_HOME_" + fi + fi +fi + +NXT_JAVAC="${NXT_JAVA_HOME}/bin/javac" + +if [ ! -x "$NXT_JAVAC" ]; then + $echo + $echo $0: error: javac not found. + $echo + exit 1 +fi + +NXT_JAVA_INCLUDE="-I${NXT_JAVA_HOME}/include" + +case "$NXT_SYSTEM" in + Linux) + NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/linux" + ;; + Darwin) + NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/darwin" + ;; + FreeBSD) + NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/freebsd" + ;; +esac + +if [ -z "$NXT_JAVA_LIB_PATH" ]; then + $echo -n "checking library path" + $echo "checking library path ..." >> $NXT_AUTOCONF_ERR + + if [ ! -x "$NXT_JAVA" ]; then + $echo + $echo $0: error: java executable not found. + $echo + exit 1 + fi + + NXT_JAVA_LIB_PATH=`$NXT_JAVA -XshowSettings 2>&1 | grep -F -e sun.boot.library.path | sed -e 's/^.*= //'` + + if [ -z "$NXT_JAVA_LIB_PATH" ]; then + $echo + $echo $0: error: library path not found. + $echo + exit 1 + fi + + NXT_JAVA_LIB_PATH="${NXT_JAVA_LIB_PATH}/server" + + $echo " $NXT_JAVA_LIB_PATH" + $echo "got library path $NXT_JAVA_LIB_PATH" >> $NXT_AUTOCONF_ERR +fi + +NXT_JAVA_LDFLAGS="-L${NXT_JAVA_LIB_PATH} -Wl,-rpath ${NXT_JAVA_LIB_PATH} -ljvm" + + +nxt_found=no + +nxt_feature="JNI" +nxt_feature_name="" +nxt_feature_run=no +nxt_feature_incs="${NXT_JAVA_INCLUDE}" +nxt_feature_libs="${NXT_JAVA_LDFLAGS}" +nxt_feature_test=" + #include <jni.h> + + int main() { + JNI_CreateJavaVM(NULL, NULL, NULL); + return 0; + }" + +. auto/feature + + +if [ $nxt_found = no ]; then + $echo + $echo $0: error: no JNI found. + $echo + exit 1; +fi + +NXT_JAVA_VERSION=`$NXT_JAVAC -version 2>&1` +NXT_JAVA_VERSION=${NXT_JAVA_VERSION#javac } +NXT_JAVA_INCLUDE="$NXT_JAVA_INCLUDE -I$NXT_BUILD_DIR/$NXT_JAVA_MODULE -DNXT_JAVA_VERSION=$NXT_JAVA_VERSION" + +if grep ^$NXT_JAVA_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then + $echo + $echo $0: error: duplicate \"$NXT_JAVA_MODULE\" module configured. + $echo + exit 1; +fi + +. ./version + +NXT_UNIT_JAR=nginx-unit-jsc-${NXT_JAVA_MODULE}-$NXT_VERSION.jar + +NXT_JAVA_BUILD_CP=$NXT_BUILD_DIR/$NXT_JAVA_MODULE +NXT_JAVA_INSTALL_JARS= +NXT_JAVA_UNINSTALL_JARS= + +NXT_JAVA_JARS=$NXT_BUILD_DIR/$NXT_JAVA_MODULE/nxt_jars.h +mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE + +cat << END > $NXT_JAVA_JARS +#ifndef _NXT_JAVA_JARS_INCLUDED_ +#define _NXT_JAVA_JARS_INCLUDED_ + +#define NXT_JARS "$NXT_JARS" + +static const char *nxt_java_system_jars[] = { +END + +NXT_TOMCAT_VERSION=9.0.13 + +NXT_JAR_VERSION=$NXT_TOMCAT_VERSION + +NXT_JAR_NAME=tomcat-servlet-api +NXT_JAR_NAMESPACE=org/apache/tomcat/ +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-el-api +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-jsp-api +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-jasper +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-jasper-el +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-juli +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-api +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-util-scan +. auto/modules/java_get_jar + +NXT_JAR_NAME=tomcat-util +. auto/modules/java_get_jar + +NXT_JAR_NAME=ecj +NXT_JAR_VERSION=3.13.102 +NXT_JAR_NAMESPACE=org/eclipse/jdt/ +. auto/modules/java_get_jar + +cat << END >> $NXT_JAVA_JARS + NULL +}; + +static const char *nxt_java_unit_jars[] = { + "$NXT_UNIT_JAR", +END + +NXT_JAR_VERSION=9.4.12.v20180830 +NXT_JAR_NAMESPACE=org/eclipse/jetty/ + +NXT_JAR_NAME=jetty-util +. auto/modules/java_get_jar + +NXT_JAR_NAME=jetty-server +. auto/modules/java_get_jar + +NXT_JAR_NAME=jetty-http +. auto/modules/java_get_jar + +NXT_JAR_NAME=classgraph +NXT_JAR_VERSION=4.4.11 +NXT_JAR_NAMESPACE=io/github/classgraph/ +. auto/modules/java_get_jar + +cat << END >> $NXT_JAVA_JARS + NULL +}; + +#endif /* _NXT_JAVA_JARS_INCLUDED_ */ +END + +$echo " + Java module: ${NXT_JAVA_MODULE}.unit.so" + +. auto/cc/deps + +$echo >> $NXT_MAKEFILE + +NXT_JAVA_MODULE_SRCS=" \ + src/nxt_java.c \ + src/java/nxt_jni.c \ + src/java/nxt_jni_Context.c \ + src/java/nxt_jni_HeaderNamesEnumeration.c \ + src/java/nxt_jni_HeadersEnumeration.c \ + src/java/nxt_jni_InputStream.c \ + src/java/nxt_jni_OutputStream.c \ + src/java/nxt_jni_Request.c \ + src/java/nxt_jni_Response.c \ + src/java/nxt_jni_Thread.c \ + src/java/nxt_jni_URLClassLoader.c \ +" + +# The Java module object files. + +nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o + +for nxt_src in $NXT_JAVA_MODULE_SRCS; do + + nxt_obj=${nxt_src%.c}-$NXT_JAVA_MODULE.o + nxt_dep=${nxt_src%.c}-$NXT_JAVA_MODULE.dep + nxt_dep_flags=`nxt_gen_dep_flags` + nxt_dep_post=`nxt_gen_dep_post` + nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj" + + cat << END >> $NXT_MAKEFILE + +$NXT_BUILD_DIR/$nxt_obj: $nxt_src + mkdir -p $NXT_BUILD_DIR/src/java + \$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_JAVA_INCLUDE \\ + $nxt_dep_flags \\ + -o $NXT_BUILD_DIR/$nxt_obj $nxt_src + $nxt_dep_post + +-include $NXT_BUILD_DIR/$nxt_dep + +END + +done + +NXT_JAVA_SRCS=" \ + src/java/nginx/unit/Context.java \ + src/java/nginx/unit/DynamicDispatcherRequest.java \ + src/java/nginx/unit/DynamicPathRequest.java \ + src/java/nginx/unit/ForwardRequestWrapper.java \ + src/java/nginx/unit/HeaderNamesEnumeration.java \ + src/java/nginx/unit/HeadersEnumeration.java \ + src/java/nginx/unit/IncludeRequestWrapper.java \ + src/java/nginx/unit/IncludeResponseWrapper.java \ + src/java/nginx/unit/InitParams.java \ + src/java/nginx/unit/InputStream.java \ + src/java/nginx/unit/JspPropertyGroup.java \ + src/java/nginx/unit/OutputStream.java \ + src/java/nginx/unit/Request.java \ + src/java/nginx/unit/RequestAttrProxy.java \ + src/java/nginx/unit/Response.java \ + src/java/nginx/unit/Session.java \ + src/java/nginx/unit/SessionAttrProxy.java \ + src/java/nginx/unit/Taglib.java \ + src/java/nginx/unit/UnitSessionCookieConfig.java \ +" + +cat << END >> $NXT_MAKEFILE + +.PHONY: ${NXT_JAVA_MODULE} +.PHONY: ${NXT_JAVA_MODULE}-install +.PHONY: ${NXT_JAVA_MODULE}-uninstall + +all: ${NXT_JAVA_MODULE} + +${NXT_JAVA_MODULE}: $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \ + $NXT_BUILD_DIR/$NXT_UNIT_JAR + +$NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so: $nxt_objs + \$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\ + $nxt_objs $NXT_JAVA_LDFLAGS $NXT_LD_OPT + + +install: ${NXT_JAVA_MODULE}-install + +${NXT_JAVA_MODULE}-install: $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\ + $NXT_BUILD_DIR/$NXT_UNIT_JAR java-shared-install + install -d \$(DESTDIR)$NXT_MODULES + install -p $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\ + \$(DESTDIR)$NXT_MODULES/ + install -d \$(DESTDIR)$NXT_JARS + install -p -m 0644 $NXT_BUILD_DIR/$NXT_UNIT_JAR \$(DESTDIR)$NXT_JARS/ + + +uninstall: ${NXT_JAVA_MODULE}-uninstall + +${NXT_JAVA_MODULE}-uninstall: java-shared-uninstall + rm -f \$(DESTDIR)$NXT_MODULES/${NXT_JAVA_MODULE}.unit.so + @rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true + rm -f \$(DESTDIR)$NXT_JARS/$NXT_UNIT_JAR + @rmdir -p \$(DESTDIR)$NXT_JARS 2>/dev/null || true + +END + +if ! grep ^$NXT_BUILD_DIR/$NXT_UNIT_JAR: $NXT_MAKEFILE 2>&1 > /dev/null; then + + cat << END >> $NXT_MAKEFILE + +.INTERMEDIATE: $NXT_BUILD_DIR/$NXT_JAVA_MODULE/.classes + +NXT_JAVA_SRCS = $NXT_JAVA_SRCS + +$NXT_BUILD_DIR/$NXT_JAVA_MODULE/.classes: \$(NXT_JAVA_SRCS) + rm -rf $NXT_BUILD_DIR/$NXT_JAVA_MODULE/nginx + $NXT_JAVAC -d $NXT_BUILD_DIR/$NXT_JAVA_MODULE -cp $NXT_JAVA_BUILD_CP \\ + \$(NXT_JAVA_SRCS) + +$NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/LICENSE: LICENSE + mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF + cp -p LICENSE \$@ + +$NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/NOTICE: NOTICE + mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF + cp -p NOTICE \$@ + + +$NXT_BUILD_DIR/$NXT_UNIT_JAR: $NXT_BUILD_DIR/$NXT_JAVA_MODULE/.classes \\ + $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/LICENSE \\ + $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/NOTICE + $NXT_JAVA_HOME/bin/jar c -C $NXT_BUILD_DIR/$NXT_JAVA_MODULE META-INF \\ + -C $NXT_BUILD_DIR/$NXT_JAVA_MODULE nginx/unit > \$@ + +END + +fi + +if ! grep ^java-shared-install: $NXT_MAKEFILE 2>&1 > /dev/null; then + + cat << END >> $NXT_MAKEFILE + +.PHONY: java-shared-install +.PHONY: java-shared-uninstall + +java-shared-install: $NXT_JAVA_INSTALL_JARS + install -d \$(DESTDIR)$NXT_JARS + install -p -m 0644 $NXT_JAVA_INSTALL_JARS \$(DESTDIR)$NXT_JARS/ + +java-shared-uninstall: + rm -f $NXT_JAVA_UNINSTALL_JARS + @rmdir -p \$(DESTDIR)$NXT_JARS 2>/dev/null || true + +END + +fi |