Skip to content

Commit

Permalink
#254: fix bash path (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Mar 21, 2024
1 parent 5e283b3 commit c29606a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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());
}
Expand Down
182 changes: 91 additions & 91 deletions cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java
Original file line number Diff line number Diff line change
@@ -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<VersionIdentifier> {

/**
* 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<VersionIdentifier> validator) {

super(name, required, alias, validator);
}

@Override
public Class<VersionIdentifier> 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<VersionIdentifier> {

/**
* 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<VersionIdentifier> validator) {

super(name, required, alias, validator);
}

@Override
public Class<VersionIdentifier> 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<VersionIdentifier> 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<CompletionCandidate> 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<VersionIdentifier> 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<CompletionCandidate> 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);
}
}
}
}
}
}

0 comments on commit c29606a

Please sign in to comment.