Skip to content

Commit 1e93f0e

Browse files
authored
Merge pull request #82 from KyoriPowered/feat/jspecify
feat!(*): Migrate to JSpecify
2 parents 63cccf5 + b4cc4a7 commit 1e93f0e

16 files changed

+93
-77
lines changed

.checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101

102102
<!-- https://checkstyle.org/config_imports.html#IllegalImport -->
103103
<module name="IllegalImport">
104-
<property name="illegalPkgs" value="sun, jdk, com.sun"/>
104+
<property name="illegalPkgs" value="sun, jdk, com.sun, org.jetbrains.annotations"/>
105105
</module>
106106

107107
<!-- https://checkstyle.org/config_coding.html#IllegalTokenText -->

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ indraSonatype {
1717
}
1818

1919
dependencies {
20-
compileOnlyApi libs.jetbrainsAnnotations
20+
compileOnlyApi libs.jetbrainsAnnotations // keep to avoid breaking builds, will be removed for 2.0
21+
compileOnlyApi libs.jspecify
2122
implementation gradleApi()
2223

2324
testImplementation platform(libs.junit.bom)

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
version = "1.0"
2+
format = { version = "1.1" }
33

44
[versions]
55
checkstyle = "10.25.0"
@@ -9,7 +9,8 @@ stylecheck = "0.2.1"
99
errorprone = "2.38.0"
1010

1111
[libraries]
12-
jetbrainsAnnotations = "org.jetbrains:annotations:25.0.0"
12+
jetbrainsAnnotations = { module = "org.jetbrains:annotations", version = "25.0.0" }
13+
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0" }
1314

1415
# test
1516
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }

mammoth-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description = "JUnit extensions for testing Gradle plugins"
33
dependencies {
44
api gradleApi()
55
api gradleTestKit()
6-
compileOnlyApi libs.jetbrainsAnnotations
6+
compileOnlyApi libs.jspecify
77
api platform(libs.junit.bom)
88
api libs.junit.api
99
implementation libs.junit.platformCommons

mammoth-test/src/main/java/net/kyori/mammoth/test/GradleFunctionalTestExtension.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2024 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -36,8 +36,9 @@
3636
import java.util.List;
3737
import java.util.Optional;
3838
import java.util.stream.Stream;
39-
import javax.annotation.Nullable;
4039
import org.gradle.util.GradleVersion;
40+
import org.jspecify.annotations.NullMarked;
41+
import org.jspecify.annotations.Nullable;
4142
import org.junit.jupiter.api.extension.Extension;
4243
import org.junit.jupiter.api.extension.ExtensionContext;
4344
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
@@ -47,6 +48,7 @@
4748
/**
4849
* An extension that can be applied to test methods to provide test template invocation context.
4950
*/
51+
@NullMarked
5052
class GradleFunctionalTestExtension implements TestTemplateInvocationContextProvider {
5153
private static final int CURRENT_JVM;
5254

mammoth-test/src/main/java/net/kyori/mammoth/test/TemplateInvocationExtensions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2022 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -29,13 +29,15 @@
2929
import java.nio.file.Path;
3030
import java.nio.file.SimpleFileVisitor;
3131
import java.nio.file.attribute.BasicFileAttributes;
32+
import org.jspecify.annotations.NullMarked;
3233
import org.junit.jupiter.api.extension.AfterEachCallback;
3334
import org.junit.jupiter.api.extension.ExtensionContext;
3435
import org.junit.jupiter.api.extension.ParameterContext;
3536
import org.junit.jupiter.api.extension.ParameterResolutionException;
3637
import org.junit.jupiter.api.extension.ParameterResolver;
3738

3839
// Template-specific context information
40+
@NullMarked
3941
class TemplateInvocationExtensions implements AfterEachCallback, ParameterResolver {
4042
private final TestContext context;
4143

mammoth-test/src/main/java/net/kyori/mammoth/test/TestContext.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2022 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -37,7 +37,7 @@
3737
import java.util.regex.Pattern;
3838
import org.gradle.testkit.runner.BuildResult;
3939
import org.gradle.testkit.runner.GradleRunner;
40-
import org.jetbrains.annotations.NotNull;
40+
import org.jspecify.annotations.NullMarked;
4141
import org.junit.jupiter.api.Assertions;
4242

4343
import static java.util.Objects.requireNonNull;
@@ -49,6 +49,7 @@
4949
*
5050
* @since 1.1.0
5151
*/
52+
@NullMarked
5253
public final class TestContext {
5354
private static final Pattern LINE_ENDING = Pattern.compile("\r\n");
5455

@@ -78,11 +79,11 @@ public final class TestContext {
7879
* @return the output directory
7980
* @since 1.1.0
8081
*/
81-
public @NotNull Path outputDirectory() {
82+
public Path outputDirectory() {
8283
return this.outputDirectory;
8384
}
8485

85-
@NotNull String gradleVersion() {
86+
String gradleVersion() {
8687
return this.gradleVersion;
8788
}
8889

@@ -93,7 +94,7 @@ public final class TestContext {
9394
* @throws IOException if an error occurs writing the input file to disk
9495
* @since 1.1.0
9596
*/
96-
public void copyInput(final @NotNull String name) throws IOException {
97+
public void copyInput(final String name) throws IOException {
9798
this.copyInput(name, name);
9899
}
99100

@@ -105,7 +106,7 @@ public void copyInput(final @NotNull String name) throws IOException {
105106
* @throws IOException if an error occurs writing the input file to disk
106107
* @since 1.1.0
107108
*/
108-
public void copyInput(final @NotNull String fromName, final @NotNull String toName) throws IOException {
109+
public void copyInput(final String fromName, final String toName) throws IOException {
109110
requireNonNull(fromName, "fromName");
110111
requireNonNull(toName, "toName");
111112
try (final InputStream is = this.resourceBase.getResourceAsStream(this.testName + "/in/" + fromName)) {
@@ -130,7 +131,7 @@ public void copyInput(final @NotNull String fromName, final @NotNull String toNa
130131
* @throws IOException if an error occurs writing the text
131132
* @since 1.2.0
132133
*/
133-
public void writeText(final @NotNull String destination, final @NotNull String text) throws IOException {
134+
public void writeText(final String destination, final String text) throws IOException {
134135
requireNonNull(destination, "destination");
135136
requireNonNull(text, "text");
136137

@@ -149,7 +150,7 @@ public void writeText(final @NotNull String destination, final @NotNull String t
149150
* @throws IOException if thrown while attempting to read the output file
150151
* @since 1.1.0
151152
*/
152-
public @NotNull String readOutput(final @NotNull String fileName) throws IOException {
153+
public String readOutput(final String fileName) throws IOException {
153154
final StringBuilder builder = new StringBuilder();
154155
try (final BufferedReader reader = Files.newBufferedReader(this.outputDirectory.resolve(fileName), StandardCharsets.UTF_8)) {
155156
final char[] buffer = new char[8192];
@@ -169,7 +170,7 @@ public void writeText(final @NotNull String destination, final @NotNull String t
169170
* @throws IOException if an error occurs reading the text
170171
* @since 1.2.0
171172
*/
172-
public void assertOutputEqualsLiteral(final @NotNull String destination, final @NotNull String text) throws IOException {
173+
public void assertOutputEqualsLiteral(final String destination, final String text) throws IOException {
173174
requireNonNull(destination, "destination");
174175
requireNonNull(text, "text");
175176

@@ -188,7 +189,7 @@ public void assertOutputEqualsLiteral(final @NotNull String destination, final @
188189
* @throws IOException if failed to read one of the files
189190
* @since 1.1.0
190191
*/
191-
public void assertOutputEquals(final @NotNull String resourceName, final @NotNull String fileName) throws IOException {
192+
public void assertOutputEquals(final String resourceName, final String fileName) throws IOException {
192193
final String actualOutput = this.readOutput(fileName);
193194

194195
final StringBuilder builder = new StringBuilder();
@@ -215,7 +216,7 @@ public void assertOutputEquals(final @NotNull String resourceName, final @NotNul
215216
* @return the new runner
216217
* @since 1.1.0
217218
*/
218-
public @NotNull GradleRunner runner(final @NotNull String@NotNull... extraArgs) {
219+
public GradleRunner runner(final String... extraArgs) {
219220
final List<String> args = new ArrayList<>(this.commonArguments.size() + extraArgs.length);
220221
args.addAll(this.commonArguments);
221222
Collections.addAll(args, extraArgs);
@@ -234,7 +235,7 @@ public void assertOutputEquals(final @NotNull String resourceName, final @NotNul
234235
* @return the result of an executed build
235236
* @since 1.1.0
236237
*/
237-
public @NotNull BuildResult build(final @NotNull String@NotNull... extraArgs) {
238+
public BuildResult build(final String... extraArgs) {
238239
return this.runner(extraArgs).build();
239240
}
240241

src/main/java/net/kyori/mammoth/Configurable.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2022 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -24,8 +24,8 @@
2424
package net.kyori.mammoth;
2525

2626
import org.gradle.api.Action;
27-
import org.jetbrains.annotations.NotNull;
28-
import org.jetbrains.annotations.Nullable;
27+
import org.jspecify.annotations.NullMarked;
28+
import org.jspecify.annotations.Nullable;
2929

3030
import static java.util.Objects.requireNonNull;
3131

@@ -34,6 +34,7 @@
3434
*
3535
* @since 1.0.0
3636
*/
37+
@NullMarked
3738
public final class Configurable {
3839
private Configurable() {
3940
}
@@ -47,7 +48,7 @@ private Configurable() {
4748
* @return the provided {@code instance}
4849
* @since 1.0.0
4950
*/
50-
public static <T> @NotNull T configure(final @NotNull T instance, final @NotNull Action<T> configureAction) {
51+
public static <T> T configure(final T instance, final Action<T> configureAction) {
5152
requireNonNull(configureAction, "configureAction").execute(instance);
5253
return instance;
5354
}
@@ -61,7 +62,7 @@ private Configurable() {
6162
* @return the provided {@code instance}
6263
* @since 1.0.0
6364
*/
64-
public static <T> @NotNull T configureIfNonNull(final @NotNull T instance, final @Nullable Action<T> configureAction) {
65+
public static <T> T configureIfNonNull(final T instance, final @Nullable Action<T> configureAction) {
6566
if (configureAction != null) {
6667
configureAction.execute(instance);
6768
}

src/main/java/net/kyori/mammoth/Extensions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2022 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -24,12 +24,14 @@
2424
package net.kyori.mammoth;
2525

2626
import org.gradle.api.plugins.ExtensionContainer;
27+
import org.jspecify.annotations.NullMarked;
2728

2829
/**
2930
* Helpers for working with extensions.
3031
*
3132
* @since 1.0.0
3233
*/
34+
@NullMarked
3335
public final class Extensions {
3436
private Extensions() {
3537
}

src/main/java/net/kyori/mammoth/GradleCompat.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of mammoth, licensed under the MIT License.
33
*
4-
* Copyright (c) 2021-2023 KyoriPowered
4+
* Copyright (c) 2021-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -28,8 +28,10 @@
2828
import org.gradle.api.Project;
2929
import org.gradle.api.provider.Provider;
3030
import org.gradle.util.GradleVersion;
31-
import org.jetbrains.annotations.Nullable;
31+
import org.jspecify.annotations.NullMarked;
32+
import org.jspecify.annotations.Nullable;
3233

34+
@NullMarked
3335
final class GradleCompat {
3436
static final boolean SHOULD_USE_CONVENTION = hasMethod(Project.class, "getConvention") && !hasMinGradleVersion("8.2");
3537
static final boolean HAS_FOR_USE_AT_CONFIGURATION_TIME = hasMethod(Provider.class, "forUseAtConfigurationTime") && !hasMinGradleVersion("7.6");

0 commit comments

Comments
 (0)