diff options
author | zaaarf <zaaarf@proton.me> | 2023-03-13 13:03:49 +0100 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-03-13 13:03:49 +0100 |
commit | 6e2ea19ab48987e01543b6db188f8e5ce3d1eeb9 (patch) | |
tree | 4c3970735dd7fa82d4358eb3b744a7d2de21755c /src/main/java/ftbsc/lll/processor | |
parent | df3590d097e28309f7ed2dc3cc3d8413a9f56b49 (diff) |
feat: may now pass local files as mappings
Diffstat (limited to 'src/main/java/ftbsc/lll/processor')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index c6343a6..aaaa2f0 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -3,6 +3,7 @@ package ftbsc.lll.processor; import com.squareup.javapoet.*; import ftbsc.lll.IInjector; import ftbsc.lll.exceptions.AmbiguousDefinitionException; +import ftbsc.lll.exceptions.InvalidResourceException; import ftbsc.lll.exceptions.MappingNotFoundException; import ftbsc.lll.exceptions.TargetNotFoundException; import ftbsc.lll.processor.annotations.*; @@ -20,6 +21,8 @@ import javax.tools.FileObject; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; @@ -61,14 +64,26 @@ public class LilleroProcessor extends AbstractProcessor { String location = processingEnv.getOptions().get("mappingsFile"); if(location == null) mapper = null; - else { //TODO: add local file + else { + InputStream targetStream; try { - URL url = new URL(location); - InputStream is = url.openStream(); - mapper = new ObfuscationMapper(new BufferedReader(new InputStreamReader(is, - StandardCharsets.UTF_8)).lines()); - is.close(); - } catch(IOException ignored) {} //TODO: proper handling + 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); + } + } + //assuming its tsrg file + //todo: replace crappy homebaked parser with actual library + this.mapper = new ObfuscationMapper(new BufferedReader(new InputStreamReader(targetStream, + StandardCharsets.UTF_8)).lines()); } } |