Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(*): Migrate to JSpecify #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

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

<!-- https://checkstyle.org/config_coding.html#IllegalTokenText -->
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ indraSonatype {
}

dependencies {
compileOnlyApi libs.jetbrainsAnnotations
compileOnlyApi libs.jspecify
implementation gradleApi()

testImplementation platform(libs.junit.bom)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stylecheck = "0.2.1"
errorprone = "2.30.0"

[libraries]
jetbrainsAnnotations = "org.jetbrains:annotations:25.0.0"
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0" }

# test
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
Expand Down
2 changes: 1 addition & 1 deletion mammoth-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "JUnit extensions for testing Gradle plugins"
dependencies {
api gradleApi()
api gradleTestKit()
compileOnlyApi libs.jetbrainsAnnotations
compileOnlyApi libs.jspecify
api platform(libs.junit.bom)
api libs.junit.api
implementation libs.junit.platformCommons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.gradle.util.GradleVersion;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
Expand Down
23 changes: 11 additions & 12 deletions mammoth-test/src/main/java/net/kyori/mammoth/test/TestContext.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of mammoth, licensed under the MIT License.
*
* Copyright (c) 2021-2022 KyoriPowered
* Copyright (c) 2021-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,7 +37,6 @@
import java.util.regex.Pattern;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Assertions;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -78,11 +77,11 @@ public final class TestContext {
* @return the output directory
* @since 1.1.0
*/
public @NotNull Path outputDirectory() {
public Path outputDirectory() {
return this.outputDirectory;
}

@NotNull String gradleVersion() {
String gradleVersion() {
return this.gradleVersion;
}

Expand All @@ -93,7 +92,7 @@ public final class TestContext {
* @throws IOException if an error occurs writing the input file to disk
* @since 1.1.0
*/
public void copyInput(final @NotNull String name) throws IOException {
public void copyInput(final String name) throws IOException {
this.copyInput(name, name);
}

Expand All @@ -105,7 +104,7 @@ public void copyInput(final @NotNull String name) throws IOException {
* @throws IOException if an error occurs writing the input file to disk
* @since 1.1.0
*/
public void copyInput(final @NotNull String fromName, final @NotNull String toName) throws IOException {
public void copyInput(final String fromName, final String toName) throws IOException {
requireNonNull(fromName, "fromName");
requireNonNull(toName, "toName");
try (final InputStream is = this.resourceBase.getResourceAsStream(this.testName + "/in/" + fromName)) {
Expand All @@ -130,7 +129,7 @@ public void copyInput(final @NotNull String fromName, final @NotNull String toNa
* @throws IOException if an error occurs writing the text
* @since 1.2.0
*/
public void writeText(final @NotNull String destination, final @NotNull String text) throws IOException {
public void writeText(final String destination, final String text) throws IOException {
requireNonNull(destination, "destination");
requireNonNull(text, "text");

Expand All @@ -149,7 +148,7 @@ public void writeText(final @NotNull String destination, final @NotNull String t
* @throws IOException if thrown while attempting to read the output file
* @since 1.1.0
*/
public @NotNull String readOutput(final @NotNull String fileName) throws IOException {
public String readOutput(final String fileName) throws IOException {
final StringBuilder builder = new StringBuilder();
try (final BufferedReader reader = Files.newBufferedReader(this.outputDirectory.resolve(fileName), StandardCharsets.UTF_8)) {
final char[] buffer = new char[8192];
Expand All @@ -169,7 +168,7 @@ public void writeText(final @NotNull String destination, final @NotNull String t
* @throws IOException if an error occurs reading the text
* @since 1.2.0
*/
public void assertOutputEqualsLiteral(final @NotNull String destination, final @NotNull String text) throws IOException {
public void assertOutputEqualsLiteral(final String destination, final String text) throws IOException {
requireNonNull(destination, "destination");
requireNonNull(text, "text");

Expand All @@ -188,7 +187,7 @@ public void assertOutputEqualsLiteral(final @NotNull String destination, final @
* @throws IOException if failed to read one of the files
* @since 1.1.0
*/
public void assertOutputEquals(final @NotNull String resourceName, final @NotNull String fileName) throws IOException {
public void assertOutputEquals(final String resourceName, final String fileName) throws IOException {
final String actualOutput = this.readOutput(fileName);

final StringBuilder builder = new StringBuilder();
Expand All @@ -215,7 +214,7 @@ public void assertOutputEquals(final @NotNull String resourceName, final @NotNul
* @return the new runner
* @since 1.1.0
*/
public @NotNull GradleRunner runner(final @NotNull String@NotNull... extraArgs) {
public GradleRunner runner(final String... extraArgs) {
final List<String> args = new ArrayList<>(this.commonArguments.size() + extraArgs.length);
args.addAll(this.commonArguments);
Collections.addAll(args, extraArgs);
Expand All @@ -234,7 +233,7 @@ public void assertOutputEquals(final @NotNull String resourceName, final @NotNul
* @return the result of an executed build
* @since 1.1.0
*/
public @NotNull BuildResult build(final @NotNull String@NotNull... extraArgs) {
public BuildResult build(final String... extraArgs) {
return this.runner(extraArgs).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
* annotating methods that have a parameter of either type {@link net.kyori.mammoth.test.TestContext}
* or {@link org.gradle.testkit.runner.GradleRunner}.</p>
*/
@NullMarked
package net.kyori.mammoth.test;

import org.jspecify.annotations.NullMarked;
9 changes: 4 additions & 5 deletions src/main/java/net/kyori/mammoth/Configurable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of mammoth, licensed under the MIT License.
*
* Copyright (c) 2021-2022 KyoriPowered
* Copyright (c) 2021-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,8 +24,7 @@
package net.kyori.mammoth;

import org.gradle.api.Action;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

import static java.util.Objects.requireNonNull;

Expand All @@ -47,7 +46,7 @@ private Configurable() {
* @return the provided {@code instance}
* @since 1.0.0
*/
public static <T> @NotNull T configure(final @NotNull T instance, final @NotNull Action<T> configureAction) {
public static <T> T configure(final T instance, final Action<T> configureAction) {
requireNonNull(configureAction, "configureAction").execute(instance);
return instance;
}
Expand All @@ -61,7 +60,7 @@ private Configurable() {
* @return the provided {@code instance}
* @since 1.0.0
*/
public static <T> @NotNull T configureIfNonNull(final @NotNull T instance, final @Nullable Action<T> configureAction) {
public static <T> T configureIfNonNull(final T instance, final @Nullable Action<T> configureAction) {
if (configureAction != null) {
configureAction.execute(instance);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/kyori/mammoth/GradleCompat.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of mammoth, licensed under the MIT License.
*
* Copyright (c) 2021-2023 KyoriPowered
* Copyright (c) 2021-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -28,7 +28,7 @@
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

final class GradleCompat {
static final boolean SHOULD_USE_CONVENTION = hasMethod(Project.class, "getConvention") && !hasMinGradleVersion("8.2");
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/kyori/mammoth/IsolatingClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.Iterator;
import java.util.Set;
import org.gradle.api.file.FileCollection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

/**
* A factory for classloaders that will load classes from themselves rather than its parent where possible.
Expand All @@ -54,7 +53,7 @@ private IsolatingClassLoader() {
* @return the newly created loader
* @since 1.4.0
*/
public static @NotNull URLClassLoader isolatingClassLoader(final @Nullable ClassLoader parent, final @NotNull URL @NotNull... urls) {
public static URLClassLoader isolatingClassLoader(final @Nullable ClassLoader parent, final URL... urls) {
return new IsolatingClassLoaderImpl(urls, parent);
}

Expand All @@ -66,7 +65,7 @@ private IsolatingClassLoader() {
* @return the newly created loader
* @since 1.4.0
*/
public static @NotNull URLClassLoader isolatingClassLoader(final @Nullable ClassLoader parent, final @NotNull FileCollection files) {
public static URLClassLoader isolatingClassLoader(final @Nullable ClassLoader parent, final FileCollection files) {
final Set<File> unwrapped = files.getFiles();
final URL[] urls = new URL[unwrapped.size()];
final Iterator<File> it = files.iterator();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/kyori/mammoth/IsolatingClassLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

final class IsolatingClassLoaderImpl extends URLClassLoader {
static {
ClassLoader.registerAsParallelCapable();
}

private final ClassLoader parent;
private final @Nullable ClassLoader parent;

// todo: maybe add transformer function (UnaryOperator<byte[]>)? just for fun
// todo: add a filter
IsolatingClassLoaderImpl(final URL[] urls, final ClassLoader parent) {
IsolatingClassLoaderImpl(final URL[] urls, final @Nullable ClassLoader parent) {
super(urls, parent);
this.parent = parent;
}

@Override
protected @Nullable Class<?> loadClass(final @NotNull String name, final boolean resolve) throws ClassNotFoundException {
protected @Nullable Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
synchronized (this.getClassLoadingLock(name)) {
Class<?> result = this.findLoadedClass(name);
if (result == null) {
Expand Down Expand Up @@ -78,7 +77,7 @@ final class IsolatingClassLoaderImpl extends URLClassLoader {
}

@Override
public @NotNull Enumeration<URL> getResources(final String name) throws IOException {
public Enumeration<URL> getResources(final String name) throws IOException {
return new Enumeration<URL>() {
@Nullable Enumeration<URL> active = IsolatingClassLoaderImpl.this.findResources(name);
@Nullable Enumeration<URL> staged = IsolatingClassLoaderImpl.this.parent == null
Expand All @@ -102,7 +101,7 @@ public boolean hasMoreElements() {
}

@Override
public @NotNull URL nextElement() {
public URL nextElement() {
final @Nullable Enumeration<URL> component = this.nextComponent();
if (component == null) {
throw new NoSuchElementException();
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/net/kyori/mammoth/ProjectOrSettingsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of mammoth, licensed under the MIT License.
*
* Copyright (c) 2021-2022 KyoriPowered
* Copyright (c) 2021-2024 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -32,8 +32,7 @@
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

/**
* A plugin that can be applied to either a {@link Project} or {@link Settings}.
Expand All @@ -42,7 +41,7 @@
*/
public interface ProjectOrSettingsPlugin extends Plugin<Object> {
@Override
default void apply(final @NotNull Object target) {
default void apply(final Object target) {
if (target instanceof Project) {
final Project project = (Project) target;
GradleCompat.requireMinimumVersion(this.minimumGradleVersion(), this, project.getDisplayName());
Expand Down Expand Up @@ -71,10 +70,10 @@ default void apply(final @NotNull Object target) {
* @since 1.3.0
*/
void applyToProject(
final @NotNull Project target,
final @NotNull PluginContainer plugins,
final @NotNull ExtensionContainer extensions,
final @NotNull TaskContainer tasks
final Project target,
final PluginContainer plugins,
final ExtensionContainer extensions,
final TaskContainer tasks
);

/**
Expand All @@ -86,9 +85,9 @@ void applyToProject(
* @since 1.3.0
*/
void applyToSettings(
final @NotNull Settings target,
final @NotNull PluginContainer plugins,
final @NotNull ExtensionContainer extensions
final Settings target,
final PluginContainer plugins,
final ExtensionContainer extensions
);

/**
Expand All @@ -108,7 +107,7 @@ void applyToSettings(
* @return whether the Settings that created the provided project has this plugin applied
* @since 1.3.0
*/
default boolean isAppliedToSettingsOf(final @NotNull Project project) {
default boolean isAppliedToSettingsOf(final Project project) {
return project.getGradle().getPlugins().hasPlugin(this.getClass());
}
}
Loading