mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 14:44:51 +01:00
feat: may now pass local files as mappings
This commit is contained in:
parent
df3590d097
commit
6e2ea19ab4
3 changed files with 57 additions and 10 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
package ftbsc.lll.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when a resource passed as an argument is not found.
|
||||||
|
*/
|
||||||
|
public class InvalidResourceException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty constructor, used when the provided resource exists but is empty.
|
||||||
|
*/
|
||||||
|
public InvalidResourceException() {
|
||||||
|
super("The specified resource was empty!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Named constructor, used when the specified resource doesn't exist.
|
||||||
|
* @param name the resource name
|
||||||
|
*/
|
||||||
|
public InvalidResourceException(String name) {
|
||||||
|
super("Specified resource " + name + " was not found!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,27 @@
|
||||||
package ftbsc.lll.exceptions;
|
package ftbsc.lll.exceptions;
|
||||||
|
|
||||||
import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
|
import ftbsc.lll.processor.tools.obfuscation.IMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown upon failure to find the requested mapping within a loaded {@link ObfuscationMapper}.
|
* Thrown upon failure to find the requested mapping within a loaded {@link IMapper}.
|
||||||
*/
|
*/
|
||||||
public class MappingNotFoundException extends RuntimeException {
|
public class MappingNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new mapping not found exception for the specified mapping.
|
* Constructs a new mapping not found exception for the specified mapping.
|
||||||
* @param mapping the detail message
|
* @param mapping the relevant mapping
|
||||||
*/
|
*/
|
||||||
public MappingNotFoundException(String mapping) {
|
public MappingNotFoundException(String mapping) {
|
||||||
super("Could not find mapping for " + mapping + "!");
|
super("Could not find mapping for " + mapping + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new mapping not found exception for the specified mapping
|
||||||
|
* with the specified reason.
|
||||||
|
* @param mapping the relevant mapping
|
||||||
|
* @param reason the reason message
|
||||||
|
*/
|
||||||
|
public MappingNotFoundException(String mapping, String reason) {
|
||||||
|
this(mapping + ": " + reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ftbsc.lll.processor;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import ftbsc.lll.IInjector;
|
import ftbsc.lll.IInjector;
|
||||||
import ftbsc.lll.exceptions.AmbiguousDefinitionException;
|
import ftbsc.lll.exceptions.AmbiguousDefinitionException;
|
||||||
|
import ftbsc.lll.exceptions.InvalidResourceException;
|
||||||
import ftbsc.lll.exceptions.MappingNotFoundException;
|
import ftbsc.lll.exceptions.MappingNotFoundException;
|
||||||
import ftbsc.lll.exceptions.TargetNotFoundException;
|
import ftbsc.lll.exceptions.TargetNotFoundException;
|
||||||
import ftbsc.lll.processor.annotations.*;
|
import ftbsc.lll.processor.annotations.*;
|
||||||
|
@ -20,6 +21,8 @@ import javax.tools.FileObject;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
import javax.tools.StandardLocation;
|
import javax.tools.StandardLocation;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -61,14 +64,26 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
String location = processingEnv.getOptions().get("mappingsFile");
|
String location = processingEnv.getOptions().get("mappingsFile");
|
||||||
if(location == null)
|
if(location == null)
|
||||||
mapper = null;
|
mapper = null;
|
||||||
else { //TODO: add local file
|
else {
|
||||||
|
InputStream targetStream;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(location);
|
URI target = new URI(location);
|
||||||
InputStream is = url.openStream();
|
targetStream = target.toURL().openStream();
|
||||||
mapper = new ObfuscationMapper(new BufferedReader(new InputStreamReader(is,
|
} 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());
|
StandardCharsets.UTF_8)).lines());
|
||||||
is.close();
|
|
||||||
} catch(IOException ignored) {} //TODO: proper handling
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue