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 <mthomsen@apache.org>
This commit is contained in:
Endre Zoltan Kovacs 2019-11-26 17:50:55 +01:00 committed by Mike Thomsen
parent 41b47a5156
commit c15876494a
No known key found for this signature in database
GPG Key ID: 88511C3D4CAD246F
5 changed files with 177 additions and 11 deletions

View File

@ -112,6 +112,34 @@ language governing permissions and limitations under the License. -->
<artifactId>javax.servlet-api</artifactId>
<scope>compile</scope>
</dependency>
<!-- dependencies for jaxb/activation/annotation for running NiFi on Java 11 -->
<!-- TODO: remove these once minimum Java version is 11 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>

View File

@ -32,8 +32,34 @@
<useProjectArtifact>false</useProjectArtifact>
<directoryMode>0770</directoryMode>
<fileMode>0660</fileMode>
<excludes>
<!-- exclude jaxb/activation libs from lib, they'll be included in the java11 subdir -->
<!-- TODO: remove these once minimum Java version is 11 -->
<exclude>javax.xml.bind:jaxb-api</exclude>
<exclude>com.sun.xml.bind:jaxb-impl</exclude>
<exclude>com.sun.xml.bind:jaxb-core</exclude>
<exclude>javax.activation:javax.activation-api</exclude>
</excludes>
</dependencySet>
<!-- Write out the bootstrap libs for java11 to its own dir -->
<!-- TODO: remove this dependency set once minimum Java version is 11 -->
<dependencySet>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib/java11</outputDirectory>
<directoryMode>0770</directoryMode>
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>javax.xml.bind:jaxb-api</include>
<include>com.sun.xml.bind:jaxb-impl</include>
<include>com.sun.xml.bind:jaxb-core</include>
<include>javax.activation:javax.activation-api</include>
</includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/bin</directory>

View File

@ -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% %* "

View File

@ -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 "$@"
}

View File

@ -59,7 +59,6 @@
<version>3.7.1.Final</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
@ -67,4 +66,59 @@
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<!-- This profile, activating when compiling on Java versions above
1.8, provides configuration changes to allow NiFi to be compiled on those
JDKs. -->
<id>jigsaw</id>
<activation>
<jdk>(1.8,)</jdk>
</activation>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
</profiles>
</project>