diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7914fdb65..bf2fe93fa 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,3 +11,7 @@ updates: interval: "weekly" day: "saturday" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25782d819..012608561 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: matrix: os: [ ubuntu-20.04, ubuntu-22.04 ] java: [ '11', '17' ] - db: [ 'mysql:5.7', 'mysql:8.0', 'mariadb:10.3', 'mariadb:10.4', 'mariadb:10.5', 'mariadb:10.6' ] + db: [ 'mysql:5.7', 'mysql:8.0', 'mariadb:10.3', 'mariadb:10.4.30', 'mariadb:10.5.21', 'mariadb:10.6.14' ] runs-on: ${{ matrix.os }} services: mysql: @@ -21,9 +21,9 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Java ${{ matrix.Java }} - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: ${{ matrix.java }} distribution: 'temurin' @@ -39,7 +39,7 @@ jobs: mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT SUPER ON *.* TO 'steve'@'%';" -v || true - name: Build with Maven - run: mvn -B -V -Dmaven.javadoc.skip=true -Ptest clean package --file pom.xml + run: ./mvnw -B -V -Dmaven.javadoc.skip=true -Ptest clean package --file pom.xml - name: Start the app and visit signin web page run: | diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index 4f8a63a82..93f815e87 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -5,12 +5,12 @@ jobs: license-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Java 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 11 distribution: 'temurin' @@ -21,7 +21,7 @@ jobs: pmd: runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: distribution: 'temurin' @@ -29,7 +29,7 @@ jobs: - name: Run PMD uses: pmd/pmd-github-action@v1 with: - version: '6.49.0' + version: 'latest' sourcePath: './src/main/java' rulesets: './src/main/resources/maven-pmd-plugin-default.xml' - name: Fail build if there are violations @@ -38,7 +38,7 @@ jobs: checkstyle: runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: distribution: 'temurin' diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 000000000..bf82ff01c Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 000000000..5785e2f7e --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/Dockerfile b/Dockerfile index 1f288ce71..a7b0fd4a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM maven:3.6.1-jdk-11 +FROM eclipse-temurin:11-jdk ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 @@ -21,6 +21,6 @@ COPY . /code # Wait for the db to startup(via dockerize), then # Build and run steve, requires a db to be available on port 3306 CMD dockerize -wait tcp://mariadb:3306 -timeout 60s && \ - mvn clean package -Pdocker -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2" && \ + ./mvnw clean package -Pdocker -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2" && \ java -jar target/steve.jar diff --git a/README.md b/README.md index 2686158a8..a3d0af74f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ https://github.com/steve-community/steve/wiki/Charging-Station-Compatibility SteVe requires * JDK 11 (both Oracle JDK and Adoptium are supported) * Maven -* MariaDB 10.2.1 or later. MySQL 5.7.7 or later works as well, but especially MySQL 8 introduces more hassle. We suggest MariaDB 10.4. +* MySQL or MariaDB. You should use [one of these](.github/workflows/main.yml#L11) supported versions. to build and run. @@ -92,7 +92,7 @@ SteVe is designed to run standalone, a java servlet container / web server (e.g. To compile SteVe simply use Maven. A runnable `jar` file containing the application and configuration will be created in the subdirectory `steve/target`. ``` - # mvn package + # ./mvnw package ``` 5. Run SteVe: diff --git a/docker-compose.yml b/docker-compose.yml index 63f93f04c..ed45a457a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,12 @@ volumes: services: db: - image: mariadb:10.4 + # Pinning MariaDB to point release 10.4.30 works around the issues with the + # database migrations seen with 10.4.31 in issue #1212. + # + # TODO: Get database migrations to work with the latest point releases of + # MariaDB 10.4. + image: mariadb:10.4.30 ports: - 3306:3306 environment: diff --git a/k8s/docker/Dockerfile b/k8s/docker/Dockerfile index 48b19a9cf..2f073d728 100644 --- a/k8s/docker/Dockerfile +++ b/k8s/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM maven:3.6.1-jdk-11 +FROM eclipse-temurin:11-jdk MAINTAINER daynnnnn ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 @@ -21,7 +21,7 @@ RUN sed -i 's|${db.user}|${env.DB_USERNAME}|g' pom.xml RUN sed -i 's|${db.password}|${env.DB_PASSWORD}|g' pom.xml RUN sed -i 's|${db.schema}|${env.DB_DATABASE}|g' pom.xml -RUN mvn clean package -Pkubernetes -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2" +RUN ./mvnw clean package -Pkubernetes -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2" CMD java -jar target/steve.jar diff --git a/mvnw b/mvnw new file mode 100755 index 000000000..5643201c7 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 000000000..8a15b7f31 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 65bd8865f..6b9b7746b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.rwth.idsg steve - 3.5.0 + 3.6.0 jar SteVe @@ -37,13 +37,13 @@ 3.16.7 3.5.5 - 5.3.23 - 5.7.5 + 5.3.31 + 5.7.10 8.0.30 10.0.14 - 1.18.28 - 2.15.1 - 4.2 + 1.18.30 + 2.16.0 + 4.3 jdbc:mysql://${db.ip}:${db.port}/${db.schema}?useSSL=true&serverTimezone=UTC @@ -154,7 +154,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.3.0 + 3.4.1 enforce-java @@ -166,6 +166,9 @@ [11,) + + [3.3.9,) + @@ -184,14 +187,14 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.0 + 3.2.2 org.apache.maven.plugins maven-pmd-plugin - 3.21.0 + 3.21.2 ${project.basedir}/src/main/resources/maven-pmd-plugin-default.xml @@ -201,7 +204,7 @@ com.github.spotbugs spotbugs-maven-plugin - 4.7.3.4 + 4.8.1.0 false de.rwth.idsg.steve.- @@ -217,16 +220,16 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.0 + 3.3.1 ${basedir}/src/main/resources/checkstyle.xml - pl.project13.maven - git-commit-id-plugin - 4.9.10 + io.github.git-commit-id + git-commit-id-maven-plugin + 7.0.0 initialize @@ -245,7 +248,7 @@ org.codehaus.mojo properties-maven-plugin - 1.1.0 + 1.2.1 initialize @@ -264,7 +267,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.6.0 + 3.6.1 copy-dependencies @@ -478,9 +481,23 @@ org.apache.logging.log4j log4j-bom - 2.20.0 + 2.21.1 + import + pom + + + org.junit + junit-bom + 5.10.1 + pom import + + + org.slf4j + slf4j-bom + 2.0.9 pom + import @@ -538,7 +555,7 @@ com.google.guava guava - 32.0.0-jre + 32.1.3-jre com.fasterxml.jackson.core @@ -619,12 +636,10 @@ org.slf4j slf4j-api - 2.0.7 org.slf4j jcl-over-slf4j - 2.0.7 com.lmax @@ -700,7 +715,7 @@ com.zaxxer HikariCP - 5.0.1 + 5.1.0 org.jooq @@ -723,25 +738,23 @@ org.junit.jupiter junit-jupiter-engine - 5.9.3 test org.junit.jupiter junit-jupiter-params - 5.9.3 test org.mockito mockito-junit-jupiter - 5.3.1 + 5.7.0 test net.bytebuddy byte-buddy - 1.14.4 + 1.14.9 test diff --git a/src/main/java/de/rwth/idsg/steve/Application.java b/src/main/java/de/rwth/idsg/steve/Application.java index 6334239cc..196e2d4f4 100644 --- a/src/main/java/de/rwth/idsg/steve/Application.java +++ b/src/main/java/de/rwth/idsg/steve/Application.java @@ -64,6 +64,7 @@ public static void main(String[] args) throws Exception { app.start(); app.join(); } catch (Exception e) { + log.error("Application failed to start", e); if (app != null) { app.stop(); } diff --git a/src/main/resources/config/prod/log4j2.xml b/src/main/resources/config/prod/log4j2.xml index 7f741148f..0c6fbeba3 100644 --- a/src/main/resources/config/prod/log4j2.xml +++ b/src/main/resources/config/prod/log4j2.xml @@ -2,7 +2,7 @@ - [%-5p] %d %c - %m%n + [%-5p] %d %c (%t) - %m%n @@ -33,4 +33,4 @@ - \ No newline at end of file + diff --git a/src/main/resources/webapp/WEB-INF/views/data-man/transactions.jsp b/src/main/resources/webapp/WEB-INF/views/data-man/transactions.jsp index 6bca9b4ba..4a323f1cf 100644 --- a/src/main/resources/webapp/WEB-INF/views/data-man/transactions.jsp +++ b/src/main/resources/webapp/WEB-INF/views/data-man/transactions.jsp @@ -123,7 +123,7 @@ Transactions - + diff --git a/src/test/java/de/rwth/idsg/steve/utils/OcppJsonChargePoint.java b/src/test/java/de/rwth/idsg/steve/utils/OcppJsonChargePoint.java index 5ff59a2b6..b40792af7 100644 --- a/src/test/java/de/rwth/idsg/steve/utils/OcppJsonChargePoint.java +++ b/src/test/java/de/rwth/idsg/steve/utils/OcppJsonChargePoint.java @@ -19,9 +19,14 @@ package de.rwth.idsg.steve.utils; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.NullNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import de.rwth.idsg.ocpp.jaxb.RequestType; import de.rwth.idsg.ocpp.jaxb.ResponseType; import de.rwth.idsg.steve.SteveException; @@ -32,9 +37,13 @@ import de.rwth.idsg.steve.ocpp.ws.data.MessageType; import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall; import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError; +import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonMessage; import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResponse; import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult; import de.rwth.idsg.steve.ocpp.ws.pipeline.Serializer; +import lombok.Getter; +import lombok.Setter; +import lombok.Value; import lombok.extern.slf4j.Slf4j; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; @@ -49,8 +58,10 @@ import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -68,11 +79,15 @@ public class OcppJsonChargePoint { private final String chargeBoxId; private final String connectionPath; private final Map responseContextMap; - private final ResponseDeserializer deserializer; + private final Map requestContextMap; + private final MessageDeserializer deserializer; private final WebSocketClient client; private final CountDownLatch closeHappenedSignal; - private CountDownLatch receivedResponsesSignal; + private final Thread testerThread; + private RuntimeException testerThreadInterruptReason; + + private CountDownLatch receivedMessagesSignal; private Session session; public OcppJsonChargePoint(OcppVersion version, String chargeBoxId, String pathPrefix) { @@ -84,9 +99,11 @@ public OcppJsonChargePoint(String ocppVersion, String chargeBoxId, String pathPr this.chargeBoxId = chargeBoxId; this.connectionPath = pathPrefix + chargeBoxId; this.responseContextMap = new LinkedHashMap<>(); // because we want to keep the insertion order of test cases - this.deserializer = new ResponseDeserializer(); + this.requestContextMap = new HashMap<>(); + this.deserializer = new MessageDeserializer(); this.client = new WebSocketClient(); this.closeHappenedSignal = new CountDownLatch(1); + this.testerThread = Thread.currentThread(); } @OnWebSocketConnect @@ -108,19 +125,22 @@ public void onError(Session session, Throwable throwable) { @OnWebSocketMessage public void onMessage(Session session, String msg) { try { - OcppJsonResponse response = deserializer.extractResponse(msg); - ResponseContext ctx = responseContextMap.remove(response.getMessageId()); - - if (response instanceof OcppJsonResult) { - ctx.responseHandler.accept(((OcppJsonResult) response).getPayload()); - } else if (response instanceof OcppJsonError) { - ctx.errorHandler.accept((OcppJsonError) response); + OcppJsonMessage ocppMsg = deserializer.extract(msg); + + if (ocppMsg instanceof OcppJsonResult) { + ResponseContext ctx = responseContextMap.remove(ocppMsg.getMessageId()); + ctx.responseHandler.accept(((OcppJsonResult) ocppMsg).getPayload()); + } else if (ocppMsg instanceof OcppJsonError) { + ResponseContext ctx = responseContextMap.remove(ocppMsg.getMessageId()); + ctx.errorHandler.accept((OcppJsonError) ocppMsg); + } else if (ocppMsg instanceof OcppJsonCallForTesting) { + handleCall((OcppJsonCallForTesting) ocppMsg); } } catch (Exception e) { log.error("Exception", e); } finally { - if (receivedResponsesSignal != null) { - receivedResponsesSignal.countDown(); + if (receivedMessagesSignal != null) { + receivedMessagesSignal.countDown(); } } } @@ -165,13 +185,30 @@ public void prepare(RequestType payload, String action, responseContextMap.put(messageId, resCtx); } + public void expectRequest(RequestType expectedRequest, ResponseType plannedResponse) { + String requestPayload; + JsonNode responsePayload; + try { + ObjectMapper mapper = JsonObjectMapper.INSTANCE.getMapper(); + requestPayload = mapper.writeValueAsString(expectedRequest); + responsePayload = mapper.valueToTree(plannedResponse); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + String action = getOperationName(expectedRequest); + requestContextMap.put(action, new RequestContext(requestPayload, responsePayload)); + } + public void process() { + int requestCount = requestContextMap.values().size(); + int responseCount = responseContextMap.values().size(); + receivedMessagesSignal = new CountDownLatch(requestCount + responseCount); + // copy the values in a new list to be iterated over, because otherwise we get a ConcurrentModificationException, // since the onMessage(..) uses the same responseContextMap to remove an item while looping over its items here. ArrayList values = new ArrayList<>(responseContextMap.values()); - receivedResponsesSignal = new CountDownLatch(values.size()); - // send all messages for (ResponseContext ctx : values) { try { @@ -183,8 +220,11 @@ public void process() { // wait for all responses to arrive and be processed try { - receivedResponsesSignal.await(); + receivedMessagesSignal.await(); } catch (InterruptedException e) { + if (testerThreadInterruptReason != null) { + throw testerThreadInterruptReason; + } throw new RuntimeException(e); } } @@ -221,6 +261,27 @@ private static String getOperationName(RequestType requestType) { return s; } + private void handleCall(OcppJsonCallForTesting call) { + try { + ArrayNode node = JsonObjectMapper.INSTANCE.getMapper() + .createArrayNode() + .add(MessageType.CALL_RESULT.getTypeNr()) + .add(call.getMessageId()) + .add(call.getContext().getResponsePayload()); + + String str = JsonObjectMapper.INSTANCE.getMapper().writeValueAsString(node); + session.getRemote().sendString(str); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Value + private static class RequestContext { + String requestPayload; + JsonNode responsePayload; + } + private static class ResponseContext { private final String outgoingMessage; private final Class responseClass; @@ -239,9 +300,9 @@ private ResponseContext(String outgoingMessage, } } - private class ResponseDeserializer { + private class MessageDeserializer { - private OcppJsonResponse extractResponse(String msg) throws Exception { + private OcppJsonMessage extract(String msg) throws Exception { ObjectMapper mapper = JsonObjectMapper.INSTANCE.getMapper(); try (JsonParser parser = mapper.getFactory().createParser(msg)) { @@ -259,6 +320,8 @@ private OcppJsonResponse extractResponse(String msg) throws Exception { return handleResult(messageId, parser); case CALL_ERROR: return handleError(messageId, parser); + case CALL: + return handleCall(messageId, parser); default: throw new SteveException("Unknown enum type"); } @@ -301,6 +364,54 @@ private OcppJsonResponse handleError(String messageId, JsonParser parser) throws error.setErrorDetails(details); return error; } + + private OcppJsonCall handleCall(String messageId, JsonParser parser) { + // parse action + String action; + try { + parser.nextToken(); + action = parser.getText(); + } catch (IOException e) { + throw new RuntimeException(); + } + + // parse request payload + String req; + try { + parser.nextToken(); + JsonNode requestPayload = parser.readValueAsTree(); + + // https://github.com/steve-community/steve/issues/1109 + if (requestPayload instanceof NullNode) { + requestPayload = new ObjectNode(JsonNodeFactory.instance); + } + + req = requestPayload.toString(); + } catch (IOException e) { + log.error("Exception occurred", e); + throw new RuntimeException(); + } + + RequestContext context = requestContextMap.get(action); + if (context == null) { + testerThreadInterruptReason = new RuntimeException("Unexpected message arrived: " + req); + testerThread.interrupt(); + } else if (Objects.equals(context.requestPayload, req)) { + requestContextMap.remove(action); + } + + OcppJsonCallForTesting call = new OcppJsonCallForTesting(); + call.setAction(action); + call.setMessageId(messageId); + call.setContext(context); + return call; + } + } + + @Setter + @Getter + private static class OcppJsonCallForTesting extends OcppJsonCall { + private RequestContext context; } }