From 4ff2947c9a76ce4cac26c306ca27aba6ce4808d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Fri, 29 Nov 2024 13:34:41 +0100 Subject: [PATCH] #758: improve status commandlet (#816) --- .../ide/commandlet/StatusCommandlet.java | 53 +++++++++++++++++++ .../tools/ide/context/AbstractIdeContext.java | 23 ++++++-- .../devonfw/tools/ide/context/IdeContext.java | 5 ++ .../AbstractEnvironmentVariables.java | 6 +++ .../ide/environment/EnvironmentVariables.java | 5 ++ .../EnvironmentVariablesPropertiesFile.java | 16 ++++++ 6 files changed, 103 insertions(+), 5 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/StatusCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/StatusCommandlet.java index 0f2e5b59c..1513187fd 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/StatusCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/StatusCommandlet.java @@ -1,6 +1,10 @@ package com.devonfw.tools.ide.commandlet; +import java.nio.file.Path; + +import com.devonfw.tools.ide.context.GitContext; import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.environment.EnvironmentVariables; /** * {@link Commandlet} to print a status report about IDEasy. @@ -26,5 +30,54 @@ public String getName() { @Override public void run() { + + this.context.logIdeHomeAndRootStatus(); + logOnlineStatus(); + logSettingsGitStatus(); + logSettingsLegacyStatus(); + } + + private void logSettingsLegacyStatus() { + EnvironmentVariables variables = this.context.getVariables(); + boolean hasLegacyProperties = false; + while (variables != null) { + Path legacyProperties = variables.getLegacyPropertiesFilePath(); + if (legacyProperties != null) { + hasLegacyProperties = true; + this.context.warning("Found legacy properties {}", legacyProperties); + } + variables = variables.getParent(); + } + if (hasLegacyProperties) { + this.context.warning( + "Your settings are outdated and contain legacy configurations. Please consider upgrading your settings:\nhttps://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc#upgrade"); + } + } + + private void logSettingsGitStatus() { + Path settingsPath = this.context.getSettingsPath(); + if (settingsPath != null) { + GitContext gitContext = this.context.getGitContext(); + if (gitContext.isRepositoryUpdateAvailable(settingsPath)) { + this.context.warning("Your settings are not up-to-date, please run 'ide update'."); + } else { + this.context.success("Your settings are up-to-date."); + } + String branch = gitContext.determineCurrentBranch(settingsPath); + this.context.debug("Your settings branch is {}", branch); + if (!"master".equals(branch) && !"main".equals(branch)) { + this.context.warning("Your settings are on a custom branch: {}", branch); + } + } + } + + private void logOnlineStatus() { + if (this.context.isOfflineMode()) { + this.context.warning("You have configured offline mode via CLI."); + } else if (this.context.isOnline()) { + this.context.success("You are online."); + } else { + this.context.warning("You are offline. Check your internet connection and potential proxy settings."); + } } } 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 223e03278..28f8f0a7e 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 @@ -659,6 +659,19 @@ public IdeSubLogger level(IdeLogLevel level) { return this.startContext.level(level); } + @Override + public void logIdeHomeAndRootStatus() { + + if (this.ideRoot != null) { + success("IDE_ROOT is set to {}", this.ideRoot); + } + if (this.ideHome == null) { + warning(getMessageIdeHomeNotFound()); + } else { + success("IDE_HOME is set to {}", this.ideHome); + } + } + @Override public String askForInput(String message, String defaultValue) { @@ -875,11 +888,11 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) { if (cmd.isIdeHomeRequired()) { debug(getMessageIdeHomeFound()); } - } - if (this.settingsPath != null) { - if (getGitContext().isRepositoryUpdateAvailable(this.settingsPath) || - (getGitContext().fetchIfNeeded(this.settingsPath) && getGitContext().isRepositoryUpdateAvailable(this.settingsPath))) { - interaction("Updates are available for the settings repository. If you want to pull the latest changes, call ide update."); + if (this.settingsPath != null) { + if (getGitContext().isRepositoryUpdateAvailable(this.settingsPath) || + (getGitContext().fetchIfNeeded(this.settingsPath) && getGitContext().isRepositoryUpdateAvailable(this.settingsPath))) { + interaction("Updates are available for the settings repository. If you want to pull the latest changes, call ide update."); + } } } cmd.run(); diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java index 3ca74ea16..787a38d64 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java @@ -545,4 +545,9 @@ default String findBashRequired() { */ WindowsPathSyntax getPathSyntax(); + /** + * logs the status of {@link #getIdeHome() IDE_HOME} and {@link #getIdeRoot() IDE_ROOT}. + */ + void logIdeHomeAndRootStatus(); + } diff --git a/cli/src/main/java/com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java b/cli/src/main/java/com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java index 8983a0166..52445bf7b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java +++ b/cli/src/main/java/com/devonfw/tools/ide/environment/AbstractEnvironmentVariables.java @@ -73,6 +73,12 @@ public Path getPropertiesFilePath() { return null; } + @Override + public Path getLegacyPropertiesFilePath() { + + return null; + } + @Override public VariableSource getSource() { diff --git a/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java b/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java index 40339213c..de52a53e8 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java +++ b/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java @@ -118,6 +118,11 @@ default EnvironmentVariables getByType(EnvironmentVariablesType type) { */ Path getPropertiesFilePath(); + /** + * @return the {@link Path} to the {@link #LEGACY_PROPERTIES} if they exist for this {@link EnvironmentVariables} or {@code null} otherwise (does not exist). + */ + Path getLegacyPropertiesFilePath(); + /** * @return the {@link VariableSource} of this {@link EnvironmentVariables}. */ diff --git a/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFile.java b/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFile.java index 64e1d9cd6..877b43295 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFile.java +++ b/cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariablesPropertiesFile.java @@ -252,6 +252,22 @@ public Path getPropertiesFilePath() { return this.propertiesFilePath; } + @Override + public Path getLegacyPropertiesFilePath() { + + if (this.propertiesFilePath == null) { + return null; + } + if (this.propertiesFilePath.getFileName().toString().equals(LEGACY_PROPERTIES)) { + return this.propertiesFilePath; + } + Path legacyProperties = this.propertiesFilePath.getParent().resolve(LEGACY_PROPERTIES); + if (Files.exists(legacyProperties)) { + return legacyProperties; + } + return null; + } + @Override public String set(String name, String value, boolean export) {