Add support for mixin files outside of root in MixinRefmapHelper (#536)

* Add support for mixin files outside of root in MixinRefmapHelper

* Fix checkstyle + Integration tests + Checks all srcDirs from sourceSet

* Redid part that failed to save for last commit

* Other issues fixed

* Checkstyle again

* Made getting root paths safer

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* CodeNarc for test

* Normalized all paths to fix issues on Windows

* Removed debug line used to test return value of lamdba

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
val = int(1) 2021-12-29 23:16:13 +01:00 committed by GitHub
parent 63f2b51b2c
commit 7611e3a632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 2 deletions

View file

@ -76,7 +76,7 @@ public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinEx
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"));
MixinExtension.setMixinInformationContainer(sourceSet, new MixinExtension.MixinInformationContainer(sourceSet, refmapName, pattern));
isDefault = false;

View file

@ -136,12 +136,34 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
MixinExtension.getMixinInformationContainer(sourceSet)
);
String[] rootPaths = sourceSet.getResources().getSrcDirs().stream()
.map(root -> {
String rootPath = root.getAbsolutePath().replace("\\", "/");
if (rootPath.charAt(rootPath.length() - 1) != '/') {
rootPath += '/';
}
return rootPath;
})
.toArray(String[]::new);
final String refmapName = container.refmapNameProvider().get();
final List<String> mixinConfigs = container.sourceSet().getResources()
.matching(container.mixinConfigPattern())
.getFiles()
.stream()
.map(File::getName)
.map(file -> {
String s = file.getAbsolutePath().replace("\\", "/");
for (String rootPath : rootPaths) {
if (s.startsWith(rootPath)) {
s = s.substring(rootPath.length());
}
}
return s;
})
.filter(allMixinConfigs::contains)
.toList();

View file

@ -67,6 +67,9 @@ class MixinApAutoRefmapTest extends Specification implements GradleProjectTestTr
def j5 = JsonParser.parseReader(new InputStreamReader(jar.getInputStream(jar.getEntry("irrelevant.mixins.json"))))
!j5.asJsonObject.has("refmap")
def j6 = JsonParser.parseReader(new InputStreamReader(jar.getInputStream(jar.getEntry("subfolder/subfolder.mixins.json"))))
j6.asJsonObject.getAsJsonPrimitive("refmap").getAsString() == "refmap0001.json"
where:
version << STANDARD_TEST_VERSIONS
}

View file

@ -0,0 +1,15 @@
package net.fabricmc.example.mixin;
import net.minecraft.client.gui.screen.ChatScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ChatScreen.class)
public class ExampleMixinSubfolder {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
System.out.println("This line is printed by an example mod mixin!");
}
}

View file

@ -24,6 +24,7 @@
},
"mixins": [
"main.mixins.json",
"subfolder/subfolder.mixins.json",
{
"config": "blabla.json",
"environment": "client"

View file

@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.fabricmc.example.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
],
"client": [
"ExampleMixinSubfolder"
],
"injectors": {
"defaultRequire": 1
}
}