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>
This commit is contained in:
		
							parent
							
								
									52873435b7
								
							
						
					
					
						commit
						3b0dc7f0f4
					
				
					 20 changed files with 99 additions and 71 deletions
				
			
		|  | @ -37,6 +37,7 @@ repositories { | |||
| 		url = 'https://maven.fabricmc.net/' | ||||
| 	} | ||||
| 	mavenCentral() | ||||
| 	mavenLocal() | ||||
| } | ||||
| 
 | ||||
| configurations { | ||||
|  | @ -77,7 +78,7 @@ dependencies { | |||
| 	} | ||||
| 
 | ||||
| 	// 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:access-widener:1.1.0' | ||||
|  |  | |||
|  | @ -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.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) { | ||||
|  | @ -102,5 +102,5 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI { | |||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	MixinApExtension getMixin(); | ||||
| 	MixinExtension getMixin(); | ||||
| } | ||||
|  |  | |||
|  | @ -154,11 +154,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(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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() | ||||
|  |  | |||
|  | @ -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()))); | ||||
| 	} | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ import net.fabricmc.loom.configuration.ide.SetupIntelijRunConfigs; | |||
| import net.fabricmc.loom.configuration.providers.LaunchProvider; | ||||
| import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl; | ||||
| 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; | ||||
| 
 | ||||
| public final class CompileConfiguration { | ||||
|  | @ -137,14 +137,20 @@ public final class CompileConfiguration { | |||
| 				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 | ||||
| 			System.setProperty("log4j2.disable.jmx", "true"); | ||||
| 			System.setProperty("log4j.shutdownHookEnabled", "false"); | ||||
| 			System.setProperty("log4j.skipJansi", "true"); | ||||
| 
 | ||||
| 			project.getLogger().info("Configuring compiler arguments for Java"); | ||||
| 			MixinApExtension mixinApExtension = LoomGradleExtension.get(project).getMixin(); | ||||
| 			mixinApExtension.init(); | ||||
| 
 | ||||
| 			new JavaApInvoker(project).configureMixin(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -190,7 +190,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); | ||||
| 			} | ||||
| 
 | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ import org.gradle.api.provider.Property; | |||
| import org.gradle.api.publish.maven.MavenPublication; | ||||
| 
 | ||||
| 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.RunConfigSettings; | ||||
| import net.fabricmc.loom.configuration.processors.JarProcessor; | ||||
|  | @ -135,7 +135,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA | |||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void mixin(Action<MixinApExtensionAPI> action) { | ||||
| 	public void mixin(Action<MixinExtensionAPI> action) { | ||||
| 		action.execute(getMixin()); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -181,7 +181,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA | |||
| 		} | ||||
| 
 | ||||
| 		@Override | ||||
| 		public MixinApExtension getMixin() { | ||||
| 		public MixinExtension getMixin() { | ||||
| 			throw new RuntimeException("Yeah... something is really wrong"); | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ import net.fabricmc.loom.configuration.processors.JarProcessorManager; | |||
| 
 | ||||
| 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; | ||||
| 
 | ||||
|  | @ -64,7 +64,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(); | ||||
| 	} | ||||
|  | @ -165,7 +165,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen | |||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public MixinApExtension getMixin() { | ||||
| 	public MixinExtension getMixin() { | ||||
| 		return this.mixinApExtension; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -34,7 +34,7 @@ import org.gradle.api.provider.Property; | |||
| import org.gradle.api.publish.maven.MavenPublication; | ||||
| 
 | ||||
| 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.RunConfigSettings; | ||||
| import net.fabricmc.loom.configuration.processors.JarProcessor; | ||||
|  | @ -116,13 +116,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(); | ||||
| 	} | ||||
|  |  | |||
|  | @ -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,39 +47,37 @@ 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"; | ||||
| 		getProject().getLogger().info("Could not find refmap definition, will be using default name: " + defaultRefmapName); | ||||
| 		String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json"; | ||||
| 		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; | ||||
| 
 | ||||
|  | @ -90,7 +88,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 | ||||
|  | @ -73,6 +73,7 @@ import net.fabricmc.loom.util.ZipReprocessorUtil; | |||
| 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"; | ||||
|  | @ -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 | ||||
| 		remapAccessWidener.set(false); | ||||
| 		addDefaultNestedDependencies.set(true); | ||||
| 
 | ||||
| 		if (!LoomGradleExtension.get(getProject()).getMixin().getUseLegacyMixinAp().get()) { | ||||
| 			remapOptions.add(b -> b.extension(new MixinExtension())); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@TaskAction | ||||
|  | @ -171,8 +176,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 (getAddNestedDependencies().getOrElse(false)) { | ||||
|  |  | |||
|  | @ -69,6 +69,8 @@ java { | |||
| 
 | ||||
| loom { | ||||
| 	mixin { | ||||
| 		useLegacyMixinAp = true | ||||
| 
 | ||||
| 		defaultRefmapName = "refmap0000.json" | ||||
| 		add(sourceSets["main"], "refmap0001.json") | ||||
| 		add(sourceSets["mixin"], "refmap0002.json") | ||||
|  |  | |||
|  | @ -68,6 +68,8 @@ java { | |||
| 
 | ||||
| loom { | ||||
| 	mixin { | ||||
| 		useLegacyMixinAp = true | ||||
| 
 | ||||
| 		defaultRefmapName = "default-refmap0000.json" | ||||
| 		add(sourceSets["main"], "main-refmap0000.json") | ||||
| 		add(sourceSets["mixin"]) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue