Merge remote-tracking branch 'FabricMC/dev/0.8' into dev/0.8

# Conflicts:
#	.github/workflows/test-push.yml
#	build.gradle
#	settings.gradle
#	src/test/groovy/net/fabricmc/loom/test/integration/dependencyResolutionManagement.groovy
This commit is contained in:
shedaniel
2021-05-30 19:17:56 +08:00
43 changed files with 1062 additions and 113 deletions

View File

@@ -33,9 +33,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.PluginAware;
import net.fabricmc.loom.bootstrap.BootstrappedPlugin;
import net.fabricmc.loom.configuration.CompileConfiguration;
import net.fabricmc.loom.configuration.FabricApiExtension;
import net.fabricmc.loom.configuration.MavenPublication;
@@ -44,12 +45,20 @@ import net.fabricmc.loom.configuration.providers.mappings.MappingsCache;
import net.fabricmc.loom.decompilers.DecompilerConfiguration;
import net.fabricmc.loom.task.LoomTasks;
public class LoomGradlePlugin implements Plugin<Project> {
public class LoomGradlePlugin implements BootstrappedPlugin {
public static boolean refreshDeps;
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@Override
public void apply(PluginAware target) {
target.getPlugins().apply(LoomRepositoryPlugin.class);
if (target instanceof Project project) {
apply(project);
}
}
public void apply(Project project) {
String loomVersion = LoomGradlePlugin.class.getPackage().getImplementationVersion();
Set<String> loggedVersions = new HashSet<>(Arrays.asList(System.getProperty("loom.printed.logged", "").split(",")));

View File

@@ -0,0 +1,200 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 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;
import java.io.File;
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.initialization.Settings;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.PluginAware;
public class LoomRepositoryPlugin implements Plugin<PluginAware> {
@Override
public void apply(PluginAware target) {
RepositoryHandler repositories = null;
if (target instanceof Settings settings) {
repositories = settings.getDependencyResolutionManagement().getRepositories();
// leave a marker so projects don't try to override these
settings.getGradle().getPluginManager().apply(LoomRepositoryPlugin.class);
} else if (target instanceof Project project) {
if (project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
return;
}
repositories = project.getRepositories();
} else if (target instanceof Gradle) {
return;
} else {
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
}
Cache cache = new Cache(target);
// MavenConfiguration.java
repositories.flatDir(repo -> {
repo.setName("UserLocalCacheFiles");
repo.dir(cache.getRootBuildCache());
});
repositories.maven(repo -> {
repo.setName("UserLocalRemappedMods");
repo.setUrl(cache.getRemappedModCache());
});
repositories.maven(repo -> {
repo.setName("Fabric");
repo.setUrl("https://maven.fabricmc.net/");
});
repositories.maven(repo -> {
repo.setName("Mojang");
repo.setUrl("https://libraries.minecraft.net/");
});
repositories.mavenCentral();
// MinecraftMappedProvider.java
repositories.ivy(repo -> {
repo.setUrl(cache.getUserCache());
repo.patternLayout(layout -> {
layout.artifact("[revision]/[artifact]-[revision](-[classifier])(.[ext])");
});
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
// MinecraftProcessedProvider.java
repositories.ivy(repo -> {
repo.setUrl(cache.getRootPersistentCache());
repo.patternLayout(layout -> {
layout.artifact("[revision]/[artifact]-[revision](-[classifier])(.[ext])");
});
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
}
}
final class Cache {
private PluginAware target;
Cache(PluginAware target) {
if (target instanceof Project || target instanceof Settings) {
this.target = target;
} else {
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
}
}
File getUserCache() {
File gradleUserHomeDir = null;
if (target instanceof Settings settings) {
gradleUserHomeDir = settings.getGradle().getGradleUserHomeDir();
} else if (target instanceof Project project) {
gradleUserHomeDir = project.getGradle().getGradleUserHomeDir();
} else {
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
}
File userCache = new File(gradleUserHomeDir, "caches" + File.separator + "fabric-loom");
if (!userCache.exists()) {
userCache.mkdirs();
}
return userCache;
}
public File getRootPersistentCache() {
File rootDir = null;
if (target instanceof Settings settings) {
rootDir = settings.getRootDir();
} else if (target instanceof Project project) {
rootDir = project.getRootDir();
} else {
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
}
File persistentCache = new File(rootDir, ".gradle" + File.separator + "loom-cache");
if (!persistentCache.exists()) {
persistentCache.mkdirs();
}
return persistentCache;
}
public File getRootBuildCache() {
File rootDir = null;
if (target instanceof Settings settings) {
rootDir = settings.getRootDir();
} else if (target instanceof Project project) {
rootDir = project.getRootDir();
} else {
throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass());
}
File buildCache = new File(rootDir, "build" + File.separator + "loom-cache");
if (!buildCache.exists()) {
buildCache.mkdirs();
}
return buildCache;
}
public File getRemappedModCache() {
File remappedModCache = new File(getRootPersistentCache(), "remapped_mods");
if (!remappedModCache.exists()) {
remappedModCache.mkdir();
}
return remappedModCache;
}
public File getNestedModCache() {
File nestedModCache = new File(getRootPersistentCache(), "nested_mods");
if (!nestedModCache.exists()) {
nestedModCache.mkdir();
}
return nestedModCache;
}
public File getNativesJarStore() {
File natives = new File(getUserCache(), "natives/jars");
if (!natives.exists()) {
natives.mkdirs();
}
return natives;
}
}

View File

@@ -32,7 +32,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
@@ -42,7 +43,6 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
@@ -103,17 +103,17 @@ public final class NestedDependencyProvider implements NestedJarProvider {
visited.add(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion());
// TODO change this to allow just normal jar tasks, so a project can have a none loom sub project
Collection<Task> remapJarTasks = dependencyProject.getTasksByName("remapJar", false);
Collection<Task> jarTasks = dependencyProject.getTasksByName("jar", false);
for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) {
if (task instanceof RemapJarTask remapJarTask) {
File file = remapJarTask.getArchiveFile().get().getAsFile();
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
} else if (task instanceof AbstractArchiveTask abstractArchiveTask) {
File file = abstractArchiveTask.getArchiveFile().get().getAsFile();
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
if (task instanceof AbstractArchiveTask abstractArchiveTask) {
fileList.add(new DependencyInfo<>(
projectDependency,
new ProjectDependencyMetaExtractor(),
abstractArchiveTask.getArchiveFile().get().getAsFile(),
abstractArchiveTask.getArchiveClassifier().getOrNull()
));
}
}
}
@@ -133,14 +133,13 @@ public final class NestedDependencyProvider implements NestedJarProvider {
continue;
}
List<File> files = dependency
.getModuleArtifacts()
.stream()
.map(ResolvedArtifact::getFile)
.collect(Collectors.toList());
for (File file : files) {
fileList.add(new DependencyInfo<>(dependency, new ResolvedDependencyMetaExtractor(), file));
for (var artifact : dependency.getModuleArtifacts()) {
fileList.add(new DependencyInfo<>(
dependency,
new ResolvedDependencyMetaExtractor(),
artifact.getFile(),
artifact.getClassifier()
));
}
}
@@ -195,7 +194,12 @@ public final class NestedDependencyProvider implements NestedJarProvider {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("schemaVersion", 1);
jsonObject.addProperty("id", (metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency)).replaceAll("\\.", "_").toLowerCase(Locale.ENGLISH));
jsonObject.addProperty("id",
(metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency) + info.getClassifierSuffix())
.replaceAll("\\.", "_")
.toLowerCase(Locale.ENGLISH)
);
jsonObject.addProperty("version", metaExtractor.version(dependency));
jsonObject.addProperty("name", metaExtractor.name(dependency));
@@ -206,8 +210,8 @@ public final class NestedDependencyProvider implements NestedJarProvider {
return LoomGradlePlugin.GSON.toJson(jsonObject);
}
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file) {
public void validateInputs() {
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file, @Nullable String classifier) {
void validateInputs() {
if (!file.exists()) {
throw new RuntimeException("Failed to include nested jars, as it could not be found @ " + file.getAbsolutePath());
}
@@ -216,6 +220,14 @@ public final class NestedDependencyProvider implements NestedJarProvider {
throw new RuntimeException("Failed to include nested jars, as file was not a jar: " + file.getAbsolutePath());
}
}
String getClassifierSuffix() {
if (classifier == null) {
return "";
} else {
return "_" + classifier;
}
}
}
private interface DependencyMetaExtractor<D> {

View File

@@ -142,8 +142,6 @@ public final class CompileConfiguration {
p.afterEvaluate(project -> {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MavenConfiguration.setup(project);
LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager);

View File

@@ -45,6 +45,7 @@ import net.fabricmc.loom.configuration.mods.ModProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.loom.LoomRepositoryPlugin;
public class LoomDependencyManager {
private static class ProviderList {
@@ -194,7 +195,9 @@ public class LoomDependencyManager {
project.getLogger().debug("Loom adding " + name + " from installer JSON");
if (jsonElement.getAsJsonObject().has("url")) {
// If user choose to use dependencyResolutionManagement, then they should declare
// these repositories manually in the settings file.
if (jsonElement.getAsJsonObject().has("url") && !project.getGradle().getPlugins().hasPlugin(LoomRepositoryPlugin.class)) {
String url = jsonElement.getAsJsonObject().get("url").getAsString();
long count = project.getRepositories().stream().filter(artifactRepository -> artifactRepository instanceof MavenArtifactRepository)
.map(artifactRepository -> (MavenArtifactRepository) artifactRepository)

View File

@@ -1,74 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 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.configuration;
import org.gradle.api.Project;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import net.fabricmc.loom.LoomGradleExtension;
public class MavenConfiguration {
public static void setup(Project project) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
project.getRepositories().flatDir(repo -> {
repo.setName("UserLocalCacheFiles");
repo.dir(extension.getRootProjectBuildCache());
});
project.getRepositories().maven(repo -> {
repo.setName("UserLocalRemappedMods");
repo.setUrl(extension.getRemappedModCache());
});
project.getRepositories().maven(repo -> {
repo.setName("Fabric");
repo.setUrl("https://maven.fabricmc.net/");
});
project.getRepositories().maven(repo -> {
repo.setName("Mojang");
repo.setUrl("https://libraries.minecraft.net/");
});
project.getRepositories().maven(repo -> {
repo.setName("Forge");
repo.setUrl("https://maven.minecraftforge.net/");
repo.metadataSources(sources -> {
sources.mavenPom();
try {
MavenArtifactRepository.MetadataSources.class.getDeclaredMethod("ignoreGradleMetadataRedirection")
.invoke(sources);
} catch (Throwable ignored) {
// Method not available
}
});
});
project.getRepositories().mavenCentral();
}
}

View File

@@ -37,7 +37,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvid
import net.fabricmc.loom.util.Constants;
public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public static final String PROJECT_MAPPED_CLASSIFIER = "projectmapped";
public final String projectMappedClassifier;
private File projectMappedJar;
@@ -46,6 +46,8 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public MinecraftProcessedProvider(Project project, JarProcessorManager jarProcessorManager) {
super(project);
this.jarProcessorManager = jarProcessorManager;
this.projectMappedClassifier = "project-" + project.getPath().replace(':', '@')
+ "-mapped";
}
@Override
@@ -65,14 +67,12 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
jarProcessorManager.process(projectMappedJar);
}
getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER)));
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER)));
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(projectMappedClassifier)));
}
private void invalidateJars() {
File dir = getJarDirectory(getExtension().getUserCache(), PROJECT_MAPPED_CLASSIFIER);
File dir = getJarDirectory(getExtension().getUserCache(), projectMappedClassifier);
if (dir.exists()) {
getProject().getLogger().warn("Invalidating project jars");
@@ -89,7 +89,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
super.initFiles(minecraftProvider, mappingsProvider);
projectMappedJar = new File(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER), "minecraft-" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER) + ".jar");
projectMappedJar = new File(getJarDirectory(getExtension().getRootProjectPersistentCache(), projectMappedClassifier), "minecraft-" + getJarVersionString(projectMappedClassifier) + ".jar");
}
@Override

View File

@@ -290,8 +290,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
}
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getUserCache(), "mapped")));
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString("mapped")));
}

View File

@@ -106,7 +106,14 @@ public abstract class AbstractFernFlowerDecompiler implements LoomDecompiler {
spec.getMainClass().set(fernFlowerExecutor().getName());
spec.jvmArgs("-Xms200m", "-Xmx3G");
spec.setArgs(args);
spec.setErrorOutput(System.err);
spec.setErrorOutput(new ConsumingOutputStream(line -> {
if (line.startsWith("Inconsistent inner class entries")) {
// Suppress this
return;
}
System.err.println(line);
}));
spec.setStandardOutput(new ConsumingOutputStream(line -> {
if (line.startsWith("Listening for transport") || !line.contains("::")) {
System.out.println(line);