. Allow the setting up of command line options to be passed to the
invoked Java VM. Reviewed by: hq
This commit is contained in:
parent
ec1e5b414b
commit
3694308948
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=164308
8 changed files with 236 additions and 13 deletions
|
@ -8,8 +8,7 @@
|
|||
#
|
||||
|
||||
PORTNAME= javavmwrapper
|
||||
PORTVERSION= 2.0
|
||||
PORTREVISION= 7
|
||||
PORTVERSION= 2.1
|
||||
CATEGORIES= java
|
||||
MASTER_SITES= # none
|
||||
DISTFILES= # none
|
||||
|
@ -25,7 +24,7 @@ NO_WRKSUBDIR= yes
|
|||
PKGINSTALL= ${WRKDIR}/pkg-install
|
||||
|
||||
MAN1= checkvms.1 javavm.1 registervm.1 unregistervm.1
|
||||
MAN5= javavms.5
|
||||
MAN5= javavm_opts.conf.5 javavms.5
|
||||
|
||||
SRC= ${.CURDIR}/src
|
||||
SCRIPTS= classpath javavmwrapper
|
||||
|
@ -62,7 +61,11 @@ do-install:
|
|||
.endfor
|
||||
${INSTALL_MAN} ${WRKDIR}/registervm.1 \
|
||||
${MAN1PREFIX}/man/man1/unregistervm.1
|
||||
${INSTALL_MAN} ${WRKDIR}/${MAN5} ${MAN5PREFIX}/man/man5
|
||||
.for _man in ${MAN5}
|
||||
${INSTALL_MAN} ${WRKDIR}/${_man} ${MAN5PREFIX}/man/man5
|
||||
.endfor
|
||||
${INSTALL_DATA} ${FILESDIR}/javavm_opts.conf.dist \
|
||||
${PREFIX}/etc/javavm_opts.conf.dist
|
||||
|
||||
post-install:
|
||||
${SETENV} PKG_PREFIX=${PREFIX} ${SH} ${PKGINSTALL} ${PKGNAME} \
|
||||
|
|
52
java/javavmwrapper/files/javavm_opts.conf.dist
Normal file
52
java/javavmwrapper/files/javavm_opts.conf.dist
Normal file
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# javavm_opts.conf.dist
|
||||
#
|
||||
# This file is sourced by javavm to determine the options to pass to the
|
||||
# Java command that its invoking.
|
||||
#
|
||||
# There are four different types of environment variables that are used
|
||||
# to determine the options for a particular command.
|
||||
#
|
||||
# 1. JAVAVM_OPTS
|
||||
#
|
||||
# The contents of this variable are passed as options to all java
|
||||
# commands invoked by javavm.
|
||||
#
|
||||
# 2. JAVAVM_OPTS_JAVA_HOME_DIR
|
||||
#
|
||||
# The contents of this variable are passed as options to all java
|
||||
# commands invoked by javavm within the JAVA_HOME_DIR directory specified.
|
||||
# The JAVA_HOME_DIR specified here is the directory portion of $JAVA_HOME
|
||||
# with special characters replaced by an underscore. For example, the
|
||||
# standard installation of the jdk15 port puts it in /usr/local/jdk1.5.0,
|
||||
# so to affect all of its programmes you would set JAVAVM_OPTS_jdk1_5_0.
|
||||
#
|
||||
# 3. JAVAVM_OPTS_JAVAVM_PROG
|
||||
#
|
||||
# The contents of this variable are passed as options to all invocations
|
||||
# of the specified java programme. For example, if you always wish to
|
||||
# have -deprecation passed to javac, then you would set JAVAVM_OPTS_javac.
|
||||
#
|
||||
# 4. JAVAVM_OPTS_JAVA_HOME_JAVAVM_PROG
|
||||
#
|
||||
# The contents of this variable are passed as options to the invocation
|
||||
# of the specified java programme within the specified JAVA_HOME
|
||||
# directory. This allows the options to only affect a single programme.
|
||||
# For example, to pass -Xlint to the javac in /usr/local/jdk1.5.0/bin
|
||||
# you would set JAVAVM_OPTS_jdk1_5_0_javac.
|
||||
#
|
||||
# These variables "stack", in that if multiple variables are
|
||||
# defined which apply to a particular command then all the variables
|
||||
# contents will be passed to the command as options. For example,
|
||||
# if you set JAVAVM_OPTS_jdk1_5_0 and JAVAVM_OPTS_javac, then the
|
||||
# contents of both variables will be passed to an invocation of
|
||||
# /usr/local/jdk1.5.0/bin/javac.
|
||||
#
|
||||
# Note that the order in which variables stack is an implementation
|
||||
# detail and should not be relied upon.
|
||||
#
|
||||
|
||||
# This is required on SMP machines for Diablo JDK 1.5.0_06 build 0
|
||||
JAVAVM_OPTS_diablo_jdk1_5_0=-XX:+UseMembar
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# $FreeBSD: /tmp/pcvs/ports/java/javavmwrapper/files/pkg-install.in,v 1.2 2005-04-11 21:21:16 glewis Exp $
|
||||
# $FreeBSD: /tmp/pcvs/ports/java/javavmwrapper/files/pkg-install.in,v 1.3 2006-06-03 17:32:24 glewis Exp $
|
||||
|
||||
LOCALBASE=%%LOCALBASE%%
|
||||
|
||||
|
@ -9,6 +9,17 @@ if [ "x${2}" != "xPOST-INSTALL" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# The option configuration file
|
||||
OPTION_CONF="${PKG_PREFIX}/etc/javavm_opts.conf"
|
||||
|
||||
# Install default javavm options configuration
|
||||
if [ ! -e "${OPTION_CONF}" ]; then
|
||||
cp "${OPTION_CONF}.dist" "${OPTION_CONF}"
|
||||
else
|
||||
echo "${OPTION_CONF} already exists - not installing."
|
||||
echo "You may need to hand merge changes."
|
||||
fi
|
||||
|
||||
# Ensure all JDKs and JREs are installed
|
||||
for jvm in "${LOCALBASE}"/*jdk* "${LOCALBASE}"/*jre*; do
|
||||
if [ -x "${jvm}/bin/java" ]; then
|
||||
|
|
|
@ -9,6 +9,18 @@ if [ "x${2}" != "xDEINSTALL" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# The option configuration file
|
||||
OPTION_CONF="${PKG_PREFIX}/etc/javavm_opts.conf"
|
||||
|
||||
# Remove the option configuration file if its identical to the
|
||||
# distributed version.
|
||||
if [ -f "${OPTION_CONF}" -a -f "${OPTION_CONF}.dist" ]; then
|
||||
if [ `sed -e '/^#/d' -e '/^\s*$/d' "${OPTION_CONF}" | sort | md5` = \
|
||||
`sed -e '/^#/d' -e '/^\s*$/d' "${OPTION_CONF}.dist" | sort | md5` ]; then
|
||||
rm -f "${OPTION_CONF}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# The configuration file
|
||||
CONF="${PKG_PREFIX}/etc/javavms"
|
||||
|
||||
|
|
|
@ -3,3 +3,4 @@ bin/javavm
|
|||
bin/registervm
|
||||
bin/unregistervm
|
||||
bin/checkvms
|
||||
etc/javavm_opts.conf.dist
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.\"
|
||||
.\" Copyright (C) 2005 Greg Lewis. All rights reserved.
|
||||
.\"
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
|
@ -9,7 +9,7 @@
|
|||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
|
@ -124,6 +124,12 @@ Currently allowed versions are
|
|||
.Ql 1.5
|
||||
and
|
||||
.Ql 1.5+ .
|
||||
.It Ev JAVAVM_OPTS
|
||||
The contents of this environment variable will be passed to the invoked
|
||||
Java VM as options.
|
||||
For more information on environment variables which can be used to set
|
||||
options see
|
||||
.Pa %%PREFIX%%/etc/javavm_opts.conf.dist .
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
|
@ -157,6 +163,7 @@ Execute MyApp with either a Java VM that is either version 1.2 or version 1.4.
|
|||
.Xr make 1 ,
|
||||
.Xr registervm 1 ,
|
||||
.Xr unregistervm 1 ,
|
||||
.Xr javavm_opts.conf 5 ,
|
||||
.Xr javavms 5
|
||||
.Sh BUGS
|
||||
The internal selection procedure of
|
||||
|
|
97
java/javavmwrapper/src/javavm_opts.conf.5
Normal file
97
java/javavmwrapper/src/javavm_opts.conf.5
Normal file
|
@ -0,0 +1,97 @@
|
|||
.\"
|
||||
.\" Copyright (C) 2006 Greg Lewis. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd May 28, 2006
|
||||
.Os
|
||||
.Dt JAVAVM_OPTS.CONF 5
|
||||
.Sh NAME
|
||||
.Nm javavm_opts.conf
|
||||
.Nd the Java VM wrapper options configuration file.
|
||||
.Sh DESCRIPTION
|
||||
The file
|
||||
.Nm
|
||||
contains variables which set options that should be passed to the
|
||||
Java VM that is invoked by the Java VM wrapper.
|
||||
.Pp
|
||||
Which Java VM a variable provides options for is determined by the variable
|
||||
name. The Java VM wrapper currently recognises the following patterns for
|
||||
variable names:
|
||||
.Bl -tag -width indent
|
||||
.It Ev JAVAVM_OPTS
|
||||
The options specified by this variable are passed to all Java VM
|
||||
invocations. In practise, this variable should be reserved for use
|
||||
on the command line and not set in
|
||||
.Nm .
|
||||
.It Ev JAVAVM_OPTS_JAVA_HOME_DIR
|
||||
The contents of this variable are passed as options to all java
|
||||
commands invoked by javavm within the
|
||||
.Pa JAVA_HOME_DIR
|
||||
directory specified.
|
||||
The
|
||||
.Pa JAVA_HOME_DIR
|
||||
specified here is the directory portion of
|
||||
.Ev JAVA_HOME
|
||||
with special characters replaced by an underscore.
|
||||
.It Ev JAVAVM_OPTS_JAVA_PROG
|
||||
The contents of this variable are passed as options to all invocations
|
||||
of the specified java programme.
|
||||
.It Ev JAVAVM_OPTS_JAVA_HOME_DIR_JAVA_PROG
|
||||
The contents of this variable are passed as options to the invocation
|
||||
of the specified java programme within the specified JAVA_HOME
|
||||
directory.
|
||||
This allows the options to only affect a single programme.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
.It Pa %%PREFIX%%/etc/javavm_opts.conf
|
||||
The location of the Java VM wrapper options configuration file.
|
||||
.It Pa %%PREFIX%%/etc/javavm_opts.conf.dist
|
||||
The location of the example Java VM wrapper options configuration file
|
||||
distributed with the Java VM wrapper.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Bl -tag -width indent
|
||||
.It Ev JAVAVM_OPTS_diablo_jdk1_5_0=-XX:+UseMembar
|
||||
Run the Java VMs installed by the Diablo JDK in
|
||||
.Pa %%PREFIX%%/diablo-jdk1.5.0
|
||||
with the option
|
||||
.Dq -XX:+UseMembar .
|
||||
.It Ev JAVAVM_OPTS_javac=-deprecation
|
||||
Run the
|
||||
.Pa javac
|
||||
programme with the option
|
||||
.Dq -deprecation .
|
||||
.It Ev JAVAVM_OPTS_diablo_jdk1_5_0_javac=-Xlint
|
||||
Run the javac installed by the Diablo JDK with the option
|
||||
.Dq -Xlint .
|
||||
.El
|
||||
.Pp
|
||||
Due to stacking, if the above three variables were set, then the javac
|
||||
installed by the Diablo JDK would run with the options
|
||||
.Dq -XX:+UseMembar -deprecation -Xlint
|
||||
(although not necessarily in that order).
|
||||
.Sh SEE ALSO
|
||||
.Xr javavm 1
|
|
@ -34,6 +34,7 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
|||
|
||||
_JAVAVM_PREFIX="%%PREFIX%%"
|
||||
_JAVAVM_CONF="${_JAVAVM_PREFIX}/etc/javavms"
|
||||
_JAVAVM_OPTS_CONF="${_JAVAVM_PREFIX}/etc/javavm_opts.conf"
|
||||
_JAVAVM_PROG=`basename "${0}"`
|
||||
_JAVAVM_MAKE=/usr/bin/make
|
||||
|
||||
|
@ -52,6 +53,33 @@ tryJavaCommand () {
|
|||
echo "${_JAVAVM_PROG}: warning: couldn't run specified Java command - \"${1}\"" >&2
|
||||
}
|
||||
|
||||
#
|
||||
# Set java command options, if applicable
|
||||
# 1 - Name of the java programme to be executed.
|
||||
# 2 - Base directory of JAVA_HOME for the java programme to be executed.
|
||||
#
|
||||
setJavaOptions () {
|
||||
local OPTS_PROG=`echo ${1} | sed -e s/\\\\./_/g -e s/-/_/g`
|
||||
local OPTS_JAVA_HOME=`echo ${2} | sed -e s/\\\\./_/g -e s/-/_/g`
|
||||
local JAVA_HOME_PROG_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_JAVA_HOME}_${OPTS_PROG}\} 2>/dev/null`"
|
||||
local JAVA_HOME_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_JAVA_HOME}\} 2>/dev/null`"
|
||||
local PROG_OPTS="`eval echo \$\{JAVAVM_OPTS_${OPTS_PROG}\} 2>/dev/null`"
|
||||
|
||||
# Possible environment variables are stackable
|
||||
if [ ! -z "${JAVA_HOME_PROG_OPTS}" ]; then
|
||||
_JAVAVM_OPTS="${_JAVAVM_OPTS} ${JAVA_HOME_PROG_OPTS}"
|
||||
fi
|
||||
if [ ! -z "${JAVA_HOME_OPTS}" ]; then
|
||||
_JAVAVM_OPTS="${_JAVAVM_OPTS} ${JAVA_HOME_OPTS}"
|
||||
fi
|
||||
if [ ! -z "${PROG_OPTS}" ]; then
|
||||
_JAVAVM_OPTS="${_JAVAVM_OPTS} ${PROG_OPTS}"
|
||||
fi
|
||||
if [ ! -z "${JAVAVM_OPTS}" ]; then
|
||||
_JAVAVM_OPTS="${_JAVAVM_OPTS} ${JAVAVM_OPTS}"
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Create symbolic links for all of a Java VMs executables.
|
||||
#
|
||||
|
@ -412,15 +440,23 @@ if [ "${_JAVAVM_PROG}" = "javavm" ]; then
|
|||
_JAVAVM_PROG=java
|
||||
fi
|
||||
|
||||
# Initialise options
|
||||
if [ -r "${_JAVAVM_OPTS_CONF}" ]; then
|
||||
. "${_JAVAVM_OPTS_CONF}"
|
||||
fi
|
||||
_JAVAVM_OPTS=
|
||||
|
||||
# Ignore JAVA_HOME if it's set to %%PREFIX%%
|
||||
if [ "`realpath "${JAVA_HOME}"`" != "`realpath "${_JAVAVM_PREFIX}"`" ]; then
|
||||
# Otherwise use JAVA_HOME if it's set
|
||||
if [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
elif [ ! -z "${JAVA_HOME}" -a -x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -442,12 +478,14 @@ if [ ! -z "${_JAVAVM_BSD_PORT_MK}" ]; then
|
|||
JAVA_HOME=`"${_JAVAVM_MAKE}" -f "${_JAVAVM_BSD_PORT_MK}" -V JAVA_HOME USE_JAVA=yes 2>/dev/null`
|
||||
if [ ! -z "${JAVA_HOME}" -a \
|
||||
-x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
elif [ ! -z "${JAVA_HOME}" -a \
|
||||
-x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -561,12 +599,14 @@ for _JAVAVM_JAVAVM in ${_JAVAVM_VMS}; do
|
|||
# Check if the command exists and try to run it.
|
||||
if [ ! -z "${JAVA_HOME}" -a \
|
||||
-x "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
elif [ ! -z "${JAVA_HOME}" -a \
|
||||
-x "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ]; then
|
||||
setJavaOptions "${_JAVAVM_PROG}" "`basename ${JAVA_HOME}`"
|
||||
export JAVA_HOME
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" "${@}"
|
||||
tryJavaCommand "${JAVA_HOME}/jre/bin/${_JAVAVM_PROG}" ${_JAVAVM_OPTS} "${@}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in a new issue