Skip to content

Commit e6ac0d5

Browse files
committed
Make capability in --help human readable
1 parent 0638c2d commit e6ac0d5

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,16 @@ public void showHelp(String progName, boolean linkableRuntimeEnabled) {
592592

593593
log.println(bundleHelper.getMessage("main.command.files"));
594594
// If the JDK build has the run-time image capability show it
595-
// in the help output
596-
log.println(bundleHelper.getMessage("main.runtime.image.linking.capability",
597-
linkableRuntimeEnabled ? "+" : "-"));
595+
// in the help output in human readable form.
596+
String qualifier = null;
597+
if (linkableRuntimeEnabled) {
598+
qualifier = bundleHelper.getMessage("main.runtime.image.linking.cap.enabled");
599+
} else {
600+
qualifier = bundleHelper.getMessage("main.runtime.image.linking.cap.disabled");
601+
}
602+
log.println(bundleHelper.getMessage("main.runtime.image.linking.cap.sect.header"));
603+
log.println(bundleHelper.getMessage("main.runtime.image.linking.cap.msg",
604+
qualifier));
598605
}
599606

600607
public void listPlugins() {

src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ main.extended.help.footer=\
111111
\ used, one pattern per line\n\
112112
\n\
113113
114-
main.runtime.image.linking.capability=Capabilities: {0}run-time-image
114+
main.runtime.image.linking.cap.enabled=enabled
115+
main.runtime.image.linking.cap.disabled=disabled
116+
main.runtime.image.linking.cap.sect.header=Capabilities:
117+
main.runtime.image.linking.cap.msg=\ Linking from run-time image {0}
115118

116119
error.prefix=Error:
117120
warn.prefix=Warning:

test/jdk/tools/jlink/JLinkHelpCapabilityTest.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* @test id=run-time-image-cap-yes
3030
* @summary Test jlink --help for capability output (true)
3131
* @requires (vm.compMode != "Xcomp" & jlink.runtime.linkable)
32-
* @run main/othervm JLinkHelpCapabilityTest true
32+
* @run main/othervm -Duser.language=en JLinkHelpCapabilityTest true
3333
*/
3434

3535
/*
3636
* @test id=run-time-image-cap-no
3737
* @summary Test jlink --help for capability output (false)
3838
* @requires (vm.compMode != "Xcomp" & !jlink.runtime.linkable)
39-
* @run main/othervm JLinkHelpCapabilityTest false
39+
* @run main/othervm -Duser.language=en JLinkHelpCapabilityTest false
4040
*/
4141
public class JLinkHelpCapabilityTest {
4242
static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
@@ -46,18 +46,36 @@ public class JLinkHelpCapabilityTest {
4646

4747
public static void main(String[] args) throws Exception {
4848
boolean runtimeLinkCap = Boolean.parseBoolean(args[0]);
49-
String capabilities = String.format("Capabilities: %srun-time-image",
50-
runtimeLinkCap ? "+" : "-");
49+
String capabilities = String.format("Linking from run-time image %s",
50+
runtimeLinkCap ? "enabled" : "disabled");
5151
{
5252
// Verify capability in --help output
5353
StringWriter writer = new StringWriter();
5454
PrintWriter pw = new PrintWriter(writer);
5555
JLINK_TOOL.run(pw, pw, "--help");
5656
String output = writer.toString().trim();
5757
String lines[] = output.split("\n");
58-
if (!capabilities.equals(lines[lines.length - 1])) {
58+
String capabilitiesMsg = null;
59+
boolean seenCap = false;
60+
for (int i = 0; i < lines.length; i++) {
61+
if (lines[i].startsWith("Capabilities:")) {
62+
seenCap = true;
63+
continue; // skip 'Capabilities:'
64+
}
65+
if (!seenCap) {
66+
continue;
67+
} else {
68+
// Line after capabilities is the message we care about
69+
capabilitiesMsg = lines[i].trim();
70+
break;
71+
}
72+
}
73+
System.out.println("DEBUG: Capabilities:");
74+
System.out.println("DEBUG: " + capabilitiesMsg);
75+
if (!capabilities.equals(capabilitiesMsg)) {
5976
System.err.println(output);
60-
throw new AssertionError("'--help': Capabilities mismatch. Expected: '" + capabilities +"'");
77+
throw new AssertionError("'--help': Capabilities mismatch. Expected: '" +
78+
capabilities +"' but got '" + capabilitiesMsg + "'");
6179
}
6280
}
6381
}

0 commit comments

Comments
 (0)