Make run.sh / designer.bat compatible with java/openjfx
* Use JAVAFX_HOME to add extra classpath for openjfx * Add back the jre_specific_vm_options when needed
This commit is contained in:
@ -3,4 +3,49 @@ set TOPDIR=%~dp0..
|
||||
set OPTS=
|
||||
set MAIN_CLASS=net.sourceforge.pmd.util.fxdesigner.DesignerStarter
|
||||
|
||||
java -classpath "%TOPDIR%\lib\*" %OPTS% %MAIN_CLASS% %*
|
||||
|
||||
:: sets the jver variable to the java version, eg 901 for 9.0.1+x or 180 for 1.8.0_171-b11
|
||||
:: sets the jvendor variable to either java (oracle) or openjdk
|
||||
for /f tokens^=1^,3^,4^,5^ delims^=.-_+^"^ %%j in ('java -version 2^>^&1 ^| find "version"') do (
|
||||
set jvendor=%%j
|
||||
if %%l EQU ea (
|
||||
set /A "jver=%%k00"
|
||||
) else (
|
||||
set /A jver=%%k%%l%%m
|
||||
)
|
||||
)
|
||||
|
||||
Set "jreopts="
|
||||
:: oracle java 9 and 10 has javafx included as a module
|
||||
if /I "%jvendor%" EQU "java" (
|
||||
if %jver% GEQ 900 (
|
||||
if %jver% LSS 1100 (
|
||||
:: enable reflection
|
||||
Set jreopts=--add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
set "_needjfxlib=0"
|
||||
if /I "%jvendor%" EQU "openjdk" set _needjfxlib=1
|
||||
if /I "%jvendor%" EQU "java" (
|
||||
if %jver% GEQ 1100 set _needjfxlib=1
|
||||
)
|
||||
if %_needjfxlib% EQU 1 (
|
||||
if %jver% LSS 1000 (
|
||||
echo For openjfx at least java 10 is required.
|
||||
pause
|
||||
exit
|
||||
)
|
||||
if [%JAVAFX_HOME%] EQU [] (
|
||||
echo The environment variable JAVAFX_HOME is missing.
|
||||
pause
|
||||
exit
|
||||
)
|
||||
set "classpath=%TOPDIR%\lib\*;%JAVAFX_HOME%\lib\*"
|
||||
) else (
|
||||
set "classpath=%TOPDIR%\lib\*"
|
||||
)
|
||||
|
||||
|
||||
java %jreopts% -classpath "%classpath%" %OPTS% %MAIN_CLASS% %*
|
||||
|
@ -29,6 +29,7 @@ cygwin_paths() {
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if ${cygwin} ; then
|
||||
[ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --windows "${JAVA_HOME}")
|
||||
[ -n "${JAVAFX_HOME}" ] && JAVAFX_HOME=$(cygpath --windows "${JAVAFX_HOME}")
|
||||
[ -n "${DIRECTORY}" ] && DIRECTORY=$(cygpath --windows "${DIRECTORY}")
|
||||
classpath=$(cygpath --path --windows "${classpath}")
|
||||
fi
|
||||
@ -38,6 +39,7 @@ convert_cygwin_vars() {
|
||||
# If cygwin, convert to Unix form before manipulating
|
||||
if ${cygwin} ; then
|
||||
[ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}")
|
||||
[ -n "${JAVAFX_HOME}" ] && JAVAFX_HOME=$(cygpath --unix "${JAVAFX_HOME}")
|
||||
[ -n "${CLASSPATH}" ] && CLASSPATH=$(cygpath --path --unix "${CLASSPATH}")
|
||||
fi
|
||||
}
|
||||
@ -74,6 +76,91 @@ check_lib_dir() {
|
||||
fi
|
||||
}
|
||||
|
||||
function script_exit() {
|
||||
echo $1 >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
determine_java_version() {
|
||||
local full_ver=$(java -version 2>&1)
|
||||
# java_ver is eg "18" for java 1.8, "90" for java 9.0, "100" for java 10.0.x
|
||||
readonly java_ver=$(echo $full_ver | sed -n '{
|
||||
# replace early access versions, e.g. 11-ea with 11.0.0
|
||||
s/-ea/.0.0/
|
||||
# replace versions such as 10 with 10.0.0
|
||||
s/version "\([0-9]\{1,\}\)"/version "\1.0.0"/
|
||||
# extract the major and minor parts of the version
|
||||
s/^.* version "\(.*\)\.\(.*\)\..*".*$/\1\2/p
|
||||
}')
|
||||
# java_vendor is either java (oracle) or openjdk
|
||||
readonly java_vendor=$(echo $full_ver | sed -n -e 's/^\(.*\) version .*$/\1/p')
|
||||
}
|
||||
|
||||
jre_specific_vm_options() {
|
||||
if [ "${APPNAME}" = "designer" ]
|
||||
then
|
||||
options=""
|
||||
|
||||
if [ "$java_ver" -ge 80 ] && [ "$java_ver" -lt 90 ]
|
||||
then
|
||||
# no options needed for java8.
|
||||
options=""
|
||||
elif [ "$java_ver" -ge 90 ] && [ "$java_ver" -lt 110 ] && [ "$java_vendor" = "java" ]
|
||||
then
|
||||
# java9 and java10 from oracle contain javafx as a module
|
||||
# open internal module of javafx to reflection (for our TreeViewWrapper)
|
||||
options="--add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED"
|
||||
# The rest here is for RichtextFX
|
||||
options+=" --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED"
|
||||
options+=" --add-opens javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED"
|
||||
options+=" --add-opens javafx.graphics/com.sun.javafx.text=ALL-UNNAMED"
|
||||
options+=" --add-opens javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED"
|
||||
# Warn of remaining illegal accesses
|
||||
options+=" --illegal-access=warn"
|
||||
elif [ "$java_vendor" = "openjdk" ] || ( [ "$java_vendor" = "java" ] && [ "$java_ver" -ge 110 ] )
|
||||
then
|
||||
# openjdk and java11 from oracle onwards do not contain javafx directly
|
||||
# there are no extra options either - javafx will be added to the classpath without modules
|
||||
options=""
|
||||
fi
|
||||
|
||||
echo $options
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
function add_pmd_classpath() {
|
||||
if [ -n "$classpath" ]; then
|
||||
classpath="$classpath:${LIB_DIR}/*"
|
||||
else
|
||||
classpath="${LIB_DIR}/*"
|
||||
fi
|
||||
}
|
||||
|
||||
function add_openjfx_classpath() {
|
||||
if [ "${APPNAME}" = "designer" ]
|
||||
then
|
||||
if [ "$java_vendor" = "openjdk" ] && [ "$java_ver" -lt 100 ]
|
||||
then
|
||||
script_exit "For openjfx at least java 10 is required"
|
||||
elif [ "$java_vendor" = "openjdk" ] || ( [ "$java_vendor" = "java" ] && [ "$java_ver" -ge 110 ] )
|
||||
then
|
||||
# openjfx is required for openjdk builds and oracle java 11 or later
|
||||
if [ -z "${JAVAFX_HOME}" ]
|
||||
then
|
||||
script_exit "The environment variable JAVAFX_HOME is missing."
|
||||
else
|
||||
if [ -n "$classpath" ]; then
|
||||
classpath="$classpath:${JAVAFX_HOME}/lib/*"
|
||||
else
|
||||
classpath="${JAVAFX_HOME}/lib/*"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
readonly APPNAME="${1}"
|
||||
if [ -z "${APPNAME}" ]; then
|
||||
usage
|
||||
@ -114,19 +201,12 @@ convert_cygwin_vars
|
||||
|
||||
classpath=$CLASSPATH
|
||||
|
||||
cd "${CWD}"
|
||||
|
||||
for jarfile in "${LIB_DIR}"/*.jar; do
|
||||
if [ -n "$classpath" ]; then
|
||||
classpath=$classpath:$jarfile
|
||||
else
|
||||
classpath=$jarfile
|
||||
fi
|
||||
done
|
||||
add_pmd_classpath
|
||||
determine_java_version
|
||||
add_openjfx_classpath
|
||||
|
||||
cygwin_paths
|
||||
|
||||
java_heapsize_settings
|
||||
|
||||
java ${HEAPSIZE} -cp "${classpath}" "${CLASSNAME}" "$@"
|
||||
|
||||
java ${HEAPSIZE} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$@"
|
||||
|
Reference in New Issue
Block a user