1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.lucko.spark.fabric.plugin;
import me.lucko.spark.fabric.smap.SourceDebugCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
import java.util.List;
import java.util.Set;
public class FabricSparkMixinPlugin implements IMixinConfigPlugin, IExtension {
private static final Logger LOGGER = LogManager.getLogger("spark");
@Override
public void onLoad(String mixinPackage) {
Object activeTransformer = MixinEnvironment.getCurrentEnvironment().getActiveTransformer();
if (activeTransformer instanceof IMixinTransformer transformer && transformer.getExtensions() instanceof Extensions extensions) {
extensions.add(this);
} else {
LOGGER.error(
"Failed to initialize SMAP parser for spark profiler. " +
"Mod information for mixin injected methods is now only available with the async-profiler engine."
);
}
}
@Override
public void export(MixinEnvironment env, String name, boolean force, ClassNode classNode) {
SourceDebugCache.put(name, classNode);
}
// noop
@Override public String getRefMapperConfig() { return null; }
@Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { return true; }
@Override public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { }
@Override public List<String> getMixins() { return null; }
@Override public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { }
@Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { }
@Override public boolean checkActive(MixinEnvironment environment) { return true; }
@Override public void preApply(ITargetClassContext context) { }
@Override public void postApply(ITargetClassContext context) { }
}
|