Skip to content

Commit 8d1bccb

Browse files
committed
Add comma separation support to -e and --only, improve class allowlisting
1 parent 4870677 commit 8d1bccb

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ else if (args.length > x+1) {
129129
if (arg.equals("-s") || arg.equals("--silent")) {
130130
mapOptions.put(IFernflowerPreferences.LOG_LEVEL, "error");
131131
} else if (arg.startsWith("-e=") || arg.startsWith("--add-external=")) {
132-
addPath(libraries, arg.substring(arg.indexOf('=') + 1));
132+
for (String path : arg.substring(arg.indexOf('=') + 1).split(",")) {
133+
addPath(libraries, path);
134+
}
133135
} else if (arg.startsWith("-only=") || arg.startsWith("--only=")) {
134-
whitelist.add(arg.substring(arg.indexOf('=') + 1));
136+
whitelist.addAll(Arrays.asList(arg.substring(arg.indexOf('=') + 1).split(",")));
135137
} else {
136138
if (lastPath != null) {
137139
addPath(sources, lastPath);

src/org/jetbrains/java/decompiler/main/decompiler/ConsoleHelp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public class ConsoleHelp {
3232
"If unspecified, the decompiled source will be automatically detected based on destination name.",
3333
"",
3434
"--- General options ---",
35-
"These options can be specified multiple times.",
35+
"These options can be specified multiple times. Multiple values can be passed in with commas.",
3636
"-e=<path>, --add-external=<path> - Add the specified path to the list of external libraries",
37-
"-only=<class>, --only=<class> - Only decompile the specified class",
37+
"-only=<pattern>, --only=<pattern> - Only decompile classes starting with the given pattern",
3838
"",
3939
"--- Additional options ---",
4040
"These options take the last specified value.",

src/org/jetbrains/java/decompiler/struct/ContextUnit.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,26 @@ public void save(final Function<String, StructClass> loader) throws IOException
128128

129129
sink.begin();
130130

131+
final DecompilerContext rootContext = DecompilerContext.getCurrentContext();
132+
133+
Set<String> otherNames = otherEntries.stream().map(IContextSource.Entry::path).collect(Collectors.toSet());
134+
131135
// directory entries
132136
for (String dirEntry : dirEntries) {
133-
sink.acceptDirectory(dirEntry);
137+
boolean write = true;
138+
if (!rootContext.classProcessor.isWhitelisted(dirEntry)) {
139+
// not allowed? check if an other entry starts with this path
140+
write = otherNames.stream().anyMatch(s -> s.startsWith(dirEntry));
141+
}
142+
143+
if (write) {
144+
sink.acceptDirectory(dirEntry);
145+
}
134146
}
135147

136148
// non-class entries
137-
for (IContextSource.Entry otherEntry : otherEntries) {
138-
sink.acceptOther(otherEntry.path());
149+
for (String otherEntry : otherNames) {
150+
sink.acceptOther(otherEntry);
139151
}
140152

141153
//Whooo threads!
@@ -145,7 +157,6 @@ public void save(final Function<String, StructClass> loader) throws IOException
145157
threads = Runtime.getRuntime().availableProcessors();
146158
}
147159
ForkJoinPool pool = new ForkJoinPool(threads, namingScheme(), null, true);
148-
final DecompilerContext rootContext = DecompilerContext.getCurrentContext();
149160
final List<ClassContext> toDump = new ArrayList<>(classEntries.size());
150161
Set<String> seen = new LinkedHashSet<>();
151162

0 commit comments

Comments
 (0)