diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d12ced7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +ij_continuation_indent_size = 8 + +[*.yml] +indent_size = 2 + +[*.md] +max_line_length = off diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b8afbf6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf encoding=utf-8 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ff673ab --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: Main + +on: push + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v5 + - uses: aboutbits/github-actions-java/setup-with-maven@v4 + with: + java-version: 25 + - name: Test + env: + GITHUB_USER_NAME: ${{ github.actor }} + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: >- + ./mvnw + -s $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml + --batch-mode + --fail-fast + -Dsurefire.failIfNoSpecifiedTests=false + test + shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a2b0643..4976449 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: - uses: aboutbits/github-actions-base/git-setup@v2 - uses: aboutbits/github-actions-java/setup-with-maven@v4 with: - java-version: 21 + java-version: 25 - uses: aboutbits/github-actions-java/set-version-with-maven@v4 with: version: "${{ github.event.inputs.version }}" diff --git a/.gitignore b/.gitignore index ec376bb..5fc79a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ -.idea -target \ No newline at end of file +.idea/* +!/.idea/codeStyles + +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +/.output.txt diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..0296b44 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,48 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..6a7bfad --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..cb28b0e 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 0000000..462686e --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/license.md b/license.md new file mode 100644 index 0000000..21586f5 --- /dev/null +++ b/license.md @@ -0,0 +1,7 @@ +Copyright About Bits GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..5ffcbcb --- /dev/null +++ b/lombok.config @@ -0,0 +1,9 @@ +config.stopBubbling = true + +# Required for NullAway to work +lombok.addLombokGeneratedAnnotation = true + +# Copy JSpecify annotations to generated code (constructors, getters, setters) +lombok.copyableAnnotations += org.jspecify.annotations.Nullable +lombok.copyableAnnotations += org.jspecify.annotations.NonNull +lombok.addNullAnnotations = jspecify diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..66df285 --- /dev/null +++ b/mvnw @@ -0,0 +1,308 @@ +#!/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 +# +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.2.0 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# 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 + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -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 "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); 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 2>/dev/null; \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 + +# 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/.." || exit 1; pwd) + fi + # end of workaround + done + printf '%s' "$(cd "$basedir" || exit 1; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# 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. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +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 "$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 + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..95ba6f5 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,205 @@ +@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 https://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 Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@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 WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_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 WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_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('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@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 b12520c..be3e664 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,89 @@ it.aboutbits java-checkstyle-config - 2.0.0-RC2 + 2.0.0-RC5 Checkstyle config for all JAVA projects. jar + + 25 + UTF-8 + 13.4.2 + 6.0.3 + 2.49.0 + 0.13.2 + + + + + + org.jspecify + jspecify + 1.0.0 + provided + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + provided + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + + + + + maven-compiler-plugin + 3.15.0 + + ${java.version} + ${java.version} + + + com.google.errorprone + error_prone_core + ${errorprone.version} + + + com.uber.nullaway + nullaway + ${nullaway.version} + + + + -Amapstruct.unmappedTargetPolicy=ERROR + -XDcompilePolicy=simple + --should-stop=ifError=FLOW + + -Xplugin:ErrorProne -XepDisableAllChecks -XepOpt:NullAway:AnnotatedPackages=it.aboutbits.checkstyle -XepOpt:NullAway:JSpecifyMode=true -Xep:NullAway:ERROR -XepOpt:NullAway:ExcludedFieldAnnotations=org.mockito.InjectMocks,org.mockito.Mock + + -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED + + true + + + + maven-surefire-plugin + 3.5.5 + + + + github diff --git a/src/main/java/it/aboutbits/checkstyle/AnnotationNames.java b/src/main/java/it/aboutbits/checkstyle/AnnotationNames.java new file mode 100644 index 0000000..62b1c5e --- /dev/null +++ b/src/main/java/it/aboutbits/checkstyle/AnnotationNames.java @@ -0,0 +1,54 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +@NullMarked +final class AnnotationNames { + + private AnnotationNames() { + } + + /** + * Returns the simple name of an ANNOTATION node, regardless of whether the + * source uses an imported name (@Foo) or a fully-qualified name (@a.b.Foo). + */ + static @Nullable String simpleName(DetailAST annotation) { + return lastIdentIn(annotation); + } + + /** + * Returns the text of the last IDENT reachable from {@code node}: the direct + * IDENT child when present, or the last child of the first DOT child otherwise. + */ + static @Nullable String lastIdentIn(DetailAST node) { + var ident = node.findFirstToken(TokenTypes.IDENT); + if (ident != null) { + return ident.getText(); + } + var dot = node.findFirstToken(TokenTypes.DOT); + if (dot != null) { + var last = dot.getLastChild(); + if (last != null && last.getType() == TokenTypes.IDENT) { + return last.getText(); + } + } + return null; + } + + /** + * Returns the source-text name of an ANNOTATION node: the simple name when + * the source uses an imported form, or the full dotted name when written + * inline as a fully-qualified annotation. + */ + static @Nullable String fullName(DetailAST annotation) { + var child = annotation.findFirstToken(TokenTypes.IDENT); + if (child == null) { + child = annotation.findFirstToken(TokenTypes.DOT); + } + return child == null ? null : FullIdent.createFullIdent(child).getText(); + } +} diff --git a/src/main/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheck.java b/src/main/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheck.java new file mode 100644 index 0000000..b75d01e --- /dev/null +++ b/src/main/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheck.java @@ -0,0 +1,80 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullUnmarked; + +import java.util.LinkedHashSet; +import java.util.Set; + +@NullMarked +public class JspecifyAnnotationOrderCheck extends AbstractCheck { + + public static final String MSG_KEY = "jspecify.order.notLast"; + + private Set closeAnnotations = new LinkedHashSet<>(Set.of( + NullMarked.class.getSimpleName(), + NullUnmarked.class.getSimpleName() + )); + + // Called by Checkstyle via reflection for + @SuppressWarnings("unused") + public void setCloseAnnotations(String... names) { + var next = new LinkedHashSet(); + for (var n : names) { + next.add(n.trim()); + } + this.closeAnnotations = next; + } + + @Override + public int[] getDefaultTokens() { + return new int[]{ + TokenTypes.CLASS_DEF, + TokenTypes.INTERFACE_DEF, + TokenTypes.ENUM_DEF, + TokenTypes.RECORD_DEF, + }; + } + + @Override + public int[] getAcceptableTokens() { + return getDefaultTokens(); + } + + @Override + public int[] getRequiredTokens() { + return getDefaultTokens(); + } + + @Override + public void visitToken(DetailAST ast) { + var modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); + if (modifiers == null) { + return; + } + DetailAST lastAnnotation = null; + DetailAST firstCloseAnnotation = null; + String firstCloseName = null; + for (var child = modifiers.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getType() != TokenTypes.ANNOTATION) { + continue; + } + var name = AnnotationNames.simpleName(child); + lastAnnotation = child; + if (name != null && closeAnnotations.contains(name) && firstCloseAnnotation == null) { + firstCloseAnnotation = child; + firstCloseName = name; + } + } + if (firstCloseAnnotation == null || lastAnnotation == null) { + return; + } + var lastName = AnnotationNames.simpleName(lastAnnotation); + if (lastName == null || !closeAnnotations.contains(lastName)) { + log(firstCloseAnnotation, MSG_KEY, firstCloseName); + } + } +} diff --git a/src/main/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheck.java b/src/main/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheck.java new file mode 100644 index 0000000..302e4f9 --- /dev/null +++ b/src/main/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheck.java @@ -0,0 +1,104 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +import java.util.HashSet; +import java.util.Set; + +@NullMarked +public class JspecifyInlineTypeUseCheck extends AbstractCheck { + + public static final String MSG_KEY = "jspecify.inline.notInline"; + + private static final String JSPECIFY_PACKAGE = Nullable.class.getPackageName(); + private static final String JSPECIFY_PACKAGE_DOT = JSPECIFY_PACKAGE + "."; + private static final Set TYPE_USE_ANNOTATIONS = Set.of( + Nullable.class.getSimpleName(), + NonNull.class.getSimpleName() + ); + + private Set jspecifySimpleNamesInScope = new HashSet<>(); + + @Override + public int[] getDefaultTokens() { + return new int[]{ + TokenTypes.METHOD_DEF, + TokenTypes.VARIABLE_DEF, + TokenTypes.PARAMETER_DEF, + }; + } + + @Override + public int[] getAcceptableTokens() { + return getDefaultTokens(); + } + + @Override + public int[] getRequiredTokens() { + return getDefaultTokens(); + } + + @Override + public void beginTree(DetailAST rootAST) { + jspecifySimpleNamesInScope = new HashSet<>(); + for (var node = rootAST.getFirstChild(); node != null; node = node.getNextSibling()) { + if (node.getType() != TokenTypes.IMPORT) { + continue; + } + var first = node.getFirstChild(); + if (first == null) { + continue; + } + var text = FullIdent.createFullIdent(first).getText(); + if (text.equals(JSPECIFY_PACKAGE + ".*")) { + jspecifySimpleNamesInScope.addAll(TYPE_USE_ANNOTATIONS); + } else if (text.startsWith(JSPECIFY_PACKAGE_DOT)) { + var simple = text.substring(JSPECIFY_PACKAGE_DOT.length()); + if (TYPE_USE_ANNOTATIONS.contains(simple)) { + jspecifySimpleNamesInScope.add(simple); + } + } + } + } + + @Override + public void visitToken(DetailAST ast) { + var modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); + var type = ast.findFirstToken(TokenTypes.TYPE); + if (modifiers == null || type == null) { + return; + } + for (var child = modifiers.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getType() != TokenTypes.ANNOTATION) { + continue; + } + var simple = AnnotationNames.simpleName(child); + if (simple == null || !TYPE_USE_ANNOTATIONS.contains(simple)) { + continue; + } + if (!isJspecifyAnnotation(child, simple)) { + continue; + } + if (child.getLineNo() < type.getLineNo()) { + log(child, MSG_KEY, simple); + } + } + } + + private boolean isJspecifyAnnotation(DetailAST annotation, String simpleName) { + var fullName = AnnotationNames.fullName(annotation); + if (fullName == null) { + return false; + } + if (fullName.contains(".")) { + return fullName.equals(JSPECIFY_PACKAGE_DOT + simpleName); + } + return jspecifySimpleNamesInScope.contains(simpleName); + } +} diff --git a/src/main/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheck.java b/src/main/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheck.java new file mode 100644 index 0000000..a9b85fd --- /dev/null +++ b/src/main/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheck.java @@ -0,0 +1,127 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullUnmarked; +import org.jspecify.annotations.Nullable; + +import java.util.ArrayList; + +@NullMarked +public class JspecifyMapStructMapperAnnotationCheck extends AbstractCheck { + + public static final String MSG_KEY = "jspecify.mapstruct.annotation.invalid"; + + private String mapperAnnotationName = "Mapper"; + private String annotateWithAnnotationName = "AnnotateWith"; + private String nullUnmarkedAnnotationName = NullUnmarked.class.getSimpleName(); + + // The three setters below are called by Checkstyle via reflection for the corresponding entries. + @SuppressWarnings("unused") + public void setMapperAnnotationName(String name) { + this.mapperAnnotationName = name; + } + + @SuppressWarnings("unused") + public void setAnnotateWithAnnotationName(String name) { + this.annotateWithAnnotationName = name; + } + + @SuppressWarnings("unused") + public void setNullUnmarkedAnnotationName(String name) { + this.nullUnmarkedAnnotationName = name; + } + + @Override + public int[] getDefaultTokens() { + return new int[]{TokenTypes.INTERFACE_DEF, TokenTypes.CLASS_DEF}; + } + + @Override + public int[] getAcceptableTokens() { + return getDefaultTokens(); + } + + @Override + public int[] getRequiredTokens() { + return getDefaultTokens(); + } + + @Override + public void visitToken(DetailAST ast) { + var modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); + if (modifiers == null) { + return; + } + if (ast.getType() == TokenTypes.CLASS_DEF && modifiers.findFirstToken(TokenTypes.ABSTRACT) == null) { + return; + } + var annotations = new ArrayList(); + var hasMapper = false; + for (var child = modifiers.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getType() != TokenTypes.ANNOTATION) { + continue; + } + annotations.add(child); + if (mapperAnnotationName.equals(AnnotationNames.simpleName(child))) { + hasMapper = true; + } + } + if (!hasMapper) { + return; + } + if (annotations.size() < 2) { + logInvalid(ast); + return; + } + var last = annotations.getLast(); + var secondLast = annotations.get(annotations.size() - 2); + var lastOk = nullUnmarkedAnnotationName.equals(AnnotationNames.simpleName(last)); + var secondLastOk = annotateWithAnnotationName.equals(AnnotationNames.simpleName(secondLast)) + && annotateWithArgumentReferences(secondLast, nullUnmarkedAnnotationName); + if (!lastOk || !secondLastOk) { + logInvalid(ast); + } + } + + private void logInvalid(DetailAST ast) { + var name = ast.findFirstToken(TokenTypes.IDENT); + log(ast, MSG_KEY, name != null ? name.getText() : ""); + } + + private static boolean annotateWithArgumentReferences(DetailAST annotation, String expectedClassName) { + for (var child = annotation.getFirstChild(); child != null; child = child.getNextSibling()) { + var found = switch (child.getType()) { + case TokenTypes.EXPR -> classLiteralName(child); + case TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR -> memberValuePairClassLiteralName(child); + default -> null; + }; + if (expectedClassName.equals(found)) { + return true; + } + } + return false; + } + + private static @Nullable String memberValuePairClassLiteralName(DetailAST pair) { + var ident = pair.findFirstToken(TokenTypes.IDENT); + if (ident == null || !"value".equals(ident.getText())) { + return null; + } + var expr = pair.findFirstToken(TokenTypes.EXPR); + return expr == null ? null : classLiteralName(expr); + } + + private static @Nullable String classLiteralName(DetailAST expr) { + var dot = expr.findFirstToken(TokenTypes.DOT); + if (dot == null) { + return null; + } + if (dot.findFirstToken(TokenTypes.LITERAL_CLASS) == null) { + return null; + } + return AnnotationNames.lastIdentIn(dot); + } +} diff --git a/src/main/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheck.java b/src/main/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheck.java new file mode 100644 index 0000000..baae5e9 --- /dev/null +++ b/src/main/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheck.java @@ -0,0 +1,72 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullUnmarked; + +import java.util.Set; + +@NullMarked +public class JspecifyOnTopLevelTypesCheck extends AbstractCheck { + + public static final String MSG_KEY = "jspecify.toplevel.missing"; + + private static final Set JSPECIFY_TYPE_ANNOTATIONS = Set.of( + NullMarked.class.getSimpleName(), + NullUnmarked.class.getSimpleName() + ); + + @Override + public int[] getDefaultTokens() { + return new int[]{ + TokenTypes.CLASS_DEF, + TokenTypes.INTERFACE_DEF, + TokenTypes.ENUM_DEF, + TokenTypes.RECORD_DEF, + }; + } + + @Override + public int[] getAcceptableTokens() { + return getDefaultTokens(); + } + + @Override + public int[] getRequiredTokens() { + return getDefaultTokens(); + } + + @Override + public void visitToken(DetailAST ast) { + if (!isTopLevel(ast)) { + return; + } + var modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); + if (modifiers == null) { + logMissing(ast); + return; + } + for (var child = modifiers.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getType() != TokenTypes.ANNOTATION) { + continue; + } + var name = AnnotationNames.simpleName(child); + if (name != null && JSPECIFY_TYPE_ANNOTATIONS.contains(name)) { + return; + } + } + logMissing(ast); + } + + private void logMissing(DetailAST ast) { + var name = ast.findFirstToken(TokenTypes.IDENT); + log(ast, MSG_KEY, name != null ? name.getText() : ""); + } + + private static boolean isTopLevel(DetailAST ast) { + var parent = ast.getParent(); + return parent == null || parent.getType() == TokenTypes.COMPILATION_UNIT; + } +} diff --git a/src/main/resources/checkstyle-suppressions.xml b/src/main/resources/checkstyle-suppressions-default.xml similarity index 100% rename from src/main/resources/checkstyle-suppressions.xml rename to src/main/resources/checkstyle-suppressions-default.xml diff --git a/src/main/resources/checkstyle.xml b/src/main/resources/checkstyle.xml index 8c33e4c..75f421e 100644 --- a/src/main/resources/checkstyle.xml +++ b/src/main/resources/checkstyle.xml @@ -52,6 +52,10 @@ + + + + @@ -158,6 +162,20 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/it/aboutbits/checkstyle/messages.properties b/src/main/resources/it/aboutbits/checkstyle/messages.properties new file mode 100644 index 0000000..67dbf4e --- /dev/null +++ b/src/main/resources/it/aboutbits/checkstyle/messages.properties @@ -0,0 +1,4 @@ +jspecify.toplevel.missing=Top-level type ''{0}'' must be annotated with @NullMarked or @NullUnmarked. +jspecify.order.notLast=@{0} must be the last annotation before the type declaration. +jspecify.inline.notInline=@{0} must appear inline before the type, not on its own line above the declaration. +jspecify.mapstruct.annotation.invalid=MapStruct @Mapper type ''{0}'' must end with @AnnotateWith(NullUnmarked.class) then @NullUnmarked as the last two annotations before the ''interface''/''abstract class'' keyword. diff --git a/src/test/java/it/aboutbits/checkstyle/CheckTestSupport.java b/src/test/java/it/aboutbits/checkstyle/CheckTestSupport.java new file mode 100644 index 0000000..ff757cf --- /dev/null +++ b/src/test/java/it/aboutbits/checkstyle/CheckTestSupport.java @@ -0,0 +1,87 @@ +package it.aboutbits.checkstyle; + +import com.puppycrawl.tools.checkstyle.Checker; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.AuditEvent; +import com.puppycrawl.tools.checkstyle.api.AuditListener; + +import org.jspecify.annotations.NullMarked; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +@NullMarked +public abstract class CheckTestSupport { + + protected List runCheck( + Class checkClass, + String fixtureResourcePath + ) throws Exception { + return runCheck(checkClass, fixtureResourcePath, Map.of()); + } + + protected List runCheck( + Class checkClass, + String fixtureResourcePath, + Map properties + ) throws Exception { + var checkCfg = new DefaultConfiguration(checkClass.getName()); + for (var entry : properties.entrySet()) { + checkCfg.addProperty(entry.getKey(), entry.getValue()); + } + var twCfg = new DefaultConfiguration("TreeWalker"); + twCfg.addChild(checkCfg); + var rootCfg = new DefaultConfiguration("Checker"); + rootCfg.addChild(twCfg); + + var checker = new Checker(); + checker.setModuleClassLoader(getClass().getClassLoader()); + checker.configure(rootCfg); + + var listener = new CapturingListener(); + checker.addListener(listener); + + var url = getClass().getResource(fixtureResourcePath); + if (url == null) { + throw new IllegalStateException("Fixture not found on classpath: " + fixtureResourcePath); + } + var file = new File(url.toURI()); + checker.process(List.of(file)); + checker.destroy(); + return Collections.unmodifiableList(listener.messages); + } + + static final class CapturingListener implements AuditListener { + final List messages = new ArrayList<>(); + + @Override + public void auditStarted(AuditEvent event) { + } + + @Override + public void auditFinished(AuditEvent event) { + } + + @Override + public void fileStarted(AuditEvent event) { + } + + @Override + public void fileFinished(AuditEvent event) { + } + + @Override + public void addError(AuditEvent event) { + messages.add(event.getLine() + ":" + event.getMessage()); + } + + @Override + public void addException(AuditEvent event, Throwable throwable) { + messages.add("EXCEPTION:" + throwable.getMessage()); + } + } +} diff --git a/src/test/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheckTest.java b/src/test/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheckTest.java new file mode 100644 index 0000000..ffd71e0 --- /dev/null +++ b/src/test/java/it/aboutbits/checkstyle/JspecifyAnnotationOrderCheckTest.java @@ -0,0 +1,65 @@ +package it.aboutbits.checkstyle; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@NullMarked +class JspecifyAnnotationOrderCheckTest extends CheckTestSupport { + + private static final String BASE = "/it/aboutbits/checkstyle/jspecifyAnnotationOrder/"; + + @Test + void jspecifyAnnotationAsLastPasses() throws Exception { + var v = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "GoodLast.java"); + assertEquals(List.of(), v); + } + + @Test + void jspecifyAnnotationFollowedByOtherFailsAndHighlightsCloseAnnotation() throws Exception { + var v = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "BadInMiddle.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().contains(NullMarked.class.getSimpleName()), v.toString()); + assertTrue(v.getFirst().startsWith("6:"), "violation should be reported on the @NullMarked line: " + v); + } + + @Test + void jspecifyAnnotationAsFirstFailsAndHighlightsCloseAnnotation() throws Exception { + var v = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "BadFirst.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().startsWith("5:"), "violation should be reported on the @NullMarked line: " + v); + } + + @Test + void noJspecifyAnnotationDoesNotFire() throws Exception { + var v = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "NoJspecify.java"); + assertEquals(List.of(), v); + } + + @Test + void customCloseAnnotationsArePicked() throws Exception { + var properties = Map.of("closeAnnotations", "Custom,AnotherClose"); + + var ok = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "CustomCloseLast.java", properties); + assertEquals(List.of(), ok); + + var bad = runCheck(JspecifyAnnotationOrderCheck.class, BASE + "CustomCloseInMiddle.java", properties); + assertEquals(1, bad.size()); + assertTrue(bad.getFirst().contains("Custom"), bad.toString()); + } + + @Test + void closeAnnotationsAreTrimmed() throws Exception { + var v = runCheck( + JspecifyAnnotationOrderCheck.class, + BASE + "GoodLast.java", + Map.of("closeAnnotations", " NullMarked , NullUnmarked ") + ); + assertEquals(List.of(), v); + } +} diff --git a/src/test/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheckTest.java b/src/test/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheckTest.java new file mode 100644 index 0000000..a5d169a --- /dev/null +++ b/src/test/java/it/aboutbits/checkstyle/JspecifyInlineTypeUseCheckTest.java @@ -0,0 +1,80 @@ +package it.aboutbits.checkstyle; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@NullMarked +class JspecifyInlineTypeUseCheckTest extends CheckTestSupport { + + private static final String BASE = "/it/aboutbits/checkstyle/jspecifyInlineTypeUse/"; + + @Test + void inlineMethodReturnPasses() throws Exception { + assertEquals(List.of(), runCheck(JspecifyInlineTypeUseCheck.class, BASE + "GoodInlineMethod.java")); + } + + @Test + void inlineFieldPasses() throws Exception { + assertEquals(List.of(), runCheck(JspecifyInlineTypeUseCheck.class, BASE + "GoodInlineField.java")); + } + + @Test + void inlineParameterPasses() throws Exception { + assertEquals(List.of(), runCheck(JspecifyInlineTypeUseCheck.class, BASE + "GoodInlineParameter.java")); + } + + @Test + void inlineLocalPasses() throws Exception { + assertEquals(List.of(), runCheck(JspecifyInlineTypeUseCheck.class, BASE + "GoodInlineLocal.java")); + } + + @Test + void annotationOnLineAboveMethodFails() throws Exception { + var v = runCheck(JspecifyInlineTypeUseCheck.class, BASE + "BadAboveMethod.java"); + assertEquals(1, v.size(), v.toString()); + } + + @Test + void annotationOnLineAboveFieldFails() throws Exception { + var v = runCheck(JspecifyInlineTypeUseCheck.class, BASE + "BadAboveField.java"); + assertEquals(1, v.size(), v.toString()); + } + + @Test + void annotationOnLineAboveParameterFails() throws Exception { + var v = runCheck(JspecifyInlineTypeUseCheck.class, BASE + "BadAboveParameter.java"); + assertEquals(1, v.size(), v.toString()); + } + + @Test + void annotationOnLineAboveLocalFails() throws Exception { + var v = runCheck(JspecifyInlineTypeUseCheck.class, BASE + "BadAboveLocal.java"); + assertEquals(1, v.size(), v.toString()); + } + + @Test + void nonJspecifyNullableImportedFromElsewhereIsIgnored() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyInlineTypeUseCheck.class, BASE + "NonJspecifyNullableAboveFieldIgnored.java") + ); + } + + @Test + void nonJspecifyFullyQualifiedNullableIsIgnored() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyInlineTypeUseCheck.class, BASE + "NonJspecifyFqnNullableAboveFieldIgnored.java") + ); + } + + @Test + void fullyQualifiedJspecifyNullableAboveFieldFails() throws Exception { + var v = runCheck(JspecifyInlineTypeUseCheck.class, BASE + "JspecifyFqnAboveFieldFails.java"); + assertEquals(1, v.size(), v.toString()); + } +} diff --git a/src/test/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheckTest.java b/src/test/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheckTest.java new file mode 100644 index 0000000..75ec938 --- /dev/null +++ b/src/test/java/it/aboutbits/checkstyle/JspecifyMapStructMapperAnnotationCheckTest.java @@ -0,0 +1,113 @@ +package it.aboutbits.checkstyle; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@NullMarked +class JspecifyMapStructMapperAnnotationCheckTest extends CheckTestSupport { + + private static final String BASE = "/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/"; + + @Test + void wellOrderedMapperPasses() throws Exception { + assertEquals(List.of(), runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java")); + } + + @Test + void mapperWithNamedValueArgumentPasses() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapperNamedValue.java") + ); + } + + @Test + void swappedOrderFails() throws Exception { + var v = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "BadOrderSwapped.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().contains("BadOrderSwapped"), v.toString()); + } + + @Test + void missingAnnotateWithFails() throws Exception { + var v = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "BadMissingAnnotateWith.java"); + assertEquals(1, v.size()); + } + + @Test + void annotateWithWrongClassLiteralFails() throws Exception { + var v = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "BadWrongClassLiteral.java"); + assertEquals(1, v.size()); + } + + @Test + void interfaceWithoutMapperIsIgnored() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "NonMapperInterfaceIgnored.java") + ); + } + + @Test + void customMapperAnnotationNameIsHonored() throws Exception { + var properties = Map.of("mapperAnnotationName", "MyMapper"); + + var ok = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "CustomMapperGood.java", properties); + assertEquals(List.of(), ok); + + var bad = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "CustomMapperBad.java", properties); + assertEquals(1, bad.size()); + assertTrue(bad.getFirst().contains("CustomMapperBad"), bad.toString()); + } + + @Test + void customAnnotateWithAnnotationNameIsHonored() throws Exception { + var properties = Map.of("annotateWithAnnotationName", "MyAnnotateWith"); + + var ok = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "CustomAnnotateWithGood.java", properties); + assertEquals(List.of(), ok); + + var bad = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java", properties); + assertEquals(1, bad.size(), bad.toString()); + } + + @Test + void customNullUnmarkedAnnotationNameIsHonored() throws Exception { + var properties = Map.of("nullUnmarkedAnnotationName", "MyUnmarked"); + + var ok = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "CustomNullUnmarkedGood.java", properties); + assertEquals(List.of(), ok); + + var bad = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "GoodMapper.java", properties); + assertEquals(1, bad.size(), bad.toString()); + } + + @Test + void wellOrderedAbstractClassMapperPasses() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "GoodAbstractMapper.java") + ); + } + + @Test + void abstractClassMapperWithSwappedOrderFails() throws Exception { + var v = runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "BadAbstractMapperOrderSwapped.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().contains("BadAbstractMapperOrderSwapped"), v.toString()); + } + + @Test + void nonAbstractClassWithMapperAnnotationIsIgnored() throws Exception { + assertEquals( + List.of(), + runCheck(JspecifyMapStructMapperAnnotationCheck.class, BASE + "NonAbstractClassWithMapperAnnotationIgnored.java") + ); + } +} diff --git a/src/test/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheckTest.java b/src/test/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheckTest.java new file mode 100644 index 0000000..3f70a6c --- /dev/null +++ b/src/test/java/it/aboutbits/checkstyle/JspecifyOnTopLevelTypesCheckTest.java @@ -0,0 +1,59 @@ +package it.aboutbits.checkstyle; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@NullMarked +class JspecifyOnTopLevelTypesCheckTest extends CheckTestSupport { + + private static final String BASE = "/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/"; + + @Test + void classMarkedWithNullMarkedPasses() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "GoodMarked.java"); + assertEquals(List.of(), v); + } + + @Test + void classMarkedWithNullUnmarkedPasses() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "GoodUnmarked.java"); + assertEquals(List.of(), v); + } + + @Test + void fullyQualifiedJspecifyAnnotationPasses() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "GoodFullyQualified.java"); + assertEquals(List.of(), v); + } + + @Test + void classWithoutJspecifyAnnotationFails() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "BadMissing.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().contains("BadMissing"), v.toString()); + } + + @Test + void annotationDeclarationIsExempt() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "AnnotationDefExempt.java"); + assertEquals(List.of(), v); + } + + @Test + void nestedClassIsNotChecked() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "NestedClassOnly.java"); + assertEquals(List.of(), v); + } + + @Test + void recordWithoutJspecifyFails() throws Exception { + var v = runCheck(JspecifyOnTopLevelTypesCheck.class, BASE + "BadRecord.java"); + assertEquals(1, v.size()); + assertTrue(v.getFirst().contains("BadRecord"), v.toString()); + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadFirst.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadFirst.java new file mode 100644 index 0000000..2043b47 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadFirst.java @@ -0,0 +1,8 @@ +package fixtures.r2; + +import org.jspecify.annotations.NullMarked; + +@NullMarked +@SuppressWarnings("foo") +public class BadFirst { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadInMiddle.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadInMiddle.java new file mode 100644 index 0000000..144e4ae --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/BadInMiddle.java @@ -0,0 +1,9 @@ +package fixtures.r2; + +import org.jspecify.annotations.NullMarked; + +@SuppressWarnings("foo") +@NullMarked +@Deprecated +public class BadInMiddle { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseInMiddle.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseInMiddle.java new file mode 100644 index 0000000..d17621e --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseInMiddle.java @@ -0,0 +1,6 @@ +package fixtures.r2; + +@Custom +@Deprecated +public class CustomCloseInMiddle { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseLast.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseLast.java new file mode 100644 index 0000000..9c46735 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/CustomCloseLast.java @@ -0,0 +1,6 @@ +package fixtures.r2; + +@Deprecated +@Custom +public class CustomCloseLast { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/GoodLast.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/GoodLast.java new file mode 100644 index 0000000..170426b --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/GoodLast.java @@ -0,0 +1,9 @@ +package fixtures.r2; + +import org.jspecify.annotations.NullMarked; + +@SuppressWarnings("foo") +@Deprecated +@NullMarked +public class GoodLast { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/NoJspecify.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/NoJspecify.java new file mode 100644 index 0000000..acf7962 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyAnnotationOrder/NoJspecify.java @@ -0,0 +1,6 @@ +package fixtures.r2; + +@SuppressWarnings("foo") +@Deprecated +public class NoJspecify { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveField.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveField.java new file mode 100644 index 0000000..8aa136e --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveField.java @@ -0,0 +1,8 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class BadAboveField { + @Nullable + private String name; +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveLocal.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveLocal.java new file mode 100644 index 0000000..bb07f2c --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveLocal.java @@ -0,0 +1,10 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class BadAboveLocal { + public void baz() { + @Nullable + String s = null; + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveMethod.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveMethod.java new file mode 100644 index 0000000..70e2d91 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveMethod.java @@ -0,0 +1,10 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class BadAboveMethod { + @Nullable + public String foo() { + return null; + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveParameter.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveParameter.java new file mode 100644 index 0000000..8ce01bd --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/BadAboveParameter.java @@ -0,0 +1,11 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class BadAboveParameter { + public void bar( + @Nullable + String s + ) { + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineField.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineField.java new file mode 100644 index 0000000..1e7cf84 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineField.java @@ -0,0 +1,7 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class GoodInlineField { + private @Nullable String name; +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineLocal.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineLocal.java new file mode 100644 index 0000000..d479149 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineLocal.java @@ -0,0 +1,9 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class GoodInlineLocal { + public void baz() { + @Nullable String s = null; + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineMethod.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineMethod.java new file mode 100644 index 0000000..fd4d521 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineMethod.java @@ -0,0 +1,9 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class GoodInlineMethod { + public @Nullable String foo() { + return null; + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineParameter.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineParameter.java new file mode 100644 index 0000000..498438b --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/GoodInlineParameter.java @@ -0,0 +1,8 @@ +package fixtures.r3; + +import org.jspecify.annotations.Nullable; + +public class GoodInlineParameter { + public void bar(@Nullable String s) { + } +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/JspecifyFqnAboveFieldFails.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/JspecifyFqnAboveFieldFails.java new file mode 100644 index 0000000..6bd2e0b --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/JspecifyFqnAboveFieldFails.java @@ -0,0 +1,6 @@ +package fixtures.r3; + +public class JspecifyFqnAboveFieldFails { + @org.jspecify.annotations.Nullable + private String name; +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyFqnNullableAboveFieldIgnored.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyFqnNullableAboveFieldIgnored.java new file mode 100644 index 0000000..d80cb01 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyFqnNullableAboveFieldIgnored.java @@ -0,0 +1,6 @@ +package fixtures.r3; + +public class NonJspecifyFqnNullableAboveFieldIgnored { + @org.jetbrains.annotations.Nullable + private String name; +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyNullableAboveFieldIgnored.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyNullableAboveFieldIgnored.java new file mode 100644 index 0000000..4f950ad --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyInlineTypeUse/NonJspecifyNullableAboveFieldIgnored.java @@ -0,0 +1,8 @@ +package fixtures.r3; + +import org.jetbrains.annotations.Nullable; + +public class NonJspecifyNullableAboveFieldIgnored { + @Nullable + private String name; +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadAbstractMapperOrderSwapped.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadAbstractMapperOrderSwapped.java new file mode 100644 index 0000000..3e30986 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadAbstractMapperOrderSwapped.java @@ -0,0 +1,11 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@NullUnmarked +@AnnotateWith(NullUnmarked.class) +public abstract class BadAbstractMapperOrderSwapped { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadMissingAnnotateWith.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadMissingAnnotateWith.java new file mode 100644 index 0000000..b5aab6f --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadMissingAnnotateWith.java @@ -0,0 +1,9 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.Mapper; + +@Mapper +@NullUnmarked +public interface BadMissingAnnotateWith { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadOrderSwapped.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadOrderSwapped.java new file mode 100644 index 0000000..d88ea64 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadOrderSwapped.java @@ -0,0 +1,11 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@NullUnmarked +@AnnotateWith(NullUnmarked.class) +public interface BadOrderSwapped { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadWrongClassLiteral.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadWrongClassLiteral.java new file mode 100644 index 0000000..7b6e3ac --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/BadWrongClassLiteral.java @@ -0,0 +1,12 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith(NullMarked.class) +@NullUnmarked +public interface BadWrongClassLiteral { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomAnnotateWithGood.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomAnnotateWithGood.java new file mode 100644 index 0000000..b7e1691 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomAnnotateWithGood.java @@ -0,0 +1,10 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.Mapper; + +@Mapper +@MyAnnotateWith(NullUnmarked.class) +@NullUnmarked +public interface CustomAnnotateWithGood { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperBad.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperBad.java new file mode 100644 index 0000000..18d0c4a --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperBad.java @@ -0,0 +1,10 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; + +@MyMapper +@NullUnmarked +@AnnotateWith(NullUnmarked.class) +public interface CustomMapperBad { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperGood.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperGood.java new file mode 100644 index 0000000..c4bd321 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomMapperGood.java @@ -0,0 +1,10 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; + +@MyMapper +@AnnotateWith(NullUnmarked.class) +@NullUnmarked +public interface CustomMapperGood { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomNullUnmarkedGood.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomNullUnmarkedGood.java new file mode 100644 index 0000000..127ef93 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/CustomNullUnmarkedGood.java @@ -0,0 +1,10 @@ +package fixtures.r4; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith(MyUnmarked.class) +@MyUnmarked +public interface CustomNullUnmarkedGood { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodAbstractMapper.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodAbstractMapper.java new file mode 100644 index 0000000..900d945 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodAbstractMapper.java @@ -0,0 +1,11 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith(NullUnmarked.class) +@NullUnmarked +public abstract class GoodAbstractMapper { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapper.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapper.java new file mode 100644 index 0000000..5ebf772 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapper.java @@ -0,0 +1,11 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith(NullUnmarked.class) +@NullUnmarked +public interface GoodMapper { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapperNamedValue.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapperNamedValue.java new file mode 100644 index 0000000..9c9da8e --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/GoodMapperNamedValue.java @@ -0,0 +1,11 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullUnmarked; +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith(value = NullUnmarked.class) +@NullUnmarked +public interface GoodMapperNamedValue { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonAbstractClassWithMapperAnnotationIgnored.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonAbstractClassWithMapperAnnotationIgnored.java new file mode 100644 index 0000000..ffbe622 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonAbstractClassWithMapperAnnotationIgnored.java @@ -0,0 +1,7 @@ +package fixtures.r4; + +import org.mapstruct.Mapper; + +@Mapper +public class NonAbstractClassWithMapperAnnotationIgnored { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonMapperInterfaceIgnored.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonMapperInterfaceIgnored.java new file mode 100644 index 0000000..96b75f4 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyMapStructMapperAnnotation/NonMapperInterfaceIgnored.java @@ -0,0 +1,8 @@ +package fixtures.r4; + +import org.jspecify.annotations.NullMarked; + +@NullMarked +public interface NonMapperInterfaceIgnored { + String greet(); +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/AnnotationDefExempt.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/AnnotationDefExempt.java new file mode 100644 index 0000000..81baf6e --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/AnnotationDefExempt.java @@ -0,0 +1,4 @@ +package fixtures.r1; + +public @interface AnnotationDefExempt { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadMissing.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadMissing.java new file mode 100644 index 0000000..ab36582 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadMissing.java @@ -0,0 +1,4 @@ +package fixtures.r1; + +public class BadMissing { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadRecord.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadRecord.java new file mode 100644 index 0000000..f9794bd --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/BadRecord.java @@ -0,0 +1,4 @@ +package fixtures.r1; + +public record BadRecord(String name) { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodFullyQualified.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodFullyQualified.java new file mode 100644 index 0000000..6a4ea06 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodFullyQualified.java @@ -0,0 +1,5 @@ +package fixtures.r1; + +@org.jspecify.annotations.NullMarked +public class GoodFullyQualified { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodMarked.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodMarked.java new file mode 100644 index 0000000..824651f --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodMarked.java @@ -0,0 +1,7 @@ +package fixtures.r1; + +import org.jspecify.annotations.NullMarked; + +@NullMarked +public class GoodMarked { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodUnmarked.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodUnmarked.java new file mode 100644 index 0000000..1c75e6c --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/GoodUnmarked.java @@ -0,0 +1,7 @@ +package fixtures.r1; + +import org.jspecify.annotations.NullUnmarked; + +@NullUnmarked +public class GoodUnmarked { +} diff --git a/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/NestedClassOnly.java b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/NestedClassOnly.java new file mode 100644 index 0000000..a8fc2b9 --- /dev/null +++ b/src/test/resources/it/aboutbits/checkstyle/jspecifyOnTopLevelTypes/NestedClassOnly.java @@ -0,0 +1,9 @@ +package fixtures.r1; + +import org.jspecify.annotations.NullMarked; + +@NullMarked +public class NestedClassOnly { + public static class Inner { + } +}