Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> knownIndyBsm, Object... bsmArgs) {
private Handle getLambdaImplementedMethod(String name, String desc, Handle bsm, Set<String> 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.getLogger().warn("unknown invokedynamic bsm: %s/%s%s (tag=%d iif=%b)", bsm.getOwner(), bsm.getName(), bsm.getDesc(), bsm.getTag(), bsm.isInterface());
return null;
}
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/net/fabricmc/tinyremapper/ConsoleLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package net.fabricmc.tinyremapper;

import net.fabricmc.tinyremapper.api.TrLogger;

public final class ConsoleLogger implements TrLogger {
private TrLogger.Level level;

public ConsoleLogger(TrLogger.Level level) {
this.level = level;
}

public ConsoleLogger() {
this(TrLogger.Level.INFO);
}

public void setLevel(TrLogger.Level level) {
this.level = level;
}

@Override
public void log(Level level, String message) {
if (this.level.compareTo(level) <= 0) {
System.out.println("[" + level + "] " + message);
}
}
}
30 changes: 18 additions & 12 deletions src/main/java/net/fabricmc/tinyremapper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.regex.Pattern;

import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation;
import net.fabricmc.tinyremapper.api.TrLogger;

public class Main {
public static void main(String[] rawArgs) {
Expand Down Expand Up @@ -69,6 +70,8 @@ public static void main(String[] rawArgs) {
ServiceLoader.load(TinyRemapper.CLIExtensionProvider.class);
cliProviderLoader.iterator().forEachRemaining(provider -> providerMap.put(provider.name(), provider));

final ConsoleLogger logger = new ConsoleLogger();

for (String arg : rawArgs) {
if (arg.startsWith("--")) {
int valueSepPos = arg.indexOf('=');
Expand All @@ -94,7 +97,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);
}

Expand Down Expand Up @@ -135,7 +138,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);
}

Expand All @@ -144,7 +147,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);
}

Expand All @@ -156,8 +159,11 @@ public static void main(String[] rawArgs) {
case "extension":
handleExtension(providerMap, arg.substring(valueSepPos + 1), providedExtensions);
break;
case "loglevel":
logger.setLevel(TrLogger.Level.valueOf(arg.substring(valueSepPos + 1).toUpperCase(Locale.ENGLISH)));
break;
default:
System.out.println("invalid argument: "+arg+".");
logger.error("invalid argument: "+arg+".");
System.exit(1);
}
} else {
Expand All @@ -166,22 +172,22 @@ public static void main(String[] rawArgs) {
}

if (args.size() < 5) {
System.out.println("usage: <input> <output> <mappings> <from> <to> [<classpath>]... [--reverse] [--forcePropagation=<file>] [--propagatePrivate] [--ignoreConflicts]");
logger.error("usage: <input> <output> <mappings> <from> <to> [<classpath>]... [--reverse] [--forcePropagation=<file>] [--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);
}

Path output = Paths.get(args.get(1));
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);
}

Expand All @@ -194,7 +200,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);
}
}
Expand All @@ -203,7 +209,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);
}

Expand All @@ -225,7 +231,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);
}

Expand All @@ -247,7 +253,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)
Expand Down Expand Up @@ -285,7 +291,7 @@ 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);
}

private static void handleExtension(Map<String, TinyRemapper.CLIExtensionProvider> providerMap, String extName, List<TinyRemapper.Extension> providedExtensions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading