diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2c3bfa2ff..312ffd311 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/1270[#1270]: IDEasy now loads global user settings if outside a project * https://github.com/devonfw/IDEasy/issues/1552[#1552]: Add Commandlet to fix TLS issue * https://github.com/devonfw/IDEasy/issues/1799[#1799]: Add support for file URL in GitUrl validation for local development * https://github.com/devonfw/IDEasy/issues/1760[#1760]: Accept empty input for single option diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java index 7a1df72be..3a2f98f12 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java @@ -1,5 +1,6 @@ package com.devonfw.tools.ide.commandlet; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -8,7 +9,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.devonfw.tools.ide.cli.CliExitException; import com.devonfw.tools.ide.context.AbstractIdeContext; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.environment.EnvironmentVariablesType; @@ -65,9 +65,6 @@ public boolean isProcessableOutput() { @Override protected void doRun() { - if (this.context.getIdeHome() == null) { - throw new CliExitException(); - } boolean winCmd = false; WindowsPathSyntax pathSyntax = null; @@ -84,9 +81,12 @@ protected void doRun() { List variables = this.context.getVariables().collectVariables(); Map variableMap = variables.stream().collect(Collectors.toMap(VariableLine::getName, v -> v)); - EnvironmentVariableCollectorContext environmentVariableCollectorContext = new EnvironmentVariableCollectorContext(variableMap, - new VariableSource(EnvironmentVariablesType.TOOL, this.context.getSoftwarePath()), pathSyntax); - setEnvironmentVariablesInLocalTools(environmentVariableCollectorContext); + Path softwarePath = this.context.getSoftwarePath(); + if (softwarePath != null) { + EnvironmentVariableCollectorContext environmentVariableCollectorContext = new EnvironmentVariableCollectorContext(variableMap, + new VariableSource(EnvironmentVariablesType.TOOL, softwarePath), pathSyntax); + setEnvironmentVariablesInLocalTools(environmentVariableCollectorContext); + } printLines(variableMap, winCmd); } 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 58198ec6b..dba4ec6e0 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 @@ -601,6 +601,9 @@ public Path getUserHome() { protected void setUserHome(Path userHome) { this.userHome = userHome; + this.userHomeIde = userHome.resolve(FOLDER_DOT_IDE); + this.downloadPath = userHome.resolve("Downloads/ide"); + this.variables = null; resetPrivacyMap(); } diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandletGlobalTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandletGlobalTest.java new file mode 100644 index 000000000..082c0cd9d --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandletGlobalTest.java @@ -0,0 +1,41 @@ +package com.devonfw.tools.ide.commandlet; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.log.IdeLogEntry; + +/** + * Test of {@link EnvironmentCommandlet} for global configuration. + */ +class EnvironmentCommandletGlobalTest extends AbstractIdeContextTest { + + @Test + void testRunOutsideProject(@TempDir Path tempDir) throws IOException { + + // arrange + Path userHome = tempDir.resolve("user"); + Path userHomeIde = userHome.resolve(".ide"); + Files.createDirectories(userHomeIde); + Files.writeString(userHomeIde.resolve("ide.properties"), "export FOO=bar\n"); + + IdeTestContext context = new IdeTestContext(tempDir.resolve("cwd"), null); + context.setUserHome(userHome); + + EnvironmentCommandlet env = context.getCommandletManager().getCommandlet(EnvironmentCommandlet.class); + + // act + env.run(); + + // assert + assertThat(context).log().hasEntries( // + IdeLogEntry.ofProcessable("export FOO=\"bar\"") // + ); + } +}