diff --git a/src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java b/src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java index 8cd09b92..1dae707a 100644 --- a/src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java +++ b/src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java @@ -280,15 +280,14 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst bootstrapMethodArguments); } - private static Handle getLambdaImplementedMethod(String name, String desc, Handle bsm, Set knownIndyBsm, Object... bsmArgs) { + private Handle getLambdaImplementedMethod(String name, String desc, Handle bsm, Set knownIndyBsm, Object... bsmArgs) { if (isJavaLambdaMetafactory(bsm)) { assert desc.endsWith(";"); return new Handle(Opcodes.H_INVOKEINTERFACE, desc.substring(desc.lastIndexOf(')') + 2, desc.length() - 1), name, ((Type) bsmArgs[0]).getDescriptor(), true); } else if (knownIndyBsm.contains(bsm.getOwner())) { return null; } else { - System.out.printf("unknown invokedynamic bsm: %s/%s%s (tag=%d iif=%b)%n", bsm.getOwner(), bsm.getName(), bsm.getDesc(), bsm.getTag(), bsm.isInterface()); - + tr.getEnvironment().getLogger().warn("unknown invokedynamic bsm: %s/%s%s (tag=%d iif=%b)", bsm.getOwner(), bsm.getName(), bsm.getDesc(), bsm.getTag(), bsm.isInterface()); return null; } } diff --git a/src/main/java/net/fabricmc/tinyremapper/ConsoleLogger.java b/src/main/java/net/fabricmc/tinyremapper/ConsoleLogger.java new file mode 100644 index 00000000..af755087 --- /dev/null +++ b/src/main/java/net/fabricmc/tinyremapper/ConsoleLogger.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, 2018, Player, asie + * Copyright (c) 2019, 2022, FabricMC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package net.fabricmc.tinyremapper; + +import net.fabricmc.tinyremapper.api.TrLogger; + +public final class ConsoleLogger implements TrLogger { + private final TrLogger.Level level; + + public ConsoleLogger(TrLogger.Level level) { + this.level = level; + } + + public ConsoleLogger() { + this(TrLogger.Level.INFO); + } + + @Override + public void log(Level level, String message) { + if (this.level.compareTo(level) <= 0) { + System.out.println("[" + level + "] " + message); + } + } +} diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 7548a40c..6ba742ba 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -36,6 +36,7 @@ import java.util.regex.Pattern; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; +import net.fabricmc.tinyremapper.api.TrLogger; import net.fabricmc.tinyremapper.extension.mixin.MixinExtension; public class Main { @@ -61,6 +62,8 @@ public static void main(String[] rawArgs) { int threads = -1; boolean enableMixin = false; + final TrLogger logger = new ConsoleLogger(); + for (String arg : rawArgs) { if (arg.startsWith("--")) { int valueSepPos = arg.indexOf('='); @@ -86,7 +89,7 @@ public static void main(String[] rawArgs) { case "enabled": propagateBridges = LinkedMethodPropagation.ENABLED; break; case "compatible": propagateBridges = LinkedMethodPropagation.COMPATIBLE; break; default: - System.out.println("invalid propagateBridges: "+arg.substring(valueSepPos + 1)); + logger.error("invalid propagateBridges: "+arg.substring(valueSepPos + 1)); System.exit(1); } @@ -124,7 +127,7 @@ public static void main(String[] rawArgs) { case "fixmeta": ncCopyMode = NonClassCopyMode.FIX_META_INF; break; case "skipmeta": ncCopyMode = NonClassCopyMode.SKIP_META_INF; break; default: - System.out.println("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1)); + logger.error("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1)); System.exit(1); } @@ -133,7 +136,7 @@ public static void main(String[] rawArgs) { threads = Integer.parseInt(arg.substring(valueSepPos + 1)); if (threads <= 0) { - System.out.println("Thread count must be > 0"); + logger.error("Thread count must be > 0"); System.exit(1); } @@ -142,7 +145,7 @@ public static void main(String[] rawArgs) { enableMixin = true; break; default: - System.out.println("invalid argument: "+arg+"."); + logger.error("invalid argument: "+arg+"."); System.exit(1); } } else { @@ -151,14 +154,14 @@ public static void main(String[] rawArgs) { } if (args.size() < 5) { - System.out.println("usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); + logger.error("usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); System.exit(1); } Path input = Paths.get(args.get(0)); if (!Files.isReadable(input)) { - System.out.println("Can't read input file "+input+"."); + logger.error("Can't read input file "+input+"."); System.exit(1); } @@ -166,7 +169,7 @@ public static void main(String[] rawArgs) { Path mappings = Paths.get(args.get(2)); if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { - System.out.println("Can't read mappings file "+mappings+"."); + logger.error("Can't read mappings file "+mappings+"."); System.exit(1); } @@ -179,7 +182,7 @@ public static void main(String[] rawArgs) { classpath[i] = Paths.get(args.get(i + 5)); if (!Files.isReadable(classpath[i])) { - System.out.println("Can't read classpath file "+i+": "+classpath[i]+"."); + logger.error("Can't read classpath file "+i+": "+classpath[i]+"."); System.exit(1); } } @@ -188,7 +191,7 @@ public static void main(String[] rawArgs) { forcePropagation = new HashSet<>(); if (!forcePropagationFile.canRead()) { - System.out.println("Can't read forcePropagation file "+forcePropagationFile+"."); + logger.error("Can't read forcePropagation file "+forcePropagationFile+"."); System.exit(1); } @@ -210,7 +213,7 @@ public static void main(String[] rawArgs) { if (knownIndyBsmFile != null) { if (!knownIndyBsmFile.canRead()) { - System.out.println("Can't read knownIndyBsm file "+knownIndyBsmFile+"."); + logger.error("Can't read knownIndyBsm file "+knownIndyBsmFile+"."); System.exit(1); } @@ -232,7 +235,7 @@ public static void main(String[] rawArgs) { long startTime = System.nanoTime(); - TinyRemapper.Builder builder = TinyRemapper.newRemapper() + TinyRemapper.Builder builder = TinyRemapper.newRemapper(logger) .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) .ignoreFieldDesc(ignoreFieldDesc) .withForcedPropagation(forcePropagation) @@ -269,6 +272,6 @@ public static void main(String[] rawArgs) { remapper.finish(); } - System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); + logger.info("Finished after %.2f ms.", (System.nanoTime() - startTime) / 1e6); } } diff --git a/src/main/java/net/fabricmc/tinyremapper/PackageAccessChecker.java b/src/main/java/net/fabricmc/tinyremapper/PackageAccessChecker.java index 6ff613d9..b8579dd7 100644 --- a/src/main/java/net/fabricmc/tinyremapper/PackageAccessChecker.java +++ b/src/main/java/net/fabricmc/tinyremapper/PackageAccessChecker.java @@ -61,7 +61,7 @@ public static void checkClass(String accessingClass, String targetClass, String // target class is not public and in a different package // -> invalid access detected, needs to be public - System.out.printf("Invalid access from %s in %s to package-private class %s after remapping.%n", + remapper.tr.getLogger().warn("Invalid access from %s in %s to package-private class %s after remapping.%n", source, mappedAccessor, mappedTarget); @@ -211,7 +211,7 @@ public static void checkMember(String accessingOwner, String owner, String name, } } - System.out.printf("Invalid access from %s in %s to %s after remapping.%n", + remapper.tr.getLogger().warn("Invalid access from %s in %s to %s after remapping.%n", source, mappedAccessor, inaccessible); diff --git a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java index c3bc435c..af115b4d 100644 --- a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java +++ b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java @@ -65,12 +65,17 @@ import net.fabricmc.tinyremapper.IMappingProvider.Member; import net.fabricmc.tinyremapper.api.TrClass; import net.fabricmc.tinyremapper.api.TrEnvironment; +import net.fabricmc.tinyremapper.api.TrLogger; import net.fabricmc.tinyremapper.api.TrMember; import net.fabricmc.tinyremapper.api.TrMember.MemberType; public class TinyRemapper { public static class Builder { - private Builder() { } + private final TrLogger logger; + + private Builder(TrLogger logger) { + this.logger = Objects.requireNonNull(logger, "logger"); + } public Builder withMappings(IMappingProvider provider) { mappingProviders.add(provider); @@ -215,6 +220,10 @@ public Builder extension(TinyRemapper.Extension extension) { return this; } + public TrLogger getLogger() { + return logger; + } + public TinyRemapper build() { TinyRemapper remapper = new TinyRemapper(mappingProviders, ignoreFieldDesc, threadCount, keepInputData, @@ -223,7 +232,7 @@ public TinyRemapper build() { removeFrames, ignoreConflicts, resolveMissing, checkPackageAccess || fixPackageAccess, fixPackageAccess, rebuildSourceFilenames, skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex, analyzeVisitors, stateProcessors, preApplyVisitors, postApplyVisitors, - extraRemapper); + extraRemapper, logger); return remapper; } @@ -305,7 +314,8 @@ private TinyRemapper(Collection mappingProviders, boolean igno boolean renameInvalidLocals, Pattern invalidLvNamePattern, boolean inferNameFromSameLvIndex, List analyzeVisitors, List stateProcessors, List preApplyVisitors, List postApplyVisitors, - Remapper extraRemapper) { + Remapper extraRemapper, TrLogger logger) { + this.logger = logger; this.mappingProviders = mappingProviders; this.ignoreFieldDesc = ignoreFieldDesc; this.threadCount = threadCount > 0 ? threadCount : Math.max(Runtime.getRuntime().availableProcessors(), 2); @@ -338,7 +348,11 @@ private TinyRemapper(Collection mappingProviders, boolean igno } public static Builder newRemapper() { - return new Builder(); + return new Builder(new ConsoleLogger()); + } + + public static Builder newRemapper(TrLogger logger) { + return new Builder(logger); } public void finish() { @@ -477,7 +491,7 @@ private static void addClass(ClassInstance cls, Map out, } } else if (cls.isInput) { if (prev.isInput) { - System.out.printf("duplicate input class %s, from %s and %s%n", name, prev.srcPath, cls.srcPath); + cls.tr.getLogger().warn("duplicate input class %s, from %s and %s", name, prev.srcPath, cls.srcPath); prev.addInputTags(cls.getInputTags()); return; } else if (out.replace(name, prev, cls)) { // cas with retry-loop on failure @@ -717,10 +731,11 @@ private void checkClassMappings() { } } - System.out.println("non-unique class target name mappings:"); + logger.warn("non-unique class target name mappings:"); for (String target : duplicates) { - System.out.print(" ["); + StringBuilder sb = new StringBuilder(); + sb.append(" ["); boolean first = true; for (Map.Entry e : classMap.entrySet()) { @@ -728,14 +743,15 @@ private void checkClassMappings() { if (first) { first = false; } else { - System.out.print(", "); + sb.append(", "); } - System.out.print(e.getKey()); + sb.append(e.getKey()); } } - System.out.printf("] -> %s%n", target); + sb.append(String.format("] -> %s", target)); + getLogger().warn(sb.toString()); } throw new RuntimeException("duplicate class target name mappings detected"); @@ -813,7 +829,7 @@ private void handleConflicts(MrjState state) { if (testSet.size() != cls.getMembers().size()) { if (!targetNameCheckFailed) { targetNameCheckFailed = true; - System.out.println("Mapping target name conflicts detected:"); + getLogger().warn("Mapping target name conflicts detected:"); } Map> duplicates = new HashMap<>(); @@ -831,22 +847,23 @@ private void handleConflicts(MrjState state) { if (members.size() < 2) continue; MemberInstance anyMember = members.get(0); - System.out.printf(" %ss %s/[", anyMember.type, cls.getName()); + StringBuilder sb = new StringBuilder(String.format(" %ss %s/[", anyMember.type, cls.getName())); for (int i = 0; i < members.size(); i++) { - if (i != 0) System.out.print(", "); + if (i != 0) sb.append(", "); MemberInstance member = members.get(i); if (member.newNameOriginatingCls != null && !member.newNameOriginatingCls.equals(cls.getName())) { - System.out.print(member.newNameOriginatingCls); - System.out.print('/'); + sb.append(member.newNameOriginatingCls); + sb.append('/'); } - System.out.print(member.name); + sb.append(member.name); } - System.out.printf("]%s -> %s%n", MemberInstance.getId(anyMember.type, "", anyMember.desc, ignoreFieldDesc), MemberInstance.getNameFromId(anyMember.type, nameDesc, ignoreFieldDesc)); + sb.append(String.format("]%s -> %s", MemberInstance.getId(anyMember.type, "", anyMember.desc, ignoreFieldDesc), MemberInstance.getNameFromId(anyMember.type, nameDesc, ignoreFieldDesc))); + getLogger().warn(sb.toString()); } } @@ -856,7 +873,7 @@ private void handleConflicts(MrjState state) { boolean unfixableConflicts = false; if (!conflicts.isEmpty()) { - System.out.println("Mapping source name conflicts detected:"); + getLogger().warn("Mapping source name conflicts detected:"); for (Map.Entry> entry : conflicts.entrySet()) { MemberInstance member = entry.getKey(); @@ -864,7 +881,7 @@ private void handleConflicts(MrjState state) { Set names = entry.getValue(); names.add(member.cls.getName()+"/"+newName); - System.out.printf(" %s %s %s (%s) -> %s%n", member.cls.getName(), member.type.name(), member.name, member.desc, names); + getLogger().warn(" %s %s %s (%s) -> %s", member.cls.getName(), member.type.name(), member.name, member.desc, names); if (ignoreConflicts) { Map mappings = member.type == TrMember.MemberType.METHOD ? methodMap : fieldMap; @@ -886,14 +903,14 @@ private void handleConflicts(MrjState state) { unfixableConflicts = true; } else { member.forceSetNewName(mappingName); - System.out.println(" fixable: replaced with "+mappingName); + getLogger().warn(" fixable: replaced with "+mappingName); } } } } if (!conflicts.isEmpty() && !ignoreConflicts || unfixableConflicts || targetNameCheckFailed) { - if (ignoreConflicts || targetNameCheckFailed) System.out.println("There were unfixable conflicts."); + if (ignoreConflicts || targetNameCheckFailed) getLogger().error("There were unfixable conflicts."); throw new RuntimeException("Unfixable conflicts"); } @@ -946,7 +963,7 @@ public void apply(final BiConsumer outputConsumer, InputTag... i if (fixPackageAccess) { if (needsFixes) { - System.out.printf("Fixing access for %d classes and %d members.%n", classesToMakePublic.size(), membersToMakePublic.size()); + getLogger().warn("Fixing access for %d classes and %d members.", classesToMakePublic.size(), membersToMakePublic.size()); } for (Map.Entry entry : outputBuffer.entrySet()) { @@ -1192,6 +1209,10 @@ public AsmRemapper getRemapper() { return (AsmRemapper) getEnvironment().getRemapper(); } + public TrLogger getLogger() { + return logger; + } + private static void waitForAll(Iterable> futures) { try { for (Future future : futures) { @@ -1317,6 +1338,11 @@ public AsmRemapper getRemapper() { return remapper; } + @Override + public TrLogger getLogger() { + return tr.logger; + } + @Override public ClassInstance getClass(String internalName) { return classes.get(internalName); @@ -1360,6 +1386,7 @@ public void propagate(TrMember m, String newName) { private final List stateProcessors; private final List preApplyVisitors; private final List postApplyVisitors; + private final TrLogger logger; final Remapper extraRemapper; final AtomicReference> singleInputTags = new AtomicReference<>(Collections.emptyMap()); // cache for tag -> { tag } diff --git a/src/main/java/net/fabricmc/tinyremapper/api/TrEnvironment.java b/src/main/java/net/fabricmc/tinyremapper/api/TrEnvironment.java index 55c37b05..a70e0cb4 100644 --- a/src/main/java/net/fabricmc/tinyremapper/api/TrEnvironment.java +++ b/src/main/java/net/fabricmc/tinyremapper/api/TrEnvironment.java @@ -21,6 +21,7 @@ public interface TrEnvironment { int getMrjVersion(); TrRemapper getRemapper(); + TrLogger getLogger(); /** * @return the class with the passed name, or null if not found. diff --git a/src/main/java/net/fabricmc/tinyremapper/api/TrLogger.java b/src/main/java/net/fabricmc/tinyremapper/api/TrLogger.java new file mode 100644 index 00000000..8686ab7a --- /dev/null +++ b/src/main/java/net/fabricmc/tinyremapper/api/TrLogger.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016, 2018, Player, asie + * Copyright (c) 2019, 2022, FabricMC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package net.fabricmc.tinyremapper.api; + +public interface TrLogger { + void log(Level level, String message); + + default void log(Level level, String message, Object... args) { + log(level, String.format(message, args)); + } + + default void debug(String message) { + log(Level.DEBUG, message); + } + + default void debug(String message, Object... args) { + log(Level.DEBUG, message, args); + } + + default void info(String message) { + log(Level.INFO, message); + } + + default void info(String message, Object... args) { + log(Level.INFO, message, args); + } + + default void warn(String message) { + log(Level.WARN, message); + } + + default void warn(String message, Object... args) { + log(Level.WARN, message, args); + } + + default void error(String message) { + log(Level.ERROR, message); + } + + default void error(String message, Object... args) { + log(Level.ERROR, message, args); + } + + enum Level { + DEBUG, + INFO, + WARN, + ERROR + } +} diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/MixinExtension.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/MixinExtension.java index 95d2e8ea..e0eeb371 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/MixinExtension.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/MixinExtension.java @@ -35,8 +35,6 @@ import net.fabricmc.tinyremapper.TinyRemapper.Builder; import net.fabricmc.tinyremapper.api.TrClass; import net.fabricmc.tinyremapper.api.TrEnvironment; -import net.fabricmc.tinyremapper.extension.mixin.common.Logger; -import net.fabricmc.tinyremapper.extension.mixin.common.Logger.Level; import net.fabricmc.tinyremapper.extension.mixin.common.data.CommonData; import net.fabricmc.tinyremapper.extension.mixin.hard.HardTargetMixinClassVisitor; import net.fabricmc.tinyremapper.extension.mixin.soft.SoftTargetMixinClassVisitor; @@ -52,7 +50,6 @@ *

If the filter is null, all inputs will be processed. */ public class MixinExtension implements TinyRemapper.Extension { - private final Logger logger; private final Map>> tasks; private final Set targets; private final /* @Nullable */ Predicate inputTagFilter; @@ -74,27 +71,18 @@ public enum AnnotationTarget { * Remap mixin annotation. */ public MixinExtension() { - this(Level.WARN); - } - - public MixinExtension(Logger.Level logLevel) { - this(EnumSet.allOf(AnnotationTarget.class), logLevel); - } - - public MixinExtension(Set targets) { - this(targets, Level.WARN); + this(EnumSet.allOf(AnnotationTarget.class)); } public MixinExtension(/* @Nullable */ Predicate inputTagFilter) { - this(EnumSet.allOf(AnnotationTarget.class), Level.WARN, inputTagFilter); + this(EnumSet.allOf(AnnotationTarget.class), inputTagFilter); } - public MixinExtension(Set targets, Logger.Level logLevel) { - this(targets, logLevel, null); + public MixinExtension(Set targets) { + this(targets, null); } - public MixinExtension(Set targets, Logger.Level logLevel, /* @Nullable */ Predicate inputTagFilter) { - this.logger = new Logger(logLevel); + public MixinExtension(Set targets, /* @Nullable */ Predicate inputTagFilter) { this.tasks = new ConcurrentHashMap<>(); this.targets = targets; this.inputTagFilter = inputTagFilter; @@ -112,13 +100,13 @@ public void attach(Builder builder) { } private void stateProcessor(TrEnvironment environment) { - CommonData data = new CommonData(environment, logger); + CommonData data = new CommonData(environment); for (Consumer task : tasks.getOrDefault(environment.getMrjVersion(), Collections.emptyList())) { try { task.accept(data); } catch (RuntimeException e) { - logger.error(e.getMessage()); + environment.getLogger().error(e.getMessage()); } } } @@ -163,7 +151,7 @@ public ClassVisitor insertAnalyzeVisitor(boolean isInput, int mrjVersion, String private final class PreApplyVisitorProvider implements TinyRemapper.ApplyVisitorProvider { @Override public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) { - return new SoftTargetMixinClassVisitor(new CommonData(cls.getEnvironment(), logger), next); + return new SoftTargetMixinClassVisitor(new CommonData(cls.getEnvironment()), next); } @Override diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/Logger.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/Logger.java deleted file mode 100644 index 400d762d..00000000 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/Logger.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Player, asie - * Copyright (c) 2021, FabricMC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package net.fabricmc.tinyremapper.extension.mixin.common; - -public final class Logger { - public enum Level { - INFO, WARN, ERROR - } - - private final Level level; - - public Logger(Level level) { - this.level = level; - } - - public void info(String message) { - if (this.level.compareTo(Level.INFO) <= 0) { - System.out.println("[INFO] [MIXIN] " + message); - } - } - - public void warn(String message) { - if (this.level.compareTo(Level.WARN) <= 0) { - if (USE_ANSI) { - System.out.println(ANSI_YELLOW + "[WARN] [MIXIN] " + ANSI_RESET + message); - } else { - System.out.println("[WARN] [MIXIN] " + message); - } - } - } - - public void error(String message) { - if (this.level.compareTo(Level.ERROR) <= 0) { - if (USE_ANSI) { - System.out.println(ANSI_RED + "[ERROR] [MIXIN] " + ANSI_RESET + message); - } else { - System.out.println("[ERROR] [MIXIN] " + message); - } - } - } - - private static final boolean USE_ANSI = false; - - private static final String ANSI_RESET = "\u001B[0m"; - private static final String ANSI_BLACK = "\u001B[30m"; - private static final String ANSI_RED = "\u001B[31m"; - private static final String ANSI_GREEN = "\u001B[32m"; - private static final String ANSI_YELLOW = "\u001B[33m"; - private static final String ANSI_BLUE = "\u001B[34m"; - private static final String ANSI_PURPLE = "\u001B[35m"; - private static final String ANSI_CYAN = "\u001B[36m"; - private static final String ANSI_WHITE = "\u001B[37m"; -} diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/MapUtility.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/MapUtility.java index a2bc7582..915b54bb 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/MapUtility.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/MapUtility.java @@ -23,16 +23,17 @@ import java.util.Objects; import net.fabricmc.tinyremapper.api.TrClass; +import net.fabricmc.tinyremapper.api.TrLogger; import net.fabricmc.tinyremapper.api.TrMember; import net.fabricmc.tinyremapper.api.TrRemapper; public final class MapUtility { private final TrRemapper remapper; - private final Logger logger; + private final TrLogger logger; public static final List IGNORED_NAME = Arrays.asList("", ""); - public MapUtility(TrRemapper remapper, Logger logger) { + public MapUtility(TrRemapper remapper, TrLogger logger) { this.remapper = Objects.requireNonNull(remapper); this.logger = Objects.requireNonNull(logger); } diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/ResolveUtility.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/ResolveUtility.java index 521d7711..5ced7e74 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/ResolveUtility.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/ResolveUtility.java @@ -27,6 +27,7 @@ import net.fabricmc.tinyremapper.api.TrClass; import net.fabricmc.tinyremapper.api.TrEnvironment; import net.fabricmc.tinyremapper.api.TrField; +import net.fabricmc.tinyremapper.api.TrLogger; import net.fabricmc.tinyremapper.api.TrMember; import net.fabricmc.tinyremapper.api.TrMember.MemberType; import net.fabricmc.tinyremapper.api.TrMethod; @@ -51,11 +52,11 @@ public final class ResolveUtility { public static int FLAG_NON_SYN = 0x8; private final TrEnvironment environment; - private final Logger logger; + private final TrLogger logger; - public ResolveUtility(TrEnvironment environment, Logger logger) { + public ResolveUtility(TrEnvironment environment) { this.environment = Objects.requireNonNull(environment); - this.logger = Objects.requireNonNull(logger); + this.logger = environment.getLogger(); } public Optional resolveClass(String name) { diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/data/CommonData.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/data/CommonData.java index c655f50c..44c4f276 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/data/CommonData.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/common/data/CommonData.java @@ -21,24 +21,26 @@ import java.util.Objects; import net.fabricmc.tinyremapper.api.TrEnvironment; +import net.fabricmc.tinyremapper.api.TrLogger; import net.fabricmc.tinyremapper.api.TrMember; -import net.fabricmc.tinyremapper.extension.mixin.common.Logger; import net.fabricmc.tinyremapper.extension.mixin.common.MapUtility; import net.fabricmc.tinyremapper.extension.mixin.common.ResolveUtility; public final class CommonData { private final TrEnvironment environment; - public final Logger logger; public final ResolveUtility resolver; public final MapUtility mapper; - public CommonData(TrEnvironment environment, Logger logger) { + public CommonData(TrEnvironment environment) { this.environment = Objects.requireNonNull(environment); - this.logger = Objects.requireNonNull(logger); - this.resolver = new ResolveUtility(environment, logger); - this.mapper = new MapUtility(environment.getRemapper(), logger); + this.resolver = new ResolveUtility(environment); + this.mapper = new MapUtility(environment.getRemapper(), environment.getLogger()); + } + + public TrLogger getLogger() { + return this.environment.getLogger(); } public void propagate(TrMember member, String newName) { diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/ImplementsAnnotationVisitor.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/ImplementsAnnotationVisitor.java index a76492e0..d0654cec 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/ImplementsAnnotationVisitor.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/ImplementsAnnotationVisitor.java @@ -184,7 +184,7 @@ protected Optional getMappedName() { List collection = stream.distinct().collect(Collectors.toList()); if (collection.size() > 1) { - data.logger.error(String.format(Message.CONFLICT_MAPPING, self.getName(), collection)); + data.getLogger().error(String.format(Message.CONFLICT_MAPPING, self.getName(), collection)); } return collection.stream().findFirst(); diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/util/ConvertibleMappable.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/util/ConvertibleMappable.java index ef0fbb61..376e762c 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/util/ConvertibleMappable.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/util/ConvertibleMappable.java @@ -62,9 +62,9 @@ protected Optional getMappedName() { .collect(Collectors.toList()); if (collection.size() > 1) { - data.logger.error(String.format(Message.CONFLICT_MAPPING, self.getName(), collection)); + data.getLogger().error(String.format(Message.CONFLICT_MAPPING, self.getName(), collection)); } else if (collection.isEmpty()) { - data.logger.warn(String.format(Message.NO_MAPPING_RECURSIVE, self.getName(), targets)); + data.getLogger().warn(String.format(Message.NO_MAPPING_RECURSIVE, self.getName(), targets)); } return collection.stream().findFirst(); diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/AtAnnotationVisitor.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/AtAnnotationVisitor.java index 7b154594..6c6c0a31 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/AtAnnotationVisitor.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/AtAnnotationVisitor.java @@ -138,7 +138,7 @@ private static class AtMethodMappable implements IMappable { @Override public MemberInfo result() { if (!info.isFullyQualified()) { - data.logger.warn(String.format(Message.NOT_FULLY_QUALIFIED, info)); + data.getLogger().warn(String.format(Message.NOT_FULLY_QUALIFIED, info)); return info; } diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java index dcf9c5f8..c9e56949 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java @@ -112,9 +112,9 @@ public MemberInfo result() { .distinct().collect(Collectors.toList()); if (collection.size() > 1) { - data.logger.error(String.format(Message.CONFLICT_MAPPING, info.getName(), collection)); + data.getLogger().error(String.format(Message.CONFLICT_MAPPING, info.getName(), collection)); } else if (collection.isEmpty()) { - data.logger.warn(String.format(Message.NO_MAPPING_NON_RECURSIVE, info.getName(), targets)); + data.getLogger().warn(String.format(Message.NO_MAPPING_NON_RECURSIVE, info.getName(), targets)); } return collection.stream().findFirst() diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/DescAnnotationVisitor.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/DescAnnotationVisitor.java index b0ecac47..b441e25c 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/DescAnnotationVisitor.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/DescAnnotationVisitor.java @@ -137,7 +137,7 @@ public void visitEnd() { if (proposedName == null) { proposedName = remapped; } else if (!proposedName.equals(remapped)) { - data.logger.error(String.format(Message.MULTIPLE_MAPPING_CHOICES, value + desc, owner + "." + remapped + desc, proposedName + desc)); + data.getLogger().error(String.format(Message.MULTIPLE_MAPPING_CHOICES, value + desc, owner + "." + remapped + desc, proposedName + desc)); } } @@ -148,7 +148,7 @@ public void visitEnd() { } } else if (expectedType == MemberType.FIELD) { if (ret == null) { - data.logger.warn(String.format(Message.NOT_FULLY_QUALIFIED, owner + "." + value)); + data.getLogger().warn(String.format(Message.NOT_FULLY_QUALIFIED, owner + "." + value)); super.visit("value", value); super.visitEnd(); return; @@ -169,7 +169,7 @@ public void visitEnd() { if (proposedName == null) { proposedName = remapped; } else if (!proposedName.equals(remapped)) { - data.logger.error(String.format(Message.MULTIPLE_MAPPING_CHOICES, value + desc, owner + "." + remapped + desc, proposedName + desc)); + data.getLogger().error(String.format(Message.MULTIPLE_MAPPING_CHOICES, value + desc, owner + "." + remapped + desc, proposedName + desc)); } } diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/util/NamedMappable.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/util/NamedMappable.java index 691c6603..09553a0e 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/util/NamedMappable.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/util/NamedMappable.java @@ -61,9 +61,9 @@ public String result() { .distinct().collect(Collectors.toList()); if (collection.size() > 1) { - data.logger.error(String.format(Message.CONFLICT_MAPPING, this.name, collection)); + data.getLogger().error(String.format(Message.CONFLICT_MAPPING, this.name, collection)); } else if (collection.isEmpty()) { - data.logger.warn(String.format(Message.NO_MAPPING_RECURSIVE, this.name, targets)); + data.getLogger().warn(String.format(Message.NO_MAPPING_RECURSIVE, this.name, targets)); } return collection.stream().findFirst().orElse(name);