From 8e3284a904633b5434104668936be5251e520241 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sat, 26 Aug 2023 22:37:47 +0200 Subject: feat: updated to use mapper 0.1 --- .../lll/processor/tools/ProcessorOptions.java | 35 +++++----------------- .../processor/tools/containers/FieldContainer.java | 3 +- .../tools/containers/MethodContainer.java | 3 +- 3 files changed, 11 insertions(+), 30 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java b/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java index de751bc..77d0dad 100644 --- a/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java +++ b/src/main/java/ftbsc/lll/processor/tools/ProcessorOptions.java @@ -1,18 +1,14 @@ package ftbsc.lll.processor.tools; import ftbsc.lll.IInjector; -import ftbsc.lll.exceptions.InvalidResourceException; import ftbsc.lll.mapper.IMapper; +import ftbsc.lll.mapper.MapperProvider; import javax.annotation.processing.ProcessingEnvironment; -import java.io.*; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; -import java.util.stream.Collectors; /** * Class in charge of containing, parsing and processing all processor options, @@ -63,28 +59,11 @@ public class ProcessorOptions { public ProcessorOptions(ProcessingEnvironment env) { this.env = env; String location = env.getOptions().get("mappingsFile"); - if(location == null) - this.mapper = null; - else { - InputStream targetStream; - try { - URI target = new URI(location); - targetStream = target.toURL().openStream(); - } catch(URISyntaxException | IOException e) { - //may be a local file path - File f = new File(location); - if(!f.exists()) - throw new InvalidResourceException(location); - try { - targetStream = new FileInputStream(f); - } catch(FileNotFoundException ex) { - throw new InvalidResourceException(location); - } - } - this.mapper = IMapper.getMappers(new BufferedReader( - new InputStreamReader(targetStream, StandardCharsets.UTF_8)).lines().collect(Collectors.toList()) - ).iterator().next(); //TODO: add logic for choosing a specific one - } + if(location != null) { + List lines = MapperProvider.fetchFromLocalOrRemote(location); + this.mapper = MapperProvider.getMapper(lines); + this.mapper.populate(lines, true); + } else this.mapper = null; this.anonymousClassWarning = parseBooleanArg(env.getOptions().get("anonymousClassWarning"), true); this.obfuscateInjectorMetadata = parseBooleanArg(env.getOptions().get("obfuscateInjectorMetadata"), true); this.noServiceProvider = parseBooleanArg(env.getOptions().get("noServiceProvider"), false); diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java index 0074ebe..9154193 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java @@ -74,7 +74,8 @@ public class FieldContainer { this.name = this.elem.getSimpleName().toString(); this.descriptor = descriptorFromType(this.elem.asType(), options.env); } - this.descriptorObf = options.mapper == null ? this.descriptor : MappingUtils.obfuscateType(Type.getType(this.descriptor), options.mapper).getDescriptor(); + this.descriptorObf = options.mapper == null ? this.descriptor + : MappingUtils.mapType(Type.getType(this.descriptor), options.mapper, false).getDescriptor(); this.nameObf = findMemberName(parent.fqn, this.name, null, options.mapper); } diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java index f646a1c..2878ec6 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java @@ -79,7 +79,8 @@ public class MethodContainer { this.name = this.elem.getSimpleName().toString(); this.descriptor = descriptorFromExecutableElement(this.elem, options.env); } - this.descriptorObf = options.mapper == null ? this.descriptor : MappingUtils.obfuscateMethodDescriptor(this.descriptor, options.mapper); + this.descriptorObf = options.mapper == null ? this.descriptor + : MappingUtils.mapMethodDescriptor(this.descriptor, options.mapper, false); this.nameObf = findMemberName(parent.fqn, this.name, this.descriptor, options.mapper); } -- cgit v1.2.3-56-ga3b1