From 332e2218e2a255f1aa60e1ca796c58218930c55a Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 23 Jul 2024 12:31:55 -0500 Subject: [PATCH] changes for key binding for on demand tests in dev mode --- .../tools/common/plugins/util/DevUtil.java | 33 ++++++++++++++----- .../common/plugins/util/BaseDevUtilTest.java | 4 +-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java index 8556574d..ccf73509 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java @@ -364,6 +364,7 @@ private enum FileTrackMode { protected List monitoredWebResourceDirs; private boolean hotTests; private Path tempConfigPath; + private boolean changeOnDemandTestsAction; private boolean skipTests; private boolean skipUTs; private boolean skipITs; @@ -440,7 +441,7 @@ private enum FileTrackMode { protected boolean skipInstallFeature; public DevUtil(File buildDirectory, File serverDirectory, File sourceDirectory, File testSourceDirectory, - File configDirectory, File projectDirectory, File multiModuleProjectDirectory, List resourceDirs, + File configDirectory, File projectDirectory, File multiModuleProjectDirectory, List resourceDirs, boolean changeOnDemandTestsAction, boolean hotTests, boolean skipTests, boolean skipUTs, boolean skipITs, boolean skipInstallFeature, String applicationId, long serverStartTimeout, int appStartupTimeout, int appUpdateTimeout, long compileWaitMillis, boolean libertyDebug, boolean useBuildRecompile, boolean gradle, boolean pollingTest, boolean container, @@ -457,6 +458,7 @@ public DevUtil(File buildDirectory, File serverDirectory, File sourceDirectory, this.projectDirectory = projectDirectory; this.multiModuleProjectDirectory = multiModuleProjectDirectory; this.resourceDirs = resourceDirs; + this.changeOnDemandTestsAction = changeOnDemandTestsAction; this.hotTests = hotTests; this.skipTests = skipTests; this.skipUTs = skipUTs; @@ -2532,12 +2534,14 @@ private void printTestsMessage(boolean formatForAttention) { if (skipTests) { return; } + String actionKey = changeOnDemandTestsAction ? "t" : "Enter"; + String actionKeyInstruction = changeOnDemandTestsAction ? "type 't' and press Enter" : "press the Enter key"; + String message = hotTests ? "Tests will run automatically when changes are detected. You can also "+actionKeyInstruction+" to run tests on demand." : "run tests on demand, "+actionKeyInstruction+"."; + if (hotTests) { - String message = "Tests will run automatically when changes are detected. You can also press the Enter key to run tests on demand."; - info(formatForAttention ? formatAttentionMessage("Enter - " + message) : message); + info(formatForAttention ? formatAttentionMessage(actionKey + " - " + message) : message); } else { - String message = "run tests on demand, press Enter."; - info(formatForAttention ? formatAttentionMessage("Enter - " + message) : "To " + message); + info(formatForAttention ? formatAttentionMessage(actionKey + " - " + message) : "To " + message); } } @@ -2685,13 +2689,15 @@ private void readInput() { HotKey r = new HotKey("r"); HotKey g = new HotKey("g"); HotKey o = new HotKey("o"); + HotKey t = new HotKey("t"); HotKey enter = new HotKey(""); if (scanner.hasNextLine()) { synchronized (inputUnavailable) { inputUnavailable.notify(); } while (!shutdown) { - debug("Waiting for Enter key to run tests"); + debug("Waiting for action key"); + if (!scanner.hasNextLine()) { break; } @@ -2721,14 +2727,16 @@ private void readInput() { warn("Cannot optimize features because automatic generation of features is off."); warn("To toggle the automatic generation of features, type 'g' and press Enter."); } - } else if (enter.isPressed(line)){ - debug("Detected Enter key. Running tests... "); + } else if ((t.isPressed(line) && isChangeOnDemandTestsAction()) || (enter.isPressed(line) && !isChangeOnDemandTestsAction())) { + debug("Detected test command. Running tests... "); if (isMultiModuleProject()) { // force run tests across all modules in multi module scenario runTestThread(false, executor, -1, true, getAllBuildFiles()); } else { runTestThread(false, executor, -1, true, buildFile); } + } else if (enter.isPressed(line) && isChangeOnDemandTestsAction()) { + warn("Unrecognized command: Enter. To see the help menu, type 'h' and press Enter."); } else { warn("Unrecognized command: " + line + ". To see the help menu, type 'h' and press Enter."); } @@ -5496,6 +5504,15 @@ public boolean isMultiModuleProject() { return (upstreamProjects != null && !upstreamProjects.isEmpty()); } + /** + * Returns the value of changeOnDemandTestsAction boolean. + * + * @return value of changeOnDemandTestsAction + */ + public boolean isChangeOnDemandTestsAction() { + return this.changeOnDemandTestsAction; + } + /** * Gets an array of all the buildFiles in a multi module project * diff --git a/src/test/java/io/openliberty/tools/common/plugins/util/BaseDevUtilTest.java b/src/test/java/io/openliberty/tools/common/plugins/util/BaseDevUtilTest.java index 7c0b062f..0600ffb8 100644 --- a/src/test/java/io/openliberty/tools/common/plugins/util/BaseDevUtilTest.java +++ b/src/test/java/io/openliberty/tools/common/plugins/util/BaseDevUtilTest.java @@ -39,13 +39,13 @@ public class DevTestUtil extends DevUtil { public DevTestUtil(File serverDirectory, File sourceDirectory, File testSourceDirectory, File configDirectory, List resourceDirs, List webResourceDirs, boolean hotTests, boolean skipTests) throws IOException { super(temp.newFolder(), serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, null, null, - resourceDirs, hotTests, skipTests, false, false, false, null, 30, 30, 5, 500, true, false, false, false, + resourceDirs, false, hotTests, skipTests, false, false, false, null, 30, 30, 5, 500, true, false, false, false, false, null, null, null, 0, false, null, false, null, null, false, null, null, null, false, null, null, webResourceDirs); } public DevTestUtil(File serverDirectory, File buildDir) { super(buildDir, serverDirectory, null, null, null, null, null, - null, false, false, false, false, false, null, 30, 30, 5, 500, true, false, false, false, + null, false, false, false, false, false, false, null, 30, 30, 5, 500, true, false, false, false, false, null, null, null, 0, false, null, false, null, null, false, null, null, null, false, null, null, null); }