Skip to content

Commit b4b272b

Browse files
haewifulmsridharcoderabbitai[bot]
authored
Generate astubx from JSON output of jdk-javac-plugin (#1243)
This support will be used to generate an astubx JDK model from the JSpecify annotated JDK. Includes extensive unit testing and integration testing of the support. We will likely need to add more features as we try to support all the annotations present in the JDK (on wildcards, etc.). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an ASTUBX generator and CLI to produce .astubx bundles capturing method return-type and nullability metadata; added annotated and unannotated test libraries and a service provider to supply generated stubx files. - **Chores** - Integrated .astubx generation into the build lifecycle, added new modules, migrated projects to Java 21 toolchains, and updated formatting guard to exclude the jdk-annotations module. - **Tests** - Added unit and integration tests validating JDK/JSPECIFY nullability scenarios and end-to-end .astubx generation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Manu Sridharan <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 7e2a06f commit b4b272b

File tree

20 files changed

+1595
-18
lines changed

20 files changed

+1595
-18
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ subprojects { project ->
114114

115115
// Spotless complains when applied to the folders containing projects
116116
// when they do not have a build.gradle file
117-
if (project.name != "jar-infer" && project.name != "library-model") {
117+
if (project.name != "jar-infer" && project.name != "library-model" && project.name != "jdk-annotations") {
118118
project.apply plugin: "com.diffplug.spotless"
119119
spotless {
120120
java {

code-coverage-report/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@ dependencies {
8383
implementation project(':library-model:library-model-generator')
8484
implementation project(':library-model:library-model-generator-integration-test')
8585
implementation project(':jdk-javac-plugin')
86+
implementation project(':jdk-annotations:astubx-generator')
87+
implementation project(':jdk-annotations:jdk-integration-test')
8688
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
plugins {
2+
id "java-library"
3+
id "com.gradleup.shadow"
4+
}
5+
6+
java {
7+
toolchain {
8+
languageVersion = JavaLanguageVersion.of(21)
9+
}
10+
}
11+
12+
// Allow Java 21 features for this module
13+
tasks.withType(JavaCompile).configureEach {
14+
sourceCompatibility = JavaVersion.VERSION_21
15+
targetCompatibility = JavaVersion.VERSION_21
16+
}
17+
18+
19+
jar{
20+
manifest {
21+
attributes('Main-Class':'com.uber.nullaway.jdkannotations.AstubxGeneratorCLI')
22+
}
23+
// add this classifier so that the output file for the jar task differs from
24+
// the output file for the shadowJar task (otherwise they overwrite each other's
25+
// outputs, forcing the tasks to always re-run)
26+
archiveClassifier = "nonshadow"
27+
}
28+
29+
shadowJar {
30+
mergeServiceFiles()
31+
configurations = [
32+
project.configurations.runtimeClasspath
33+
]
34+
archiveClassifier = ""
35+
}
36+
shadowJar.dependsOn jar
37+
assemble.dependsOn shadowJar
38+
39+
dependencies {
40+
implementation project(":jdk-annotations:astubx-generator")
41+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.uber.nullaway.jdkannotations;
2+
3+
public class AstubxGeneratorCLI {
4+
public static void main(String[] args) {
5+
if (args.length != 2) {
6+
System.err.println("Invalid number of arguments. Required: <inputPath> <outputPath>");
7+
System.exit(2);
8+
}
9+
AstubxGenerator.generateAstubx(args[0], args[1]);
10+
}
11+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id "java-library"
3+
id 'nullaway.java-test-conventions'
4+
}
5+
6+
// Require JDK 21, since the jdk-javac-plugin requires it
7+
java {
8+
toolchain {
9+
languageVersion = JavaLanguageVersion.of(21)
10+
}
11+
}
12+
13+
// Allow Java 21 features for this module
14+
tasks.withType(JavaCompile).configureEach {
15+
sourceCompatibility = JavaVersion.VERSION_21
16+
targetCompatibility = JavaVersion.VERSION_21
17+
}
18+
19+
// Don't test on JDK 17; we require JDK 21
20+
tasks.named("testJdk17").configure {
21+
onlyIf { false }
22+
}
23+
24+
tasks.withType(Test).configureEach { test ->
25+
// Ensure the plugin JAR exists
26+
dependsOn(":jdk-javac-plugin:shadowJar")
27+
}
28+
29+
dependencies {
30+
implementation project(":library-model:library-model-generator")
31+
implementation project(":jdk-javac-plugin")
32+
implementation deps.build.gson
33+
implementation deps.build.guava
34+
35+
testImplementation deps.test.junit4
36+
testImplementation deps.build.jspecify
37+
testImplementation(deps.build.errorProneTestHelpers) {
38+
exclude group: "junit", module: "junit"
39+
}
40+
}

0 commit comments

Comments
 (0)