Skip to content

Commit

Permalink
Make a local release of the reference checker (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Povirk <[email protected]>
  • Loading branch information
wmdietl and cpovirk authored Jul 25, 2024
1 parent 36855b8 commit af9dfbc
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 3 deletions.
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:jspecify/jspecify-reference-checker.git'
developerConnection = 'scm:git:[email protected]:jspecify/jspecify-reference-checker.git'
url = 'https://github.com/jspecify/jspecify-reference-checker'
}
developers {
developer {
id = 'cpovirk'
name = 'Chris Povirk'
email = '[email protected]'
}
developer {
id = 'netdpb'
name = 'David P. Baker'
email = '[email protected]'
}
developer {
id = 'wmdietl'
name = 'Werner M. Dietl'
email = '[email protected]'
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion demo
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions usage-demo/README.md
Original file line number Diff line number Diff line change
@@ -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).
70 changes: 70 additions & 0 deletions usage-demo/build.gradle
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 2 additions & 0 deletions usage-demo/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Project name is read-only in build scripts, and defaults to directory name.
rootProject.name = "jspecify-reference-checker-usage-demo"
26 changes: 26 additions & 0 deletions usage-demo/src/main/java/demo/Demo.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit af9dfbc

Please sign in to comment.