From c29606aad6c151b78eca0a9f098e9924130c71b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Thu, 21 Mar 2024 19:32:44 +0100 Subject: [PATCH] #254: fix bash path (#259) --- .../ide/commandlet/EnvironmentCommandlet.java | 11 +- .../tools/ide/property/VersionProperty.java | 182 +++++++++--------- 2 files changed, 99 insertions(+), 94 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java index 5496067fc..b1bf15c2a 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java @@ -1,11 +1,12 @@ package com.devonfw.tools.ide.commandlet; -import java.util.Collection; - import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.environment.VariableLine; import com.devonfw.tools.ide.os.WindowsPathSyntax; import com.devonfw.tools.ide.property.FlagProperty; +import com.devonfw.tools.ide.variable.IdeVariables; + +import java.util.Collection; /** * {@link Commandlet} to print the environment variables. @@ -47,7 +48,11 @@ public void run() { if (this.context.getSystemInfo().isWindows()) { line = normalizeWindowsValue(line); } - String lineValue = "\"" + line.getValue() + "\""; + String lineValue = line.getValue(); + if (IdeVariables.PATH.getName().equals(line.getName())) { + lineValue = this.context.getPath().toString(this.bash.isTrue()); + } + lineValue = "\"" + lineValue + "\""; line = line.withValue(lineValue); this.context.info(line.toString()); } diff --git a/cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java b/cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java index 5ceb204aa..a93d2942f 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java +++ b/cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java @@ -1,98 +1,98 @@ -package com.devonfw.tools.ide.property; - +package com.devonfw.tools.ide.property; + import java.util.Collections; import java.util.List; import java.util.function.Consumer; import java.util.stream.IntStream; -import com.devonfw.tools.ide.commandlet.Commandlet; -import com.devonfw.tools.ide.completion.CompletionCandidate; -import com.devonfw.tools.ide.completion.CompletionCandidateCollector; -import com.devonfw.tools.ide.context.IdeContext; -import com.devonfw.tools.ide.tool.ToolCommandlet; -import com.devonfw.tools.ide.version.VersionIdentifier; -import com.devonfw.tools.ide.version.VersionSegment; - -/** - * {@link Property} for {@link VersionIdentifier} as {@link #getValueType() value type}. - */ -public class VersionProperty 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 VersionProperty(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 VersionProperty(String name, boolean required, String alias, Consumer validator) { - - super(name, required, alias, validator); - } - - @Override - public Class getValueType() { - - return VersionIdentifier.class; - } - - @Override - public VersionIdentifier parse(String valueAsString, IdeContext context) { - - return VersionIdentifier.of(valueAsString); - } - - @Override - protected void completeValue(String arg, IdeContext context, Commandlet commandlet, - CompletionCandidateCollector collector) { - - ToolCommandlet tool = commandlet.getToolForVersionCompletion(); - if (tool != null) { - completeVersion(VersionIdentifier.of(arg), tool, context, commandlet, collector); - } - } +import com.devonfw.tools.ide.commandlet.Commandlet; +import com.devonfw.tools.ide.completion.CompletionCandidate; +import com.devonfw.tools.ide.completion.CompletionCandidateCollector; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.tool.ToolCommandlet; +import com.devonfw.tools.ide.version.VersionIdentifier; +import com.devonfw.tools.ide.version.VersionSegment; + +/** + * {@link Property} for {@link VersionIdentifier} as {@link #getValueType() value type}. + */ +public class VersionProperty 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 VersionProperty(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 VersionProperty(String name, boolean required, String alias, Consumer validator) { + + super(name, required, alias, validator); + } + + @Override + public Class getValueType() { + + return VersionIdentifier.class; + } + + @Override + public VersionIdentifier parse(String valueAsString, IdeContext context) { + + return VersionIdentifier.of(valueAsString); + } + + @Override + protected void completeValue(String arg, IdeContext context, Commandlet commandlet, + CompletionCandidateCollector collector) { + + ToolCommandlet tool = commandlet.getToolForVersionCompletion(); + if (tool != null) { + completeVersion(VersionIdentifier.of(arg), tool, context, commandlet, collector); + } + } private void completeVersion(VersionIdentifier version2complete, ToolCommandlet tool, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) { - - collector.disableSorting(); - if (tool != null) { - String text; - if (version2complete == null) { - text = ""; - } else { - text = version2complete.toString(); - if (version2complete.isPattern()) { - collector.add(text, "Given version pattern.", this, commandlet); - return; - } - } - List versions = context.getUrls().getSortedVersions(tool.getName(), - tool.getEdition()); - int size = versions.size(); - String[] sorderCandidates = IntStream.rangeClosed(1, size).mapToObj(i -> versions.get(size - i).toString()) - .toArray(String[]::new); - collector.addAllMatches(text, sorderCandidates, this, commandlet); - List candidates = collector.getCandidates(); - Collections.reverse(candidates); - CompletionCandidate latest = collector.createCandidate(text + VersionSegment.PATTERN_MATCH_ANY_STABLE_VERSION, "Latest stable matching version", this, commandlet); - if (candidates.isEmpty()) { - candidates.add(latest); - } else { - candidates.add(1, latest); - } + + collector.disableSorting(); + if (tool != null) { + String text; + if (version2complete == null) { + text = ""; + } else { + text = version2complete.toString(); + if (version2complete.isPattern()) { + collector.add(text, "Given version pattern.", this, commandlet); + return; + } + } + List versions = context.getUrls().getSortedVersions(tool.getName(), tool.getEdition()); + int size = versions.size(); + String[] sortedCandidates = IntStream.rangeClosed(1, size).mapToObj(i -> versions.get(size - i).toString()) + .toArray(String[]::new); + collector.addAllMatches(text, sortedCandidates, this, commandlet); + List candidates = collector.getCandidates(); + Collections.reverse(candidates); + CompletionCandidate latest = collector.createCandidate(text + VersionSegment.PATTERN_MATCH_ANY_STABLE_VERSION, + "Latest stable matching version", this, commandlet); + if (candidates.isEmpty()) { + candidates.add(latest); + } else { + candidates.add(1, latest); + } collector.add(text + VersionSegment.PATTERN_MATCH_ANY_VERSION, "Latest matching version including unstable versions", this, commandlet); - } - } -} + } + } +}