From f1df58a5f372059e7ef99f2b8ee7bade6cd9c21c Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:56:07 +0200 Subject: [PATCH 1/3] Revert "DependencyDownloader: Upgrade (transitive) Log4J if needed" This reverts commit acd9ad739bc990598f2a43772ea24a97ce9a2f76. --- .../loom/util/DependencyDownloader.java | 54 +------------------ .../DependencyDownloaderTest.groovy | 40 -------------- 2 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 src/test/groovy/net/fabricmc/loom/test/unit/architectury/DependencyDownloaderTest.groovy diff --git a/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java b/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java index 903ba0f81..0ab345936 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2021-2024 FabricMC + * Copyright (c) 2021-2023 FabricMC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,13 +35,10 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; -import org.gradle.api.artifacts.DependencyResolveDetails; import org.gradle.api.artifacts.ModuleDependency; -import org.gradle.api.artifacts.ModuleVersionSelector; import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.attributes.Attribute; import org.gradle.api.file.FileCollection; -import org.jetbrains.annotations.VisibleForTesting; /** * Simplified but powerful dependency downloading. @@ -49,11 +46,6 @@ * @author Juuz */ public final class DependencyDownloader { - private static final String LOG4J_GROUP = "org.apache.logging.log4j"; - private static final String LOG4J_NAME = "log4j-core"; - private static final String LOG4J_MINIMUM_VERSION = "2.17.1"; - private static final int[] LOG4J_MINIMUM_VERSION_COMPONENTS = {2, 17, 1}; - private final Project project; private final List dependencies = new ArrayList<>(); private final Map, Object> attributes = new HashMap<>(); @@ -141,7 +133,6 @@ public FileCollection download(boolean transitive, boolean resolve) { attributes.attribute((Attribute) attribute, value); }); }); - config.getResolutionStrategy().eachDependency(DependencyDownloader::upgradeLog4j); FileCollection files = config.fileCollection(dep -> true); if (resolve) { @@ -151,49 +142,6 @@ public FileCollection download(boolean transitive, boolean resolve) { return files; } - private static void upgradeLog4j(DependencyResolveDetails details) { - ModuleVersionSelector requested = details.getRequested(); - - if (LOG4J_GROUP.equals(requested.getGroup()) && LOG4J_NAME.equals(requested.getName())) { - final String requestedVersion = requested.getVersion(); - - if (requestedVersion != null && shouldUpgradeLog4jVersion(requestedVersion)) { - details.useVersion(LOG4J_MINIMUM_VERSION); - } - } - } - - @VisibleForTesting - public static boolean shouldUpgradeLog4jVersion(String requestedVersion) { - final String[] splitVersion = requestedVersion.split("\\."); - - for (int i = 0; i < LOG4J_MINIMUM_VERSION_COMPONENTS.length; i++) { - if (i >= splitVersion.length) { - // Not enough version components in the requested version, upgrade just to be sure. - return true; - } - - final int minimumComponent = LOG4J_MINIMUM_VERSION_COMPONENTS[i]; - final String givenComponentStr = splitVersion[i]; - final int givenComponent; - - try { - givenComponent = Integer.parseInt(givenComponentStr); - } catch (NumberFormatException e) { - // We can't read the version component for comparing, upgrade just to be sure. - return true; - } - - if (givenComponent < minimumComponent) { - // Too old, upgrade. - return true; - } - } - - // Seems to be new enough, let's not upgrade. - return false; - } - /** * Resolves a dependency as well as its transitive dependencies into a {@link FileCollection}. * diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/DependencyDownloaderTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/architectury/DependencyDownloaderTest.groovy deleted file mode 100644 index 80fba3a14..000000000 --- a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/DependencyDownloaderTest.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of fabric-loom, licensed under the MIT License (MIT). - * - * Copyright (c) 2024 FabricMC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.fabricmc.loom.test.unit.architectury - -import spock.lang.Specification - -class DependencyDownloaderTest extends Specification { - def "upgrading log4j (should upgrade: #shouldUpgrade, requested: #version)"() { - where: - version | shouldUpgrade - '2.17.1' | false - '2.hello.3' | true - 'world.1.0' | true - '3.0.0-beta1' | false - '3.0.0-alpha1' | false - '2.16.0' | true - } -} From dfbdf266786f9376c3a37422215eac0199f81e84 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:05:25 +0200 Subject: [PATCH 2/3] DependencyDownloader: Support platform dependencies --- .../loom/util/DependencyDownloader.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java b/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java index 0ab345936..ec4e86edb 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyDownloader.java @@ -65,6 +65,17 @@ public DependencyDownloader add(String dependencyNotation) { return this; } + /** + * Adds a platform dependency. + * + * @param dependencyNotation the dependency notation + * @return this downloader + */ + public DependencyDownloader platform(String dependencyNotation) { + dependencies.add(new DependencyEntry.Platform(dependencyNotation)); + return this; + } + /** * Adds all dependencies from a configuration to download. * @@ -137,6 +148,10 @@ public FileCollection download(boolean transitive, boolean resolve) { if (resolve) { files = project.files(files.getFiles()); + + for (File file : files) { + System.out.println(file.getAbsolutePath()); + } } return files; @@ -190,6 +205,13 @@ public Dependency getDependency(DependencyHandler dependencies, boolean transiti } } + record Platform(String notation) implements DependencyEntry { + @Override + public Dependency getDependency(DependencyHandler dependencies, boolean transitive) { + return dependencies.platform(notation); + } + } + record Direct(Dependency dependency) implements DependencyEntry { @Override public Dependency getDependency(DependencyHandler dependencies, boolean transitive) { From fcd0701a5bde5d1ef6212baf90fda94321f804ff Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:06:32 +0200 Subject: [PATCH 3/3] Upgrade Log4J version used by AT tool --- gradle/runtime.libs.versions.toml | 2 ++ .../accesstransformer/AccessTransformerJarProcessor.java | 1 + 2 files changed, 3 insertions(+) diff --git a/gradle/runtime.libs.versions.toml b/gradle/runtime.libs.versions.toml index 139b0444a..4f746c174 100644 --- a/gradle/runtime.libs.versions.toml +++ b/gradle/runtime.libs.versions.toml @@ -19,6 +19,7 @@ access-transformers-new = "8.0.5" unprotect = "1.2.0" asm = "9.3" union-relauncher = "1.0.0" +access-transformers-log4j = "2.17.1" [libraries] # Decompilers @@ -43,3 +44,4 @@ access-transformers-new = { module = "net.minecraftforge:accesstransformers", ve unprotect = { module = "io.github.juuxel:unprotect", version.ref = "unprotect" } asm = { module = "org.ow2.asm:asm", version.ref = "asm" } union-relauncher = { module = "io.github.juuxel:union-relauncher", version.ref = "union-relauncher" } +access-transformers-log4j-bom = { module = "org.apache.logging.log4j:log4j-bom", version.ref = "access-transformers-log4j" } diff --git a/src/main/java/net/fabricmc/loom/configuration/accesstransformer/AccessTransformerJarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/accesstransformer/AccessTransformerJarProcessor.java index 52528301f..f7bbcc59c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesstransformer/AccessTransformerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesstransformer/AccessTransformerJarProcessor.java @@ -161,6 +161,7 @@ public static void executeAt(Project project, Path input, Path output, AccessTra FileCollection classpath = new DependencyDownloader(project) .add((serverBundleMetadataPresent ? LoomVersions.ACCESS_TRANSFORMERS_NEW : LoomVersions.ACCESS_TRANSFORMERS).mavenNotation()) .add(LoomVersions.ASM.mavenNotation()) + .platform(LoomVersions.ACCESS_TRANSFORMERS_LOG4J_BOM.mavenNotation()) .download(); List args = new ArrayList<>(); args.add("--inJar");