From d21d83b137555a63269dbce89578de28d9ffd33b Mon Sep 17 00:00:00 2001 From: marcus8448 Date: Sat, 7 Sep 2024 15:32:03 -0700 Subject: [PATCH] fix: don't expose loom to plugin consumers (use the version of loom installed by the buildscript) --- .github/workflows/commit.yml | 2 +- README.md | 2 +- build.gradle.kts | 12 +- gradle.properties | 5 +- gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew.bat | 188 +++++++++--------- .../mojarn/api/MojarnMappingsSpecBuilder.java | 8 + .../mojarn/impl/MojarnExtensionImpl.java | 9 +- .../mojarn/impl/MojarnMappingsSpec.java | 6 +- .../impl/MojarnMappingsSpecBuilderImpl.java | 25 +++ .../mojarn/impl/package-info.java | 4 + 11 files changed, 142 insertions(+), 123 deletions(-) create mode 100644 src/main/java/dev/galacticraft/mojarn/impl/package-info.java diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 4c89f07..7e75edf 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -10,7 +10,7 @@ jobs: uses: actions/checkout@v4 - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v3 + uses: gradle/actions/wrapper-validation@v4 - name: Setup JDK 17 uses: actions/setup-java@v4 diff --git a/README.md b/README.md index e6862e8..f487602 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ pluginManagement { Then, add the following to your `build.gradle.kts` file: ```kotlin plugins { - id("dev.galacticraft.mojarn") version("0.2.0+7") + id("dev.galacticraft.mojarn") version("0.4.1+11") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 3fc8af3..7e00e64 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,7 +23,7 @@ plugins { `java-gradle-plugin` `maven-publish` - id("com.gradle.plugin-publish") version("1.2.1") + id("com.gradle.plugin-publish") version("1.2.2") id("org.cadixdev.licenser") version("0.6.1") } @@ -35,7 +35,6 @@ val pluginVersion = project.property("plugin.version").toString() val loomVersion = project.property("loom.version").toString() val mappingIoVersion = project.property("mapping-io.version").toString() -val junitVersion = project.property("junit.version").toString() group = pluginGroup version = "$pluginVersion+${System.getenv("GITHUB_RUN_NUMBER") ?: "0"}" @@ -65,11 +64,8 @@ repositories { dependencies { implementation(gradleApi()) - implementation("net.fabricmc:fabric-loom:${loomVersion}") { isTransitive = false } + compileOnly("net.fabricmc:fabric-loom:${loomVersion}") implementation("net.fabricmc:mapping-io:${mappingIoVersion}") - - testImplementation(platform("org.junit:junit-bom:${junitVersion}")) - testImplementation("org.junit.jupiter:junit-jupiter") } tasks.withType { @@ -81,10 +77,6 @@ tasks.withType { from("LICENSE") } -tasks.test { - useJUnitPlatform() -} - tasks.javadoc { options.encoding = "UTF-8" } diff --git a/gradle.properties b/gradle.properties index db83af0..c5bb2af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,7 @@ plugin.group=dev.galacticraft plugin.name=Mojarn plugin.id=mojarn plugin.description=Mixes official and yarn mappings for better argument names -plugin.version=0.4.0 +plugin.version=0.4.1 -loom.version=1.7.2 +loom.version=1.7.3 mapping-io.version=0.6.1 -junit.version=5.10.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 68e8816..2b18997 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 9b42019..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,94 +1,94 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@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 ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -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 - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -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 - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@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 ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +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 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +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 + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java b/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java index cdbe6ac..0afb795 100644 --- a/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java +++ b/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java @@ -28,6 +28,14 @@ * A builder for a Mojarn mappings spec. */ public interface MojarnMappingsSpecBuilder { + /** + * Whether to name synthetic methods. + * @param nameSyntheticMethods whether to name synthetic methods + * @return this builder + * @see net.fabricmc.loom.api.mappings.layered.spec.MojangMappingsSpecBuilder#setNameSyntheticMembers(boolean) + */ + MojarnMappingsSpecBuilder nameSyntheticMethods(boolean nameSyntheticMethods); + /** * Whether to remap arguments with class types. * @param remapArguments whether to map arguments with class types diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java index cc938ff..a177e08 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java @@ -26,11 +26,7 @@ import dev.galacticraft.mojarn.api.MojarnMappingsSpecBuilder; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; -import net.fabricmc.loom.configuration.providers.mappings.file.FileMappingsSpec; import net.fabricmc.loom.configuration.providers.mappings.file.FileMappingsSpecBuilderImpl; -import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec; -import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec; -import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpecBuilderImpl; import org.gradle.api.Action; import org.gradle.api.artifacts.Dependency; @@ -53,9 +49,6 @@ public Dependency mappings(Object file, Action b.addLayer(new MojarnMappingsSpec(new IntermediaryMappingsSpec(), mojangSpec, fileSpec, builder.remapArguments, builder.partialMatch, builder.skipDifferent, builder.skipCI, builder.mapVariables))); + return loom.layered(b -> b.addLayer(builder.build(fileBuilder.build()))); } } diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java index cfb86d8..1885f06 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java @@ -26,11 +26,9 @@ import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; import org.jetbrains.annotations.NotNull; -import java.util.Objects; - -public record MojarnMappingsSpec(@NotNull MappingsSpec intermediary, @NotNull MappingsSpec mojang, @NotNull MappingsSpec yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean skipCI, boolean matchVariables) implements MappingsSpec { +public record MojarnMappingsSpec(@NotNull MappingsSpec intermediary, @NotNull MappingsSpec mojang, @NotNull MappingsSpec yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean matchVariables, boolean skipCI) implements MappingsSpec { @Override public MojarnMappingsLayer createLayer(MappingContext context) { - return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.skipCI, this.matchVariables); + return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.matchVariables, this.skipCI); } } diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java index 808bbc7..d95126a 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java @@ -23,8 +23,12 @@ package dev.galacticraft.mojarn.impl; import dev.galacticraft.mojarn.api.MojarnMappingsSpecBuilder; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; +import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec; +import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpecBuilderImpl; public class MojarnMappingsSpecBuilderImpl implements MojarnMappingsSpecBuilder { + boolean nameSyntheticMethods = false; boolean remapArguments = true; boolean partialMatch = false; boolean skipDifferent = false; @@ -32,6 +36,12 @@ public class MojarnMappingsSpecBuilderImpl implements MojarnMappingsSpecBuilder boolean skipCI = true; boolean fileIsEnigma = false; + @Override + public MojarnMappingsSpecBuilder nameSyntheticMethods(boolean nameSyntheticMethods) { + this.nameSyntheticMethods = nameSyntheticMethods; + return this; + } + @Override public MojarnMappingsSpecBuilder remapArguments(boolean remapArguments) { this.remapArguments = remapArguments; @@ -67,4 +77,19 @@ public MojarnMappingsSpecBuilder fileIsEnigma() { this.fileIsEnigma = true; return this; } + + public MojarnMappingsSpec build(MappingsSpec intermediary, MappingsSpec mojang, MappingsSpec file) { + return new MojarnMappingsSpec(intermediary, mojang, file, this.remapArguments, this.partialMatch, this.skipDifferent, this.mapVariables, this.skipCI); + } + + public MojarnMappingsSpec build(MappingsSpec intermediary, MappingsSpec file) { + MojangMappingsSpecBuilderImpl builder = MojangMappingsSpecBuilderImpl.builder(); + builder.setNameSyntheticMembers(this.nameSyntheticMethods); + + return this.build(intermediary, builder.build(), file); + } + + public MojarnMappingsSpec build(MappingsSpec file) { + return this.build(new IntermediaryMappingsSpec(), file); + } } diff --git a/src/main/java/dev/galacticraft/mojarn/impl/package-info.java b/src/main/java/dev/galacticraft/mojarn/impl/package-info.java new file mode 100644 index 0000000..95515ba --- /dev/null +++ b/src/main/java/dev/galacticraft/mojarn/impl/package-info.java @@ -0,0 +1,4 @@ +@ApiStatus.Internal +package dev.galacticraft.mojarn.impl; + +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file