diff --git a/docs/jte-jspecify-nullmarked.md b/docs/jte-jspecify-nullmarked.md new file mode 100644 index 000000000..c79aae915 --- /dev/null +++ b/docs/jte-jspecify-nullmarked.md @@ -0,0 +1,114 @@ +--- +title: jte-jspecify-nullmarked NullMarked annotation generator +description: A generator extension for jte that adds @NullMarked package annotations to generated classes. +--- + +# jte-jspecify-nullmarked NullMarked Annotation Generator + +jte-jspecify-nullmarked is a generator extension for jte that creates `package-info.java` files annotated +with `@NullMarked` for each package containing generated classes. This enables null-safety tooling +(such as NullAway or ErrorProne) to treat generated classes as null-safe, preventing build failures +in projects that enforce null-safety annotations. + +## Setup + +Add `jspecify` 1.0.0 or later to your project dependencies, then configure the build plugin to use the extension. + +=== "Maven" + + Add to your `` section: + + ```xml linenums="1" + + org.jspecify + jspecify + 1.0.0 + + ``` + + Add to your `` section: + + ```xml linenums="1" + + gg.jte + jte-maven-plugin + ${jte.version} + + ${project.basedir}/src/main/jte + Html + + + gg.jte.jspecify.NullMarkedExtension + + + + + + generate-sources + + generate + + + + + + gg.jte + jte-jspecify-nullmarked + ${jte.version} + + + + ``` + +=== "Gradle (Groovy DSL)" + + ```groovy linenums="1" + plugins { + id 'gg.jte.gradle' version '${jte.version}' + } + + dependencies { + implementation 'gg.jte:jte-runtime:${jte.version}' + implementation 'org.jspecify:jspecify:1.0.0' + jteGenerate 'gg.jte:jte-jspecify-nullmarked:${jte.version}' + } + + jte { + generate() + jteExtension 'gg.jte.jspecify.NullMarkedExtension' + } + ``` + +=== "Gradle (Kotlin DSL)" + + ```kotlin linenums="1" + plugins { + id("gg.jte.gradle") version "${jte.version}" + } + + dependencies { + implementation("gg.jte:jte-runtime:${jte.version}") + implementation("org.jspecify:jspecify:1.0.0") + jteGenerate("gg.jte:jte-jspecify-nullmarked:${jte.version}") + } + + jte { + generate() + jteExtension("gg.jte.jspecify.NullMarkedExtension") + } + ``` + +Run the build to generate classes. + +## Output + +For each package containing generated classes, a `package-info.java` file is created: + +```java +@NullMarked +package gg.jte.generated.precompiled; + +import org.jspecify.annotations.NullMarked; +``` + +If a `package-info.java` already exists in a package directory, it is left unchanged. diff --git a/jte-jspecify-nullmarked/README.md b/jte-jspecify-nullmarked/README.md new file mode 100644 index 000000000..a71b2581f --- /dev/null +++ b/jte-jspecify-nullmarked/README.md @@ -0,0 +1,3 @@ +# jte-nullmarked + +See official docs: . diff --git a/jte-jspecify-nullmarked/pom.xml b/jte-jspecify-nullmarked/pom.xml new file mode 100644 index 000000000..ba5eb1d65 --- /dev/null +++ b/jte-jspecify-nullmarked/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + gg.jte + jte-parent + 3.2.5-SNAPSHOT + + + jte-jspecify-nullmarked + jte-jspecify-nullmarked + jar + + + gg.jte + jte-extension-api + 3.2.5-SNAPSHOT + compile + + + gg.jte + jte-extension-api-mocks + 3.2.5-SNAPSHOT + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + gg.jte.jspecify.nullmarked + + + + + + + + diff --git a/jte-jspecify-nullmarked/src/main/java/gg/jte/jspecify/NullMarkedExtension.java b/jte-jspecify-nullmarked/src/main/java/gg/jte/jspecify/NullMarkedExtension.java new file mode 100644 index 000000000..4eed9fa36 --- /dev/null +++ b/jte-jspecify-nullmarked/src/main/java/gg/jte/jspecify/NullMarkedExtension.java @@ -0,0 +1,52 @@ +package gg.jte.jspecify; + +import gg.jte.extension.api.JteConfig; +import gg.jte.extension.api.JteExtension; +import gg.jte.extension.api.TemplateDescription; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; +import java.util.stream.Collectors; + +@SuppressWarnings("unused") +public class NullMarkedExtension implements JteExtension { + + @Override + public String name() { + return "NullMarked package-info generator"; + } + + @Override + public Collection generate(JteConfig config, Set templateDescriptions) { + if (config.generatedSourcesRoot() == null || templateDescriptions.isEmpty()) { + return Collections.emptyList(); + } + + return templateDescriptions.stream() + .map(TemplateDescription::packageName) + .distinct() + .map(pkg -> writePackageInfo(config.generatedSourcesRoot(), pkg)) + .collect(Collectors.toList()); + } + + private Path writePackageInfo(Path sourcesRoot, String packageName) { + Path packageDir = sourcesRoot.resolve(packageName.replace('.', '/')); + Path file = packageDir.resolve("package-info.java"); + if (Files.exists(file)) { + return file; + } + try { + Files.createDirectories(packageDir); + Files.writeString(file, + "@NullMarked\npackage " + packageName + ";\n\nimport org.jspecify.annotations.NullMarked;\n"); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return file; + } +} diff --git a/jte-jspecify-nullmarked/src/test/java/gg/jte/jspecify/NullMarkedExtensionTest.java b/jte-jspecify-nullmarked/src/test/java/gg/jte/jspecify/NullMarkedExtensionTest.java new file mode 100644 index 000000000..5ab2a02d6 --- /dev/null +++ b/jte-jspecify-nullmarked/src/test/java/gg/jte/jspecify/NullMarkedExtensionTest.java @@ -0,0 +1,94 @@ +package gg.jte.jspecify; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Set; + +import static gg.jte.extension.api.mocks.MockConfig.mockConfig; +import static gg.jte.extension.api.mocks.MockTemplateDescription.mockTemplateDescription; +import static org.assertj.core.api.Assertions.assertThat; + +class NullMarkedExtensionTest { + + private final NullMarkedExtension extension = new NullMarkedExtension(); + + @TempDir + Path tempDir; + + @Test + void singlePackage() throws IOException { + var config = mockConfig().generatedSourcesRoot(tempDir).packageName("com.example"); + var template = mockTemplateDescription().packageName("com.example").className("JtefooGenerated").name("foo.jte"); + + Collection result = extension.generate(config, Set.of(template)); + + assertThat(result).hasSize(1); + Path packageInfo = tempDir.resolve("com/example/package-info.java"); + assertThat(packageInfo).exists(); + assertThat(Files.readString(packageInfo)).isEqualTo( + "@NullMarked\npackage com.example;\n\nimport org.jspecify.annotations.NullMarked;\n"); + } + + @Test + void multipleTemplatesSamePackage() { + var config = mockConfig().generatedSourcesRoot(tempDir).packageName("com.example"); + var t1 = mockTemplateDescription().packageName("com.example").className("JtefooGenerated").name("foo.jte"); + var t2 = mockTemplateDescription().packageName("com.example").className("JtebarGenerated").name("bar.jte"); + + Collection result = extension.generate(config, Set.of(t1, t2)); + + assertThat(result).hasSize(1); + assertThat(tempDir.resolve("com/example/package-info.java")).exists(); + } + + @Test + void multiplePackages() { + var config = mockConfig().generatedSourcesRoot(tempDir).packageName("com.example"); + var t1 = mockTemplateDescription().packageName("com.example").className("JtefooGenerated").name("foo.jte"); + var t2 = mockTemplateDescription().packageName("com.example.sub").className("JtebarGenerated").name("sub/bar.jte"); + + Collection result = extension.generate(config, Set.of(t1, t2)); + + assertThat(result).hasSize(2); + assertThat(tempDir.resolve("com/example/package-info.java")).exists(); + assertThat(tempDir.resolve("com/example/sub/package-info.java")).exists(); + } + + @Test + void existingPackageInfoIsNotOverwritten() throws IOException { + var config = mockConfig().generatedSourcesRoot(tempDir).packageName("com.example"); + var template = mockTemplateDescription().packageName("com.example").className("JtefooGenerated").name("foo.jte"); + Path packageDir = tempDir.resolve("com/example"); + Files.createDirectories(packageDir); + Path existing = packageDir.resolve("package-info.java"); + Files.writeString(existing, "// existing content\n"); + + extension.generate(config, Set.of(template)); + + assertThat(Files.readString(existing)).isEqualTo("// existing content\n"); + } + + @Test + void emptyTemplates() { + var config = mockConfig().generatedSourcesRoot(tempDir).packageName("com.example"); + + Collection result = extension.generate(config, Set.of()); + + assertThat(result).isEmpty(); + } + + @Test + void nullSourcesRoot() { + var config = mockConfig().packageName("com.example"); + + Collection result = extension.generate(config, Set.of( + mockTemplateDescription().packageName("com.example").className("JtefooGenerated").name("foo.jte"))); + + assertThat(result).isEmpty(); + } +} diff --git a/mkdocs.yml b/mkdocs.yml index 4d1b72aff..cd8be6263 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -88,6 +88,7 @@ nav: - "Kotlin Templates": kotlin.md - "Extensions": - "jte-models Facade Generator": jte-models.md + - "jte-jspecify-nullmarked NullMarked Annotation Generator": jte-jspecify-nullmarked.md - "Extensions API": jte-extension-api.md - "Spring Boot Support": - "Spring Boot Starter 4": spring-boot-starter-4.md diff --git a/pom.xml b/pom.xml index 03734d451..15af14adc 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ jte-extension-api jte-extension-api-mocks jte-native-resources + jte-jspecify-nullmarked jte-models jte-watcher jte-maven-plugin @@ -64,6 +65,7 @@ test/jte-hotreload-test test/jte-test-report test/jte-runtime-cp-test-models + test/jte-runtime-cp-test-nullmarked jte-deploy-nexus diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/build.gradle b/test/jte-runtime-cp-test-nullmarked-gradle/build.gradle new file mode 100644 index 000000000..e29c0e8c6 --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java' + id 'gg.jte.gradle' version '3.2.5-SNAPSHOT' +} + +repositories { + mavenCentral() + mavenLocal() +} + +group = 'gg.jte.testgroup' + +test { + useJUnitPlatform() +} + +dependencies { + implementation('gg.jte:jte-runtime:3.2.5-SNAPSHOT') + implementation('org.jspecify:jspecify:1.0.0') + testImplementation('org.junit.jupiter:junit-jupiter:5.9.0') + testImplementation('org.assertj:assertj-core:3.27.7') + testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.9.0') + jteGenerate('gg.jte:jte-jspecify-nullmarked:3.2.5-SNAPSHOT') +} + +jte { + generate() + jteExtension('gg.jte.jspecify.NullMarkedExtension') +} diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.jar b/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..ccebba771 Binary files /dev/null and b/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.properties b/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..fc10b601f --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/gradlew b/test/jte-runtime-cp-test-nullmarked-gradle/gradlew new file mode 100755 index 000000000..79a61d421 --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed 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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/gradlew.bat b/test/jte-runtime-cp-test-nullmarked-gradle/gradlew.bat new file mode 100644 index 000000000..93e3f59f1 --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem 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, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/settings.gradle b/test/jte-runtime-cp-test-nullmarked-gradle/settings.gradle new file mode 100644 index 000000000..e72c0c2f9 --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + gradlePluginPortal() + } +} + +buildCache { + local { + directory "${System.getProperty("test.build.cache.dir")}" + } +} diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/helloWorld.jte b/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/helloWorld.jte new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/helloWorld.jte @@ -0,0 +1 @@ +Hello World diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/tag/hello.jte b/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/tag/hello.jte new file mode 100644 index 000000000..462947c7c --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/src/main/jte/tag/hello.jte @@ -0,0 +1,2 @@ +@param String name +Hello ${name}! diff --git a/test/jte-runtime-cp-test-nullmarked-gradle/src/test/java/gg/jte/NullMarkedTest.java b/test/jte-runtime-cp-test-nullmarked-gradle/src/test/java/gg/jte/NullMarkedTest.java new file mode 100644 index 000000000..b0bf3d82f --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked-gradle/src/test/java/gg/jte/NullMarkedTest.java @@ -0,0 +1,21 @@ +package gg.jte; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NullMarkedTest { + + @Test + void rootPackageIsNullMarked() throws ClassNotFoundException { + Package pkg = Class.forName("gg.jte.generated.precompiled.JtehelloWorldGenerated").getPackage(); + assertThat(pkg.isAnnotationPresent(NullMarked.class)).isTrue(); + } + + @Test + void tagPackageIsNullMarked() throws ClassNotFoundException { + Package pkg = Class.forName("gg.jte.generated.precompiled.tag.JtehelloGenerated").getPackage(); + assertThat(pkg.isAnnotationPresent(NullMarked.class)).isTrue(); + } +} diff --git a/test/jte-runtime-cp-test-nullmarked/pom.xml b/test/jte-runtime-cp-test-nullmarked/pom.xml new file mode 100644 index 000000000..6a387dc28 --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + gg.jte + jte-runtime-cp-test-nullmarked + 3.2.5-SNAPSHOT + jar + + + UTF-8 + 17 + 17 + 5.9.0 + true + true + + + + + gg.jte + jte-runtime + 3.2.5-SNAPSHOT + + + org.jspecify + jspecify + 1.0.0 + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.assertj + assertj-core + 3.27.7 + test + + + + + + + maven-surefire-plugin + 3.5.3 + + + + gg.jte + jte-maven-plugin + 3.2.5-SNAPSHOT + + ${basedir}/src/main/jte + Html + + + gg.jte.jspecify.NullMarkedExtension + + + + + + generate-sources + + generate + + + + + + gg.jte + jte-jspecify-nullmarked + 3.2.5-SNAPSHOT + + + + + + + diff --git a/test/jte-runtime-cp-test-nullmarked/src/main/jte/helloWorld.jte b/test/jte-runtime-cp-test-nullmarked/src/main/jte/helloWorld.jte new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked/src/main/jte/helloWorld.jte @@ -0,0 +1 @@ +Hello World diff --git a/test/jte-runtime-cp-test-nullmarked/src/main/jte/tag/hello.jte b/test/jte-runtime-cp-test-nullmarked/src/main/jte/tag/hello.jte new file mode 100644 index 000000000..462947c7c --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked/src/main/jte/tag/hello.jte @@ -0,0 +1,2 @@ +@param String name +Hello ${name}! diff --git a/test/jte-runtime-cp-test-nullmarked/src/test/java/gg/jte/NullMarkedTest.java b/test/jte-runtime-cp-test-nullmarked/src/test/java/gg/jte/NullMarkedTest.java new file mode 100644 index 000000000..b0bf3d82f --- /dev/null +++ b/test/jte-runtime-cp-test-nullmarked/src/test/java/gg/jte/NullMarkedTest.java @@ -0,0 +1,21 @@ +package gg.jte; + +import org.jspecify.annotations.NullMarked; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NullMarkedTest { + + @Test + void rootPackageIsNullMarked() throws ClassNotFoundException { + Package pkg = Class.forName("gg.jte.generated.precompiled.JtehelloWorldGenerated").getPackage(); + assertThat(pkg.isAnnotationPresent(NullMarked.class)).isTrue(); + } + + @Test + void tagPackageIsNullMarked() throws ClassNotFoundException { + Package pkg = Class.forName("gg.jte.generated.precompiled.tag.JtehelloGenerated").getPackage(); + assertThat(pkg.isAnnotationPresent(NullMarked.class)).isTrue(); + } +}