mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 05:27:43 -05:00
Merge remote-tracking branch 'FabricMC/dev/0.10' into dev/future
# Conflicts: # build.gradle # src/main/java/net/fabricmc/loom/LoomGradleExtension.java # src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java # src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java # src/main/java/net/fabricmc/loom/build/MixinRefmapHelper.java # src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java # src/main/java/net/fabricmc/loom/configuration/MavenPublication.java # src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java # src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java # src/main/java/net/fabricmc/loom/extension/MixinExtensionImpl.java # src/main/java/net/fabricmc/loom/task/RemapJarTask.java # src/main/java/net/fabricmc/loom/util/Constants.java # src/main/java/net/fabricmc/loom/util/SourceRemapper.java # src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy
This commit is contained in:
@@ -50,7 +50,7 @@ import net.fabricmc.loom.configuration.providers.forge.SrgProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
|
||||
import net.fabricmc.loom.extension.LoomFiles;
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
|
||||
public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
static LoomGradleExtension get(Project project) {
|
||||
@@ -109,7 +109,7 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
MixinApExtension getMixin();
|
||||
MixinExtension getMixin();
|
||||
|
||||
// ===================
|
||||
// Architectury Loom
|
||||
|
||||
@@ -83,12 +83,12 @@ public class LoomGradlePlugin implements BootstrappedPlugin {
|
||||
}
|
||||
|
||||
// Apply default plugins
|
||||
project.apply(ImmutableMap.of("plugin", "java"));
|
||||
project.apply(ImmutableMap.of("plugin", "java-library"));
|
||||
project.apply(ImmutableMap.of("plugin", "eclipse"));
|
||||
project.apply(ImmutableMap.of("plugin", "idea"));
|
||||
|
||||
// Setup extensions, minecraft wraps loom
|
||||
var extension = project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project));
|
||||
LoomGradleExtensionAPI extension = project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project));
|
||||
project.getExtensions().create(LoomGradleExtensionAPI.class, "minecraft", MinecraftGradleExtension.class, extension);
|
||||
project.getExtensions().create("fabricApi", FabricApiExtension.class, project);
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
@@ -160,11 +161,11 @@ public interface LoomGradleExtensionAPI {
|
||||
|
||||
NamedDomainObjectContainer<RunConfigSettings> getRunConfigs();
|
||||
|
||||
@ApiStatus.Experimental
|
||||
void mixin(Action<MixinApExtensionAPI> action);
|
||||
void mixin(Action<MixinExtensionAPI> action);
|
||||
|
||||
@ApiStatus.Experimental
|
||||
MixinApExtensionAPI getMixin();
|
||||
// TODO: move this from LoomGradleExtensionAPI to LoomGradleExtension once getRefmapName & setRefmapName is removed.
|
||||
MixinExtensionAPI getMixin();
|
||||
|
||||
Property<String> getCustomMinecraftManifest();
|
||||
|
||||
@@ -182,6 +183,35 @@ public interface LoomGradleExtensionAPI {
|
||||
return getCustomMinecraftManifest().getOrNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, Loom will replace the {@code -dev} jars in the {@code *Elements} configurations
|
||||
* with remapped outgoing variants.
|
||||
*
|
||||
* <p>Will only apply if {@link #getRemapArchives()} is also true.
|
||||
*
|
||||
* @return the property controlling the setup of remapped variants
|
||||
*/
|
||||
Property<Boolean> getSetupRemappedVariants();
|
||||
|
||||
/**
|
||||
* Disables the deprecated POM generation for a publication.
|
||||
* This is useful if you want to suppress deprecation warnings when you're not using software components.
|
||||
*
|
||||
* <p>Experimental API: Will be removed in Loom 0.12 together with the deprecated POM generation functionality.
|
||||
*
|
||||
* @param publication the maven publication
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
void disableDeprecatedPomGeneration(MavenPublication publication);
|
||||
|
||||
/**
|
||||
* Reads the mod version from the fabric.mod.json file located in the main sourcesets resources.
|
||||
* This is useful if you want to set the gradle version based of the version in the fabric.mod.json file.
|
||||
*
|
||||
* @return the version defined in the fabric.mod.json
|
||||
*/
|
||||
String getModVersion();
|
||||
|
||||
// ===================
|
||||
// Architectury Loom
|
||||
// ===================
|
||||
|
||||
@@ -31,7 +31,9 @@ import org.gradle.api.tasks.util.PatternSet;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface MixinApExtensionAPI {
|
||||
public interface MixinExtensionAPI {
|
||||
Property<Boolean> getUseLegacyMixinAp();
|
||||
|
||||
Property<String> getDefaultRefmapName();
|
||||
|
||||
/**
|
||||
@@ -45,27 +47,27 @@ public interface MixinApExtensionAPI {
|
||||
void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSet the sourceSet that applies Mixin AP.
|
||||
* @param refmapName the output ref-map name.
|
||||
*/
|
||||
void add(SourceSet sourceSet, String refmapName);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSet the sourceSet that applies Mixin AP.
|
||||
* @param action used for filter the mixin json files.
|
||||
*/
|
||||
void add(SourceSet sourceSet, Action<PatternSet> action);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSet the sourceSet that applies Mixin AP.
|
||||
*/
|
||||
void add(SourceSet sourceSet);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSetName the name of sourceSet that applies Mixin AP.
|
||||
* @param refmapName the output ref-map name.
|
||||
* @param action used for filter the mixin json files.
|
||||
@@ -73,21 +75,21 @@ public interface MixinApExtensionAPI {
|
||||
void add(String sourceSetName, String refmapName, Action<PatternSet> action);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSetName the name of sourceSet that applies Mixin AP.
|
||||
* @param refmapName the output ref-map name.
|
||||
*/
|
||||
void add(String sourceSetName, String refmapName);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSetName the name of sourceSet that applies Mixin AP.
|
||||
* @param action used for filter the mixin json files.
|
||||
*/
|
||||
void add(String sourceSetName, Action<PatternSet> action);
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinApExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* Apply Mixin AP to sourceSet. See {@link MixinExtensionAPI#add(SourceSet, String, Action)} for more detail.
|
||||
* @param sourceSetName the name of sourceSet that applies Mixin AP.
|
||||
*/
|
||||
void add(String sourceSetName);
|
||||
@@ -48,7 +48,7 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
|
||||
public final class MixinRefmapHelper {
|
||||
private MixinRefmapHelper() { }
|
||||
@@ -57,14 +57,14 @@ public final class MixinRefmapHelper {
|
||||
|
||||
public static boolean addRefmapName(Project project, Path outputPath) {
|
||||
try {
|
||||
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
File output = outputPath.toFile();
|
||||
|
||||
Collection<String> allMixinConfigs = getMixinConfigurationFiles(readFabricModJson(output));
|
||||
|
||||
return mixin.getMixinSourceSetsStream().map(sourceSet -> {
|
||||
MixinApExtension.MixinInformationContainer container = Objects.requireNonNull(
|
||||
MixinApExtension.getMixinInformationContainer(sourceSet)
|
||||
MixinExtension.MixinInformationContainer container = Objects.requireNonNull(
|
||||
MixinExtension.getMixinInformationContainer(sourceSet)
|
||||
);
|
||||
|
||||
Stream<String> mixinConfigs = sourceSet.getResources()
|
||||
@@ -113,7 +113,7 @@ public final class MixinRefmapHelper {
|
||||
JsonArray mixins = fabricModJson.getAsJsonArray("mixins");
|
||||
|
||||
if (mixins == null) {
|
||||
return Collections.emptySet();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return StreamSupport.stream(mixins.spliterator(), false)
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
}
|
||||
|
||||
protected static Collection<Configuration> getApConfigurations(Project project, Function<String, String> getApConfigNameFunc) {
|
||||
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
return mixin.getApConfigurationsStream(getApConfigNameFunc).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
private void passMixinArguments(T task, SourceSet sourceSet) {
|
||||
try {
|
||||
LoomGradleExtension loom = LoomGradleExtension.get(project);
|
||||
String refmapName = Objects.requireNonNull(MixinApExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
Map<String, String> args = new HashMap<>() {{
|
||||
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, loom.getNextMixinMappings().getCanonicalPath());
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
|
||||
public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
|
||||
public JavaApInvoker(Project project) {
|
||||
@@ -46,7 +46,7 @@ public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
|
||||
}
|
||||
|
||||
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
|
||||
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.jetbrains.kotlin.gradle.plugin.KaptExtension;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
|
||||
public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
|
||||
private final KaptExtension kaptExtension = project.getExtensions().getByType(KaptExtension.class);
|
||||
@@ -66,7 +66,7 @@ public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
|
||||
}
|
||||
|
||||
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
|
||||
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
|
||||
SourceSet sourceSet = entry.getKey();
|
||||
task.doLast(t -> {
|
||||
try {
|
||||
String refmapName = Objects.requireNonNull(MixinApExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
Path src = Paths.get(getRefmapDestination(task, refmapName));
|
||||
Path dest = Paths.get(task.getDestinationDir().toString(), refmapName);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.scala.ScalaCompile;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
|
||||
public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
|
||||
public ScalaApInvoker(Project project) {
|
||||
@@ -47,7 +47,7 @@ public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
|
||||
}
|
||||
|
||||
private static Map<SourceSet, ScalaCompile> getInvokerTasks(Project project) {
|
||||
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.SCALA)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((ScalaCompile) entry.getValue())));
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ 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;
|
||||
@@ -133,7 +134,7 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var artifact : dependency.getModuleArtifacts()) {
|
||||
for (ResolvedArtifact artifact : dependency.getModuleArtifacts()) {
|
||||
fileList.add(new DependencyInfo<>(
|
||||
dependency,
|
||||
new ResolvedDependencyMetaExtractor(),
|
||||
|
||||
@@ -25,14 +25,12 @@
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.jvm.tasks.Jar;
|
||||
|
||||
import net.fabricmc.loom.extension.MixinApExtension;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.build.mixin.JavaApInvoker;
|
||||
import net.fabricmc.loom.build.mixin.KaptApInvoker;
|
||||
@@ -48,6 +46,7 @@ import net.fabricmc.loom.configuration.providers.forge.McpConfigProvider;
|
||||
import net.fabricmc.loom.configuration.providers.forge.PatchProvider;
|
||||
import net.fabricmc.loom.configuration.providers.forge.SrgProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
import net.fabricmc.loom.task.GenVsCodeProjectTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
@@ -56,7 +55,6 @@ public final class CompileConfiguration {
|
||||
}
|
||||
|
||||
public static void setupConfigurations(Project project) {
|
||||
final ConfigurationContainer configurations = project.getConfigurations();
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
project.afterEvaluate(project1 -> {
|
||||
@@ -121,11 +119,18 @@ public final class CompileConfiguration {
|
||||
extension.createLazyConfiguration(entry.getRemappedConfiguration())
|
||||
.configure(configuration -> configuration.setTransitive(false));
|
||||
|
||||
extendsFrom(entry.getTargetConfiguration(configurations), entry.getRemappedConfiguration(), project);
|
||||
|
||||
if (entry.isOnModCompileClasspath()) {
|
||||
if (entry.compileClasspath()) {
|
||||
extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH, entry.sourceConfiguration(), project);
|
||||
extendsFrom(Constants.Configurations.MOD_COMPILE_CLASSPATH_MAPPED, entry.getRemappedConfiguration(), project);
|
||||
extendsFrom(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, entry.getRemappedConfiguration(), project);
|
||||
}
|
||||
|
||||
if (entry.runtimeClasspath()) {
|
||||
extendsFrom(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, entry.getRemappedConfiguration(), project);
|
||||
}
|
||||
|
||||
if (entry.hasConsumerConfiguration()) {
|
||||
extendsFrom(entry.consumerConfiguration(), entry.sourceConfiguration(), project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +142,7 @@ public final class CompileConfiguration {
|
||||
extendsFrom(Constants.Configurations.LOADER_DEPENDENCIES, Constants.Configurations.MINECRAFT_DEPENDENCIES, project);
|
||||
extendsFrom(Constants.Configurations.MINECRAFT_NAMED, Constants.Configurations.LOADER_DEPENDENCIES, project);
|
||||
|
||||
extendsFrom(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, Constants.Configurations.MAPPINGS_FINAL, project);
|
||||
extendsFrom(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.MAPPINGS_FINAL, project);
|
||||
|
||||
extendsFrom(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES, project);
|
||||
extendsFrom(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES, project);
|
||||
@@ -195,25 +200,10 @@ public final class CompileConfiguration {
|
||||
extension.getUnmappedModCollection().from(jarTask);
|
||||
}
|
||||
|
||||
// Disable some things used by log4j via the mixin AP that prevent it from being garbage collected
|
||||
System.setProperty("log4j2.disable.jmx", "true");
|
||||
System.setProperty("log4j.shutdownHookEnabled", "false");
|
||||
System.setProperty("log4j.skipJansi", "true");
|
||||
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
|
||||
|
||||
project.getLogger().info("Configuring compiler arguments for Java");
|
||||
MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixin();
|
||||
mixinApExtension.init();
|
||||
|
||||
new JavaApInvoker(project).configureMixin();
|
||||
|
||||
if (project.getPluginManager().hasPlugin("scala")) {
|
||||
project.getLogger().info("Configuring compiler arguments for Scala");
|
||||
new ScalaApInvoker(project).configureMixin();
|
||||
}
|
||||
|
||||
if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) {
|
||||
project.getLogger().info("Configuring compiler arguments for Kapt plugin");
|
||||
new KaptApInvoker(project).configureMixin();
|
||||
if (mixin.getUseLegacyMixinAp().get()) {
|
||||
setupMixinAp(project, mixin);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,6 +213,29 @@ public final class CompileConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupMixinAp(Project project, MixinExtension mixin) {
|
||||
mixin.init();
|
||||
|
||||
// Disable some things used by log4j via the mixin AP that prevent it from being garbage collected
|
||||
System.setProperty("log4j2.disable.jmx", "true");
|
||||
System.setProperty("log4j.shutdownHookEnabled", "false");
|
||||
System.setProperty("log4j.skipJansi", "true");
|
||||
|
||||
project.getLogger().info("Configuring compiler arguments for Java");
|
||||
|
||||
new JavaApInvoker(project).configureMixin();
|
||||
|
||||
if (project.getPluginManager().hasPlugin("scala")) {
|
||||
project.getLogger().info("Configuring compiler arguments for Scala");
|
||||
new ScalaApInvoker(project).configureMixin();
|
||||
}
|
||||
|
||||
if (project.getPluginManager().hasPlugin("org.jetbrains.kotlin.kapt")) {
|
||||
project.getLogger().info("Configuring compiler arguments for Kapt plugin");
|
||||
new KaptApInvoker(project).configureMixin();
|
||||
}
|
||||
}
|
||||
|
||||
private static void extendsFrom(String a, String b, Project project) {
|
||||
project.getConfigurations().getByName(a, configuration -> configuration.extendsFrom(project.getConfigurations().getByName(b)));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.jar.Manifest;
|
||||
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.util.GradleVersion;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
@@ -46,7 +47,7 @@ public final record JarManifestConfiguration(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
var tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion());
|
||||
Optional<String> tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion());
|
||||
|
||||
attributes.putValue("Fabric-Gradle-Version", GradleVersion.current().getVersion());
|
||||
attributes.putValue("Fabric-Loom-Version", LoomGradlePlugin.LOOM_VERSION);
|
||||
@@ -63,7 +64,7 @@ public final record JarManifestConfiguration(Project project) {
|
||||
|
||||
private void addMixinVersion(Attributes attributes) {
|
||||
// Not super ideal that this uses the mod compile classpath, should prob look into making this not a thing at somepoint
|
||||
var dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES)
|
||||
Optional<Dependency> dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES)
|
||||
.getDependencies()
|
||||
.stream()
|
||||
.filter(dep -> "sponge-mixin".equals(dep.getName()))
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -171,15 +170,7 @@ public class LoomDependencyManager {
|
||||
|
||||
ModCompileRemapper.remapDependencies(project, mappingsIdentifier, extension, sourceRemapper);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
sourceRemapper.remapAll();
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException("Failed to remap mod sources", exception);
|
||||
}
|
||||
|
||||
project.getLogger().info("Source remapping took: %dms".formatted(System.currentTimeMillis() - start));
|
||||
sourceRemapper.remapAll();
|
||||
|
||||
for (Runnable runnable : afterTasks) {
|
||||
runnable.run();
|
||||
@@ -200,7 +191,8 @@ public class LoomDependencyManager {
|
||||
modDep.setTransitive(false);
|
||||
loaderDepsConfig.getDependencies().add(modDep);
|
||||
|
||||
if (!extension.ideSync()) {
|
||||
// TODO: work around until https://github.com/FabricMC/Mixin/pull/60 and https://github.com/FabricMC/fabric-mixin-compile-extensions/issues/14 is fixed.
|
||||
if (!extension.ideSync() && extension.getMixin().getUseLegacyMixinAp().get()) {
|
||||
apDepsConfig.getDependencies().add(modDep);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,14 @@
|
||||
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import groovy.util.Node;
|
||||
import org.gradle.api.Project;
|
||||
@@ -35,48 +40,70 @@ import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.ExcludeRule;
|
||||
import org.gradle.api.artifacts.ModuleDependency;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.publish.Publication;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.DeprecationHelper;
|
||||
import net.fabricmc.loom.util.GroovyXmlUtil;
|
||||
|
||||
public final class MavenPublication {
|
||||
private static final Map<String, String> CONFIGURATION_TO_SCOPE = Map.of(
|
||||
JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, "compile",
|
||||
JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, "runtime"
|
||||
);
|
||||
private static final Set<Publication> EXCLUDED_PUBLICATIONS = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
|
||||
private MavenPublication() {
|
||||
}
|
||||
|
||||
public static void configure(Project project) {
|
||||
project.afterEvaluate((p) -> {
|
||||
// add modsCompile to maven-publish
|
||||
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
|
||||
AtomicBoolean reportedDeprecation = new AtomicBoolean(false);
|
||||
|
||||
if (mavenPublish == null) {
|
||||
p.getLogger().info("No maven publications for project [" + p.getName() + "], skipping configuration.");
|
||||
return;
|
||||
}
|
||||
CONFIGURATION_TO_SCOPE.forEach((configurationName, scope) -> {
|
||||
Configuration config = p.getConfigurations().getByName(configurationName);
|
||||
|
||||
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
|
||||
if (!entry.hasMavenScope()) {
|
||||
continue;
|
||||
// add modsCompile to maven-publish
|
||||
PublishingExtension mavenPublish = p.getExtensions().findByType(PublishingExtension.class);
|
||||
|
||||
if (mavenPublish != null) {
|
||||
p.getLogger().info("Processing maven publication for project [" + p.getName() + "] of " + entry.sourceConfiguration());
|
||||
processEntry(project, scope, config, mavenPublish, reportedDeprecation);
|
||||
}
|
||||
|
||||
Configuration compileModsConfig = p.getConfigurations().getByName(entry.sourceConfiguration());
|
||||
|
||||
p.getLogger().info("Processing maven publication for project [" + p.getName() + "] of " + entry.sourceConfiguration());
|
||||
processEntry(p.getLogger(), entry, compileModsConfig, mavenPublish);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static void processEntry(Logger logger, RemappedConfigurationEntry entry, Configuration compileModsConfig, PublishingExtension mavenPublish) {
|
||||
private static boolean hasSoftwareComponent(Publication publication) {
|
||||
try {
|
||||
Method getComponent = publication.getClass().getMethod("getComponent");
|
||||
return getComponent.invoke(publication) != null;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// our hacks have broken!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove this in Loom 0.12
|
||||
private static void processEntry(Project project, String scope, Configuration config, PublishingExtension mavenPublish, AtomicBoolean reportedDeprecation) {
|
||||
mavenPublish.publications((publications) -> {
|
||||
for (Publication publication : publications) {
|
||||
if (!(publication instanceof org.gradle.api.publish.maven.MavenPublication)) {
|
||||
if (!(publication instanceof org.gradle.api.publish.maven.MavenPublication mavenPublication)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.info("Processing maven publication [" + publication.getName() + "]");
|
||||
((org.gradle.api.publish.maven.MavenPublication) publication).pom((pom) -> pom.withXml((xml) -> {
|
||||
if (hasSoftwareComponent(publication) || EXCLUDED_PUBLICATIONS.contains(publication)) {
|
||||
continue;
|
||||
} else if (!reportedDeprecation.get()) {
|
||||
DeprecationHelper deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper();
|
||||
deprecationHelper.warn("Loom is applying dependency data manually to publications instead of using a software component (from(components[\"java\"])). This is deprecated and will be removed in Loom 0.12.");
|
||||
reportedDeprecation.set(true);
|
||||
}
|
||||
|
||||
project.getLogger().info("Processing maven publication [" + publication.getName() + "]");
|
||||
mavenPublication.pom((pom) -> pom.withXml((xml) -> {
|
||||
Node dependencies = GroovyXmlUtil.getOrCreateNode(xml.asNode(), "dependencies");
|
||||
Set<String> foundArtifacts = new HashSet<>();
|
||||
|
||||
@@ -89,7 +116,7 @@ public final class MavenPublication {
|
||||
}
|
||||
});
|
||||
|
||||
for (Dependency dependency : compileModsConfig.getAllDependencies()) {
|
||||
for (Dependency dependency : config.getAllDependencies()) {
|
||||
if (foundArtifacts.contains(dependency.getGroup() + ":" + dependency.getName())) {
|
||||
logger.info("Found inserted artifact " + dependency.getGroup() + ":" + dependency.getName());
|
||||
continue;
|
||||
@@ -101,7 +128,7 @@ public final class MavenPublication {
|
||||
depNode.appendNode("groupId", dependency.getGroup());
|
||||
depNode.appendNode("artifactId", dependency.getName());
|
||||
depNode.appendNode("version", dependency.getVersion());
|
||||
depNode.appendNode("scope", entry.mavenScope());
|
||||
depNode.appendNode("scope", scope);
|
||||
|
||||
if (!(dependency instanceof ModuleDependency)) {
|
||||
continue;
|
||||
@@ -125,4 +152,8 @@ public final class MavenPublication {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void excludePublication(Publication publication) {
|
||||
EXCLUDED_PUBLICATIONS.add(publication);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.UnknownTaskException;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.PublishArtifact;
|
||||
import org.gradle.api.artifacts.dsl.ArtifactHandler;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||
@@ -58,6 +61,40 @@ public class RemapConfiguration {
|
||||
|
||||
public static void setupDefaultRemap(Project project) {
|
||||
setupRemap(project, true, DEFAULT_JAR_TASK_NAME, DEFAULT_SOURCES_JAR_TASK_NAME, DEFAULT_REMAP_JAR_TASK_NAME, DEFAULT_REMAP_SOURCES_JAR_TASK_NAME, DEFAULT_REMAP_ALL_JARS_TASK_NAME, DEFAULT_REMAP_ALL_SOURCES_TASK_NAME);
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
extension.getSetupRemappedVariants().finalizeValue();
|
||||
|
||||
if (extension.getSetupRemappedVariants().get()) {
|
||||
ArtifactHandler artifacts = project.getArtifacts();
|
||||
project.getTasks().named(DEFAULT_REMAP_JAR_TASK_NAME, task -> {
|
||||
artifacts.add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, task);
|
||||
artifacts.add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, task);
|
||||
});
|
||||
project.getTasks().named(DEFAULT_REMAP_SOURCES_JAR_TASK_NAME, RemapSourcesJarTask.class, task -> {
|
||||
if (!project.getConfigurations().getNames().contains(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME)) {
|
||||
// Sources jar may not have been created with withSourcesJar
|
||||
return;
|
||||
}
|
||||
|
||||
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput());
|
||||
|
||||
// Remove the existing artifact that does not run remapSourcesJar.
|
||||
// It doesn't seem to hurt, but I'm not sure if the file-level duplicates cause issues.
|
||||
Configuration configuration = project.getConfigurations().getByName(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME);
|
||||
configuration.getArtifacts().removeIf(a -> a != artifact && artifact.getFile().equals(a.getFile()));
|
||||
});
|
||||
|
||||
// Remove -dev jars from the default jar task
|
||||
for (String configurationName : new String[] { JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME }) {
|
||||
Configuration configuration = project.getConfigurations().getByName(configurationName);
|
||||
configuration.getArtifacts().removeIf(artifact -> {
|
||||
Task jarTask = project.getTasks().getByName(DEFAULT_JAR_TASK_NAME);
|
||||
// if the artifact is a -dev jar and "builtBy jar"
|
||||
return "dev".equals(artifact.getClassifier()) && artifact.getBuildDependencies().getDependencies(null).contains(jarTask);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental // This is only an api if you squint really hard, expect it to explode every 5 mins. If you must call in afterEvaluate on all projects
|
||||
@@ -128,6 +165,7 @@ public class RemapConfiguration {
|
||||
|
||||
rootProject.getTasks().register(remapAllSourcesTaskName, RemapAllSourcesTask.class, task -> {
|
||||
task.sourceRemapper = sourceRemapper;
|
||||
task.doLast(t -> sourceRemapper.remapAll());
|
||||
});
|
||||
|
||||
parentTask = rootProject.getTasks().getByName(remapAllSourcesTaskName);
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean isOnModCompileClasspath, String mavenScope, @Nullable String replacedWith) {
|
||||
public RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean isOnModCompileClasspath, String mavenScope) {
|
||||
this(sourceConfiguration, targetConfiguration, isOnModCompileClasspath, mavenScope, null);
|
||||
public record RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, String consumerConfiguration, @Nullable String replacedWith) {
|
||||
public RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, String consumerConfiguration) {
|
||||
this(sourceConfiguration, targetConfiguration, compileClasspath, runtimeClasspath, consumerConfiguration, null);
|
||||
}
|
||||
|
||||
public boolean hasMavenScope() {
|
||||
return mavenScope != null && !mavenScope.isEmpty();
|
||||
public boolean hasConsumerConfiguration() {
|
||||
return consumerConfiguration != null && !consumerConfiguration.isEmpty();
|
||||
}
|
||||
|
||||
public String getRemappedConfiguration() {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 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
|
||||
* 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.mods;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
|
||||
public class ModVersionParser {
|
||||
private final Project project;
|
||||
|
||||
private String version = null;
|
||||
|
||||
public ModVersionParser(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getModVersion() {
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
|
||||
File json = locateModJsonFile();
|
||||
JsonObject jsonObject;
|
||||
|
||||
try (var reader = new FileReader(json)) {
|
||||
jsonObject = LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read fabric.mod.json file");
|
||||
}
|
||||
|
||||
if (!jsonObject.has("version") || !jsonObject.get("version").isJsonPrimitive()) {
|
||||
throw new UnsupportedOperationException("Could not find valid version in the fabric.mod.json file");
|
||||
}
|
||||
|
||||
version = jsonObject.get("version").getAsString();
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private File locateModJsonFile() {
|
||||
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets()
|
||||
.getByName("main")
|
||||
.getResources()
|
||||
.matching(patternFilterable -> patternFilterable.include("fabric.mod.json"))
|
||||
.getSingleFile();
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
||||
|
||||
if (jarProcessorManager.isInvalid(projectMappedJar) || isRefreshDeps() || isForgeAtDirty) {
|
||||
getProject().getLogger().info(":processing mapped jar");
|
||||
invalidateJars();
|
||||
invalidateJar();
|
||||
|
||||
try {
|
||||
FileUtils.copyFile(super.getMappedJar(), projectMappedJar);
|
||||
@@ -71,16 +71,14 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
|
||||
getProject().getDependencies().module("net.minecraft:minecraft-" + projectMappedClassifier + ":" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier()));
|
||||
}
|
||||
|
||||
private void invalidateJars() {
|
||||
File dir = projectMappedJar.getParentFile();
|
||||
|
||||
if (dir.exists()) {
|
||||
getProject().getLogger().warn("Invalidating project jars");
|
||||
private void invalidateJar() {
|
||||
if (projectMappedJar.exists()) {
|
||||
getProject().getLogger().warn("Invalidating project jar");
|
||||
|
||||
try {
|
||||
FileUtils.cleanDirectory(dir);
|
||||
FileUtils.forceDelete(projectMappedJar);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to invalidate jars, try stopping gradle daemon or closing the game", e);
|
||||
throw new RuntimeException("Failed to invalidate jar, try stopping gradle daemon or closing the game", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.logging.configuration.ConsoleOutput;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
@@ -120,10 +121,13 @@ public class LaunchProvider extends DependencyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
//Enable ansi by default for idea and vscode
|
||||
if (new File(getProject().getRootDir(), ".vscode").exists()
|
||||
final boolean plainConsole = getProject().getGradle().getStartParameter().getConsoleOutput() == ConsoleOutput.Plain;
|
||||
final boolean ansiSupportedIDE = new File(getProject().getRootDir(), ".vscode").exists()
|
||||
|| new File(getProject().getRootDir(), ".idea").exists()
|
||||
|| (Arrays.stream(getProject().getRootDir().listFiles()).anyMatch(file -> file.getName().endsWith(".iws")))) {
|
||||
|| (Arrays.stream(getProject().getRootDir().listFiles()).anyMatch(file -> file.getName().endsWith(".iws")));
|
||||
|
||||
//Enable ansi by default for idea and vscode when gradle is not ran with plain console.
|
||||
if (ansiSupportedIDE && !plainConsole) {
|
||||
launchConfig.property("fabric.log.disableAnsi", "false");
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
|
||||
String expVersionManifest = Files.asCharSource(experimentalVersionsJson, StandardCharsets.UTF_8).read();
|
||||
ManifestVersion expManifest = LoomGradlePlugin.OBJECT_MAPPER.readValue(expVersionManifest, ManifestVersion.class);
|
||||
|
||||
var result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
|
||||
Optional<ManifestVersion.Versions> result = expManifest.versions().stream().filter(versions -> versions.id.equalsIgnoreCase(minecraftVersion)).findFirst();
|
||||
|
||||
if (result.isPresent()) {
|
||||
getProject().getLogger().lifecycle("Using fallback experimental version {}", minecraftVersion);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class LayeredMappingSpecBuilder {
|
||||
}
|
||||
|
||||
public LayeredMappingSpecBuilder parchment(String mavenNotation, Action<ParchmentMappingsSpecBuilder> action) {
|
||||
var builder = ParchmentMappingsSpecBuilder.builder(mavenNotation);
|
||||
ParchmentMappingsSpecBuilder builder = ParchmentMappingsSpecBuilder.builder(mavenNotation);
|
||||
action.execute(builder);
|
||||
layers.add(builder.build());
|
||||
return this;
|
||||
|
||||
@@ -493,6 +493,8 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
if (Files.exists(mappingsWorkingDir)) {
|
||||
Files.walkFileTree(mappingsWorkingDir, new DeletingFileVisitor());
|
||||
}
|
||||
|
||||
Files.createDirectories(mappingsWorkingDir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -46,14 +46,19 @@ import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.api.ForgeExtensionAPI;
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinApExtensionAPI;
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.mods.ModVersionParser;
|
||||
import net.fabricmc.loom.configuration.launch.LaunchProviderSettings;
|
||||
import net.fabricmc.loom.configuration.processors.JarProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
|
||||
@@ -80,6 +85,9 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
protected final Property<Boolean> shareCaches;
|
||||
protected final Property<Boolean> remapArchives;
|
||||
protected final Property<String> customManifest;
|
||||
protected final Property<Boolean> setupRemappedVariants;
|
||||
|
||||
private final ModVersionParser versionParser;
|
||||
|
||||
private NamedDomainObjectContainer<RunConfigSettings> runConfigs;
|
||||
|
||||
@@ -114,6 +122,10 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
this.remapArchives = project.getObjects().property(Boolean.class)
|
||||
.convention(true);
|
||||
this.customManifest = project.getObjects().property(String.class);
|
||||
this.setupRemappedVariants = project.getObjects().property(Boolean.class)
|
||||
.convention(true);
|
||||
|
||||
this.versionParser = new ModVersionParser(project);
|
||||
|
||||
this.deprecationHelper = new DeprecationHelper.ProjectBased(project);
|
||||
this.platform = project.getObjects().property(ModPlatform.class).convention(project.provider(Suppliers.memoize(() -> {
|
||||
@@ -193,7 +205,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mixin(Action<MixinApExtensionAPI> action) {
|
||||
public void mixin(Action<MixinExtensionAPI> action) {
|
||||
action.execute(getMixin());
|
||||
}
|
||||
|
||||
@@ -202,10 +214,25 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
return customManifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<Boolean> getSetupRemappedVariants() {
|
||||
return setupRemappedVariants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModVersion() {
|
||||
return versionParser.getModVersion();
|
||||
}
|
||||
|
||||
protected abstract Project getProject();
|
||||
|
||||
protected abstract LoomFiles getFiles();
|
||||
|
||||
@Override
|
||||
public void disableDeprecatedPomGeneration(MavenPublication publication) {
|
||||
net.fabricmc.loom.configuration.MavenPublication.excludePublication(publication);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void silentMojangMappingsLicense() {
|
||||
this.silentMojangMappingsLicense = true;
|
||||
@@ -362,7 +389,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
}
|
||||
|
||||
@Override
|
||||
public MixinApExtension getMixin() {
|
||||
public MixinExtension getMixin() {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ import net.fabricmc.loom.util.ModPlatform;
|
||||
|
||||
public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implements LoomGradleExtension {
|
||||
private final Project project;
|
||||
private final MixinApExtension mixinApExtension;
|
||||
private final MixinExtension mixinApExtension;
|
||||
private final LoomFiles loomFiles;
|
||||
private final ConfigurableFileCollection unmappedMods;
|
||||
private final Supplier<ForgeExtensionAPI> forgeExtension;
|
||||
@@ -68,7 +68,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
super(project, files);
|
||||
this.project = project;
|
||||
// Initiate with newInstance to allow gradle to decorate our extension
|
||||
this.mixinApExtension = project.getObjects().newInstance(MixinApExtensionImpl.class, project);
|
||||
this.mixinApExtension = project.getObjects().newInstance(MixinExtensionImpl.class, project);
|
||||
this.loomFiles = files;
|
||||
this.unmappedMods = project.files();
|
||||
this.forgeExtension = Suppliers.memoize(() -> isForge() ? project.getObjects().newInstance(ForgeExtensionImpl.class, project) : null);
|
||||
@@ -172,7 +172,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public MixinApExtension getMixin() {
|
||||
public MixinExtension getMixin() {
|
||||
return this.mixinApExtension;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,12 @@ import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.api.ForgeExtensionAPI;
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinApExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
@@ -126,13 +127,13 @@ public class MinecraftGradleExtension implements LoomGradleExtensionAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mixin(Action<MixinApExtensionAPI> action) {
|
||||
public void mixin(Action<MixinExtensionAPI> action) {
|
||||
reportDeprecation();
|
||||
parent.mixin(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MixinApExtensionAPI getMixin() {
|
||||
public MixinExtensionAPI getMixin() {
|
||||
reportDeprecation();
|
||||
return parent.getMixin();
|
||||
}
|
||||
@@ -143,6 +144,24 @@ public class MinecraftGradleExtension implements LoomGradleExtensionAPI {
|
||||
return parent.getCustomMinecraftManifest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<Boolean> getSetupRemappedVariants() {
|
||||
reportDeprecation();
|
||||
return parent.getSetupRemappedVariants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDeprecatedPomGeneration(MavenPublication publication) {
|
||||
reportDeprecation();
|
||||
parent.disableDeprecatedPomGeneration(publication);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModVersion() {
|
||||
reportDeprecation();
|
||||
throw new UnsupportedOperationException("Use loom extension");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void silentMojangMappingsLicense() {
|
||||
reportDeprecation();
|
||||
|
||||
@@ -41,13 +41,13 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.api.MixinApExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
|
||||
/**
|
||||
* A gradle extension to configure mixin annotation processor.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public interface MixinApExtension extends MixinApExtensionAPI {
|
||||
public interface MixinExtension extends MixinExtensionAPI {
|
||||
String MIXIN_INFORMATION_CONTAINER = "mixin";
|
||||
|
||||
/**
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
package net.fabricmc.loom.extension;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.InvalidUserDataException;
|
||||
import org.gradle.api.Project;
|
||||
@@ -33,17 +35,29 @@ import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.util.PatternSet;
|
||||
|
||||
import net.fabricmc.loom.api.MixinApExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
|
||||
public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
|
||||
protected abstract Project getProject();
|
||||
public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
protected final Project project;
|
||||
protected final Property<Boolean> useMixinAp;
|
||||
|
||||
public MixinExtensionApiImpl(Project project) {
|
||||
this.project = Objects.requireNonNull(project);
|
||||
this.useMixinAp = project.getObjects().property(Boolean.class)
|
||||
.convention(false);
|
||||
}
|
||||
|
||||
protected final PatternSet add0(SourceSet sourceSet, String refmapName) {
|
||||
return add0(sourceSet, getProject().provider(() -> refmapName));
|
||||
return add0(sourceSet, project.provider(() -> refmapName));
|
||||
}
|
||||
|
||||
protected abstract PatternSet add0(SourceSet sourceSet, Provider<String> refmapName);
|
||||
|
||||
@Override
|
||||
public Property<Boolean> getUseLegacyMixinAp() {
|
||||
return useMixinAp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) {
|
||||
PatternSet pattern = add0(sourceSet, refmapName);
|
||||
@@ -57,7 +71,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
|
||||
|
||||
@Override
|
||||
public void add(String sourceSetName, String refmapName, Action<PatternSet> action) {
|
||||
add(sourceSetName, getProject().provider(() -> refmapName), action);
|
||||
add(sourceSetName, project.provider(() -> refmapName), action);
|
||||
}
|
||||
|
||||
public void add(String sourceSetName, Provider<String> refmapName, Action<PatternSet> action) {
|
||||
@@ -96,7 +110,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
|
||||
|
||||
private SourceSet resolveSourceSet(String sourceSetName) {
|
||||
// try to find sourceSet with name sourceSetName in this project
|
||||
SourceSet sourceSet = getProject().getConvention().getPlugin(JavaPluginConvention.class)
|
||||
SourceSet sourceSet = project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets().findByName(sourceSetName);
|
||||
|
||||
if (sourceSet == null) {
|
||||
@@ -107,17 +121,12 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
|
||||
}
|
||||
|
||||
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
|
||||
private final class EnsureCompile extends MixinApExtensionApiImpl {
|
||||
private final class EnsureCompile extends MixinExtensionApiImpl {
|
||||
private EnsureCompile() {
|
||||
super();
|
||||
super(null);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Project getProject() {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<String> getDefaultRefmapName() {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
@@ -47,44 +47,42 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.util.PatternSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements MixinApExtension {
|
||||
public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinExtension {
|
||||
private boolean isDefault;
|
||||
private final Project project;
|
||||
private final Property<String> defaultRefmapName;
|
||||
|
||||
@Inject
|
||||
public MixinApExtensionImpl(Project project) {
|
||||
public MixinExtensionImpl(Project project) {
|
||||
super(project);
|
||||
this.isDefault = true;
|
||||
this.project = project;
|
||||
this.defaultRefmapName = project.getObjects().property(String.class)
|
||||
.convention(project.provider(this::getDefaultMixinRefmapName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<String> getDefaultRefmapName() {
|
||||
if (!super.getUseLegacyMixinAp().get()) throw new IllegalStateException("You need to set useLegacyMixinAp = true to configure Mixin annotation processor.");
|
||||
|
||||
return defaultRefmapName;
|
||||
}
|
||||
|
||||
private String getDefaultMixinRefmapName() {
|
||||
String defaultRefmapName = getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||
|
||||
if (getProject().getRootProject() != getProject()) {
|
||||
defaultRefmapName = getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-" + getProject().getPath().replaceFirst(":", "").replace(':', '_') + "-refmap.json";
|
||||
if (project.getRootProject() != project) {
|
||||
defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-" + getProject().getPath().replaceFirst(":", "").replace(':', '_') + "-refmap.json";
|
||||
}
|
||||
|
||||
getProject().getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName);
|
||||
project.getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName);
|
||||
return defaultRefmapName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PatternSet add0(SourceSet sourceSet, Provider<String> refmapName) {
|
||||
if (!super.getUseLegacyMixinAp().get()) throw new IllegalStateException("You need to set useLegacyMixinAp = true to configure Mixin annotation processor.");
|
||||
|
||||
PatternSet pattern = new PatternSet().setIncludes(Collections.singletonList("*.json"));
|
||||
MixinApExtension.setMixinInformationContainer(sourceSet, new MixinApExtension.MixinInformationContainer(sourceSet, refmapName, pattern));
|
||||
MixinExtension.setMixinInformationContainer(sourceSet, new MixinExtension.MixinInformationContainer(sourceSet, refmapName, pattern));
|
||||
|
||||
isDefault = false;
|
||||
|
||||
@@ -95,7 +93,7 @@ public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements Mix
|
||||
@NotNull
|
||||
public Stream<SourceSet> getMixinSourceSetsStream() {
|
||||
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
|
||||
.filter(sourceSet -> MixinApExtension.getMixinInformationContainer(sourceSet) != null);
|
||||
.filter(sourceSet -> MixinExtension.getMixinInformationContainer(sourceSet) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,10 +24,7 @@
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.api.tasks.Internal;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
|
||||
@@ -38,13 +35,4 @@ public class RemapAllSourcesTask extends AbstractLoomTask {
|
||||
public SourceRemapper getSourceRemapper() {
|
||||
return sourceRemapper;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void remap() {
|
||||
try {
|
||||
sourceRemapper.remapAll();
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException("Failed to remap mod", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.provider.SetProperty;
|
||||
import org.gradle.api.tasks.Input;
|
||||
@@ -107,6 +108,9 @@ import net.fabricmc.mapping.tree.FieldDef;
|
||||
import net.fabricmc.mapping.tree.MethodDef;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.stitch.util.Pair;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;
|
||||
|
||||
public class RemapJarTask extends Jar {
|
||||
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
|
||||
@@ -137,6 +141,10 @@ public class RemapJarTask extends Jar {
|
||||
// false by default, I have no idea why I have to do it for this property and not the other one
|
||||
remapAccessWidener.set(false);
|
||||
addDefaultNestedDependencies.set(true);
|
||||
|
||||
if (!LoomGradleExtension.get(getProject()).getMixin().getUseLegacyMixinAp().get()) {
|
||||
remapOptions.add(b -> b.extension(new MixinExtension()));
|
||||
}
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
@@ -284,8 +292,10 @@ public class RemapJarTask extends Jar {
|
||||
throw new RuntimeException("Failed to remap " + input + " to " + output + " - file missing!");
|
||||
}
|
||||
|
||||
if (MixinRefmapHelper.addRefmapName(project, output)) {
|
||||
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
|
||||
if (extension.getMixin().getUseLegacyMixinAp().get()) {
|
||||
if (MixinRefmapHelper.addRefmapName(project, output)) {
|
||||
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!toM.equals("intermediary")) {
|
||||
@@ -446,7 +456,7 @@ public class RemapJarTask extends Jar {
|
||||
FileCollection files = this.classpath;
|
||||
|
||||
if (files == null) {
|
||||
files = getProject().getConfigurations().getByName("compileClasspath");
|
||||
files = getProject().getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
|
||||
}
|
||||
|
||||
return files.getFiles().stream()
|
||||
|
||||
@@ -45,14 +45,16 @@ public class Constants {
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
|
||||
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of(
|
||||
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"),
|
||||
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"),
|
||||
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, "", "modRuntimeOnly"),
|
||||
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, ""),
|
||||
new RemappedConfigurationEntry("modCompileOnlyApi", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "compile"),
|
||||
new RemappedConfigurationEntry("modRuntimeOnly", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, "runtime")
|
||||
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, true, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, true, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, "", "modRuntimeOnly"),
|
||||
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, false, ""),
|
||||
new RemappedConfigurationEntry("modCompileOnlyApi", JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME, true, false, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modRuntimeOnly", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME)
|
||||
);
|
||||
|
||||
public static final String SOFTWARE_COMPONENT_NAME = "loom";
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
@@ -108,10 +110,10 @@ public class Constants {
|
||||
* Constants for versions of dependencies.
|
||||
*/
|
||||
public static final class Versions {
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS = "0.4.4";
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS = "0.4.6";
|
||||
public static final String DEV_LAUNCH_INJECTOR = "0.2.1+build.8";
|
||||
public static final String TERMINAL_CONSOLE_APPENDER = "1.2.0";
|
||||
public static final String JETBRAINS_ANNOTATIONS = "19.0.0";
|
||||
public static final String JETBRAINS_ANNOTATIONS = "22.0.0";
|
||||
public static final String JAVAX_ANNOTATIONS = "3.0.2";
|
||||
public static final String FORGE_RUNTIME = "1.0.1";
|
||||
public static final String ACCESS_TRANSFORMERS = "3.0.1";
|
||||
|
||||
@@ -32,26 +32,20 @@ import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.SourceProcessor;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.util.gradle.ProgressLogger;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.stitch.util.StitchUtil;
|
||||
@@ -60,8 +54,9 @@ public class SourceRemapper {
|
||||
private final Project project;
|
||||
private String from;
|
||||
private String to;
|
||||
private final List<RemapTask> remapTasks = new ArrayList<>();
|
||||
private boolean hasStartedRemap = false;
|
||||
private final List<Consumer<ProgressLogger>> remapTasks = new ArrayList<>();
|
||||
|
||||
private Mercury mercury;
|
||||
|
||||
public SourceRemapper(Project project, boolean named) {
|
||||
this(project, named ? intermediary(project) : "named", !named ? intermediary(project) : "named");
|
||||
@@ -78,165 +73,106 @@ public class SourceRemapper {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public static void remapSources(Project project, File input, File output, String from, String to, boolean reproducibleFileOrder, boolean preserveFileTimestamps) throws IOException {
|
||||
public static void remapSources(Project project, File input, File output, String from, String to, boolean reproducibleFileOrder, boolean preserveFileTimestamps) {
|
||||
SourceRemapper sourceRemapper = new SourceRemapper(project, from, to);
|
||||
sourceRemapper.scheduleRemapSources(input, output, reproducibleFileOrder, preserveFileTimestamps);
|
||||
sourceRemapper.remapAll();
|
||||
}
|
||||
|
||||
public void scheduleRemapSources(File source, File destination, boolean reproducibleFileOrder, boolean preserveFileTimestamps) {
|
||||
this.scheduleRemapSources(new RemapTask(source, destination, reproducibleFileOrder, preserveFileTimestamps));
|
||||
remapTasks.add((logger) -> {
|
||||
try {
|
||||
logger.progress("remapping sources - " + source.getName());
|
||||
remapSourcesInner(source, destination);
|
||||
ZipReprocessorUtil.reprocessZip(destination, reproducibleFileOrder, preserveFileTimestamps);
|
||||
|
||||
// Set the remapped sources creation date to match the sources if we're likely succeeded in making it
|
||||
destination.setLastModified(source.lastModified());
|
||||
} catch (Exception e) {
|
||||
// Failed to remap, lets clean up to ensure we try again next time
|
||||
destination.delete();
|
||||
throw new RuntimeException("Failed to remap sources for " + source, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void scheduleRemapSources(RemapTask data) {
|
||||
if (hasStartedRemap) {
|
||||
throw new UnsupportedOperationException("Cannot add data after remapping has started");
|
||||
}
|
||||
|
||||
this.remapTasks.add(data);
|
||||
}
|
||||
|
||||
public void remapAll() throws IOException {
|
||||
hasStartedRemap = true;
|
||||
|
||||
public void remapAll() {
|
||||
if (remapTasks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
project.getLogger().lifecycle(":remapping " + remapTasks.size() + " sources");
|
||||
int threads = Math.min(remapTasks.size(), Math.max(2, Runtime.getRuntime().availableProcessors()));
|
||||
ExecutorService ioExecutor = Executors.newFixedThreadPool(2);
|
||||
ExecutorService remapExecutor = Executors.newFixedThreadPool(threads);
|
||||
project.getLogger().lifecycle(":remapping sources");
|
||||
|
||||
List<CompletableFuture<Void>> completableFutures = new ArrayList<>();
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, SourceRemapper.class.getName());
|
||||
progressLogger.start("Remapping dependency sources", "sources");
|
||||
|
||||
{
|
||||
// We have to build the Mercury instances on the main thread as createMercuryRemapper resolves gradle stuff
|
||||
// TODO refactor this a bit to not do that.
|
||||
Deque<Mercury> mercuryQueue = new ConcurrentLinkedDeque<>();
|
||||
remapTasks.forEach(consumer -> consumer.accept(progressLogger));
|
||||
|
||||
final SourceProcessor remapper = createMercuryRemapper();
|
||||
final Set<Path> inputClasspath = getInputClasspath(project);
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
Mercury mercury = createMercuryWithClassPath(project, to.equals("named"));
|
||||
mercury.getProcessors().add(remapper);
|
||||
mercury.getClassPath().addAll(inputClasspath);
|
||||
|
||||
mercuryQueue.add(mercury);
|
||||
}
|
||||
|
||||
ThreadLocal<Mercury> mercuryThreadLocal = ThreadLocal.withInitial(() -> Objects.requireNonNull(mercuryQueue.pop(), "No Mercury instances left"));
|
||||
|
||||
for (RemapTask remapTask : this.remapTasks) {
|
||||
completableFutures.add(
|
||||
CompletableFuture.supplyAsync(() ->
|
||||
prepareForRemap(remapTask), ioExecutor)
|
||||
.thenApplyAsync(remapData -> doRemap(mercuryThreadLocal.get(), remapData), remapExecutor)
|
||||
.thenAcceptAsync(remapData -> completeRemap(remapData, remapTask), ioExecutor)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (CompletableFuture<Void> future : completableFutures) {
|
||||
try {
|
||||
future.join();
|
||||
} catch (CompletionException e) {
|
||||
try {
|
||||
throw e.getCause();
|
||||
} catch (IOException ioe) {
|
||||
throw ioe;
|
||||
} catch (Throwable unknown) {
|
||||
throw new RuntimeException("An unknown exception occured when remapping", unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ioExecutor.shutdown();
|
||||
remapExecutor.shutdown();
|
||||
progressLogger.completed();
|
||||
|
||||
// TODO: FIXME - WORKAROUND https://github.com/FabricMC/fabric-loom/issues/45
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private RemapData prepareForRemap(RemapTask remapTask) {
|
||||
try {
|
||||
File source = remapTask.source();
|
||||
final File destination = remapTask.destination();
|
||||
private void remapSourcesInner(File source, File destination) throws Exception {
|
||||
project.getLogger().info(":remapping source jar");
|
||||
Mercury mercury = getMercuryInstance();
|
||||
|
||||
if (source.equals(destination)) {
|
||||
if (source.isDirectory()) {
|
||||
throw new RuntimeException("Directories must differ!");
|
||||
}
|
||||
|
||||
source = new File(destination.getAbsolutePath().substring(0, destination.getAbsolutePath().lastIndexOf('.')) + "-dev.jar");
|
||||
|
||||
try {
|
||||
com.google.common.io.Files.move(destination, source);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not rename " + destination.getName() + "!", e);
|
||||
}
|
||||
if (source.equals(destination)) {
|
||||
if (source.isDirectory()) {
|
||||
throw new RuntimeException("Directories must differ!");
|
||||
}
|
||||
|
||||
Path srcPath = source.toPath();
|
||||
boolean isSrcTmp = false;
|
||||
source = new File(destination.getAbsolutePath().substring(0, destination.getAbsolutePath().lastIndexOf('.')) + "-dev.jar");
|
||||
|
||||
if (!source.isDirectory()) {
|
||||
// create tmp directory
|
||||
isSrcTmp = true;
|
||||
srcPath = Files.createTempDirectory("fabric-loom-src");
|
||||
ZipUtil.unpack(source, srcPath.toFile());
|
||||
try {
|
||||
com.google.common.io.Files.move(destination, source);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not rename " + destination.getName() + "!", e);
|
||||
}
|
||||
|
||||
if (!destination.isDirectory() && destination.exists()) {
|
||||
if (!destination.delete()) {
|
||||
throw new RuntimeException("Could not delete " + destination.getName() + "!");
|
||||
}
|
||||
}
|
||||
|
||||
StitchUtil.FileSystemDelegate dstFs = remapTask.destination().isDirectory() ? null : StitchUtil.getJarFileSystem(remapTask.destination(), true);
|
||||
Path dstPath = dstFs != null ? dstFs.get().getPath("/") : remapTask.destination().toPath();
|
||||
|
||||
return new RemapData(Objects.requireNonNull(srcPath, "srcPath"), Objects.requireNonNull(dstPath, "dstPath"), dstFs, isSrcTmp);
|
||||
} catch (IOException e) {
|
||||
throw new CompletionException("Failed to prepare for remap", e);
|
||||
}
|
||||
}
|
||||
|
||||
private RemapData doRemap(Mercury mercury, RemapData remapData) {
|
||||
Path srcPath = source.toPath();
|
||||
boolean isSrcTmp = false;
|
||||
|
||||
if (!source.isDirectory()) {
|
||||
// create tmp directory
|
||||
isSrcTmp = true;
|
||||
srcPath = Files.createTempDirectory("fabric-loom-src");
|
||||
ZipUtil.unpack(source, srcPath.toFile());
|
||||
}
|
||||
|
||||
if (!destination.isDirectory() && destination.exists()) {
|
||||
if (!destination.delete()) {
|
||||
throw new RuntimeException("Could not delete " + destination.getName() + "!");
|
||||
}
|
||||
}
|
||||
|
||||
StitchUtil.FileSystemDelegate dstFs = destination.isDirectory() ? null : StitchUtil.getJarFileSystem(destination, true);
|
||||
Path dstPath = dstFs != null ? dstFs.get().getPath("/") : destination.toPath();
|
||||
|
||||
try {
|
||||
mercury.rewrite(remapData.source(), remapData.destination());
|
||||
mercury.rewrite(srcPath, dstPath);
|
||||
} catch (Exception e) {
|
||||
project.getLogger().warn("Could not remap " + remapData.source().toString() + " fully!", e);
|
||||
// TODO do something more with this error? delete the dst file in complete remap?
|
||||
project.getLogger().warn("Could not remap " + source.getName() + " fully!", e);
|
||||
}
|
||||
|
||||
return remapData;
|
||||
}
|
||||
copyNonJavaFiles(srcPath, dstPath, project, source);
|
||||
|
||||
private void completeRemap(RemapData remapData, RemapTask remapTask) {
|
||||
try {
|
||||
copyNonJavaFiles(remapData.source(), remapData.destination(), project, remapTask.source());
|
||||
if (dstFs != null) {
|
||||
dstFs.close();
|
||||
}
|
||||
|
||||
if (remapData.dstFs() != null) {
|
||||
remapData.dstFs().close();
|
||||
}
|
||||
|
||||
if (remapData.isSrcTmp()) {
|
||||
Files.walkFileTree(remapData.source(), new DeletingFileVisitor());
|
||||
}
|
||||
|
||||
ZipReprocessorUtil.reprocessZip(remapTask.destination(), remapTask.reproducibleFileOrder(), remapTask.preserveFileTimestamps());
|
||||
|
||||
// Set the remapped sources creation date to match the sources if we're likely succeeded in making it
|
||||
remapTask.destination().setLastModified(remapTask.source().lastModified());
|
||||
} catch (IOException e) {
|
||||
throw new CompletionException("Failed to complete remap", e);
|
||||
if (isSrcTmp) {
|
||||
Files.walkFileTree(srcPath, new DeletingFileVisitor());
|
||||
}
|
||||
}
|
||||
|
||||
private SourceProcessor createMercuryRemapper() {
|
||||
private Mercury getMercuryInstance() {
|
||||
if (this.mercury != null) {
|
||||
return this.mercury;
|
||||
}
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
|
||||
|
||||
@@ -259,7 +195,35 @@ public class SourceRemapper {
|
||||
}
|
||||
});
|
||||
|
||||
return MercuryRemapper.create(mappings);
|
||||
Mercury mercury = extension.getOrCreateSrcMercuryCache(toNamed ? 1 : 0, () -> {
|
||||
Mercury m = createMercuryWithClassPath(project, toNamed);
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
|
||||
if (Files.isRegularFile(path)) {
|
||||
m.getClassPath().add(path);
|
||||
}
|
||||
}
|
||||
|
||||
m.getClassPath().add(extension.getMinecraftMappedProvider().getMappedJar().toPath());
|
||||
m.getClassPath().add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath());
|
||||
|
||||
Set<File> files = project.getConfigurations()
|
||||
.detachedConfiguration(project.getDependencies().create(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS))
|
||||
.resolve();
|
||||
|
||||
for (File file : files) {
|
||||
m.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
m.getProcessors().add(MercuryRemapper.create(mappings));
|
||||
|
||||
return m;
|
||||
});
|
||||
|
||||
this.mercury = mercury;
|
||||
return mercury;
|
||||
}
|
||||
|
||||
private static void copyNonJavaFiles(Path from, Path to, Project project, File source) throws IOException {
|
||||
@@ -277,49 +241,23 @@ public class SourceRemapper {
|
||||
}
|
||||
|
||||
public static Mercury createMercuryWithClassPath(Project project, boolean toNamed) {
|
||||
Mercury mercury = new Mercury();
|
||||
mercury.setGracefulClasspathChecks(true);
|
||||
|
||||
List<Path> classpath = mercury.getClassPath();
|
||||
classpath.addAll(getCompileClasspath(project, toNamed));
|
||||
|
||||
return mercury;
|
||||
}
|
||||
|
||||
private static Set<Path> getCompileClasspath(Project project, boolean toNamed) {
|
||||
Set<Path> classpath = new HashSet<>();
|
||||
Mercury m = new Mercury();
|
||||
m.setGracefulClasspathChecks(true);
|
||||
|
||||
for (File file : project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES).getFiles()) {
|
||||
classpath.add(file.toPath());
|
||||
m.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
if (!toNamed) {
|
||||
for (File file : project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).getFiles()) {
|
||||
classpath.add(file.toPath());
|
||||
for (File file : project.getConfigurations().getByName("compileClasspath").getFiles()) {
|
||||
m.getClassPath().add(file.toPath());
|
||||
}
|
||||
} else {
|
||||
for (RemappedConfigurationEntry entry : Constants.MOD_COMPILE_ENTRIES) {
|
||||
for (File inputFile : project.getConfigurations().getByName(entry.sourceConfiguration()).getFiles()) {
|
||||
classpath.add(inputFile.toPath());
|
||||
m.getClassPath().add(inputFile.toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return classpath;
|
||||
}
|
||||
|
||||
private static Set<Path> getInputClasspath(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
Set<Path> classpath = new HashSet<Path>();
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
|
||||
if (Files.isRegularFile(path)) {
|
||||
classpath.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
classpath.add(extension.getMinecraftMappedProvider().getMappedJar().toPath());
|
||||
classpath.add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath());
|
||||
@@ -339,7 +277,7 @@ public class SourceRemapper {
|
||||
classpath.add(file.toPath());
|
||||
}
|
||||
|
||||
return classpath;
|
||||
return m;
|
||||
}
|
||||
|
||||
private static boolean isJavaFile(Path path) {
|
||||
@@ -347,10 +285,4 @@ public class SourceRemapper {
|
||||
// ".java" is not a valid java file
|
||||
return name.endsWith(".java") && name.length() != 5;
|
||||
}
|
||||
|
||||
public static record RemapTask(File source, File destination, boolean reproducibleFileOrder, boolean preserveFileTimestamps) {
|
||||
}
|
||||
|
||||
public static record RemapData(Path source, Path destination, StitchUtil.FileSystemDelegate dstFs, boolean isSrcTmp) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user