From c15876494a7fb9ea5eb6cacf02a6ee5f46faa333 Mon Sep 17 00:00:00 2001 From: Endre Zoltan Kovacs Date: Tue, 26 Nov 2019 17:50:55 +0100 Subject: [PATCH] NIFI-6897: making nifi-toolkit >= java 8 compliant fixing cli.bat cygwin fix: on windows ${JAVA} can have spaces in it. ...must wrap in quotes some jvms doesn't print a dot after the major version ...removing that from patter matching This closes #3908 Signed-off-by: Mike Thomsen --- nifi-toolkit/nifi-toolkit-assembly/pom.xml | 28 ++++++++++ .../src/main/assembly/dependencies.xml | 26 +++++++++ .../src/main/resources/bin/cli.bat | 46 ++++++++++++--- .../src/main/resources/bin/cli.sh | 32 ++++++++++- nifi-toolkit/pom.xml | 56 ++++++++++++++++++- 5 files changed, 177 insertions(+), 11 deletions(-) diff --git a/nifi-toolkit/nifi-toolkit-assembly/pom.xml b/nifi-toolkit/nifi-toolkit-assembly/pom.xml index b9cf707014..d5a74f97dc 100644 --- a/nifi-toolkit/nifi-toolkit-assembly/pom.xml +++ b/nifi-toolkit/nifi-toolkit-assembly/pom.xml @@ -112,6 +112,34 @@ language governing permissions and limitations under the License. --> javax.servlet-api compile + + + + + javax.xml.bind + jaxb-api + 2.3.0 + + + com.sun.xml.bind + jaxb-impl + 2.3.0 + + + com.sun.xml.bind + jaxb-core + 2.3.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + javax.activation + javax.activation-api + 1.2.0 + diff --git a/nifi-toolkit/nifi-toolkit-assembly/src/main/assembly/dependencies.xml b/nifi-toolkit/nifi-toolkit-assembly/src/main/assembly/dependencies.xml index a96953bfc4..b4f15ea56a 100644 --- a/nifi-toolkit/nifi-toolkit-assembly/src/main/assembly/dependencies.xml +++ b/nifi-toolkit/nifi-toolkit-assembly/src/main/assembly/dependencies.xml @@ -32,8 +32,34 @@ false 0770 0660 + + + + javax.xml.bind:jaxb-api + com.sun.xml.bind:jaxb-impl + com.sun.xml.bind:jaxb-core + javax.activation:javax.activation-api + + + + + + runtime + false + lib/java11 + 0770 + 0664 + true + + javax.xml.bind:jaxb-api + com.sun.xml.bind:jaxb-impl + com.sun.xml.bind:jaxb-core + javax.activation:javax.activation-api + + + ${project.basedir}/src/main/resources/bin diff --git a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.bat b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.bat index 46b7363d9c..f342a197aa 100644 --- a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.bat +++ b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.bat @@ -15,27 +15,55 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. rem - rem Use JAVA_HOME if it's set; otherwise, just use java - if "%JAVA_HOME%" == "" goto noJavaHome if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome set JAVA_EXE=%JAVA_HOME%\bin\java.exe goto startConfig - :noJavaHome echo The JAVA_HOME environment variable is not defined correctly. echo Instead the PATH will be used to find the java executable. echo. set JAVA_EXE=java goto startConfig - :startConfig -set LIB_DIR=%~dp0..\classpath;%~dp0..\lib - +set LIB_DIR=%~dp0..\classpath;%~dp0..\lib\ +if "%NIFI_TOOLKIT_HOME%" == "" ( + set NIFI_TOOLKIT_HOME=%~dp0.. +) else ( + SET trailing_char=%NIFI_TOOLKIT_HOME:~-1% + if "%trailing_char%" == "\" (set NIFI_TOOLKIT_HOME=%NIFI_TOOLKIT_HOME:~0,-1%) +) if "%JAVA_OPTS%" == "" set JAVA_OPTS=-Xms128m -Xmx256m +for /f tokens^=2-5^ delims^=.-+_^" %%j in ('"%JAVA_EXE%" -fullversion 2^>^&1') do ( + set "java_version=%%j%%k%%l%%m" + set "major=%%j" + set "minor=%%k" + set "micro=%%l" + set "build=%%m" +) +set compatibility_arg= +set compatibility_lib= +if %major% EQU 9 ( + set compatibility_arg=--add-modules=java.xml.bind + echo Detected Java 9 runtime version +) else if %major% EQU 10 ( + set compatibility_arg=--add-modules=java.xml.bind + echo Detected Java 10 runtime version +) else if %major% GEQ 11 ( + set compatibility_lib=%NIFI_TOOLKIT_HOME%\lib\java11\ + echo Detected java 11 or later runtime version: %major% +) +if not "%compatibility_arg%" == "" (set JAVA_OPTS=%JAVA_OPTS% %compatibility_arg%) +if not "%compatibility_lib%" == "" ( + set LIB_DIR="%LIB_DIR%*;%compatibility_lib%*" +) else ( + set LIB_DIR="%LIB_DIR%*" +) -SET JAVA_PARAMS=-cp %LIB_DIR%\* %JAVA_OPTS% org.apache.nifi.toolkit.cli.CLIMain - -cmd.exe /C ""%JAVA_EXE%" %JAVA_PARAMS% %* "" +rem remove surrounding quotes +SET LIB_DIR=%LIB_DIR:"=% +SET JAVA_OPTS=%JAVA_OPTS:"=% +SET JAVA_PARAMS=-cp %LIB_DIR% %JAVA_OPTS% org.apache.nifi.toolkit.cli.CLIMain +cmd.exe /C ""%JAVA_EXE%" %JAVA_PARAMS% %* " \ No newline at end of file diff --git a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh index 509385938c..9ba36d59e7 100644 --- a/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh +++ b/nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh @@ -88,6 +88,33 @@ locateJava() { fi } +apply_java_compatibility() { + compatibility_arg="" + compatibility_lib="" + java_version="$("${JAVA}" -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')" + + case "$java_version" in + 9*|10*) + compatibility_arg="--add-modules=java.xml.bind" + ;; + [1-9][1-9]*) + # java versions 11-99 + compatibility_lib="${NIFI_TOOLKIT_HOME}/lib/java11/*" + ;; + 1.*) + ;; + esac + + JAVA_OPTS="${JAVA_OPTS:--Xms128m -Xmx256m}" + if [ "x${compatibility_arg}" != "x" ]; then + JAVA_OPTS="${JAVA_OPTS} $compatibility_arg" + fi + + if [ "x${compatibility_lib}" != "x" ]; then + CLASSPATH="$CLASSPATH$classpath_separator$compatibility_lib" + fi +} + init() { # Determine if there is special OS handling we must perform detectOS @@ -101,17 +128,20 @@ run() { sudo_cmd_prefix="" if $cygwin; then + classpath_separator=";" NIFI_TOOLKIT_HOME=$(cygpath --path --windows "${NIFI_TOOLKIT_HOME}") CLASSPATH="$NIFI_TOOLKIT_HOME/classpath;$(cygpath --path --windows "${LIBS}")" else + classpath_separator=":" CLASSPATH="$NIFI_TOOLKIT_HOME/classpath:${LIBS}" fi export JAVA_HOME="$JAVA_HOME" export NIFI_TOOLKIT_HOME="$NIFI_TOOLKIT_HOME" + apply_java_compatibility umask 0077 - exec "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@" + exec "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS} org.apache.nifi.toolkit.cli.CLIMain "$@" } diff --git a/nifi-toolkit/pom.xml b/nifi-toolkit/pom.xml index 04ee821989..026c1f863c 100644 --- a/nifi-toolkit/pom.xml +++ b/nifi-toolkit/pom.xml @@ -59,7 +59,6 @@ 3.7.1.Final - @@ -67,4 +66,59 @@ slf4j-log4j12 + + + + jigsaw + + (1.8,) + + + 11 + 11 + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.14.0 + + + + + + + + javax.xml.bind + jaxb-api + 2.3.0 + + + com.sun.xml.bind + jaxb-core + 2.3.0 + + + com.sun.xml.bind + jaxb-impl + 2.3.0 + + + com.sun.activation + javax.activation + 1.2.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + +