Skip to content

Commit c815ca3

Browse files
authored
improved code-style, added missing JavaDoc, code-cleanup (#198)
1 parent 410d834 commit c815ca3

File tree

66 files changed

+295
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+295
-321
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Map;
88
import java.util.Objects;
99

10-
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
1110
import com.devonfw.tools.ide.context.IdeContext;
1211
import com.devonfw.tools.ide.property.KeywordProperty;
1312
import com.devonfw.tools.ide.property.Property;

cli/src/main/java/com/devonfw/tools/ide/commandlet/CompleteCommandlet.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import java.util.Collections;
43
import java.util.List;
54

65
import com.devonfw.tools.ide.cli.CliArguments;

cli/src/main/java/com/devonfw/tools/ide/commandlet/EditionGetCommandlet.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import com.devonfw.tools.ide.cli.CliException;
43
import com.devonfw.tools.ide.context.IdeContext;
54
import com.devonfw.tools.ide.property.ToolProperty;
65
import com.devonfw.tools.ide.tool.ToolCommandlet;
76
import com.devonfw.tools.ide.version.VersionIdentifier;
87

9-
import static com.devonfw.tools.ide.process.ProcessResult.TOOL_NOT_INSTALLED;
10-
118
/**
129
* An internal {@link Commandlet} to get the installed edition for a tool.
1310
*

cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
import com.devonfw.tools.ide.cli.CliArgument;
1919
import com.devonfw.tools.ide.cli.CliArguments;
20-
import com.devonfw.tools.ide.cli.CliException;
2120
import com.devonfw.tools.ide.completion.IdeCompleter;
2221
import com.devonfw.tools.ide.context.AbstractIdeContext;
2322
import com.devonfw.tools.ide.context.IdeContext;
2423
import com.devonfw.tools.ide.property.BooleanProperty;
25-
import com.devonfw.tools.ide.property.FlagProperty;
2624
import com.devonfw.tools.ide.property.KeywordProperty;
2725
import com.devonfw.tools.ide.property.Property;
2826

@@ -166,8 +164,7 @@ private boolean apply(CliArgument argument, Commandlet commandlet) {
166164
}
167165
currentProperty = valueIterator.next();
168166
this.context.trace("Next value candidate is {}", currentProperty);
169-
if (currentProperty instanceof KeywordProperty) {
170-
KeywordProperty keyword = (KeywordProperty) currentProperty;
167+
if (currentProperty instanceof KeywordProperty keyword) {
171168
if (keyword.matches(arg)) {
172169
keyword.setValue(Boolean.TRUE);
173170
this.context.trace("Keyword matched");

cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionListCommandlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* An internal {@link Commandlet} to list versions for a tool.
99
*
10-
* @see ToolCommandlet#listVersions())
10+
* @see ToolCommandlet#listVersions()
1111
*/
1212
public class VersionListCommandlet extends Commandlet {
1313

cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionSetCommandlet.java

-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import java.util.List;
4-
import java.util.stream.IntStream;
5-
6-
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
73
import com.devonfw.tools.ide.context.IdeContext;
84
import com.devonfw.tools.ide.property.ToolProperty;
95
import com.devonfw.tools.ide.property.VersionProperty;
106
import com.devonfw.tools.ide.tool.ToolCommandlet;
117
import com.devonfw.tools.ide.version.VersionIdentifier;
12-
import com.devonfw.tools.ide.version.VersionSegment;
138

149
/**
1510
* An internal {@link Commandlet} to set a tool version.

cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.io.IOException;
55
import java.nio.file.Files;
66
import java.nio.file.Path;
7-
import java.nio.file.Paths;
87
import java.util.ArrayList;
98
import java.util.HashMap;
109
import java.util.Iterator;
@@ -26,7 +25,7 @@ public class SystemPath {
2625
private final Map<String, Path> tool2pathMap;
2726

2827
private final List<Path> paths;
29-
28+
3029
private final IdeContext context;
3130

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

131+
/**
132+
* @param toolPath the {@link Path} to the tool installation.
133+
* @return the {@link Path} to the binary executable of the tool. E.g. is "software/mvn" is given
134+
* "software/mvn/bin/mvn" could be returned.
135+
*/
132136
public Path findBinary(Path toolPath) {
137+
133138
Path parent = toolPath.getParent();
134139
String fileName = toolPath.getFileName().toString();
135140

cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidate.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.devonfw.tools.ide.completion;
22

3-
import com.devonfw.tools.ide.version.VersionSegment;
4-
53
/**
64
* Candidate for auto-completion.
75
*
@@ -13,6 +11,6 @@ public record CompletionCandidate(String text, String description) implements Co
1311
@Override
1412
public int compareTo(CompletionCandidate o) {
1513

16-
return text.compareTo(o.text);
14+
return this.text.compareTo(o.text);
1715
}
1816
}

cli/src/main/java/com/devonfw/tools/ide/completion/IdeCompleter.java

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
package com.devonfw.tools.ide.completion;
22

3-
import java.util.ArrayList;
4-
import java.util.Collection;
5-
import java.util.HashSet;
63
import java.util.List;
7-
import java.util.Set;
8-
import java.util.regex.Matcher;
9-
import java.util.regex.Pattern;
104

11-
import com.devonfw.tools.ide.cli.CliArguments;
12-
import com.devonfw.tools.ide.completion.CompletionCandidate;
13-
import com.devonfw.tools.ide.context.AbstractIdeContext;
145
import org.jline.reader.Candidate;
156
import org.jline.reader.Completer;
167
import org.jline.reader.LineReader;
178
import org.jline.reader.ParsedLine;
18-
import org.jline.reader.impl.completer.ArgumentCompleter;
19-
import org.jline.reader.impl.completer.NullCompleter;
20-
import org.jline.utils.AttributedString;
21-
22-
import com.devonfw.tools.ide.commandlet.Commandlet;
23-
import com.devonfw.tools.ide.commandlet.HelpCommandlet;
24-
import com.devonfw.tools.ide.context.IdeContext;
25-
import com.devonfw.tools.ide.property.Property;
26-
import com.devonfw.tools.ide.property.ToolProperty;
27-
import com.devonfw.tools.ide.property.VersionProperty;
28-
import com.devonfw.tools.ide.tool.ToolCommandlet;
29-
import com.devonfw.tools.ide.version.VersionIdentifier;
9+
10+
import com.devonfw.tools.ide.cli.CliArguments;
11+
import com.devonfw.tools.ide.context.AbstractIdeContext;
3012

3113
/**
3214
* Implements the {@link Completer} for jline3 autocompletion. Inspired by picocli

cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.net.InetAddress;
55
import java.nio.file.Files;
66
import java.nio.file.Path;
7-
import java.nio.file.Paths;
87
import java.nio.file.attribute.FileTime;
98
import java.time.Duration;
109
import java.util.HashMap;
@@ -141,7 +140,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
141140
this.fileAccess = new FileAccessImpl(this);
142141
String workspace = WORKSPACE_MAIN;
143142
if (userDir == null) {
144-
this.cwd = Paths.get(System.getProperty("user.dir"));
143+
this.cwd = Path.of(System.getProperty("user.dir"));
145144
} else {
146145
this.cwd = userDir.toAbsolutePath();
147146
}
@@ -184,7 +183,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
184183
root = System.getenv("IDE_ROOT");
185184
}
186185
if (root != null) {
187-
Path rootPath = Paths.get(root);
186+
Path rootPath = Path.of(root);
188187
if (Files.isDirectory(rootPath)) {
189188
if (!ideRootPath.equals(rootPath)) {
190189
warning("Variable IDE_ROOT is set to '{}' but for your project '{}' would have been expected.");
@@ -224,12 +223,12 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
224223
if (isTest()) {
225224
// only for testing...
226225
if (this.ideHome == null) {
227-
this.userHome = Paths.get("/non-existing-user-home-for-testing");
226+
this.userHome = Path.of("/non-existing-user-home-for-testing");
228227
} else {
229228
this.userHome = this.ideHome.resolve("home");
230229
}
231230
} else {
232-
this.userHome = Paths.get(System.getProperty("user.home"));
231+
this.userHome = Path.of(System.getProperty("user.home"));
233232
}
234233
this.userHomeIde = this.userHome.resolve(".ide");
235234
this.downloadPath = this.userHome.resolve("Downloads/ide");
@@ -663,8 +662,8 @@ public void gitPullOrClone(Path target, String gitRepoUrl) {
663662
}
664663

665664
/**
666-
* Checks if the Git repository in the specified target folder needs an update by
667-
* inspecting the modification time of a magic file.
665+
* Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of
666+
* a magic file.
668667
*
669668
* @param urlsPath The Path to the Urls repository.
670669
* @param repoUrl The git remote URL of the Urls repository.
@@ -701,7 +700,6 @@ private void gitPullOrCloneIfNeeded(Path urlsPath, String repoUrl) {
701700
}
702701
}
703702

704-
705703
@Override
706704
public IdeSubLogger level(IdeLogLevel level) {
707705

@@ -814,8 +812,9 @@ public int run(CliArguments arguments) {
814812
}
815813

816814
/**
817-
* @param cmd the potential {@link Commandlet} to {@link #apply(CliArguments, Commandlet, CompletionCandidateCollector) apply} and
818-
* {@link Commandlet#run() run}.
815+
* @param cmd the potential {@link Commandlet} to
816+
* {@link #apply(CliArguments, Commandlet, CompletionCandidateCollector) apply} and {@link Commandlet#run()
817+
* run}.
819818
* @return {@code true} if the given {@link Commandlet} matched and did {@link Commandlet#run() run} successfully,
820819
* {@code false} otherwise (the {@link Commandlet} did not match and we have to try a different candidate).
821820
*/

cli/src/main/java/com/devonfw/tools/ide/context/IdeContextConsole.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.devonfw.tools.ide.context;
22

3-
import me.tongfei.progressbar.ProgressBarBuilder;
4-
import me.tongfei.progressbar.ProgressBarStyle;
53
import java.util.Scanner;
64

75
import com.devonfw.tools.ide.io.IdeProgressBar;
86
import com.devonfw.tools.ide.io.IdeProgressBarConsole;
97
import com.devonfw.tools.ide.log.IdeLogLevel;
108
import com.devonfw.tools.ide.log.IdeSubLoggerOut;
119

10+
import me.tongfei.progressbar.ProgressBarBuilder;
11+
import me.tongfei.progressbar.ProgressBarStyle;
12+
1213
/**
1314
* Default implementation of {@link IdeContext} using the console.
1415
*/

cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.devonfw.tools.ide.environment;
22

33
import java.nio.file.Path;
4-
import java.nio.file.Paths;
54
import java.util.Collection;
65
import java.util.Locale;
76

@@ -46,7 +45,7 @@ default Path getPath(String name) {
4645
if (value == null) {
4746
return null;
4847
}
49-
return Paths.get(value);
48+
return Path.of(value);
5049
}
5150

5251
/**

cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.nio.file.LinkOption;
1717
import java.nio.file.NoSuchFileException;
1818
import java.nio.file.Path;
19-
import java.nio.file.Paths;
2019
import java.nio.file.attribute.BasicFileAttributes;
2120
import java.nio.file.attribute.PosixFilePermission;
2221
import java.nio.file.attribute.PosixFilePermissions;
@@ -82,7 +81,7 @@ public void download(String url, Path target) {
8281
} else if (url.startsWith("ftp") || url.startsWith("sftp")) {
8382
throw new IllegalArgumentException("Unsupported download URL: " + url);
8483
} else {
85-
Path source = Paths.get(url);
84+
Path source = Path.of(url);
8685
if (isFile(source)) {
8786
// network drive
8887
copyFileWithProgressBar(source, target);
@@ -358,15 +357,15 @@ private Path adaptPath(Path source, Path targetLink, boolean relative) throws IO
358357
if (relative) {
359358
source = targetLink.getParent().relativize(source);
360359
// to make relative links like this work: dir/link -> dir
361-
source = (source.toString().isEmpty()) ? Paths.get(".") : source;
360+
source = (source.toString().isEmpty()) ? Path.of(".") : source;
362361
}
363362
} else { // source is relative
364363
if (relative) {
365364
// even though the source is already relative, toRealPath should be called to transform paths like
366365
// this ../d1/../d2 to ../d2
367366
source = targetLink.getParent()
368367
.relativize(targetLink.resolveSibling(source).toRealPath(LinkOption.NOFOLLOW_LINKS));
369-
source = (source.toString().isEmpty()) ? Paths.get(".") : source;
368+
source = (source.toString().isEmpty()) ? Path.of(".") : source;
370369
} else { // !relative
371370
try {
372371
source = targetLink.resolveSibling(source).toRealPath(LinkOption.NOFOLLOW_LINKS);
@@ -532,7 +531,7 @@ private void unpack(Path file, Path targetDir, Function<InputStream, ArchiveInpu
532531
permissionStr = generatePermissionString(tarMode);
533532
}
534533

535-
Path entryName = Paths.get(entry.getName());
534+
Path entryName = Path.of(entry.getName());
536535
Path entryPath = targetDir.resolve(entryName).toAbsolutePath();
537536
if (!entryPath.startsWith(targetDir)) {
538537
throw new IOException("Preventing path traversal attack from " + entryName + " to " + entryPath);

cli/src/main/java/com/devonfw/tools/ide/merge/JsonMerger.java

+9-15
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,16 @@ private JsonValue mergeAndResolve(JsonValue json, JsonValue mergeJson, Environme
133133
if (mergeJson == null) {
134134
status.updated = true; // JSON to merge does not exist and needs to be created
135135
}
136-
switch (json.getValueType()) {
137-
case OBJECT:
138-
return mergeAndResolveObject((JsonObject) json, (JsonObject) mergeJson, variables, status, src);
139-
case ARRAY:
140-
return mergeAndResolveArray((JsonArray) json, (JsonArray) mergeJson, variables, status, src);
141-
case STRING:
142-
return mergeAndResolveString((JsonString) json, (JsonString) mergeJson, variables, status, src);
143-
case NUMBER:
144-
case FALSE:
145-
case TRUE:
146-
case NULL:
147-
return mergeAndResolveNativeType(json, mergeJson, variables, status);
148-
default:
136+
return switch (json.getValueType()) {
137+
case OBJECT -> mergeAndResolveObject((JsonObject) json, (JsonObject) mergeJson, variables, status, src);
138+
case ARRAY -> mergeAndResolveArray((JsonArray) json, (JsonArray) mergeJson, variables, status, src);
139+
case STRING -> mergeAndResolveString((JsonString) json, (JsonString) mergeJson, variables, status, src);
140+
case NUMBER, FALSE, TRUE, NULL -> mergeAndResolveNativeType(json, mergeJson, variables, status);
141+
default -> {
149142
this.context.error("Undefined JSON type {}", json.getClass());
150-
return null;
151-
}
143+
yield null;
144+
}
145+
};
152146
}
153147
}
154148

cli/src/main/java/com/devonfw/tools/ide/merge/XmlMerger.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ private void resolve(Element element, EnvironmentVariables variables, boolean in
182182

183183
for (int i = 0; i < nodeList.getLength(); i++) {
184184
Node node = nodeList.item(i);
185-
if (node instanceof Text) {
186-
Text text = (Text) node;
185+
if (node instanceof Text text) {
187186
String value = text.getNodeValue();
188187
String resolvedValue;
189188
if (inverse) {

0 commit comments

Comments
 (0)