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 be5a5ee10..9260188d0 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 @@ -1,11 +1,5 @@ package com.devonfw.tools.ide.tool; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Set; - import com.devonfw.tools.ide.commandlet.Commandlet; import com.devonfw.tools.ide.common.Tag; import com.devonfw.tools.ide.common.Tags; @@ -19,6 +13,12 @@ import com.devonfw.tools.ide.property.StringListProperty; import com.devonfw.tools.ide.version.VersionIdentifier; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Set; + /** * {@link Commandlet} for a tool integrated into the IDE. */ @@ -39,8 +39,7 @@ public abstract class ToolCommandlet extends Commandlet implements Tags { * * @param context the {@link IdeContext}. * @param tool the {@link #getName() tool name}. - * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} - * method. + * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} method. */ public ToolCommandlet(IdeContext context, String tool, Set tags) { @@ -93,9 +92,8 @@ public void run() { * Ensures the tool is installed and then runs this tool with the given arguments. * * @param processMode see {@link ProcessMode} - * @param toolVersion the explicit version (pattern) to run. Typically {@code null} to ensure the configured version - * is installed and use that one. Otherwise, the specified version will be installed in the software repository - * without touching and IDE installation and used to run. + * @param toolVersion the explicit version (pattern) to run. Typically {@code null} to ensure the configured version is installed and use that one. Otherwise, + * the specified version will be installed in the software repository without touching and IDE installation and used to run. * @param args the command-line arguments to run the tool. */ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, String... args) { @@ -108,8 +106,7 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri } else { throw new UnsupportedOperationException("Not yet implemented!"); } - ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(binaryPath) - .addArgs(args); + ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(binaryPath).addArgs(args); pc.run(processMode); } @@ -133,8 +130,7 @@ public String getEdition() { } /** - * @return the {@link #getName() tool} with its {@link #getEdition() edition}. The edition will be omitted if same as - * tool. + * @return the {@link #getName() tool} with its {@link #getEdition() edition}. The edition will be omitted if same as tool. * @see #getToolWithEdition(String, String) */ protected final String getToolWithEdition() { @@ -145,8 +141,7 @@ protected final String getToolWithEdition() { /** * @param tool the tool name. * @param edition the edition. - * @return the {@link #getName() tool} with its {@link #getEdition() edition}. The edition will be omitted if same as - * tool. + * @return the {@link #getName() tool} with its {@link #getEdition() edition}. The edition will be omitted if same as tool. */ protected final static String getToolWithEdition(String tool, String edition) { @@ -165,11 +160,9 @@ public VersionIdentifier getConfiguredVersion() { } /** - * Method to be called for {@link #install(boolean)} from dependent - * {@link com.devonfw.tools.ide.commandlet.Commandlet}s. + * Method to be called for {@link #install(boolean)} from dependent {@link com.devonfw.tools.ide.commandlet.Commandlet}s. * - * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and - * nothing has changed. + * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and nothing has changed. */ public boolean install() { @@ -177,12 +170,10 @@ public boolean install() { } /** - * Performs the installation of the {@link #getName() tool} managed by this - * {@link com.devonfw.tools.ide.commandlet.Commandlet}. + * Performs the installation of the {@link #getName() tool} managed by this {@link com.devonfw.tools.ide.commandlet.Commandlet}. * * @param silent - {@code true} if called recursively to suppress verbose logging, {@code false} otherwise. - * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and - * nothing has changed. + * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and nothing has changed. */ public boolean install(boolean silent) { @@ -193,8 +184,7 @@ public boolean install(boolean silent) { * Installs or updates the managed {@link #getName() tool}. * * @param silent - {@code true} if called recursively to suppress verbose logging, {@code false} otherwise. - * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and - * nothing has changed. + * @return {@code true} if the tool was newly installed, {@code false} if the tool was already installed before and nothing has changed. */ protected abstract boolean doInstall(boolean silent); @@ -270,8 +260,8 @@ public String getInstalledEdition() { } /** - * @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. + * @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) { @@ -287,10 +277,8 @@ public String getInstalledEdition(Path toolPath) { } 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); + 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); } } @@ -342,9 +330,11 @@ public void setVersion(String version) { */ public void setVersion(VersionIdentifier version, boolean hint) { + String edition = getEdition(); + this.context.getUrls().getVersionFolder(tool, edition, version); // CliException is thrown if the version is not existing + EnvironmentVariables variables = this.context.getVariables(); EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS); - String edition = getEdition(); String name = EnvironmentVariables.getToolVersionVariable(this.tool); VersionIdentifier resolvedVersion = this.context.getUrls().getVersion(this.tool, edition, version); if (version.isPattern()) { @@ -355,9 +345,8 @@ public void setVersion(VersionIdentifier version, boolean hint) { this.context.info("{}={} has been set in {}", name, version, 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()); + 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 version call the following command:"); @@ -400,9 +389,8 @@ public void setEdition(String edition, boolean hint) { 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()); + 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:"); 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 ab2f90369..14d64cad2 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,5 @@ package com.devonfw.tools.ide.url.model; -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 com.devonfw.tools.ide.cli.CliException; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.url.model.folder.UrlEdition; @@ -15,6 +8,13 @@ import com.devonfw.tools.ide.url.model.folder.UrlVersion; import com.devonfw.tools.ide.version.VersionIdentifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Service to {@link #getEdition(String, String) load} an {@link UrlEdition} to get access to its versions. */ @@ -73,8 +73,7 @@ public List getSortedEditions(String tool) { /** * @param tool the name of the {@link UrlTool}. * @param edition the name of the {@link UrlEdition}. - * @return the {@link List} of {@link VersionIdentifier}s sorted descending so the latest version comes first and the - * oldest comes last. + * @return the {@link List} of {@link VersionIdentifier}s sorted descending so the latest version comes first and the oldest comes last. */ public List getSortedVersions(String tool, String edition) { @@ -98,8 +97,8 @@ private List computeSortedVersions(String tool, String editio /** * @param tool the name of the {@link UrlTool}. * @param edition the name of the {@link UrlEdition}. - * @param version the {@link VersionIdentifier} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a - * specific version or {@code null} for the latest version. + * @param version the {@link VersionIdentifier} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for the + * latest version. * @return the latest matching {@link VersionIdentifier} for the given {@code tool} and {@code edition}. */ public VersionIdentifier getVersion(String tool, String edition, VersionIdentifier version) { @@ -117,15 +116,16 @@ public VersionIdentifier getVersion(String tool, String edition, VersionIdentifi return vi; } } - throw new CliException("Could not find any version matching '" + version + "' for tool '" + tool + "' - potentially there are " + versions.size() - + " version(s) available in " + getEdition(tool, edition).getPath() + " but none matched!"); + throw new CliException( + "Could not find any version matching '" + version + "' for tool '" + tool + "' - potentially there are " + versions.size() + " version(s) available in " + + getEdition(tool, edition).getPath() + " but none matched!"); } /** * @param tool the name of the {@link UrlTool}. * @param edition the name of the {@link UrlEdition}. - * @param version the {@link VersionIdentifier} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a - * specific version or {@code null} for the latest version. + * @param version the {@link VersionIdentifier} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for the + * latest version. * @return the latest matching {@link UrlVersion} for the given {@code tool} and {@code edition}. */ public UrlVersion getVersionFolder(String tool, String edition, VersionIdentifier version) { @@ -133,7 +133,7 @@ public UrlVersion getVersionFolder(String tool, String edition, VersionIdentifie VersionIdentifier resolvedVersion = getVersion(tool, edition, version); UrlVersion urlVersion = getEdition(tool, edition).getChild(resolvedVersion.toString()); if (urlVersion == null) { - throw new IllegalArgumentException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + "."); + throw new CliException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + "."); } return urlVersion; }