From 81027c629c3d0d4a208d246c1685805198f134cf Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Thu, 11 Jan 2024 18:40:16 +0100 Subject: [PATCH 01/11] #180: first steps towards editionSet and Get --- .../ide/commandlet/CommandletManagerImpl.java | 1 + .../ide/commandlet/EditionGetCommandlet.java | 51 +++++++++++++++++++ .../ide/commandlet/EditionSetCommandlet.java | 49 ++++++++++++++++++ .../devonfw/tools/ide/context/IdeContext.java | 3 ++ .../ide/environment/EnvironmentVariables.java | 9 ++++ .../tools/ide/property/EditionProperty.java | 43 ++++++++++++++++ .../tools/ide/tool/LocalToolCommandlet.java | 7 ++- .../tools/ide/tool/ToolCommandlet.java | 16 ++++++ cli/src/main/resources/nls/Ide.properties | 3 ++ cli/src/main/resources/nls/Ide_de.properties | 3 ++ 10 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java create mode 100644 cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java create mode 100644 cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java 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 089f909ba..772c133a7 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 @@ -58,6 +58,7 @@ private CommandletManagerImpl(IdeContext context) { add(new VersionSetCommandlet(context)); add(new VersionGetCommandlet(context)); add(new VersionListCommandlet(context)); + add(new EditionSetCommandlet(context)); add(new Gh(context)); add(new Helm(context)); add(new Java(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..ebbc74818 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java @@ -0,0 +1,51 @@ +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; + +/** + * An internal {@link Commandlet} to set a tool version. + * + * @see ToolCommandlet#setVersion(VersionIdentifier, boolean) + */ +public class EditionGetCommandlet extends Commandlet { + + /** The tool to get the version 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() { + + // i dont want to get the set edition but from the tool which is installed. + +// this.context.getVariables().getToolEdition(this.tool.getName()); +// String edition = commandlet.getEdition(); +// VersionIdentifier installedVersion = commandlet.getInstalledVersion(); +// if (installedVersion == null) { +// throw new CliException("Tool " + commandlet.getName() + " is not installed!", 4); +// } +// this.context.info(installedVersion.toString()); + } + +} 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..d2aa86ca3 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java @@ -0,0 +1,49 @@ +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.property.VersionProperty; +import com.devonfw.tools.ide.tool.ToolCommandlet; +import com.devonfw.tools.ide.version.VersionIdentifier; + +/** + * An internal {@link Commandlet} to set a tool edition. + */ +public class EditionSetCommandlet extends Commandlet { + + /** The tool to set the version 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, true); + } + +} 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 0c8d0782f..732460194 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 @@ -106,6 +106,9 @@ public interface IdeContext extends IdeLogger { /** The file where the installed software version is written to as plain text. */ String FILE_LEGACY_SOFTWARE_VERSION = ".devon.software.version"; + /** The file where the installed software edition is written to as plain text. */ + String FILE_SOFTWARE_EDITION = ".ide.software.edition"; + /** The file extension for a {@link java.util.Properties} file. */ String EXT_PROPERTIES = ".properties"; 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..4268d5f54 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java @@ -0,0 +1,43 @@ +package com.devonfw.tools.ide.property; + +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) { + + return valueAsString; + } +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index 8505dead7..31937a53f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -80,7 +80,7 @@ protected boolean doInstall(boolean silent) { if (installedVersion == null) { this.context.success("Successfully installed {} in version {}", this.tool, resolvedVersion); } else { - this.context.success("Successfully installed {} in version {} replacing previous version {]", this.tool, + this.context.success("Successfully installed {} in version {} replacing previous version {}", this.tool, resolvedVersion, installedVersion); } postInstall(); @@ -130,10 +130,13 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool) .resolve(edition).resolve(resolvedVersion.toString()); Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION); + + // mattes why is sufficient that the version file exists for it to be: already installed FileAccess fileAccess = this.context.getFileAccess(); if (Files.isDirectory(toolPath)) { if (Files.exists(toolVersionFile)) { - this.context.debug("Version {} of tool {} is already installed at {}", resolvedVersion, + // mattes this was debug before + this.context.info("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), toolPath); return createToolInstallation(toolPath, resolvedVersion, toolVersionFile); } 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 f5ab8b3be..adb8c2d84 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 @@ -388,4 +388,20 @@ public void setVersion(VersionIdentifier version, boolean hint) { } } + /** + * TODO + * + * @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){ + + //TODO if edition is set to something then check if the current set version exists also for this edition + EnvironmentVariables variables = this.context.getVariables(); + EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS); + String name = EnvironmentVariables.getToolEditionVariable(this.tool); + settingsVariables.set(name, edition, false); + settingsVariables.save(); + } + } diff --git a/cli/src/main/resources/nls/Ide.properties b/cli/src/main/resources/nls/Ide.properties index 7f1344f9d..1d522b9d0 100644 --- a/cli/src/main/resources/nls/Ide.properties +++ b/cli/src/main/resources/nls/Ide.properties @@ -3,6 +3,7 @@ values=Values: commandlets=Available commandlets: options=Options: cmd-az=Tool commandlet for Azure CLI. +cmd-eclipse=Tool commandlet for Eclipse IDE. cmd-env=Print the environment variables to set and export. cmd-get-version=Get the version of the selected tool. cmd-gh=Tool commandlet for Github CLI. @@ -18,10 +19,12 @@ 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 37815d7a1..182c2d1f6 100644 --- a/cli/src/main/resources/nls/Ide_de.properties +++ b/cli/src/main/resources/nls/Ide_de.properties @@ -3,6 +3,7 @@ values=Werte: commandlets=Verfügbare Kommandos: options=Optionen: cmd-az=Werkzeug Kommando fuer Azure Kommandoschnittstelle. +cmd-eclipse=Werkzeug Kommando fuer Eclipse IDE. cmd-env=Gibt die zu setztenden und exportierenden Umgebungsvariablen aus. cmd-get-version=Zeigt die Version des selektierten Werkzeugs an. cmd-gh=Werkzeug Kommando für die Github Kommandoschnittstelle. @@ -17,10 +18,12 @@ 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. From 13f3da2d58a4a6323222280e7783dba26f2c2ff5 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 12 Jan 2024 17:50:03 +0100 Subject: [PATCH 02/11] #180: implemented edition get set and list commandlet --- .../ide/commandlet/CommandletManagerImpl.java | 2 + .../ide/commandlet/EditionGetCommandlet.java | 34 +++++---- .../ide/commandlet/EditionListCommandlet.java | 42 +++++++++++ .../ide/commandlet/EditionSetCommandlet.java | 6 +- .../ide/commandlet/VersionGetCommandlet.java | 4 +- .../ide/commandlet/VersionListCommandlet.java | 7 +- .../devonfw/tools/ide/context/IdeContext.java | 3 - .../tools/ide/tool/LocalToolCommandlet.java | 6 +- .../tools/ide/tool/ToolCommandlet.java | 69 ++++++++++++++++++- .../tools/ide/url/model/UrlMetadata.java | 24 ++++++- 10 files changed, 167 insertions(+), 30 deletions(-) create mode 100644 cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionListCommandlet.java 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 772c133a7..5cbd657c3 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 @@ -58,7 +58,9 @@ private 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 Gh(context)); add(new Helm(context)); add(new Java(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 index ebbc74818..7f8c9c6b3 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java @@ -7,13 +7,13 @@ import com.devonfw.tools.ide.version.VersionIdentifier; /** - * An internal {@link Commandlet} to set a tool version. + * An internal {@link Commandlet} to get the installed edition for a tool. * - * @see ToolCommandlet#setVersion(VersionIdentifier, boolean) + * @see ToolCommandlet#getInstalledEdition() */ public class EditionGetCommandlet extends Commandlet { - /** The tool to get the version of. */ + /** The tool to get the edition of. */ public final ToolProperty tool; /** @@ -37,15 +37,25 @@ public String getName() { @Override public void run() { - // i dont want to get the set edition but from the tool which is installed. - -// this.context.getVariables().getToolEdition(this.tool.getName()); -// String edition = commandlet.getEdition(); -// VersionIdentifier installedVersion = commandlet.getInstalledVersion(); -// if (installedVersion == null) { -// throw new CliException("Tool " + commandlet.getName() + " is not installed!", 4); -// } -// this.context.info(installedVersion.toString()); + ToolCommandlet commandlet = this.tool.getValue(); + VersionIdentifier installedVersion = commandlet.getInstalledVersion(); + if (installedVersion == null) { + throw new CliException("Tool " + commandlet.getName() + " is not installed!", 4); + } + + String installedEdition = commandlet.getInstalledEdition(); + + if (installedEdition == null) { + this.context.warning("Couldn't get edition of tool {}.", getName()); + String configuredEdition = this.context.getVariables().getToolEdition(getName()); + if (configuredEdition == null) { + this.context.info("No edition is configured for tool {}.", getName()); + } else { + this.context.info("Configured edition for tool {} is {}.", getName(), configuredEdition); + } + } else { + this.context.info(installedEdition); + } } } 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 index d2aa86ca3..ee851d040 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionSetCommandlet.java @@ -3,16 +3,14 @@ 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.property.VersionProperty; import com.devonfw.tools.ide.tool.ToolCommandlet; -import com.devonfw.tools.ide.version.VersionIdentifier; /** * An internal {@link Commandlet} to set a tool edition. */ public class EditionSetCommandlet extends Commandlet { - /** The tool to set the version of. */ + /** The tool to set the edition of. */ public final ToolProperty tool; /** The edition to set. */ @@ -43,7 +41,7 @@ public void run() { ToolCommandlet commandlet = this.tool.getValue(); String edition = this.edition.getValue(); - commandlet.setEdition(edition, true); + 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 bfbebee1c..559ce7728 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 @@ -7,9 +7,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/context/IdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java index 732460194..0c8d0782f 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 @@ -106,9 +106,6 @@ public interface IdeContext extends IdeLogger { /** The file where the installed software version is written to as plain text. */ String FILE_LEGACY_SOFTWARE_VERSION = ".devon.software.version"; - /** The file where the installed software edition is written to as plain text. */ - String FILE_SOFTWARE_EDITION = ".ide.software.edition"; - /** The file extension for a {@link java.util.Properties} file. */ String EXT_PROPERTIES = ".properties"; diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index 31937a53f..c11c959d2 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -32,7 +32,6 @@ public LocalToolCommandlet(IdeContext context, String tool, Set tags) { super(context, tool, tags); } - /** * @return the {@link Path} where the tool is located (installed). */ @@ -66,7 +65,9 @@ protected boolean doInstall(boolean silent) { // check if we already have this version installed (linked) locally in IDE_HOME/software VersionIdentifier installedVersion = getInstalledVersion(); VersionIdentifier resolvedVersion = installation.resolvedVersion(); - if (isInstalledVersion(resolvedVersion, installedVersion, silent)) { + // check if we already have this edition installed (linked) locally in IDE_HOME/software + String installedEdition = getInstalledEdition(); + if (isInstalledVersion(resolvedVersion, installedVersion, silent) && installedEdition.equals(getEdition())) { return false; } // we need to link the version or update the link. @@ -178,6 +179,7 @@ private boolean isInstalledVersion(VersionIdentifier expectedVersion, VersionIde if (silent) { level = IdeLogLevel.DEBUG; } + // TODO this prints twice since installInRepo also prints this message this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition()); return true; 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 adb8c2d84..f623cd89a 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 @@ -329,6 +329,47 @@ 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(); + return edition; + } catch (IOException e) { + this.context.debug("When calling getInstalledEdition() for tool " + getName() + + " calling toRealPath().getParent() on " + toolPath + " failed. Returning null."); + return null; + } + + } + + /** + * 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. */ @@ -388,20 +429,44 @@ public void setVersion(VersionIdentifier version, boolean hint) { } } + 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); + } + /** * TODO * * @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){ + public void setEdition(String edition, boolean hint) { - //TODO if edition is set to something then check if the current set version exists also for this edition 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..5125cdbdf 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,25 @@ 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 = this.repository.getChild(tool).getPath(); + 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}. From 2a7a3b8423e5516c0afde3b83b6f338ddcb8fc46 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 12 Jan 2024 18:04:59 +0100 Subject: [PATCH 03/11] #180: some clean up --- .../tools/ide/commandlet/EditionGetCommandlet.java | 8 ++------ .../com/devonfw/tools/ide/tool/LocalToolCommandlet.java | 3 --- 2 files changed, 2 insertions(+), 9 deletions(-) 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 index 7f8c9c6b3..c75d35f35 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java @@ -46,13 +46,9 @@ public void run() { String installedEdition = commandlet.getInstalledEdition(); if (installedEdition == null) { - this.context.warning("Couldn't get edition of tool {}.", getName()); + this.context.warning("Couldn't get edition of installed tool {}.", getName()); String configuredEdition = this.context.getVariables().getToolEdition(getName()); - if (configuredEdition == null) { - this.context.info("No edition is configured for tool {}.", getName()); - } else { - this.context.info("Configured edition for tool {} is {}.", getName(), configuredEdition); - } + this.context.info("Configured edition for tool {} is {}.", getName(), configuredEdition); } else { this.context.info(installedEdition); } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index c11c959d2..b5a045bfc 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -131,12 +131,9 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition, Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool) .resolve(edition).resolve(resolvedVersion.toString()); Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION); - - // mattes why is sufficient that the version file exists for it to be: already installed FileAccess fileAccess = this.context.getFileAccess(); if (Files.isDirectory(toolPath)) { if (Files.exists(toolVersionFile)) { - // mattes this was debug before this.context.info("Version {} of tool {} is already installed at {}", resolvedVersion, getToolWithEdition(this.tool, edition), toolPath); return createToolInstallation(toolPath, resolvedVersion, toolVersionFile); From 910ba25f151a6ee94854b086c36187614fa40b1e Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Mon, 15 Jan 2024 10:46:44 +0100 Subject: [PATCH 04/11] #180: added javadoc --- .../main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f623cd89a..5940f7d56 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 @@ -443,7 +443,7 @@ public void setEdition(String edition) { } /** - * TODO + * 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. From 5b36863c7c3c02120ab33370b4e776f369951851 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Mon, 15 Jan 2024 14:28:26 +0100 Subject: [PATCH 05/11] #180: added missing javadoc --- .../main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java | 5 +++++ 1 file changed, 5 insertions(+) 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 5940f7d56..fee1a75f0 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 @@ -429,6 +429,11 @@ 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()) { From f2a7223ab929a242b149035771c0e649b57c5ac1 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Tue, 16 Jan 2024 12:13:24 +0100 Subject: [PATCH 06/11] #180: implemented change requests --- .../ide/commandlet/EditionGetCommandlet.java | 17 +++++++++-------- .../tools/ide/process/ProcessResult.java | 3 +++ .../tools/ide/tool/LocalToolCommandlet.java | 1 - .../devonfw/tools/ide/tool/ToolCommandlet.java | 11 ++++++++--- cli/src/main/resources/nls/Ide.properties | 4 +++- cli/src/main/resources/nls/Ide_de.properties | 4 +++- 6 files changed, 26 insertions(+), 14 deletions(-) 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 index c75d35f35..f593d473f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java @@ -6,6 +6,8 @@ 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. * @@ -40,17 +42,16 @@ public void run() { ToolCommandlet commandlet = this.tool.getValue(); VersionIdentifier installedVersion = commandlet.getInstalledVersion(); if (installedVersion == null) { - throw new CliException("Tool " + commandlet.getName() + " is not installed!", 4); + throw new CliException("Tool " + commandlet.getName() + " is not installed!", TOOL_NOT_INSTALLED); } - String installedEdition = commandlet.getInstalledEdition(); - - if (installedEdition == null) { - this.context.warning("Couldn't get edition of installed tool {}.", getName()); - String configuredEdition = this.context.getVariables().getToolEdition(getName()); - this.context.info("Configured edition for tool {} is {}.", getName(), configuredEdition); - } else { + 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/process/ProcessResult.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java index e97fdfe59..e202ac917 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java @@ -12,6 +12,9 @@ public interface ProcessResult { /** Exit code for success. */ int SUCCESS = 0; + /** Exit code if the tool is not installed */ + int TOOL_NOT_INSTALLED = 4; + /** * @return the exit code. Will be {@link #SUCCESS} on successful completion of the {@link Process}. */ diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index b5a045bfc..7c4c14c62 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -176,7 +176,6 @@ private boolean isInstalledVersion(VersionIdentifier expectedVersion, VersionIde if (silent) { level = IdeLogLevel.DEBUG; } - // TODO this prints twice since installInRepo also prints this message this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition()); return true; 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 fee1a75f0..e98de0906 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 @@ -350,11 +350,16 @@ public String getInstalledEdition(Path toolPath) { } 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) { - this.context.debug("When calling getInstalledEdition() for tool " + getName() - + " calling toRealPath().getParent() on " + toolPath + " failed. Returning null."); - return null; + 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); } } diff --git a/cli/src/main/resources/nls/Ide.properties b/cli/src/main/resources/nls/Ide.properties index 1d522b9d0..d370ef55a 100644 --- a/cli/src/main/resources/nls/Ide.properties +++ b/cli/src/main/resources/nls/Ide.properties @@ -5,6 +5,7 @@ options=Options: cmd-az=Tool commandlet for Azure CLI. 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-gradle=Tool commandlet for Gradle (Build-Tool) @@ -14,7 +15,8 @@ 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-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) diff --git a/cli/src/main/resources/nls/Ide_de.properties b/cli/src/main/resources/nls/Ide_de.properties index 182c2d1f6..ed25ea85f 100644 --- a/cli/src/main/resources/nls/Ide_de.properties +++ b/cli/src/main/resources/nls/Ide_de.properties @@ -5,6 +5,7 @@ options=Optionen: cmd-az=Werkzeug Kommando fuer Azure Kommandoschnittstelle. cmd-eclipse=Werkzeug Kommando fuer 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-helm=Werkzeug Kommando für Helm (Kubernetes Package Manager) @@ -13,7 +14,8 @@ 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-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) From d43ded2ef1bff4375b58bb599906491bdfd1261e Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 26 Jan 2024 13:03:31 +0100 Subject: [PATCH 07/11] #180: added tests --- .../tools/ide/url/model/UrlMetadata.java | 9 ++- .../commandlet/EditionGetCommandletTest.java | 69 +++++++++++++++++++ .../commandlet/EditionListCommandletTest.java | 28 ++++++++ .../commandlet/EditionSetCommandletTest.java | 58 ++++++++++++++++ .../commandlet/VersionGetCommandletTest.java | 2 +- 5 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java create mode 100644 cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java create mode 100644 cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java 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 5125cdbdf..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 @@ -62,7 +62,14 @@ public UrlEdition getEdition(String tool, String edition) { public List getSortedEditions(String tool) { List list = new ArrayList<>(); - Path path = this.repository.getChild(tool).getPath(); + 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())); 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..a6504a409 --- /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); + 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"); + // 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..aab72c895 --- /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"); + + // 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..231ded1b9 --- /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"); + editionSet.edition.setValueAsString("setEdition"); + + // 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 15d522adc..09e026c4d 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"; From 205268ea792076a3f88aab5e2c351fbe9c713e43 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 26 Jan 2024 13:15:54 +0100 Subject: [PATCH 08/11] #180: fixed bug --- .../java/com/devonfw/tools/ide/property/EditionProperty.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 index 4268d5f54..f2226254b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java +++ b/cli/src/main/java/com/devonfw/tools/ide/property/EditionProperty.java @@ -1,5 +1,7 @@ package com.devonfw.tools.ide.property; +import com.devonfw.tools.ide.context.IdeContext; + import java.util.function.Consumer; public class EditionProperty extends Property { @@ -36,7 +38,7 @@ public Class getValueType() { } @Override - public String parse(String valueAsString) { + public String parse(String valueAsString, IdeContext context) { return valueAsString; } From 9c341915c3daa209e507cfe2127ae9f30b14c08c Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 26 Jan 2024 13:19:57 +0100 Subject: [PATCH 09/11] #180: fixed bug after merge --- .../tools/ide/commandlet/EditionGetCommandletTest.java | 4 ++-- .../tools/ide/commandlet/EditionListCommandletTest.java | 2 +- .../tools/ide/commandlet/EditionSetCommandletTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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 index a6504a409..d22297cdf 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionGetCommandletTest.java @@ -26,7 +26,7 @@ public void testEditionGetCommandletRun() { EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class); // act - editionGet.tool.setValueAsString(tool); + editionGet.tool.setValueAsString(tool, context); editionGet.run(); // assert @@ -56,7 +56,7 @@ public void testVersionGetCommandletRunThrowsCliException() { 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"); + editionGet.tool.setValueAsString("java", context); // act try { editionGet.run(); 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 index aab72c895..16bde2315 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionListCommandletTest.java @@ -16,7 +16,7 @@ public void testEditionListCommandletRun() { 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"); + editionList.tool.setValueAsString("mvn", context); // act editionList.run(); 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 index 231ded1b9..bc70f23ad 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/EditionSetCommandletTest.java @@ -20,8 +20,8 @@ public void testEditionSetCommandletRun() { 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"); - editionSet.edition.setValueAsString("setEdition"); + editionSet.tool.setValueAsString("mvn", context); + editionSet.edition.setValueAsString("setEdition", context); // act editionSet.run(); From 36f75b59de03234e8a475c0dd52d9c8f602df4e8 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 26 Jan 2024 13:23:51 +0100 Subject: [PATCH 10/11] #180: added missing test resource file --- .../default/az/testEdition/testVersion/.ide.software.version | 1 + 1 file changed, 1 insertion(+) create mode 100644 cli/src/test/resources/ide-projects/_ide/software/default/az/testEdition/testVersion/.ide.software.version 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 From cadfd7a7716a8505d6e3411e8c357843bcf28e64 Mon Sep 17 00:00:00 2001 From: "CORP\\mmrzik" Date: Fri, 26 Jan 2024 13:30:37 +0100 Subject: [PATCH 11/11] #180: added empty file in dir to be able to add the dir to git --- .../ide-projects/_ide/urls/mvn/secondMvnEdition/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 cli/src/test/resources/ide-projects/_ide/urls/mvn/secondMvnEdition/.gitkeep 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