Skip to content

Commit

Permalink
Revert "DependencyDownloader: Upgrade (transitive) Log4J if needed"
Browse files Browse the repository at this point in the history
This reverts commit 37e6a3d.
  • Loading branch information
Juuxel committed Jan 24, 2024
1 parent 37e6a3d commit 939ec20
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 93 deletions.
54 changes: 1 addition & 53 deletions src/main/java/net/fabricmc/loom/util/DependencyDownloader.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,25 +35,17 @@
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.
*
* @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<DependencyEntry> dependencies = new ArrayList<>();
private final Map<Attribute<?>, Object> attributes = new HashMap<>();
Expand Down Expand Up @@ -141,7 +133,6 @@ public FileCollection download(boolean transitive, boolean resolve) {
attributes.attribute((Attribute<Object>) attribute, value);
});
});
config.getResolutionStrategy().eachDependency(DependencyDownloader::upgradeLog4j);
FileCollection files = config.fileCollection(dep -> true);

if (resolve) {
Expand All @@ -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}.
*
Expand Down

This file was deleted.

0 comments on commit 939ec20

Please sign in to comment.