Skip to content

Commit

Permalink
Merge branch 'main' into 101-implement-create-commandlet
Browse files Browse the repository at this point in the history
  • Loading branch information
salimbouch authored Feb 15, 2024
2 parents ea4b410 + 3a77034 commit b911a22
Show file tree
Hide file tree
Showing 95 changed files with 1,503 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Map;
import java.util.Objects;

import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.aws.Aws;
import com.devonfw.tools.ide.tool.az.Azure;
import com.devonfw.tools.ide.tool.cobigen.Cobigen;
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
import com.devonfw.tools.ide.tool.gh.Gh;
import com.devonfw.tools.ide.tool.gradle.Gradle;
import com.devonfw.tools.ide.tool.helm.Helm;
import com.devonfw.tools.ide.tool.java.Java;
import com.devonfw.tools.ide.tool.jmc.Jmc;
import com.devonfw.tools.ide.tool.kotlinc.Kotlinc;
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
import com.devonfw.tools.ide.tool.mvn.Mvn;
Expand All @@ -25,7 +27,6 @@
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
import com.devonfw.tools.ide.tool.terraform.Terraform;
import com.devonfw.tools.ide.tool.vscode.Vscode;
import com.devonfw.tools.ide.tool.cobigen.Cobigen;

/**
* Implementation of {@link CommandletManager}.
Expand Down Expand Up @@ -60,6 +61,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 RepositoryCommandlet(context));
add(new UpdateCommandlet(context));
Expand All @@ -81,6 +85,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Azure(context));
add(new Aws(context));
add(new Cobigen(context));
add(new Jmc(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.tools.ide.commandlet;

import java.util.Collections;
import java.util.List;

import com.devonfw.tools.ide.cli.CliArguments;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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;
import com.devonfw.tools.ide.version.VersionIdentifier;

/**
* 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) {
this.context.info("The configured edition for tool {} is {}", commandlet.getName(), commandlet.getEdition());
this.context.info("To install that edition call the following command:");
this.context.info("ide install {}", commandlet.getName());
return;
}
String installedEdition = commandlet.getInstalledEdition();
this.context.info(installedEdition);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

import com.devonfw.tools.ide.cli.CliArgument;
import com.devonfw.tools.ide.cli.CliArguments;
import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.completion.IdeCompleter;
import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.BooleanProperty;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;

Expand Down Expand Up @@ -166,8 +164,7 @@ private boolean apply(CliArgument argument, Commandlet commandlet) {
}
currentProperty = valueIterator.next();
this.context.trace("Next value candidate is {}", currentProperty);
if (currentProperty instanceof KeywordProperty) {
KeywordProperty keyword = (KeywordProperty) currentProperty;
if (currentProperty instanceof KeywordProperty keyword) {
if (keyword.matches(arg)) {
keyword.setValue(Boolean.TRUE);
this.context.trace("Keyword matched");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -30,7 +29,7 @@ public VersionListCommandlet(IdeContext context) {
@Override
public String getName() {

return "list-version";
return "list-versions";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.devonfw.tools.ide.commandlet;

import java.util.List;
import java.util.stream.IntStream;

import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
import com.devonfw.tools.ide.context.IdeContext;
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;
import com.devonfw.tools.ide.version.VersionSegment;

/**
* An internal {@link Commandlet} to set a tool version.
Expand Down
11 changes: 8 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -26,7 +25,7 @@ public class SystemPath {
private final Map<String, Path> tool2pathMap;

private final List<Path> paths;

private final IdeContext context;

private static final List<String> EXTENSION_PRIORITY = List.of(".exe", ".cmd", ".bat", ".msi", ".ps1", "");
Expand Down Expand Up @@ -61,7 +60,7 @@ public SystemPath(String envPath, Path softwarePath, char pathSeparator, IdeCont
this.paths = new ArrayList<>();
String[] envPaths = envPath.split(Character.toString(pathSeparator));
for (String segment : envPaths) {
Path path = Paths.get(segment);
Path path = Path.of(segment);
String tool = getTool(path, softwarePath);
if (tool == null) {
this.paths.add(path);
Expand Down Expand Up @@ -129,7 +128,13 @@ private Path findBinaryInOrder(Path path, String tool) {
return null;
}

/**
* @param toolPath the {@link Path} to the tool installation.
* @return the {@link Path} to the binary executable of the tool. E.g. is "software/mvn" is given
* "software/mvn/bin/mvn" could be returned.
*/
public Path findBinary(Path toolPath) {

Path parent = toolPath.getParent();
String fileName = toolPath.getFileName().toString();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.devonfw.tools.ide.completion;

import com.devonfw.tools.ide.version.VersionSegment;

/**
* Candidate for auto-completion.
*
Expand All @@ -13,6 +11,6 @@ public record CompletionCandidate(String text, String description) implements Co
@Override
public int compareTo(CompletionCandidate o) {

return text.compareTo(o.text);
return this.text.compareTo(o.text);
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
package com.devonfw.tools.ide.completion;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.devonfw.tools.ide.cli.CliArguments;
import com.devonfw.tools.ide.completion.CompletionCandidate;
import com.devonfw.tools.ide.context.AbstractIdeContext;
import org.jline.reader.Candidate;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.ParsedLine;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.NullCompleter;
import org.jline.utils.AttributedString;

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.commandlet.HelpCommandlet;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.Property;
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;

import com.devonfw.tools.ide.cli.CliArguments;
import com.devonfw.tools.ide.context.AbstractIdeContext;

/**
* Implements the {@link Completer} for jline3 autocompletion. Inspired by picocli
Expand Down
Loading

0 comments on commit b911a22

Please sign in to comment.