From ec3e0d810b494cb3baa9ac69d9d5a5ae5504def7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Mon, 20 Jan 2025 22:40:23 +0100 Subject: [PATCH] #919: prevent asking for license agreement in case of EnvironmentCommandlet to prevent blocking bash --- .../tools/ide/context/AbstractIdeContext.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java index 3c92749fe..3b4f56d8f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java @@ -22,6 +22,7 @@ import com.devonfw.tools.ide.commandlet.CommandletManager; import com.devonfw.tools.ide.commandlet.CommandletManagerImpl; import com.devonfw.tools.ide.commandlet.ContextCommandlet; +import com.devonfw.tools.ide.commandlet.EnvironmentCommandlet; import com.devonfw.tools.ide.commandlet.HelpCommandlet; import com.devonfw.tools.ide.common.SystemPath; import com.devonfw.tools.ide.completion.CompletionCandidate; @@ -879,7 +880,10 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) { } } } - ensureLicenseAgreement(); + boolean success = ensureLicenseAgreement(cmd); + if (!success) { + return ValidationResultValid.get(); + } cmd.run(); } finally { if (previousLogLevel != null) { @@ -892,15 +896,21 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) { return result; } - private void ensureLicenseAgreement() { + private boolean ensureLicenseAgreement(Commandlet cmd) { if (isTest()) { - return; // ignore for tests + return true; // ignore for tests } getFileAccess().mkdirs(this.userHomeIde); Path licenseAgreement = this.userHomeIde.resolve(FILE_LICENSE_AGREEMENT); if (Files.isRegularFile(licenseAgreement)) { - return; // success, license already accepted + return true; // success, license already accepted + } + if (cmd instanceof EnvironmentCommandlet) { + // if the license was not accepted, "$(ideasy env --bash)" that is written into a variable prevents the user from seeing the question he is asked + // in such situation the user could not open a bash terminal anymore and gets blocked what would really annoy the user so we exit here without doing or + // printing anything anymore in such case. + return false; } boolean logLevelInfoDisabled = !this.startContext.info().isEnabled(); if (logLevelInfoDisabled) { @@ -944,6 +954,7 @@ This product (with its included 3rd party components) is open-source software an if (logLevelInteractionDisabled) { this.startContext.setLogLevel(IdeLogLevel.INTERACTION, false); } + return true; } private void verifyIdeRoot() {