diff --git a/build.gradle b/build.gradle index 9068707..2dede81 100644 --- a/build.gradle +++ b/build.gradle @@ -333,3 +333,47 @@ eclipse.classpath { } } } + +publishing { + publications { + jspecifyReferenceChecker(MavenPublication) { + pom { + groupId = 'org.jspecify.reference' + artifactId = 'checker' + version = project.version + name = 'JSpecify Reference Checker' + description = 'The JSpecify Reference Checker' + url = 'http://jspecify.org/' + from components.java + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + scm { + connection = 'scm:git:git@github.com:jspecify/jspecify-reference-checker.git' + developerConnection = 'scm:git:git@github.com:jspecify/jspecify-reference-checker.git' + url = 'https://github.com/jspecify/jspecify-reference-checker' + } + developers { + developer { + id = 'cpovirk' + name = 'Chris Povirk' + email = 'cpovirk@google.com' + } + developer { + id = 'netdpb' + name = 'David P. Baker' + email = 'dpb@google.com' + } + developer { + id = 'wmdietl' + name = 'Werner M. Dietl' + email = 'wdietl@gmail.com' + } + } + } + } + } +} diff --git a/demo b/demo index 00b47c9..0e2ae5f 100755 --- a/demo +++ b/demo @@ -6,7 +6,7 @@ dir=$(dirname $0) jspecify="${dir}/../jspecify/build/libs/jspecify-0.0.0-SNAPSHOT.jar" if [ ! -e "${jspecify}" ]; then - version=0.3.0 + version=1.0.0 jspecify="${dir}/build/jspecify-${version}.jar" if [ ! -e "${jspecify}" ]; then echo "Downloading $(basename "${jspecify}") from Maven central" diff --git a/docs/development.md b/docs/development.md index 82d6602..74fb3d2 100644 --- a/docs/development.md +++ b/docs/development.md @@ -29,7 +29,7 @@ clone the repo (or your fork) somewhere, and pass `--include-build path/to/jspecify` to Gradle when building. The local clone will be used for both the annotations and the conformance test suite. -By default the reference checker depends on version `0.3.0` of the annotations, +By default the reference checker depends on version `1.0.0` of the annotations, and version `0.0.0-SNAPSHOT` of the conformance test suite. In order to depend on a different published version of either artifact, set diff --git a/gradle.properties b/gradle.properties index 412032d..7315fa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -org.jspecify\:jspecify=0.3.0 +org.jspecify\:jspecify=1.0.0 org.jspecify.conformance\:conformance-test-framework=0.0.0-SNAPSHOT org.jspecify.conformance\:conformance-tests=0.0.0-SNAPSHOT diff --git a/usage-demo/README.md b/usage-demo/README.md new file mode 100644 index 0000000..3aaf223 --- /dev/null +++ b/usage-demo/README.md @@ -0,0 +1,21 @@ +# JSpecify Reference Checker Usage Demo + +This is a simple demonstration for how a gradle project can use the JSpecify Reference Checker. + +Until the JSpecify Reference Checker is released to Maven Central, in the parent directory, +one must first run: + +```` +./gradlew PublishToMavenLocal +```` + +to publish the JSpecify Reference Checker to the local Maven repository. + +Then, in the current `usage-demo` directory, one can run: + +```` +../gradlew assemble +```` + +to assemble the demo project and get a set of three expected error messages +(plus one warning from Error Prone). diff --git a/usage-demo/build.gradle b/usage-demo/build.gradle new file mode 100644 index 0000000..3d99f03 --- /dev/null +++ b/usage-demo/build.gradle @@ -0,0 +1,70 @@ +// EISOP Checker Framework and JSpecify Reference Checker example. + +plugins { + id 'java' + id 'com.diffplug.spotless' version '6.25.0' + id 'net.ltgt.errorprone' version '3.1.0' + id 'org.checkerframework' version '0.6.42' apply false +} + +ext { + versions = [ + eisopVersion: '3.42.0-eisop4', + jspecifyVersion: '1.0.0', + jspecifyReferenceCheckerVersion: '0.0.0-SNAPSHOT' + ] +} + +repositories { + mavenLocal() + mavenCentral() +} + +// Project dependencies, e.g. error prone. +dependencies { + errorprone 'com.google.errorprone:error_prone_core:2.23.0' +} + +// Dependency on JSpecify annotations. +dependencies { + implementation "org.jspecify:jspecify:${versions.jspecifyVersion}" +} + + +apply plugin: 'org.checkerframework' + +// Configure EISOP and JSpecify Reference Checker +dependencies { + compileOnly "io.github.eisop:checker-qual:${versions.eisopVersion}" + testCompileOnly "io.github.eisop:checker-qual:${versions.eisopVersion}" + checkerFramework "io.github.eisop:checker:${versions.eisopVersion}" + + compileOnly "org.jspecify.reference:checker:${versions.jspecifyReferenceCheckerVersion}" + checkerFramework "org.jspecify.reference:checker:${versions.jspecifyReferenceCheckerVersion}" +} + +checkerFramework { + checkers = [ + 'com.google.jspecify.nullness.NullSpecChecker', + ] + extraJavacArgs = [ + // Check implementation code, i.e. method bodies. + '-AcheckImpl', + // Output the EISOP version, to ensure configuration is correct. + '-Aversion' + ] +} + +spotless { + java { + target '**/*.java' + googleJavaFormat() + formatAnnotations() + } + groovyGradle { + target '**/*.gradle' + greclipse() + indentWithSpaces(4) + trimTrailingWhitespace() + } +} diff --git a/usage-demo/settings.gradle b/usage-demo/settings.gradle new file mode 100644 index 0000000..a632f3b --- /dev/null +++ b/usage-demo/settings.gradle @@ -0,0 +1,2 @@ +// Project name is read-only in build scripts, and defaults to directory name. +rootProject.name = "jspecify-reference-checker-usage-demo" diff --git a/usage-demo/src/main/java/demo/Demo.java b/usage-demo/src/main/java/demo/Demo.java new file mode 100644 index 0000000..8f57b85 --- /dev/null +++ b/usage-demo/src/main/java/demo/Demo.java @@ -0,0 +1,26 @@ +package demo; + +import java.lang.reflect.Method; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +@NullMarked +class Demo { + // Error about usage on primitive, also a warning from Error Prone. + void conflict(@Nullable int i) {} + + Object incompatible(@Nullable Object in) { + // Error about incompatible return. + return in; + } + + String deref(@Nullable Object in) { + // Error about dereference of nullable reference. + return in.toString(); + } + + void jdkDemo(Method m) throws Exception { + // Demo to ensure the jspecify/jdk is used. No error expected. eisop/jdk would give an error. + m.invoke(null); + } +}