Skip to content

Commit

Permalink
Fix configuration cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 2, 2024
1 parent 539a92f commit 3f27a84
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 55 deletions.
46 changes: 22 additions & 24 deletions src/main/java/dev/architectury/loom/util/ForgeLoggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.StringJoiner;

import org.gradle.api.Project;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.LoomGradleExtension;
Expand All @@ -22,46 +24,42 @@ public final class ForgeLoggerConfig {
new ArtifactCoordinates("net.minecraftforge", "forge", "launcher")
);

public static void copyToPath(Project project, Path outputFile) {
try {
Files.deleteIfExists(outputFile);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

public static @Nullable File getForgeLoggerConfigSource(Project project) {
final List<String> libraries = LoomGradleExtension.get(project)
.getForgeUserdevProvider()
.getConfig()
.libraries();
boolean found = false;

for (String library : libraries) {
if (LOGGER_CONFIG_ARTIFACTS.stream().anyMatch(artifact -> artifact.matches(library))) {
final File libraryFile = project.getConfigurations()
return project.getConfigurations()
.detachedConfiguration(project.getDependencies().create(library))
.setTransitive(false)
.getSingleFile();

try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(libraryFile, false)) {
final Path configPath = fs.getPath("log4j2.xml");
Files.copy(configPath, outputFile);
found = true;
break;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}

if (!found) {
StringBuilder sb = new StringBuilder("Could not find Forge dependency with logger config. Tried to find:");
return null;
}

for (ArtifactCoordinates artifact : LOGGER_CONFIG_ARTIFACTS) {
sb.append('\n').append(" - ").append(artifact);
}
public static void copyToPath(Path libraryFile, Path outputFile) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(libraryFile, false)) {
final Path configPath = fs.getPath("log4j2.xml");
Files.copy(configPath, outputFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Contract("-> fail")
public static void throwNotFound() {
StringBuilder sb = new StringBuilder("Could not find Forge dependency with logger config. Tried to find:");

throw new RuntimeException(sb.toString());
for (ArtifactCoordinates artifact : LOGGER_CONFIG_ARTIFACTS) {
sb.append('\n').append(" - ").append(artifact);
}

throw new RuntimeException(sb.toString());
}

private record ArtifactCoordinates(String group, String name, @Nullable String classifier) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.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-2023 FabricMC
* Copyright (c) 2021-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
Expand Down Expand Up @@ -109,7 +109,10 @@ default void mixinConfig(String... mixinConfigs) {
* This is disabled by default.
*
* @return the property
* @deprecated This API is not needed on newer Minecraft versions where Forge forces its own logger config.
*/
@ApiStatus.ScheduledForRemoval(inVersion = "2.0")
@Deprecated(forRemoval = true)
Property<Boolean> getUseForgeLoggerConfig();

/**
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/net/fabricmc/loom/build/IntermediaryNamespaces.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) 2022-2023 FabricMC
* Copyright (c) 2022-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
Expand All @@ -28,6 +28,7 @@

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.util.ModPlatform;

public final class IntermediaryNamespaces {
/**
Expand All @@ -49,8 +50,14 @@ public static String runtimeIntermediary(Project project) {
* Returns the intermediary namespace of the project.
*/
public static MappingsNamespace intermediaryNamespace(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project);
return switch (extension.getPlatform().get()) {
return intermediaryNamespace(LoomGradleExtension.get(project).getPlatform().get());
}

/**
* Returns the intermediary namespace of the platform.
*/
public static MappingsNamespace intermediaryNamespace(ModPlatform platform) {
return switch (platform) {
case FABRIC, QUILT -> MappingsNamespace.INTERMEDIARY;
case FORGE -> MappingsNamespace.SRG;
case NEOFORGE -> MappingsNamespace.MOJANG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
Expand Down Expand Up @@ -117,4 +119,33 @@ public void applyTo(RunConfigSettings settings, ConfigValue.Resolver configValue
settings.property(Constants.Forge.UNION_RELAUNCHER_MAIN_CLASS_PROPERTY, main);
}
}

public Resolved resolve(ConfigValue.Resolver configValueResolver) {
final Function<ConfigValue, String> resolve = value -> value.resolve(configValueResolver);
final Collector<Map.Entry<String, ConfigValue>, ?, Map<String, String>> resolveMap =
Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().resolve(configValueResolver));

final List<String> args = this.args.stream().map(resolve).toList();
final List<String> jvmArgs = this.jvmArgs.stream().map(resolve).toList();
final Map<String, String> env = this.env.entrySet().stream().collect(resolveMap);
final Map<String, String> props = this.props.entrySet().stream().collect(resolveMap);

return new Resolved(
name,
main,
args,
jvmArgs,
env,
props
);
}

public record Resolved(
String name,
String main,
List<String> args,
List<String> jvmArgs,
Map<String, String> env,
Map<String, String> props
) { }
}
Loading

0 comments on commit 3f27a84

Please sign in to comment.