diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java index 838b0fc67..b3a1b00f6 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java @@ -56,6 +56,9 @@ public CommandletManagerImpl(IdeContext context) { add(new VersionSetCommandlet(context)); add(new VersionGetCommandlet(context)); add(new VersionListCommandlet(context)); + add(new EditionGetCommandlet(context)); + add(new EditionSetCommandlet(context)); + add(new EditionListCommandlet(context)); add(new VersionCommandlet(context)); add(new Gh(context)); add(new Helm(context)); diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java new file mode 100644 index 000000000..f593d473f --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java @@ -0,0 +1,58 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.cli.CliException; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.property.ToolProperty; +import com.devonfw.tools.ide.tool.ToolCommandlet; +import com.devonfw.tools.ide.version.VersionIdentifier; + +import static com.devonfw.tools.ide.process.ProcessResult.TOOL_NOT_INSTALLED; + +/** + * An internal {@link Commandlet} to get the installed edition for a tool. + * + * @see ToolCommandlet#getInstalledEdition() + */ +public class EditionGetCommandlet extends Commandlet { + + /** The tool to get the edition of. */ + public final ToolProperty tool; + + /** + * The constructor. + * + * @param context the {@link IdeContext}. + */ + public EditionGetCommandlet(IdeContext context) { + + super(context); + addKeyword(getName()); + this.tool = add(new ToolProperty("", true, "tool")); + } + + @Override + public String getName() { + + return "get-edition"; + } + + @Override + public void run() { + + ToolCommandlet commandlet = this.tool.getValue(); + VersionIdentifier installedVersion = commandlet.getInstalledVersion(); + if (installedVersion == null) { + throw new CliException("Tool " + commandlet.getName() + " is not installed!", TOOL_NOT_INSTALLED); + } + + try { + String installedEdition = commandlet.getInstalledEdition(); + this.context.info(installedEdition); + } catch (IllegalStateException e) { + String configuredEdition = this.context.getVariables().getToolEdition(getName()); + this.context.info("The configured edition for tool {} is {}.", getName(), configuredEdition); + + } + } + +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionListCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionListCommandlet.java new file mode 100644 index 000000000..eea3a261b --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionListCommandlet.java @@ -0,0 +1,42 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.property.ToolProperty; +import com.devonfw.tools.ide.tool.ToolCommandlet; + +/** + * An internal {@link Commandlet} to list editions for a tool. + * + * @see ToolCommandlet#listEditions() + */ +public class EditionListCommandlet extends Commandlet { + + /** The tool to list the editions of. */ + public final ToolProperty tool; + + /** + * The constructor. + * + * @param context the {@link IdeContext}. + */ + public EditionListCommandlet(IdeContext context) { + + super(context); + addKeyword(getName()); + this.tool = add(new ToolProperty("", true, "tool")); + } + + @Override + public String getName() { + + return "list-editions"; + } + + @Override + public void run() { + + ToolCommandlet commandlet = this.tool.getValue(); + commandlet.listEditions(); + } + +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java new file mode 100644 index 000000000..ee851d040 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java @@ -0,0 +1,47 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.property.EditionProperty; +import com.devonfw.tools.ide.property.ToolProperty; +import com.devonfw.tools.ide.tool.ToolCommandlet; + +/** + * An internal {@link Commandlet} to set a tool edition. + */ +public class EditionSetCommandlet extends Commandlet { + + /** The tool to set the edition of. */ + public final ToolProperty tool; + + /** The edition to set. */ + public final EditionProperty edition; + + /** + * The constructor. + * + * @param context the {@link IdeContext}. + */ + public EditionSetCommandlet(IdeContext context) { + + super(context); + addKeyword(getName()); + this.tool = add(new ToolProperty("", true, "tool")); + this.edition = add(new EditionProperty("", true, "edition")); + } + + @Override + public String getName() { + + return "set-edition"; + } + + @Override + public void run() { + + ToolCommandlet commandlet = this.tool.getValue(); + String edition = this.edition.getValue(); + + commandlet.setEdition(edition); + } + +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java index 153d93c7d..c7042d02f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java @@ -8,9 +8,9 @@ import com.devonfw.tools.ide.version.VersionIdentifier; /** - * An internal {@link Commandlet} to set a tool version. + * An internal {@link Commandlet} to get the installed version for a tool. * - * @see ToolCommandlet#setVersion(VersionIdentifier, boolean) + * @see ToolCommandlet#getInstalledVersion() */ public class VersionGetCommandlet extends Commandlet { diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionListCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionListCommandlet.java index 16d8b7d50..be8cd08d4 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionListCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionListCommandlet.java @@ -3,12 +3,11 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.property.ToolProperty; import com.devonfw.tools.ide.tool.ToolCommandlet; -import com.devonfw.tools.ide.version.VersionIdentifier; /** - * An internal {@link Commandlet} to set a tool version. + * An internal {@link Commandlet} to list versions for a tool. * - * @see ToolCommandlet#setVersion(VersionIdentifier, boolean) + * @see ToolCommandlet#listVersions()) */ public class VersionListCommandlet extends Commandlet { @@ -30,7 +29,7 @@ public VersionListCommandlet(IdeContext context) { @Override public String getName() { - return "list-version"; + return "list-versions"; } @Override 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 d99e67d1f..05fb41a40 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 @@ -226,4 +226,13 @@ static String getToolVersionVariable(String tool) { return tool.toUpperCase(Locale.ROOT) + "_VERSION"; } + /** + * @param tool the name of the tool. + * @return the name of the edition variable. + */ + static String getToolEditionVariable(String tool) { + + return tool.toUpperCase(Locale.ROOT) + "_EDITION"; + } + } diff --git a/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java b/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java new file mode 100644 index 000000000..f2226254b --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java @@ -0,0 +1,45 @@ +package com.devonfw.tools.ide.property; + +import com.devonfw.tools.ide.context.IdeContext; + +import java.util.function.Consumer; + +public class EditionProperty extends Property { + + /** + * The constructor. + * + * @param name the {@link #getName() property name}. + * @param required the {@link #isRequired() required flag}. + * @param alias the {@link #getAlias() property alias}. + */ + public EditionProperty(String name, boolean required, String alias) { + + this(name, required, alias, null); + } + + /** + * The constructor. + * + * @param name the {@link #getName() property name}. + * @param required the {@link #isRequired() required flag}. + * @param alias the {@link #getAlias() property alias}. + * @param validator the {@link Consumer} used to {@link #validate() validate} the {@link #getValue() value}. + */ + public EditionProperty(String name, boolean required, String alias, Consumer validator) { + + super(name, required, alias, validator); + } + + @Override + public Class getValueType() { + + return String.class; + } + + @Override + public String parse(String valueAsString, IdeContext context) { + + return valueAsString; + } +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java index 14e2150ef..a0e11c14d 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java @@ -330,6 +330,52 @@ protected VersionIdentifier getInstalledVersion(Path toolPath) { } } + /** + * @return the installed edition of this tool or {@code null} if not installed. + */ + public String getInstalledEdition() { + + return getInstalledEdition(this.context.getSoftwarePath().resolve(getName())); + } + + /** + * @param toolPath the installation {@link Path} where to find currently installed tool. The name of the parent + * directory of the real path corresponding to the passed {@link Path path} must be the name of the edition. + * @return the installed edition of this tool or {@code null} if not installed. + */ + public String getInstalledEdition(Path toolPath) { + + if (!Files.isDirectory(toolPath)) { + this.context.debug("Tool {} not installed in {}", getName(), toolPath); + return null; + } + try { + String edition = toolPath.toRealPath().getParent().getFileName().toString(); + if (!this.context.getUrls().getSortedEditions(getName()).contains(edition)) { + this.context.warning("The determined edition \"{}\" of tool {} is not among the editions provided by IDEasy", + edition, getName()); + } + return edition; + } catch (IOException e) { + throw new IllegalStateException("Couldn't determine the edition of " + getName() + + " from the directory structure of its software path " + toolPath + + ", assuming the name of the parent directory of the real path of the software path to be the edition " + + "of the tool.", e); + } + + } + + /** + * List the available editions of this tool. + */ + public void listEditions() { + + List editions = this.context.getUrls().getSortedEditions(getName()); + for (String edition : editions) { + this.context.info(edition); + } + } + /** * List the available versions of this tool. */ @@ -389,4 +435,49 @@ public void setVersion(VersionIdentifier version, boolean hint) { } } + /** + * Sets the tool edition in the environment variable configuration file. + * + * @param edition the edition to set. + */ + public void setEdition(String edition) { + + if ((edition == null) || edition.isBlank()) { + throw new IllegalStateException("Edition has to be specified!"); + } + + if (!Files.exists(this.context.getUrls().getEdition(getName(), edition).getPath())) { + this.context.warning("Edition {} seems to be invalid", edition); + + } + setEdition(edition, true); + } + + /** + * Sets the tool edition in the environment variable configuration file. + * + * @param edition the edition to set + * @param hint - {@code true} to print the installation hint, {@code false} otherwise. + */ + public void setEdition(String edition, boolean hint) { + + EnvironmentVariables variables = this.context.getVariables(); + EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS); + String name = EnvironmentVariables.getToolEditionVariable(this.tool); + settingsVariables.set(name, edition, false); + settingsVariables.save(); + + this.context.info("{}={} has been set in {}", name, edition, settingsVariables.getSource()); + EnvironmentVariables declaringVariables = variables.findVariable(name); + if ((declaringVariables != null) && (declaringVariables != settingsVariables)) { + this.context.warning( + "The variable {} is overridden in {}. Please remove the overridden declaration in order to make the change affect.", + name, declaringVariables.getSource()); + } + if (hint) { + this.context.info("To install that edition call the following command:"); + this.context.info("ide install {}", this.tool); + } + } + } diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/UrlMetadata.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/UrlMetadata.java index 1597c7ec2..aa324915d 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/url/model/UrlMetadata.java +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/UrlMetadata.java @@ -1,12 +1,15 @@ package com.devonfw.tools.ide.url.model; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; +import java.util.stream.Stream; import com.devonfw.tools.ide.cli.CliException; import com.devonfw.tools.ide.context.IdeContext; @@ -52,6 +55,32 @@ public UrlEdition getEdition(String tool, String edition) { return urlEdition; } + /** + * @param tool the name of the {@link UrlTool}. + * @return the sorted {@link List} of {@link String editions} . + */ + public List getSortedEditions(String tool) { + + List list = new ArrayList<>(); + Path path; + try { + path = this.repository.getChild(tool).getPath(); + } catch (NullPointerException e) { + this.context.warning("Can't get sorted editions for tool {} because it does not exist in {}.", tool, + this.repository.getPath()); + return List.of(); + } + if (Files.isDirectory(path)) { + try (Stream childStream = Files.list(path)) { + childStream.forEach(c -> list.add(c.getFileName().toString())); + } catch (IOException e) { + throw new IllegalStateException("Failed to list children of directory " + path, e); + } + } + Collections.sort(list); + return Collections.unmodifiableList(list); + } + /** * @param tool the name of the {@link UrlTool}. * @param edition the name of the {@link UrlEdition}. diff --git a/cli/src/main/resources/nls/Ide.properties b/cli/src/main/resources/nls/Ide.properties index cbbc9a9b0..9287a234c 100644 --- a/cli/src/main/resources/nls/Ide.properties +++ b/cli/src/main/resources/nls/Ide.properties @@ -2,29 +2,33 @@ usage=Usage: values=Values: commandlets=Available commandlets: options=Options: +cmd-az=Tool commandlet for Azure CLI. +cmd-eclipse=Tool commandlet for Eclipse IDE. cmd---version=Print the version of IDEasy. -cmd-az=Tool commandlet for Azure CLI cmd-complete=Internal commandlet for bash auto-completion -cmd-eclipse=Tool commandlet for Eclipse (IDE) cmd-env=Print the environment variables to set and export. +cmd-get-edition=Get the edition of the selected tool. cmd-get-version=Get the version of the selected tool. -cmd-gh=Tool commandlet for Github CLI +cmd-gh=Tool commandlet for Github CLI. cmd-gradle=Tool commandlet for Gradle (Build-Tool) cmd-helm=Tool commandlet for Helm (Kubernetes Package Manager) cmd-help=Prints this help. cmd-install=Install the selected tool. cmd-java=Tool commandlet for Java (OpenJDK) -cmd-kotlinc=Tool commandlet for Kotlin -cmd-kotlincnative=Tool commandlet for Kotlin-Native -cmd-list-version=List the available versions of the selected tool. +cmd-kotlinc=Tool commandlet for Kotlin. +cmd-kotlincnative=Tool commandlet for Kotlin-Native. +cmd-list-editions=List the available editions of the selected tool. +cmd-list-versions=List the available versions of the selected tool. cmd-mvn=Tool commandlet for Maven (Build-Tool) cmd-node=Tool commandlet for Node.js (JavaScript runtime) cmd-oc=Tool commandlet for Openshift CLI (Kubernetes Management Tool) cmd-quarkus=Tool commandlet for Quarkus (Framework for cloud-native apps) +cmd-set-edition=Set the edition of the selected tool. cmd-set-version=Set the version of the selected tool. cmd-terraform=Tool commandlet for Terraform. cmd-vscode=Tool commandlet for Visual Studio Code (IDE) val-args=The commandline arguments to pass to the tool. +val-edition=The tool edition. val-tool=The tool commandlet to select. val-version=The tool version. val-set-version-version=The tool version to set. diff --git a/cli/src/main/resources/nls/Ide_de.properties b/cli/src/main/resources/nls/Ide_de.properties index cb895c7e6..bd36a7666 100644 --- a/cli/src/main/resources/nls/Ide_de.properties +++ b/cli/src/main/resources/nls/Ide_de.properties @@ -2,27 +2,31 @@ usage=Verwendung: values=Werte: commandlets=Verfügbare Kommandos: options=Optionen: +cmd-az=Werkzeug Kommando fuer Azure Kommandoschnittstelle. +cmd-eclipse=Werkzeug Kommando fuer Eclipse IDE. cmd---version=Gibt die Version von IDEasy aus. -cmd-az=Werkzeug Kommando für die Azure Kommandoschnittstelle. -cmd-eclipse=Werkzeug Kommando für Eclipse (IDE) cmd-env=Gibt die zu setztenden und exportierenden Umgebungsvariablen aus. +cmd-get-edition=Zeigt die Edition des selektierten Werkzeugs an. cmd-get-version=Zeigt die Version des selektierten Werkzeugs an. -cmd-gh=Werkzeug Kommando für die Github Kommandoschnittstelle +cmd-gh=Werkzeug Kommando für die Github Kommandoschnittstelle. cmd-helm=Werkzeug Kommando für Helm (Kubernetes Package Manager) cmd-help=Zeigt diese Hilfe an. cmd-install=Installiert das selektierte Werkzeug. cmd-java=Werkzeug Kommando für Java (OpenJDK) -cmd-kotlinc=Werkzeug Kommando für Kotlin -cmd-kotlincnative=Werkzeug Kommando für Kotlin-Native -cmd-list-version=Listet die verfügbaren Versionen des selektierten Werkzeugs auf. +cmd-kotlinc=Werkzeug Kommando für Kotlin. +cmd-kotlincnative=Werkzeug Kommando für Kotlin-Native. +cmd-list-editions=Listet die verfügbaren Editionen des selektierten Werkzeugs auf. +cmd-list-versions=Listet die verfügbaren Versionen des selektierten Werkzeugs auf. cmd-mvn=Werkzeug Kommando für Maven (Build-Werkzeug) cmd-node=Werkzeug Kommando für Node.js (JavaScript Laufzeitumgebung) cmd-oc=Werkzeug Kommando für Openshift CLI (Kubernetes Management Tool) cmd-quarkus=Werkzeug Kommando für Quarkus (Framework für Cloud-native Anwendungen) +cmd-set-edition=Setzt die Edition des selektierten Werkzeugs. cmd-set-version=Setzt die Version des selektierten Werkzeugs. cmd-terraform=Werkzeug Kommando für Terraform. cmd-vscode=Werkzeug Kommando für Visual Studio Code (IDE) val-args=Die Kommandozeilen-Argumente zur Übergabe an das Werkzeug. +val-edition=Die Werkzeug Edition. val-tool=Das zu selektierende Werkzeug Kommando. val-version=Die Werkzeug Version. val-set-version-version=Die zu setztende Werkzeug Version. diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java new file mode 100644 index 000000000..d22297cdf --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java @@ -0,0 +1,69 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.cli.CliException; +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.log.IdeLogLevel; +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; +import java.util.List; + +/** Integration test of {@link EditionGetCommandlet}. */ + +public class EditionGetCommandletTest extends AbstractIdeContextTest { + + /** Test of {@link VersionGetCommandlet} run. */ + @Test + public void testEditionGetCommandletRun() { + + // arrange + String path = "workspaces/foo-test/my-git-repo"; + String tool = "az"; + IdeTestContext context = newContext("basic", path, true); + mockInstallTool(context, tool); + EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class); + + // act + editionGet.tool.setValueAsString(tool, context); + editionGet.run(); + + // assert + List logs = context.level(IdeLogLevel.INFO).getMessages(); + assertThat(logs).contains("testEdition"); + } + + /** + * Mocks the installation of a tool, since getEdition depends on symlinks which are not distributed with git + * + * @param context the {@link IdeContext} to use. + * @param tool the tool to mock install. + */ + private static void mockInstallTool(IdeTestContext context, String tool) { + + Path pathToInstallationOfDummyTool = context.getSoftwareRepositoryPath() + .resolve(context.getDefaultToolRepository().getId()).resolve(tool).resolve("testEdition/testVersion"); + Path pathToLinkedSoftware = context.getSoftwarePath().resolve(tool); + context.getFileAccess().symlink(pathToInstallationOfDummyTool, pathToLinkedSoftware); + } + + /** Test of {@link VersionGetCommandlet} run, when Installed Version is null. */ + @Test + public void testVersionGetCommandletRunThrowsCliException() { + + // arrange + String path = "workspaces/foo-test/my-git-repo"; + IdeContext context = newContext("basic", path, false); + EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class); + editionGet.tool.setValueAsString("java", context); + // act + try { + editionGet.run(); + failBecauseExceptionWasNotThrown(CliException.class); + } catch (CliException e) { + // assert + assertThat(e).hasMessageContaining("Tool java is not installed!"); + } + } +} diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java new file mode 100644 index 000000000..16bde2315 --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java @@ -0,0 +1,28 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.log.IdeLogLevel; +import org.junit.jupiter.api.Test; + +/** Integration test of {@link EditionListCommandlet}. */ +public class EditionListCommandletTest extends AbstractIdeContextTest { + + /** Test of {@link EditionListCommandlet} run. */ + @Test + public void testEditionListCommandletRun() { + + // arrange + String path = "workspaces/foo-test/my-git-repo"; + IdeTestContext context = newContext("basic", path, false); + EditionListCommandlet editionList = context.getCommandletManager().getCommandlet(EditionListCommandlet.class); + editionList.tool.setValueAsString("mvn", context); + + // act + editionList.run(); + + // assert + assertLogMessage(context, IdeLogLevel.INFO, "mvn"); + assertLogMessage(context, IdeLogLevel.INFO, "secondMvnEdition"); + } +} \ No newline at end of file diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java new file mode 100644 index 000000000..bc70f23ad --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java @@ -0,0 +1,58 @@ +package com.devonfw.tools.ide.commandlet; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.log.IdeLogLevel; +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; +import java.util.List; + +/** Integration test of {@link EditionSetCommandlet}. */ +public class EditionSetCommandletTest extends AbstractIdeContextTest { + + /** Test of {@link VersionSetCommandlet} run. */ + @Test + public void testEditionSetCommandletRun() { + + // arrange + String path = "workspaces/foo-test/my-git-repo"; + IdeContext context = newContext("basic", path, true); + EditionSetCommandlet editionSet = context.getCommandletManager().getCommandlet(EditionSetCommandlet.class); + editionSet.tool.setValueAsString("mvn", context); + editionSet.edition.setValueAsString("setEdition", context); + + // act + editionSet.run(); + + // assert + List logs = ((IdeTestContext) context).level(IdeLogLevel.WARNING).getMessages(); + assertThat(logs).containsExactly("Edition setEdition seems to be invalid"); + Path settingsIdeProperties = context.getSettingsPath().resolve("ide.properties"); + assertThat(settingsIdeProperties).hasContent(""" + #******************************************************************************** + # This file contains project specific environment variables + #******************************************************************************** + + JAVA_VERSION=17* + MVN_VERSION=3.9.* + ECLIPSE_VERSION=2023-03 + INTELLIJ_EDITION=ultimate + + IDE_TOOLS=mvn,eclipse + + BAR=bar-${SOME} + + TEST_ARGS1=${TEST_ARGS1} settings1 + TEST_ARGS4=${TEST_ARGS4} settings4 + TEST_ARGS5=${TEST_ARGS5} settings5 + TEST_ARGS6=${TEST_ARGS6} settings6 + TEST_ARGS7=${TEST_ARGS7} settings7 + TEST_ARGS8=settings8 + TEST_ARGS9=settings9 + TEST_ARGSb=${TEST_ARGS10} settingsb ${TEST_ARGSa} ${TEST_ARGSb} + TEST_ARGSc=${TEST_ARGSc} settingsc + MVN_EDITION=setEdition"""); + } +} \ No newline at end of file diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java index c03c68eb8..ffd46dc38 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java @@ -17,7 +17,7 @@ public class VersionGetCommandletTest extends AbstractIdeContextTest { * Test of {@link VersionGetCommandlet} run, when Installed Version is null. */ @Test - public void testVersionGetCommandletRunThrowsCliExeption() { + public void testVersionGetCommandletRunThrowsCliException() { // arrange String path = "workspaces/foo-test/my-git-repo"; diff --git a/cli/src/test/resources/ide-projects/_ide/software/default/az/testEdition/testVersion/.ide.software.version b/cli/src/test/resources/ide-projects/_ide/software/default/az/testEdition/testVersion/.ide.software.version new file mode 100644 index 000000000..9929d3a87 --- /dev/null +++ b/cli/src/test/resources/ide-projects/_ide/software/default/az/testEdition/testVersion/.ide.software.version @@ -0,0 +1 @@ +testVersion \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/_ide/urls/mvn/secondMvnEdition/.gitkeep b/cli/src/test/resources/ide-projects/_ide/urls/mvn/secondMvnEdition/.gitkeep new file mode 100644 index 000000000..e69de29bb