Use tiny-remapper to remap mixin annotation. (#441)

* use tiny-remapper 0.5.0

* add property of useLegacyMixinAp and rename mixin to mixinAp

* disable mixin ap if useLegacyMixinAp is false

* fix tests

* remove experimental for mixinAp

* enable mixin remapper

* revert changes on API

* rename MixinAp*** to Mixin***

* move useLegacyMixinAp inside MixinExtension

* cleaner code

* update test

Co-authored-by: modmuss50 <modmuss50@gmail.com>
dev/0.11
Logic 2021-09-07 06:28:51 -04:00 committed by GitHub
parent 52873435b7
commit 3b0dc7f0f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 99 additions and 71 deletions

View File

@ -37,6 +37,7 @@ repositories {
url = 'https://maven.fabricmc.net/' url = 'https://maven.fabricmc.net/'
} }
mavenCentral() mavenCentral()
mavenLocal()
} }
configurations { configurations {
@ -77,7 +78,7 @@ dependencies {
} }
// tinyfile management // tinyfile management
implementation ('net.fabricmc:tiny-remapper:0.4.3') implementation ('net.fabricmc:tiny-remapper:0.5.0')
implementation ('net.fabricmc:tiny-mappings-parser:0.3.0+build.17') implementation ('net.fabricmc:tiny-mappings-parser:0.3.0+build.17')
implementation 'net.fabricmc:access-widener:1.1.0' implementation 'net.fabricmc:access-widener:1.1.0'

View File

@ -43,7 +43,7 @@ import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.extension.LoomFiles; import net.fabricmc.loom.extension.LoomFiles;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
public interface LoomGradleExtension extends LoomGradleExtensionAPI { public interface LoomGradleExtension extends LoomGradleExtensionAPI {
static LoomGradleExtension get(Project project) { static LoomGradleExtension get(Project project) {
@ -102,5 +102,5 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
} }
@Override @Override
MixinApExtension getMixin(); MixinExtension getMixin();
} }

View File

@ -154,11 +154,11 @@ public interface LoomGradleExtensionAPI {
NamedDomainObjectContainer<RunConfigSettings> getRunConfigs(); NamedDomainObjectContainer<RunConfigSettings> getRunConfigs();
@ApiStatus.Experimental void mixin(Action<MixinExtensionAPI> action);
void mixin(Action<MixinApExtensionAPI> action);
@ApiStatus.Experimental @ApiStatus.Experimental
MixinApExtensionAPI getMixin(); // TODO: move this from LoomGradleExtensionAPI to LoomGradleExtension once getRefmapName & setRefmapName is removed.
MixinExtensionAPI getMixin();
Property<String> getCustomMinecraftManifest(); Property<String> getCustomMinecraftManifest();

View File

@ -31,7 +31,9 @@ import org.gradle.api.tasks.util.PatternSet;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Experimental @ApiStatus.Experimental
public interface MixinApExtensionAPI { public interface MixinExtensionAPI {
Property<Boolean> getUseLegacyMixinAp();
Property<String> getDefaultRefmapName(); Property<String> getDefaultRefmapName();
/** /**
@ -45,27 +47,27 @@ public interface MixinApExtensionAPI {
void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action); 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 sourceSet the sourceSet that applies Mixin AP.
* @param refmapName the output ref-map name. * @param refmapName the output ref-map name.
*/ */
void add(SourceSet sourceSet, String refmapName); 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 sourceSet the sourceSet that applies Mixin AP.
* @param action used for filter the mixin json files. * @param action used for filter the mixin json files.
*/ */
void add(SourceSet sourceSet, Action<PatternSet> action); 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. * @param sourceSet the sourceSet that applies Mixin AP.
*/ */
void add(SourceSet sourceSet); 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 sourceSetName the name of sourceSet that applies Mixin AP.
* @param refmapName the output ref-map name. * @param refmapName the output ref-map name.
* @param action used for filter the mixin json files. * @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); 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 sourceSetName the name of sourceSet that applies Mixin AP.
* @param refmapName the output ref-map name. * @param refmapName the output ref-map name.
*/ */
void add(String sourceSetName, String refmapName); 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 sourceSetName the name of sourceSet that applies Mixin AP.
* @param action used for filter the mixin json files. * @param action used for filter the mixin json files.
*/ */
void add(String sourceSetName, Action<PatternSet> action); 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. * @param sourceSetName the name of sourceSet that applies Mixin AP.
*/ */
void add(String sourceSetName); void add(String sourceSetName);

View File

@ -48,7 +48,7 @@ import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomGradlePlugin; import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
public final class MixinRefmapHelper { public final class MixinRefmapHelper {
private MixinRefmapHelper() { } private MixinRefmapHelper() { }
@ -57,14 +57,14 @@ public final class MixinRefmapHelper {
public static boolean addRefmapName(Project project, Path outputPath) { public static boolean addRefmapName(Project project, Path outputPath) {
try { try {
MixinApExtension mixin = LoomGradleExtension.get(project).getMixin(); MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
File output = outputPath.toFile(); File output = outputPath.toFile();
Collection<String> allMixinConfigs = getMixinConfigurationFiles(readFabricModJson(output)); Collection<String> allMixinConfigs = getMixinConfigurationFiles(readFabricModJson(output));
return mixin.getMixinSourceSetsStream().map(sourceSet -> { return mixin.getMixinSourceSetsStream().map(sourceSet -> {
MixinApExtension.MixinInformationContainer container = Objects.requireNonNull( MixinExtension.MixinInformationContainer container = Objects.requireNonNull(
MixinApExtension.getMixinInformationContainer(sourceSet) MixinExtension.getMixinInformationContainer(sourceSet)
); );
Stream<String> mixinConfigs = sourceSet.getResources() Stream<String> mixinConfigs = sourceSet.getResources()

View File

@ -39,7 +39,7 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.tasks.SourceSet; 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.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; 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) { 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()); 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) { private void passMixinArguments(T task, SourceSet sourceSet) {
try { try {
LoomGradleExtension loom = LoomGradleExtension.get(project); 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<>() {{ Map<String, String> args = new HashMap<>() {{
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath()); put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath());
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, loom.getNextMixinMappings().getCanonicalPath()); put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, loom.getNextMixinMappings().getCanonicalPath());

View File

@ -35,7 +35,7 @@ import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.compile.JavaCompile;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> { public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
public JavaApInvoker(Project project) { public JavaApInvoker(Project project) {
@ -46,7 +46,7 @@ public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
} }
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) { 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) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue()))); .collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
} }

View File

@ -40,7 +40,7 @@ import org.gradle.api.tasks.compile.JavaCompile;
import org.jetbrains.kotlin.gradle.plugin.KaptExtension; import org.jetbrains.kotlin.gradle.plugin.KaptExtension;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> { public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
private final KaptExtension kaptExtension = project.getExtensions().getByType(KaptExtension.class); 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) { 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) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue()))); .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(); SourceSet sourceSet = entry.getKey();
task.doLast(t -> { task.doLast(t -> {
try { 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 src = Paths.get(getRefmapDestination(task, refmapName));
Path dest = Paths.get(task.getDestinationDir().toString(), refmapName); Path dest = Paths.get(task.getDestinationDir().toString(), refmapName);

View File

@ -35,7 +35,7 @@ import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.scala.ScalaCompile; import org.gradle.api.tasks.scala.ScalaCompile;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> { public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
public ScalaApInvoker(Project project) { public ScalaApInvoker(Project project) {
@ -47,7 +47,7 @@ public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
} }
private static Map<SourceSet, ScalaCompile> getInvokerTasks(Project project) { 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) return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.SCALA)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((ScalaCompile) entry.getValue()))); .collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.requireNonNull((ScalaCompile) entry.getValue())));
} }

View File

@ -39,7 +39,7 @@ import net.fabricmc.loom.configuration.ide.SetupIntelijRunConfigs;
import net.fabricmc.loom.configuration.providers.LaunchProvider; import net.fabricmc.loom.configuration.providers.LaunchProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl; import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.extension.MixinApExtension; import net.fabricmc.loom.extension.MixinExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
public final class CompileConfiguration { public final class CompileConfiguration {
@ -137,14 +137,20 @@ public final class CompileConfiguration {
extension.getUnmappedModCollection().from(jarTask); extension.getUnmappedModCollection().from(jarTask);
} }
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
if (!mixin.getUseLegacyMixinAp().get()) {
return;
}
mixin.init();
// Disable some things used by log4j via the mixin AP that prevent it from being garbage collected // 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("log4j2.disable.jmx", "true");
System.setProperty("log4j.shutdownHookEnabled", "false"); System.setProperty("log4j.shutdownHookEnabled", "false");
System.setProperty("log4j.skipJansi", "true"); System.setProperty("log4j.skipJansi", "true");
project.getLogger().info("Configuring compiler arguments for Java"); project.getLogger().info("Configuring compiler arguments for Java");
MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixin();
mixinApExtension.init();
new JavaApInvoker(project).configureMixin(); new JavaApInvoker(project).configureMixin();

View File

@ -190,7 +190,8 @@ public class LoomDependencyManager {
modDep.setTransitive(false); modDep.setTransitive(false);
loaderDepsConfig.getDependencies().add(modDep); 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); apDepsConfig.getDependencies().add(modDep);
} }

View File

@ -35,7 +35,7 @@ import org.gradle.api.provider.Property;
import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.MavenPublication;
import net.fabricmc.loom.api.LoomGradleExtensionAPI; 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.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor; import net.fabricmc.loom.configuration.processors.JarProcessor;
@ -135,7 +135,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
} }
@Override @Override
public void mixin(Action<MixinApExtensionAPI> action) { public void mixin(Action<MixinExtensionAPI> action) {
action.execute(getMixin()); action.execute(getMixin());
} }
@ -181,7 +181,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
} }
@Override @Override
public MixinApExtension getMixin() { public MixinExtension getMixin() {
throw new RuntimeException("Yeah... something is really wrong"); throw new RuntimeException("Yeah... something is really wrong");
} }
} }

View File

@ -47,7 +47,7 @@ import net.fabricmc.loom.configuration.processors.JarProcessorManager;
public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implements LoomGradleExtension { public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implements LoomGradleExtension {
private final Project project; private final Project project;
private final MixinApExtension mixinApExtension; private final MixinExtension mixinApExtension;
private final LoomFiles loomFiles; private final LoomFiles loomFiles;
private final ConfigurableFileCollection unmappedMods; private final ConfigurableFileCollection unmappedMods;
@ -64,7 +64,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
super(project, files); super(project, files);
this.project = project; this.project = project;
// Initiate with newInstance to allow gradle to decorate our extension // 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.loomFiles = files;
this.unmappedMods = project.files(); this.unmappedMods = project.files();
} }
@ -165,7 +165,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
} }
@Override @Override
public MixinApExtension getMixin() { public MixinExtension getMixin() {
return this.mixinApExtension; return this.mixinApExtension;
} }
} }

View File

@ -34,7 +34,7 @@ import org.gradle.api.provider.Property;
import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.MavenPublication;
import net.fabricmc.loom.api.LoomGradleExtensionAPI; 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.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.processors.JarProcessor; import net.fabricmc.loom.configuration.processors.JarProcessor;
@ -116,13 +116,13 @@ public class MinecraftGradleExtension implements LoomGradleExtensionAPI {
} }
@Override @Override
public void mixin(Action<MixinApExtensionAPI> action) { public void mixin(Action<MixinExtensionAPI> action) {
reportDeprecation(); reportDeprecation();
parent.mixin(action); parent.mixin(action);
} }
@Override @Override
public MixinApExtensionAPI getMixin() { public MixinExtensionAPI getMixin() {
reportDeprecation(); reportDeprecation();
return parent.getMixin(); return parent.getMixin();
} }

View File

@ -41,13 +41,13 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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. * A gradle extension to configure mixin annotation processor.
*/ */
@ApiStatus.Experimental @ApiStatus.Experimental
public interface MixinApExtension extends MixinApExtensionAPI { public interface MixinExtension extends MixinExtensionAPI {
String MIXIN_INFORMATION_CONTAINER = "mixin"; String MIXIN_INFORMATION_CONTAINER = "mixin";
/** /**

View File

@ -24,6 +24,8 @@
package net.fabricmc.loom.extension; package net.fabricmc.loom.extension;
import java.util.Objects;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.InvalidUserDataException; import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Project; 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.SourceSet;
import org.gradle.api.tasks.util.PatternSet; 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 { public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
protected abstract Project getProject(); 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) { 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); protected abstract PatternSet add0(SourceSet sourceSet, Provider<String> refmapName);
@Override
public Property<Boolean> getUseLegacyMixinAp() {
return useMixinAp;
}
@Override @Override
public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) { public void add(SourceSet sourceSet, String refmapName, Action<PatternSet> action) {
PatternSet pattern = add0(sourceSet, refmapName); PatternSet pattern = add0(sourceSet, refmapName);
@ -57,7 +71,7 @@ public abstract class MixinApExtensionApiImpl implements MixinApExtensionAPI {
@Override @Override
public void add(String sourceSetName, String refmapName, Action<PatternSet> action) { 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) { 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) { private SourceSet resolveSourceSet(String sourceSetName) {
// try to find sourceSet with name sourceSetName in this project // 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); .getSourceSets().findByName(sourceSetName);
if (sourceSet == null) { 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 // 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() { private EnsureCompile() {
super(); super(null);
throw new RuntimeException(); throw new RuntimeException();
} }
@Override
protected Project getProject() {
throw new RuntimeException("Yeah... something is really wrong");
}
@Override @Override
public Property<String> getDefaultRefmapName() { public Property<String> getDefaultRefmapName() {
throw new RuntimeException("Yeah... something is really wrong"); throw new RuntimeException("Yeah... something is really wrong");

View File

@ -47,39 +47,37 @@ import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.util.PatternSet; import org.gradle.api.tasks.util.PatternSet;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements MixinApExtension { public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinExtension {
private boolean isDefault; private boolean isDefault;
private final Project project;
private final Property<String> defaultRefmapName; private final Property<String> defaultRefmapName;
@Inject @Inject
public MixinApExtensionImpl(Project project) { public MixinExtensionImpl(Project project) {
super(project);
this.isDefault = true; this.isDefault = true;
this.project = project;
this.defaultRefmapName = project.getObjects().property(String.class) this.defaultRefmapName = project.getObjects().property(String.class)
.convention(project.provider(this::getDefaultMixinRefmapName)); .convention(project.provider(this::getDefaultMixinRefmapName));
} }
@Override
public Project getProject() {
return this.project;
}
@Override @Override
public Property<String> getDefaultRefmapName() { public Property<String> getDefaultRefmapName() {
if (!super.getUseLegacyMixinAp().get()) throw new IllegalStateException("You need to set useLegacyMixinAp = true to configure Mixin annotation processor.");
return defaultRefmapName; return defaultRefmapName;
} }
private String getDefaultMixinRefmapName() { private String getDefaultMixinRefmapName() {
String defaultRefmapName = getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json"; String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-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; return defaultRefmapName;
} }
@Override @Override
protected PatternSet add0(SourceSet sourceSet, Provider<String> refmapName) { 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")); 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; isDefault = false;
@ -90,7 +88,7 @@ public class MixinApExtensionImpl extends MixinApExtensionApiImpl implements Mix
@NotNull @NotNull
public Stream<SourceSet> getMixinSourceSetsStream() { public Stream<SourceSet> getMixinSourceSetsStream() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream() return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
.filter(sourceSet -> MixinApExtension.getMixinInformationContainer(sourceSet) != null); .filter(sourceSet -> MixinExtension.getMixinInformationContainer(sourceSet) != null);
} }
@Override @Override

View File

@ -73,6 +73,7 @@ import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.stitch.util.Pair; import net.fabricmc.stitch.util.Pair;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils; import net.fabricmc.tinyremapper.TinyUtils;
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;
public class RemapJarTask extends Jar { public class RemapJarTask extends Jar {
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF"; private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
@ -95,6 +96,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 // false by default, I have no idea why I have to do it for this property and not the other one
remapAccessWidener.set(false); remapAccessWidener.set(false);
addDefaultNestedDependencies.set(true); addDefaultNestedDependencies.set(true);
if (!LoomGradleExtension.get(getProject()).getMixin().getUseLegacyMixinAp().get()) {
remapOptions.add(b -> b.extension(new MixinExtension()));
}
} }
@TaskAction @TaskAction
@ -171,9 +176,11 @@ public class RemapJarTask extends Jar {
throw new RuntimeException("Failed to remap " + input + " to " + output + " - file missing!"); throw new RuntimeException("Failed to remap " + input + " to " + output + " - file missing!");
} }
if (extension.getMixin().getUseLegacyMixinAp().get()) {
if (MixinRefmapHelper.addRefmapName(project, output)) { if (MixinRefmapHelper.addRefmapName(project, output)) {
project.getLogger().debug("Transformed mixin reference maps in output JAR!"); project.getLogger().debug("Transformed mixin reference maps in output JAR!");
} }
}
if (getAddNestedDependencies().getOrElse(false)) { if (getAddNestedDependencies().getOrElse(false)) {
JarNester.nestJars(nestedJarProvider.provide(), output.toFile(), project.getLogger()); JarNester.nestJars(nestedJarProvider.provide(), output.toFile(), project.getLogger());

View File

@ -69,6 +69,8 @@ java {
loom { loom {
mixin { mixin {
useLegacyMixinAp = true
defaultRefmapName = "refmap0000.json" defaultRefmapName = "refmap0000.json"
add(sourceSets["main"], "refmap0001.json") add(sourceSets["main"], "refmap0001.json")
add(sourceSets["mixin"], "refmap0002.json") add(sourceSets["mixin"], "refmap0002.json")

View File

@ -68,6 +68,8 @@ java {
loom { loom {
mixin { mixin {
useLegacyMixinAp = true
defaultRefmapName = "default-refmap0000.json" defaultRefmapName = "default-refmap0000.json"
add(sourceSets["main"], "main-refmap0000.json") add(sourceSets["main"], "main-refmap0000.json")
add(sourceSets["mixin"]) add(sourceSets["mixin"])