Fix issues resolving libraries and natives for old mc versions down to 1.3.2. (#584)

* Fix issues resolving libraries and natives for old mc versions.

Add a simple integration tests.

Fixes #583 and #582

* Test 1.6.4 and 1.3.2
dev/0.11
modmuss50 2022-01-25 15:37:03 +00:00 committed by GitHub
parent 316f9d9508
commit d4be1e7bdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.initialization.Settings;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.ExtensionAware;
@ -92,4 +93,15 @@ public class LoomRepositoryPlugin implements Plugin<PluginAware> {
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
}
public static void setupForLegacyVersions(Project project) {
// 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version.
project.getRepositories().named("Mojang", MavenArtifactRepository.class, repo -> {
repo.metadataSources(sources -> {
// Only use the maven artifact and not the pom or gradle metadata.
sources.artifact();
sources.ignoreGradleMetadataRedirection();
});
});
}
}

View File

@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2018-2021 FabricMC
* Copyright (c) 2018-2022 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
@ -31,12 +31,13 @@ import org.gradle.api.Project;
import org.gradle.api.artifacts.ExternalModuleDependency;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomRepositoryPlugin;
import net.fabricmc.loom.configuration.providers.BundleMetadata;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public class MinecraftLibraryProvider {
private static final Pattern NATIVES_PATTERN = Pattern.compile("^(?<group>.*)/(.*?)/(?<version>.*)/((?<name>.*?)-([0-9].*?)-)(?<classifier>.*).jar$");
private static final Pattern NATIVES_PATTERN = Pattern.compile("^(?<group>.*)/(.*?)/(?<version>.*)/((?<name>.*?)-(\\k<version>)-)(?<classifier>.*).jar$");
public void provide(MinecraftProvider minecraftProvider, Project project) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
@ -58,6 +59,11 @@ public class MinecraftLibraryProvider {
}
if (library.isValidForOS() && !library.hasNatives() && library.artifact() != null) {
// 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version.
if ("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3".equals(library.name())) {
LoomRepositoryPlugin.setupForLegacyVersions(project);
}
if (runtimeOnlyLog4j && library.name().startsWith("org.apache.logging.log4j")) {
// Make log4j a runtime only dep to force slf4j.
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name());
@ -74,10 +80,15 @@ public class MinecraftLibraryProvider {
if (library.hasNativesForOS()) {
MinecraftVersionMeta.Download nativeDownload = library.classifierForOS();
Matcher matcher = NATIVES_PATTERN.matcher(nativeDownload.path());
if (nativeDownload == null) {
continue;
}
final String path = nativeDownload.path();
final Matcher matcher = NATIVES_PATTERN.matcher(path);
if (!matcher.find()) {
project.getLogger().warn("Failed to match regex for natives path : " + nativeDownload.path());
project.getLogger().warn("Failed to match regex for natives path : " + path);
continue;
}

View File

@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
* Copyright (c) 2021-2022 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
@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion
class LoomTestConstants {
public final static String DEFAULT_GRADLE = GradleVersion.current().getVersion()
public final static String PRE_RELEASE_GRADLE = "7.5-20220122232041+0000"
public final static String PRE_RELEASE_GRADLE = "7.5-20220124231322+0000"
public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE]
}

View File

@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016-2021 FabricMC
* Copyright (c) 2016-2022 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
@ -45,9 +45,7 @@ class DecompileTest extends Specification implements GradleProjectTestTrait {
where:
decompiler | task | version
'fernflower' | "genSourcesWithFernFlower" | DEFAULT_GRADLE
'fernflower' | "genSourcesWithFernFlower" | PRE_RELEASE_GRADLE
'cfr' | "genSourcesWithCfr" | DEFAULT_GRADLE
'cfr' | "genSourcesWithCfr" | PRE_RELEASE_GRADLE
}

View File

@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2018-2021 FabricMC
* Copyright (c) 2018-2022 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
@ -28,7 +28,8 @@ import net.fabricmc.loom.test.util.GradleProjectTestTrait
import spock.lang.Specification
import spock.lang.Unroll
import static net.fabricmc.loom.test.LoomTestConstants.*
import static net.fabricmc.loom.test.LoomTestConstants.PRE_RELEASE_GRADLE
import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
// This test uses gradle 4.9 and 1.14.4 v1 mappings
@ -47,4 +48,40 @@ class LegacyProjectTest extends Specification implements GradleProjectTestTrait
where:
version << STANDARD_TEST_VERSIONS
}
@Unroll
def "Unsupported minecraft (minecraft #version)"() {
setup:
def gradle = gradleProject(project: "minimalBase", version: PRE_RELEASE_GRADLE)
gradle.buildGradle << """
loom {
intermediaryUrl = 'https://s.modm.us/intermediary-empty-v2.jar'
}
dependencies {
minecraft "com.mojang:minecraft:${version}"
mappings loom.layered() {
// No names
}
modImplementation "net.fabricmc:fabric-loader:0.12.12"
}
"""
when:
def result = gradle.run(task: "configureClientLaunch")
then:
result.task(":configureClientLaunch").outcome == SUCCESS
where:
version | _
'1.13.2' | _
'1.12.2' | _
'1.8.9' | _
'1.7.10' | _
'1.6.4' | _
'1.4.7' | _
'1.3.2' | _
}
}