Code review comment: Do we need to do this in Gradle as well?

Code before review:
public void execute() throws MojoFailureException, MojoExecutionException {
if (project.getPackaging().equals(ArtifactCoords.TYPE_POM)) {
getLog().info("Type of the artifact is POM, skipping dev goal");
return;
}
mavenVersionEnforcer.ensureMavenVersion(getLog(), session);
initToolchain();
String bootstrapId = handleAutoCompile();
if (enforceBuildGoal) {
final PluginDescriptor pluginDescr = getPluginDescriptor();
final Plugin pluginDef = getConfiguredPluginOrNull(pluginDescr.getGroupId(), pluginDescr.getArtifactId());
if (!isGoalConfigured(pluginDef, "build")) {
if (warnIfBuildGoalMissing) {
var currentGoal = getCurrentGoal();
getLog().warn(
"Skipping " + currentGoal + " as this is assumed to be a support library." +
" To disable this warning set warnIfBuildGoalMissing parameter to false."
+ System.lineSeparator() +
"To enable " + currentGoal +
" for this module, make sure the quarkus-maven-plugin configuration includes the build goal"
+
" or disable the enforceBuildGoal flag (via plugin configuration or via" +
" -Dquarkus.enforceBuildGoal=false).");
}
return;
}
}
saveTerminalState();
analyticsProvider.buildAnalyticsUserInput((String prompt) -> {
System.out.print(prompt);
try (Scanner scanner = new Scanner(new FilterInputStream(System.in) {
@Override
public void close() throws IOException {
}
})) {
return scanner.nextLine();
} catch (Exception e) {
getLog().warn("Failed to collect user input for analytics", e);
return "";
}
});
try {
DevModeRunner runner = new DevModeRunner(bootstrapId);
Map<Path, Long> pomFiles = readPomFileTimestamps(runner);
runner.run();
long nextCheck = System.currentTimeMillis() + 100;
for (;;) {
suspend = "n";
long sleep = Math.max(0, nextCheck - System.currentTimeMillis()) + 1;
Thread.sleep(sleep);
if (System.currentTimeMillis() > nextCheck) {
nextCheck = System.currentTimeMillis() + 100;
if (!runner.alive()) {
restoreTerminalState();
if (!runner.isExpectedExitValue()) {
throw new MojoExecutionException("Dev mode process did not complete successfully");
}
return;
}
final Set<Path> changed = new HashSet<>();
for (Map.Entry<Path, Long> e : pomFiles.entrySet()) {
long t = Files.getLastModifiedTime(e.getKey()).toMillis();
if (t > e.getValue()) {
changed.add(e.getKey());
pomFiles.put(e.getKey(), t);
}
}
if (!changed.isEmpty()) {
getLog().info("Changes detected to " + changed + ", restarting dev mode");
runner.stop();
final DevModeRunner newRunner;
try {
bootstrapId = handleAutoCompile();
newRunner = new DevModeRunner(runner.launcher.getActualDebugPort(), bootstrapId);
} catch (Exception e) {
getLog().info("Could not load changed pom.xml file, changes not applied", e);
continue;
}
newRunner.run();
runner = newRunner;
}
}
}
} catch (Exception e) {
throw new MojoFailureException("Failed to run", e);
}
}

Line under review: runner.stop();

Code after addressing the review:
public void execute() throws MojoFailureException, MojoExecutionException {
if (project.getPackaging().equals(ArtifactCoords.TYPE_POM)) {
getLog().info("Type of the artifact is POM, skipping dev goal");
return;
}
mavenVersionEnforcer.ensureMavenVersion(getLog(), session);
initToolchain();
String bootstrapId = handleAutoCompile();
if (enforceBuildGoal) {
final PluginDescriptor pluginDescr = getPluginDescriptor();
final Plugin pluginDef = getConfiguredPluginOrNull(pluginDescr.getGroupId(), pluginDescr.getArtifactId());
if (!isGoalConfigured(pluginDef, "build")) {
if (warnIfBuildGoalMissing) {
var currentGoal = getCurrentGoal();
getLog().warn(
"Skipping " + currentGoal + " as this is assumed to be a support library." +
" To disable this warning set warnIfBuildGoalMissing parameter to false."
+ System.lineSeparator() +
"To enable " + currentGoal +
" for this module, make sure the quarkus-maven-plugin configuration includes the build goal"
+
" or disable the enforceBuildGoal flag (via plugin configuration or via" +
" -Dquarkus.enforceBuildGoal=false).");
}
return;
}
}
saveTerminalState();
analyticsProvider.buildAnalyticsUserInput((String prompt) -> {
System.out.print(prompt);
try (Scanner scanner = new Scanner(new FilterInputStream(System.in) {
@Override
public void close() throws IOException {
}
})) {
return scanner.nextLine();
} catch (Exception e) {
getLog().warn("Failed to collect user input for analytics", e);
return "";
}
});
try {
DevModeRunner runner = new DevModeRunner(bootstrapId);
Map<Path, Long> pomFiles = readPomFileTimestamps(runner);
runner.run();
long nextCheck = System.currentTimeMillis() + 100;
for (;;) {
suspend = "n";
long sleep = Math.max(0, nextCheck - System.currentTimeMillis()) + 1;
Thread.sleep(sleep);
if (System.currentTimeMillis() > nextCheck) {
nextCheck = System.currentTimeMillis() + 100;
if (!runner.alive()) {
restoreTerminalState();
if (!runner.isExpectedExitValue()) {
throw new MojoExecutionException("Dev mode process did not complete successfully");
}
return;
}
final Set<Path> changed = new HashSet<>();
for (Map.Entry<Path, Long> e : pomFiles.entrySet()) {
long t = Files.getLastModifiedTime(e.getKey()).toMillis();
if (t > e.getValue()) {
changed.add(e.getKey());
pomFiles.put(e.getKey(), t);
}
}
if (!changed.isEmpty()) {
getLog().info("Changes detected to " + changed + ", restarting dev mode");
runner.stop();
final DevModeRunner newRunner;
try {
bootstrapId = handleAutoCompile();
newRunner = new DevModeRunner(runner.launcher.getActualDebugPort(), bootstrapId);
} catch (Exception e) {
getLog().info("Could not load changed pom.xml file, changes not applied", e);
continue;
}
newRunner.run();
runner = newRunner;
}
}
}
} catch (Exception e) {
throw new MojoFailureException("Failed to run", e);
}
}