Skip to content

Commit

Permalink
Upgrade to openrewrite 21
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxplay committed Dec 15, 2024
1 parent 0456c2f commit a26c682
Show file tree
Hide file tree
Showing 24 changed files with 400 additions and 297 deletions.
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
plugins {
`java-library`
`maven-publish`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "8.3.5"
}

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
tasks.shadowJar { archiveClassifier.set("final"); mergeServiceFiles() }

repositories {
mavenCentral()
}

dependencies {
api("org.openrewrite:rewrite-java-17:8.7.4")
api("org.openrewrite:rewrite-java-21:8.40.3")
api("org.cadixdev:at:0.1.0-rc1")
implementation("org.apache.logging.log4j:log4j-core:3.0.0-alpha1")
implementation("org.slf4j:slf4j-api:2.0.9")
implementation("org.apache.logging.log4j:log4j-core:3.0.0-beta3")
implementation("org.slf4j:slf4j-api:2.0.16")

testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.11.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
6 changes: 3 additions & 3 deletions restamp-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "8.3.5"
}

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
tasks.shadowJar { archiveClassifier.set("final"); mergeServiceFiles() }
tasks.assemble { dependsOn(tasks.shadowJar) }
tasks.jar {
Expand All @@ -23,7 +23,7 @@ repositories {

dependencies {
implementation(projects.restamp)
implementation("info.picocli:picocli:4.7.5")
implementation("info.picocli:picocli:4.7.6")
}

tasks.test {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/papermc/restamp/Restamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.cadixdev.at.AccessTransform;
import org.cadixdev.at.AccessTransformSet;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.openrewrite.Changeset;
import org.openrewrite.config.CompositeRecipe;
import org.openrewrite.internal.InMemoryLargeSourceSet;
Expand All @@ -20,6 +20,7 @@
/**
* The main executor of restamp.
*/
@NullMarked
public class Restamp {

/**
Expand All @@ -29,8 +30,7 @@ public class Restamp {
*
* @return the computed changeset.
*/
@NotNull
public static Changeset run(@NotNull final RestampInput input) {
public static Changeset run(final RestampInput input) {
final ModifierTransformer modifierTransformer = new ModifierTransformer();
final AccessTransformerTypeConverter accessTransformerTypeConverter = new AccessTransformerTypeConverter();
final AccessTransformSet accessTransformSet = input.accessTransformers();
Expand Down
61 changes: 26 additions & 35 deletions src/main/java/io/papermc/restamp/RestampContextConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.cadixdev.at.io.AccessTransformFormat;
import org.cadixdev.at.io.AccessTransformFormats;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;

import java.io.IOException;
Expand All @@ -30,12 +30,13 @@
* @param failWithNotApplicableAccessTransformers whether restamp should fail if not all access transformers defined in {@code accessTransformers}
* were consumed by restamp.
*/
@NullMarked
public record RestampContextConfiguration(
@NotNull ExecutionContext executionContext,
@NotNull AccessTransformSet accessTransformSet,
@NotNull Path sourceRoot,
@NotNull List<Path> sourceFiles,
@NotNull List<Path> classpath,
ExecutionContext executionContext,
AccessTransformSet accessTransformSet,
Path sourceRoot,
List<Path> sourceFiles,
List<Path> classpath,
boolean failWithNotApplicableAccessTransformers
) {

Expand All @@ -44,7 +45,7 @@ public record RestampContextConfiguration(
*
* @return the build instance.
*/
@NotNull

@Contract(value = "-> new", pure = true)
public static Builder builder() {
return new Builder();
Expand All @@ -59,10 +60,10 @@ public static class Builder {
private @Nullable AccessTransformSet accessTransformSet;
private @Nullable Path sourceRoot;
private @Nullable List<Path> sourceFiles;
private @NotNull SourceFileMode sourceFileMode = SourceFileMode.MANUAL;
private SourceFileMode sourceFileMode = SourceFileMode.MANUAL;
private boolean failWithNotApplicableAccessTransformers = false;

private @NotNull List<Path> classpath = Collections.emptyList();
private List<Path> classpath = Collections.emptyList();

/**
* Sets the execution context used by restamp for both parsing and running.
Expand All @@ -71,9 +72,9 @@ public static class Builder {
*
* @return this builder.
*/
@NotNull

@Contract(value = "_ -> this", mutates = "this")
public Builder executionContext(@NotNull final ExecutionContext executionContext) {
public Builder executionContext(final ExecutionContext executionContext) {
this.executionContext = executionContext;
return this;
}
Expand All @@ -84,13 +85,12 @@ public Builder executionContext(@NotNull final ExecutionContext executionContext
*
* @param accessTransformerPath the path to the access transformers.
*
* @throws IOException when something goes wrong loading the accessTransformSet
*
* @return this builder.
*
* @throws IOException when something goes wrong loading the accessTransformSet
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Builder accessTransformers(@NotNull final Path accessTransformerPath) throws IOException {
public Builder accessTransformers(final Path accessTransformerPath) throws IOException {
return this.accessTransformers(accessTransformerPath, AccessTransformFormats.FML);
}

Expand All @@ -100,28 +100,25 @@ public Builder accessTransformers(@NotNull final Path accessTransformerPath) thr
* @param accessTransformerPath the path to the access transformers.
* @param accessTransformerFormat the format of the access transformers defined in the file at the provided path.
*
* @throws IOException when something goes wrong loading the accessTransformSet
*
* @return this builder.
*
* @throws IOException when something goes wrong loading the accessTransformSet
*/
@NotNull
@Contract(value = "_,_ -> this", mutates = "this")
public Builder accessTransformers(@NotNull final Path accessTransformerPath, @NotNull final AccessTransformFormat accessTransformerFormat) throws IOException {
public Builder accessTransformers(final Path accessTransformerPath, final AccessTransformFormat accessTransformerFormat) throws IOException {
this.accessTransformSet = accessTransformerFormat.read(accessTransformerPath);
return this;
}

/**
* Sets the path pointing to the file holding the access transformers.
* Sets the access transformer set to be used by restamp.
*
* @param accessTransformerPath the path to the access transformers.
* @param accessTransformerFormat the format of the access transformers defined in the file at the provided path.
* @param accessTransformSet the transformer set.
*
* @return this builder.
*/
@NotNull
@Contract(value = "_,_ -> this", mutates = "this")
public Builder accessTransformSet(@NotNull final AccessTransformSet accessTransformSet) {
public Builder accessTransformSet(final AccessTransformSet accessTransformSet) {
this.accessTransformSet = AccessTransformSet.create();
this.accessTransformSet.merge(accessTransformSet);
return this;
Expand All @@ -134,9 +131,8 @@ public Builder accessTransformSet(@NotNull final AccessTransformSet accessTransf
*
* @return this builder.
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Builder sourceRoot(@NotNull final Path sourceRoot) {
public Builder sourceRoot(final Path sourceRoot) {
this.sourceRoot = sourceRoot;
return this;
}
Expand All @@ -148,9 +144,8 @@ public Builder sourceRoot(@NotNull final Path sourceRoot) {
*
* @return this builder.
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Builder sourceFiles(@NotNull final List<Path> sourceFiles) {
public Builder sourceFiles(final List<Path> sourceFiles) {
this.sourceFiles = sourceFiles;
return this;
}
Expand All @@ -163,7 +158,6 @@ public Builder sourceFiles(@NotNull final List<Path> sourceFiles) {
*
* @return this builder.
*/
@NotNull
@Contract(value = "-> this", mutates = "this")
public Builder sourceFilesFromAccessTransformers() {
this.sourceFileMode = SourceFileMode.FROM_AT_STRICT;
Expand All @@ -177,9 +171,9 @@ public Builder sourceFilesFromAccessTransformers() {
* If {@link #sourceFiles(List)} is called on this builder with a non-empty list, this option is meaningless.
*
* @param strict if true, restamp will fail if there are source files referenced in the ATs that don't exist.
*
* @return this builder.
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Builder sourceFilesFromAccessTransformers(final boolean strict) {
this.sourceFileMode = strict ? SourceFileMode.FROM_AT_STRICT : SourceFileMode.FROM_AT_GRACEFUL;
Expand All @@ -193,9 +187,8 @@ public Builder sourceFilesFromAccessTransformers(final boolean strict) {
*
* @return this builder.
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Builder classpath(@NotNull final List<Path> classpath) {
public Builder classpath(final List<Path> classpath) {
this.classpath = classpath;
return this;
}
Expand All @@ -206,7 +199,6 @@ public Builder classpath(@NotNull final List<Path> classpath) {
*
* @return this builder.
*/
@NotNull
@Contract(value = "-> this", mutates = "this")
public Builder failWithNotApplicableAccessTransformers() {
this.failWithNotApplicableAccessTransformers = true;
Expand All @@ -222,7 +214,6 @@ public Builder failWithNotApplicableAccessTransformers() {
* @throws IOException if parsing the access transformer set failed due to an {@link IOException}.
*/
@Contract(value = "-> new", pure = true)
@NotNull
public RestampContextConfiguration build() throws IllegalStateException {
if (this.executionContext == null) throw new IllegalStateException("Cannot build without an execution context");
if (this.accessTransformSet == null) throw new IllegalStateException("Cannot build without access transformers!");
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/io/papermc/restamp/RestampInput.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.papermc.restamp;

import org.cadixdev.at.AccessTransformSet;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.java.Java17Parser;
import org.openrewrite.java.Java21Parser;

import java.util.List;

Expand All @@ -18,10 +17,11 @@
* @param failWithNotApplicableAccessTransformers whether restamp should fail if not all access transformers defined in {@code accessTransformers}
* were consumed by restamp.
*/
@NullMarked
public record RestampInput(
@NotNull ExecutionContext executionContext,
@NotNull List<SourceFile> sources,
@NotNull AccessTransformSet accessTransformers,
ExecutionContext executionContext,
List<SourceFile> sources,
AccessTransformSet accessTransformers,
boolean failWithNotApplicableAccessTransformers
) {

Expand All @@ -33,9 +33,8 @@ public record RestampInput(
*
* @return the parsed restamp input, ready for consumption via {@link Restamp#run(RestampInput)}.
*/
@NotNull
public static RestampInput parseFrom(@NotNull final RestampContextConfiguration contextConfiguration) {
final Java17Parser parser = Java17Parser.builder().classpath(contextConfiguration.classpath()).build();
public static RestampInput parseFrom(final RestampContextConfiguration contextConfiguration) {
final Java21Parser parser = Java21Parser.builder().classpath(contextConfiguration.classpath()).build();

final List<SourceFile> sourceFiles = parser.parse(
contextConfiguration.sourceFiles(),
Expand Down
Loading

0 comments on commit a26c682

Please sign in to comment.