Add --only, a more aggressive version of --excluded-packages
This commit is contained in:
parent
6370404e61
commit
f63f343677
@ -165,10 +165,14 @@ public class JarRemapper extends CustomRemapper {
|
|||||||
return mapped == null ? name : mapped;
|
return mapped == null ? name : mapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remapJar(Jar jar, File target) throws IOException {
|
||||||
|
remapJar(jar, target, Collections.EMPTY_SET);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remap all the classes in a jar, writing a new jar to the target
|
* Remap all the classes in a jar, writing a new jar to the target
|
||||||
*/
|
*/
|
||||||
public void remapJar(Jar jar, File target) throws IOException {
|
public void remapJar(Jar jar, File target, Set<String> includes) throws IOException {
|
||||||
if (jar == null) {
|
if (jar == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -185,7 +189,7 @@ public class JarRemapper extends CustomRemapper {
|
|||||||
|
|
||||||
try (InputStream is = jar.getResource(name)) {
|
try (InputStream is = jar.getResource(name)) {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
if (name.endsWith(".class")) {
|
if (name.endsWith(".class") && shouldHandle(name, includes)) {
|
||||||
// remap classes
|
// remap classes
|
||||||
name = name.substring(0, name.length() - CLASS_LEN);
|
name = name.substring(0, name.length() - CLASS_LEN);
|
||||||
|
|
||||||
@ -224,6 +228,23 @@ public class JarRemapper extends CustomRemapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean shouldHandle(String name, Set<String> includes) {
|
||||||
|
if (includes.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String match : includes) {
|
||||||
|
if (match.equals(".") && !name.contains("/")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (name.startsWith(match)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remap an individual class given an InputStream to its bytecode
|
* Remap an individual class given an InputStream to its bytecode
|
||||||
*/
|
*/
|
||||||
|
@ -34,6 +34,8 @@ import net.md_5.specialsource.provider.JointProvider;
|
|||||||
import net.md_5.specialsource.provider.JarProvider;
|
import net.md_5.specialsource.provider.JarProvider;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
@ -134,6 +136,10 @@ public class SpecialSource {
|
|||||||
acceptsAll(asList("e", "excluded-packages"), "A comma seperated list of packages that should not be transformed, even if the srg specifies they should")
|
acceptsAll(asList("e", "excluded-packages"), "A comma seperated list of packages that should not be transformed, even if the srg specifies they should")
|
||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
.ofType(String.class);
|
.ofType(String.class);
|
||||||
|
|
||||||
|
acceptsAll(asList("only"), "Process only the specified packages. Similar to --excluded-packages but applies at the processing rather than loading phase")
|
||||||
|
.withRequiredArg()
|
||||||
|
.ofType(String.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -286,7 +292,7 @@ public class SpecialSource {
|
|||||||
|
|
||||||
log("Remapping final jar");
|
log("Remapping final jar");
|
||||||
JarRemapper jarRemapper = new JarRemapper(null, jarMapping, accessMapper);
|
JarRemapper jarRemapper = new JarRemapper(null, jarMapping, accessMapper);
|
||||||
jarRemapper.remapJar(jar3, (File) options.valueOf("out-jar"));
|
jarRemapper.remapJar(jar3, (File) options.valueOf("out-jar"), new HashSet<String>((Collection<String>) options.valuesOf("only")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user