< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java
Print this page
rev 14867 : 8159172: Update usage of jlink/jimage/jmod to show option patterns
Reviewed-by: mchung
*** 52,63 ****
new Option<JImageTask>(true, (task, option, arg) -> {
task.options.directory = arg;
}, "--dir"),
new Option<JImageTask>(true, (task, option, arg) -> {
! task.options.filters = arg;
! }, "--filter"),
new Option<JImageTask>(false, (task, option, arg) -> {
task.options.fullVersion = true;
}, true, "--fullversion"),
--- 52,63 ----
new Option<JImageTask>(true, (task, option, arg) -> {
task.options.directory = arg;
}, "--dir"),
new Option<JImageTask>(true, (task, option, arg) -> {
! task.options.include = arg;
! }, "--include"),
new Option<JImageTask>(false, (task, option, arg) -> {
task.options.fullVersion = true;
}, true, "--fullversion"),
*** 79,94 ****
= TASK_HELPER.newOptionsHelper(JImageTask.class, RECOGNIZED_OPTIONS);
private static final String PROGNAME = "jimage";
private static final FileSystem JRT_FILE_SYSTEM = Utils.jrtFileSystem();
private final OptionsValues options;
! private final List<Predicate<String>> filterPredicates;
private PrintWriter log;
JImageTask() {
this.options = new OptionsValues();
! this.filterPredicates = new ArrayList<>();
log = null;
}
void setLog(PrintWriter out) {
log = out;
--- 79,94 ----
= TASK_HELPER.newOptionsHelper(JImageTask.class, RECOGNIZED_OPTIONS);
private static final String PROGNAME = "jimage";
private static final FileSystem JRT_FILE_SYSTEM = Utils.jrtFileSystem();
private final OptionsValues options;
! private final List<Predicate<String>> includePredicates;
private PrintWriter log;
JImageTask() {
this.options = new OptionsValues();
! this.includePredicates = new ArrayList<>();
log = null;
}
void setLog(PrintWriter out) {
log = out;
*** 96,106 ****
}
static class OptionsValues {
Task task = Task.LIST;
String directory = ".";
! String filters = "";
boolean fullVersion;
boolean help;
boolean verbose;
boolean version;
List<File> jimages = new LinkedList<>();
--- 96,106 ----
}
static class OptionsValues {
Task task = Task.LIST;
String directory = ".";
! String include = "";
boolean fullVersion;
boolean help;
boolean verbose;
boolean version;
List<File> jimages = new LinkedList<>();
*** 198,207 ****
--- 198,209 ----
name = name.substring(1);
}
log.println(TASK_HELPER.getMessage("main.opt." + name));
}
+
+ log.println(TASK_HELPER.getMessage("main.opt.footer"));
} else {
try {
log.println(TASK_HELPER.getMessage("main.usage." +
options.task.toString().toLowerCase()));
} catch (MissingResourceException ex) {
*** 217,227 ****
if (unhandled.isEmpty()) {
return EXIT_OK;
}
}
! processFilter(options.filters);
return run() ? EXIT_OK : EXIT_ERROR;
} catch (BadArgs e) {
TASK_HELPER.reportError(e.key, e.args);
--- 219,229 ----
if (unhandled.isEmpty()) {
return EXIT_OK;
}
}
! processInclude(options.include);
return run() ? EXIT_OK : EXIT_ERROR;
} catch (BadArgs e) {
TASK_HELPER.reportError(e.key, e.args);
*** 237,255 ****
} finally {
log.flush();
}
}
! private void processFilter(String filters) {
! if (filters.isEmpty()) {
return;
}
! for (String filter : filters.split(",")) {
final PathMatcher matcher = Utils.getPathMatcher(JRT_FILE_SYSTEM, filter);
Predicate<String> predicate = (path) -> matcher.matches(JRT_FILE_SYSTEM.getPath(path));
! filterPredicates.add(predicate);
}
}
private void listTitle(File file, BasicImageReader reader) {
log.println("jimage: " + file);
--- 239,257 ----
} finally {
log.flush();
}
}
! private void processInclude(String include) {
! if (include.isEmpty()) {
return;
}
! for (String filter : include.split(",")) {
final PathMatcher matcher = Utils.getPathMatcher(JRT_FILE_SYSTEM, filter);
Predicate<String> predicate = (path) -> matcher.matches(JRT_FILE_SYSTEM.getPath(path));
! includePredicates.add(predicate);
}
}
private void listTitle(File file, BasicImageReader reader) {
log.println("jimage: " + file);
*** 386,398 ****
if (resourceAction != null) {
String[] entryNames = reader.getEntryNames();
String oldModule = "";
for (String name : entryNames) {
! boolean match = filterPredicates.isEmpty();
! for (Predicate<String> predicate : filterPredicates) {
if (predicate.test(name)) {
match = true;
break;
}
}
--- 388,400 ----
if (resourceAction != null) {
String[] entryNames = reader.getEntryNames();
String oldModule = "";
for (String name : entryNames) {
! boolean match = includePredicates.isEmpty();
! for (Predicate<String> predicate : includePredicates) {
if (predicate.test(name)) {
match = true;
break;
}
}
< prev index next >