diff options
Diffstat (limited to 'src/main/java/net/fabricmc/loom/build')
12 files changed, 65 insertions, 34 deletions
diff --git a/src/main/java/net/fabricmc/loom/build/JarRemapper.java b/src/main/java/net/fabricmc/loom/build/JarRemapper.java index 67088057..d97bf925 100644 --- a/src/main/java/net/fabricmc/loom/build/JarRemapper.java +++ b/src/main/java/net/fabricmc/loom/build/JarRemapper.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2020 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 diff --git a/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java b/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java index 1a819a13..bc775746 100644 --- a/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java +++ b/src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2018-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java index 5f72791e..4a4a808b 100644 --- a/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java +++ b/src/main/java/net/fabricmc/loom/build/ModCompileRemapper.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2019-2021 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,11 +28,14 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; import java.util.zip.ZipFile; +import com.google.common.io.Files; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.FileCollectionDependency; import org.gradle.api.artifacts.ModuleDependency; import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.artifacts.dsl.DependencyHandler; @@ -40,9 +43,11 @@ import org.gradle.api.artifacts.query.ArtifactResolutionQuery; import org.gradle.api.artifacts.result.ArtifactResult; import org.gradle.api.artifacts.result.ComponentArtifactsResult; import org.gradle.api.artifacts.result.ResolvedArtifactResult; +import org.gradle.api.file.FileCollection; import org.gradle.api.logging.Logger; import org.gradle.jvm.JvmLibrary; import org.gradle.language.base.artifact.SourcesArtifact; +import org.jetbrains.annotations.Nullable; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradlePlugin; @@ -51,12 +56,21 @@ import net.fabricmc.loom.configuration.RemappedConfigurationEntry; import net.fabricmc.loom.configuration.mods.ModProcessor; import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo; import net.fabricmc.loom.configuration.processors.dependency.RemapData; +import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.OperatingSystem; import net.fabricmc.loom.util.SourceRemapper; @SuppressWarnings("UnstableApiUsage") public class ModCompileRemapper { + // This is a placeholder that is used when the actual group is missing (null or empty). + // This can happen when the dependency is a FileCollectionDependency or from a flatDir repository. + private static final String MISSING_GROUP = "unspecified"; + + private static String replaceIfNullOrEmpty(@Nullable String s, Supplier<String> fallback) { + return s == null || s.isEmpty() ? fallback.get() : s; + } + public static void remapDependencies(Project project, String mappingsSuffix, LoomGradleExtension extension, SourceRemapper sourceRemapper) { Logger logger = project.getLogger(); DependencyHandler dependencies = project.getDependencies(); @@ -75,29 +89,18 @@ public class ModCompileRemapper { List<ModDependencyInfo> modDependencies = new ArrayList<>(); for (ResolvedArtifact artifact : sourceConfig.getResolvedConfiguration().getResolvedArtifacts()) { - // TODO: This collection doesn't appear to include FileCollection dependencies - // Might have to go based on the dependencies, rather than their resolved form? - // File dependencies use SelfResolvingDependency, which appears to be handled differently - String group = artifact.getModuleVersion().getId().getGroup(); + String group = replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getGroup(), () -> MISSING_GROUP); String name = artifact.getModuleVersion().getId().getName(); - String version = artifact.getModuleVersion().getId().getVersion(); + String version = replaceIfNullOrEmpty(artifact.getModuleVersion().getId().getVersion(), () -> Checksum.truncatedSha256(artifact.getFile())); - if (!shouldRemapMod(logger, artifact, extension.isForge(), sourceConfig.getName())) { + if (!shouldRemapMod(logger, artifact.getFile(), artifact.getId(), extension.isForge(), sourceConfig.getName())) { addToRegularCompile(project, regularConfig, artifact); continue; } ModDependencyInfo info = new ModDependencyInfo(group, name, version, artifact.getClassifier(), artifact.getFile(), remappedConfig, remapData); - - if (refreshDeps) { - info.forceRemap(); - } - modDependencies.add(info); - String remappedLog = group + ":" + name + ":" + version + (artifact.getClassifier() == null ? "" : ":" + artifact.getClassifier()) + " (" + mappingsSuffix + ")" + (info.requiresRemapping() ? " requires remapping" : " already remapped in " + info.getRemappedOutput().getAbsolutePath()); - project.getLogger().info(":providing " + remappedLog); - File remappedSources = info.getRemappedOutput("sources"); if ((!remappedSources.exists() || refreshDeps) && !OperatingSystem.isCIBuild()) { @@ -109,6 +112,36 @@ public class ModCompileRemapper { } } + // FileCollectionDependency (files/fileTree) doesn't resolve properly, + // so we have to "resolve" it on our own. The naming is "abc.jar" => "unspecified:abc:unspecified". + for (FileCollectionDependency dependency : sourceConfig.getAllDependencies().withType(FileCollectionDependency.class)) { + String group = replaceIfNullOrEmpty(dependency.getGroup(), () -> MISSING_GROUP); + FileCollection files = dependency.getFiles(); + + // Create a mod dependency for each file in the file collection + for (File artifact : files) { + if (!shouldRemapMod(logger, artifact, artifact.getName(), extension.isForge(), sourceConfig.getName())) { + dependencies.add(regularConfig.getName(), project.files(artifact)); + continue; + } + + String name = Files.getNameWithoutExtension(artifact.getAbsolutePath()); + String version = replaceIfNullOrEmpty(dependency.getVersion(), () -> Checksum.truncatedSha256(artifact)); + + ModDependencyInfo info = new ModDependencyInfo(group, name, version, null, artifact, remappedConfig, remapData); + modDependencies.add(info); + } + } + + for (ModDependencyInfo info : modDependencies) { + if (refreshDeps) { + info.forceRemap(); + } + + String remappedLog = info.getRemappedNotation() + " (" + mappingsSuffix + ")"; + project.getLogger().info(":providing " + remappedLog); + } + try { ModProcessor.processMods(project, modDependencies); } catch (IOException e) { @@ -129,26 +162,24 @@ public class ModCompileRemapper { /** * Checks if an artifact is a fabric mod, according to the presence of a fabric.mod.json. */ - private static boolean shouldRemapMod(Logger logger, ResolvedArtifact artifact, boolean forge, String config) { - File input = artifact.getFile(); - - try (ZipFile zipFile = new ZipFile(input)) { + private static boolean shouldRemapMod(Logger logger, File artifact, Object id, boolean forge, String config) { + try (ZipFile zipFile = new ZipFile(artifact)) { if (zipFile.getEntry("architectury.common.marker") != null) { - logger.info("Found architectury common mod in " + config + ": {}", artifact.getId()); + logger.info("Found architectury common mod in " + config + ": {}", id); return true; } if (forge) { if (zipFile.getEntry("META-INF/mods.toml") != null) { - logger.info("Found Forge mod in " + config + ": {}", artifact.getId()); + logger.info("Found Forge mod in " + config + ": {}", id); return true; } - logger.lifecycle(":could not find forge mod in " + config + " but forcing: {}", artifact.getId()); + logger.lifecycle(":could not find forge mod in " + config + " but forcing: {}", id); return true; } else { if (zipFile.getEntry("fabric.mod.json") != null) { - logger.info("Found Fabric mod in " + config + ": {}", artifact.getId()); + logger.info("Found Fabric mod in " + config + ": {}", id); return true; } } diff --git a/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java b/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java index a0c3987b..bb2f2f19 100644 --- a/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java +++ b/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2020-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/mixin/JavaApInvoker.java b/src/main/java/net/fabricmc/loom/build/mixin/JavaApInvoker.java index 2e52d0d7..aa7d46a7 100644 --- a/src/main/java/net/fabricmc/loom/build/mixin/JavaApInvoker.java +++ b/src/main/java/net/fabricmc/loom/build/mixin/JavaApInvoker.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2016-2020 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 diff --git a/src/main/java/net/fabricmc/loom/build/mixin/KaptApInvoker.java b/src/main/java/net/fabricmc/loom/build/mixin/KaptApInvoker.java index 41d6d0ba..5443855a 100644 --- a/src/main/java/net/fabricmc/loom/build/mixin/KaptApInvoker.java +++ b/src/main/java/net/fabricmc/loom/build/mixin/KaptApInvoker.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2020-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/mixin/ScalaApInvoker.java b/src/main/java/net/fabricmc/loom/build/mixin/ScalaApInvoker.java index 7fed5610..bc77e152 100644 --- a/src/main/java/net/fabricmc/loom/build/mixin/ScalaApInvoker.java +++ b/src/main/java/net/fabricmc/loom/build/mixin/ScalaApInvoker.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2016-2020 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 diff --git a/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java b/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java index 6330b612..662fc2cf 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/JarNester.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2018-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java index 61b05eb6..48b4db01 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/MergedNestedJarProvider.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2016-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java index 60640cb6..2dae34f6 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedDependencyProvider.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2019-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java index 184617ff..deccda49 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarPathProvider.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2016-2021 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 diff --git a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarProvider.java b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarProvider.java index 3ddbae31..79c605ce 100644 --- a/src/main/java/net/fabricmc/loom/build/nesting/NestedJarProvider.java +++ b/src/main/java/net/fabricmc/loom/build/nesting/NestedJarProvider.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016, 2017, 2018 FabricMC + * Copyright (c) 2016-2021 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 |