Skip to content

Commit

Permalink
Merge branch 'main' into fix/6-git-pull-hangs
Browse files Browse the repository at this point in the history
# Conflicts:
#	cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java
  • Loading branch information
jan-vcapgemini committed Feb 15, 2024
2 parents cf77e70 + 3a77034 commit 0d5bb39
Show file tree
Hide file tree
Showing 67 changed files with 351 additions and 317 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
@@ -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
@@ -1,13 +1,10 @@
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;

import static com.devonfw.tools.ide.process.ProcessResult.TOOL_NOT_INSTALLED;

/**
* An internal {@link Commandlet} to get the installed edition for a tool.
*
Expand Down
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 @@ -7,7 +7,7 @@
/**
* An internal {@link Commandlet} to list versions for a tool.
*
* @see ToolCommandlet#listVersions())
* @see ToolCommandlet#listVersions()
*/
public class VersionListCommandlet extends Commandlet {

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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -138,7 +137,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
this.fileAccess = new FileAccessImpl(this);
String workspace = WORKSPACE_MAIN;
if (userDir == null) {
this.cwd = Paths.get(System.getProperty("user.dir"));
this.cwd = Path.of(System.getProperty("user.dir"));
} else {
this.cwd = userDir.toAbsolutePath();
}
Expand Down Expand Up @@ -181,7 +180,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
root = System.getenv("IDE_ROOT");
}
if (root != null) {
Path rootPath = Paths.get(root);
Path rootPath = Path.of(root);
if (Files.isDirectory(rootPath)) {
if (!ideRootPath.equals(rootPath)) {
warning(
Expand Down Expand Up @@ -222,12 +221,12 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
if (isTest()) {
// only for testing...
if (this.ideHome == null) {
this.userHome = Paths.get("/non-existing-user-home-for-testing");
this.userHome = Path.of("/non-existing-user-home-for-testing");
} else {
this.userHome = this.ideHome.resolve("home");
}
} else {
this.userHome = Paths.get(System.getProperty("user.home"));
this.userHome = Path.of(System.getProperty("user.home"));
}
this.userHomeIde = this.userHome.resolve(".ide");
this.downloadPath = this.userHome.resolve("Downloads/ide");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.devonfw.tools.ide.context;

import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import java.util.Scanner;

import com.devonfw.tools.ide.io.IdeProgressBar;
import com.devonfw.tools.ide.io.IdeProgressBarConsole;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.log.IdeSubLoggerOut;

import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;

/**
* Default implementation of {@link IdeContext} using the console.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.devonfw.tools.ide.environment;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Locale;

Expand Down Expand Up @@ -46,7 +45,7 @@ default Path getPath(String name) {
if (value == null) {
return null;
}
return Paths.get(value);
return Path.of(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
Expand Down Expand Up @@ -82,7 +81,7 @@ public void download(String url, Path target) {
} else if (url.startsWith("ftp") || url.startsWith("sftp")) {
throw new IllegalArgumentException("Unsupported download URL: " + url);
} else {
Path source = Paths.get(url);
Path source = Path.of(url);
if (isFile(source)) {
// network drive
copyFileWithProgressBar(source, target);
Expand Down Expand Up @@ -358,15 +357,15 @@ private Path adaptPath(Path source, Path targetLink, boolean relative) throws IO
if (relative) {
source = targetLink.getParent().relativize(source);
// to make relative links like this work: dir/link -> dir
source = (source.toString().isEmpty()) ? Paths.get(".") : source;
source = (source.toString().isEmpty()) ? Path.of(".") : source;
}
} else { // source is relative
if (relative) {
// even though the source is already relative, toRealPath should be called to transform paths like
// this ../d1/../d2 to ../d2
source = targetLink.getParent()
.relativize(targetLink.resolveSibling(source).toRealPath(LinkOption.NOFOLLOW_LINKS));
source = (source.toString().isEmpty()) ? Paths.get(".") : source;
source = (source.toString().isEmpty()) ? Path.of(".") : source;
} else { // !relative
try {
source = targetLink.resolveSibling(source).toRealPath(LinkOption.NOFOLLOW_LINKS);
Expand Down Expand Up @@ -532,7 +531,7 @@ private void unpack(Path file, Path targetDir, Function<InputStream, ArchiveInpu
permissionStr = generatePermissionString(tarMode);
}

Path entryName = Paths.get(entry.getName());
Path entryName = Path.of(entry.getName());
Path entryPath = targetDir.resolve(entryName).toAbsolutePath();
if (!entryPath.startsWith(targetDir)) {
throw new IOException("Preventing path traversal attack from " + entryName + " to " + entryPath);
Expand Down
24 changes: 9 additions & 15 deletions cli/src/main/java/com/devonfw/tools/ide/merge/JsonMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,16 @@ private JsonValue mergeAndResolve(JsonValue json, JsonValue mergeJson, Environme
if (mergeJson == null) {
status.updated = true; // JSON to merge does not exist and needs to be created
}
switch (json.getValueType()) {
case OBJECT:
return mergeAndResolveObject((JsonObject) json, (JsonObject) mergeJson, variables, status, src);
case ARRAY:
return mergeAndResolveArray((JsonArray) json, (JsonArray) mergeJson, variables, status, src);
case STRING:
return mergeAndResolveString((JsonString) json, (JsonString) mergeJson, variables, status, src);
case NUMBER:
case FALSE:
case TRUE:
case NULL:
return mergeAndResolveNativeType(json, mergeJson, variables, status);
default:
return switch (json.getValueType()) {
case OBJECT -> mergeAndResolveObject((JsonObject) json, (JsonObject) mergeJson, variables, status, src);
case ARRAY -> mergeAndResolveArray((JsonArray) json, (JsonArray) mergeJson, variables, status, src);
case STRING -> mergeAndResolveString((JsonString) json, (JsonString) mergeJson, variables, status, src);
case NUMBER, FALSE, TRUE, NULL -> mergeAndResolveNativeType(json, mergeJson, variables, status);
default -> {
this.context.error("Undefined JSON type {}", json.getClass());
return null;
}
yield null;
}
};
}
}

Expand Down
3 changes: 1 addition & 2 deletions cli/src/main/java/com/devonfw/tools/ide/merge/XmlMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ private void resolve(Element element, EnvironmentVariables variables, boolean in

for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Text) {
Text text = (Text) node;
if (node instanceof Text text) {
String value = text.getNodeValue();
String resolvedValue;
if (inverse) {
Expand Down
28 changes: 10 additions & 18 deletions cli/src/main/java/com/devonfw/tools/ide/os/WindowsPathSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ public String replaceDrive(String path, String drive) {
throw new IllegalArgumentException(path);
}
String restPath = path.substring(3);
switch (this) {
case WINDOWS:
restPath = restPath.replace('/', '\\');
break;
case MSYS:
restPath = restPath.replace('\\', '/');
break;
default:
throw new IllegalStateException(toString());
}
restPath = switch (this) {
case WINDOWS -> restPath.replace('/', '\\');
case MSYS -> restPath.replace('\\', '/');
default -> throw new IllegalStateException(toString());
};
return getRootPath(drive) + restPath;
}

Expand All @@ -85,14 +80,11 @@ public String getRootPath(String drive) {
if ((drive.length() != 1) || !isLowerLatinLetter(Character.toLowerCase(drive.charAt(0)))) {
throw new IllegalArgumentException(drive);
}
switch (this) {
case WINDOWS:
return drive.toUpperCase(Locale.ROOT) + ":\\";
case MSYS:
return "/" + drive.toLowerCase(Locale.ROOT) + "/";
default:
throw new IllegalStateException(toString());
}
return switch (this) {
case WINDOWS -> drive.toUpperCase(Locale.ROOT) + ":\\";
case MSYS -> "/" + drive.toLowerCase(Locale.ROOT) + "/";
default -> throw new IllegalStateException(toString());
};
}

}
Loading

0 comments on commit 0d5bb39

Please sign in to comment.