8360562: sun/security/tools/keytool/i18n.java add an ability to add comment for failures

Reviewed-by: rhalade
This commit is contained in:
Mikhail Yankelevich 2025-10-03 07:37:17 +00:00
parent 3790965df3
commit ebb6fd7d78

View File

@ -63,11 +63,21 @@
import jdk.test.lib.UIBuilder;
import javax.swing.*;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Locale;
import static javax.swing.BorderFactory.createEmptyBorder;
public class i18n {
private static final String[][] TABLE = new String[][]{
{"-help", "All the output in this test should be in ${LANG}. "
@ -234,11 +244,12 @@ public class i18n {
"Output in ${LANG}. Check keytool error: java.lang"
+ ".IllegalArgumentException: if -protected is "
+ "specified, then -storepass, -keypass, and -new "
+ "must not be specified."},
+ "must not be specified."}
};
private static String TEST_SRC = System.getProperty("test.src");
private static int TIMEOUT_MS = 120000;
private volatile boolean failed = false;
private volatile String failureReason = "";
private volatile boolean aborted = false;
private Thread currentThread = null;
@ -330,6 +341,7 @@ public class i18n {
if (failed) {
System.out.println(command + ": TEST FAILED");
System.out.println("REASON: " + failureReason);
System.out.println(message);
} else {
System.out.println(command + ": TEST PASSED");
@ -348,6 +360,7 @@ public class i18n {
public void fail() {
failed = true;
failureReason = requestFailDescription();
currentThread.interrupt();
}
@ -355,4 +368,33 @@ public class i18n {
aborted = true;
currentThread.interrupt();
}
/**
* Opens a prompt to enter a failure reason to be filled by the tester
*/
public static String requestFailDescription() {
final JDialog dialogWindow = new JDialog(new JFrame(), "Failure Description", true);
final JTextArea reasonTextArea = new JTextArea(5, 20);
final JButton okButton = new JButton("OK");
okButton.addActionListener(_ -> dialogWindow.setVisible(false));
final JPanel okayBtnPanel = new JPanel(
new FlowLayout(FlowLayout.CENTER, 4, 0));
okayBtnPanel.setBorder(createEmptyBorder(4, 0, 0, 0));
okayBtnPanel.add(okButton);
final JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(new JScrollPane(reasonTextArea), BorderLayout.CENTER);
mainPanel.add(okayBtnPanel, BorderLayout.SOUTH);
dialogWindow.add(mainPanel);
dialogWindow.pack();
dialogWindow.setVisible(true);
dialogWindow.dispose();
return reasonTextArea.getText();
}
}