Skip to content

Commit

Permalink
#758: improve status commandlet (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Nov 29, 2024
1 parent ae9ec5b commit 4ff2947
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,9 @@ default String findBashRequired() {
*/
WindowsPathSyntax getPathSyntax();

/**
* logs the status of {@link #getIdeHome() IDE_HOME} and {@link #getIdeRoot() IDE_ROOT}.
*/
void logIdeHomeAndRootStatus();

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public Path getPropertiesFilePath() {
return null;
}

@Override
public Path getLegacyPropertiesFilePath() {

return null;
}

@Override
public VariableSource getSource() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit 4ff2947

Please sign in to comment.