Skip to content

Commit

Permalink
devonfw#758: improve status further (legacy settings warning)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Nov 28, 2024
1 parent 3016b42 commit eb9be2a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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 Down Expand Up @@ -31,13 +32,29 @@ public String getName() {
public void run() {

this.context.logIdeHomeAndRootStatus();
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.");
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();
Expand All @@ -53,4 +70,14 @@ public void run() {
}
}
}

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 @@ -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 eb9be2a

Please sign in to comment.