Skip to content

Commit

Permalink
Merge pull request #448 from cherylking/changeOnDemandTestsHotKey
Browse files Browse the repository at this point in the history
changes for key binding for on demand tests in dev mode
  • Loading branch information
cherylking authored Jul 24, 2024
2 parents b2ca3c9 + 332e221 commit e22ec0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ private enum FileTrackMode {
protected List<Path> monitoredWebResourceDirs;
private boolean hotTests;
private Path tempConfigPath;
private boolean changeOnDemandTestsAction;
private boolean skipTests;
private boolean skipUTs;
private boolean skipITs;
Expand Down Expand Up @@ -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<File> resourceDirs,
File configDirectory, File projectDirectory, File multiModuleProjectDirectory, List<File> 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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class DevTestUtil extends DevUtil {
public DevTestUtil(File serverDirectory, File sourceDirectory, File testSourceDirectory, File configDirectory,
List<File> resourceDirs, List<Path> 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);
}

Expand Down

0 comments on commit e22ec0b

Please sign in to comment.