Skip to content

Commit eae1f77

Browse files
committed
Merge branch 'main' into feature/223-dynamic-wiremock-ports
# Conflicts: # cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonUrlUpdaterTest.java # cli/src/test/resources/integrationtest/PythonJsonUrlUpdater/python-version.json
2 parents c3b87e2 + 20888e2 commit eae1f77

File tree

56 files changed

+1234
-559
lines changed

Some content is hidden

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

56 files changed

+1234
-559
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ jobs:
102102
git tag -a "release/${next_version}" -m "tagged version ${next_version}"
103103
export GPG_TTY=$TTY
104104
mkdir -p ./cli/target/
105-
mv ./natives/* ./cli/target/
106105
mvn --settings .mvn/settings.xml -B -ntp deploy -Pdeploy -Dgpg.pin.entry.mode=loopback -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}
107106
env:
108107
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.devonfw.tools.ide.commandlet;
22

33
import com.devonfw.tools.ide.context.IdeContext;
4+
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
45
import com.devonfw.tools.ide.property.EditionProperty;
6+
import com.devonfw.tools.ide.property.EnumProperty;
57
import com.devonfw.tools.ide.property.ToolProperty;
68
import com.devonfw.tools.ide.tool.ToolCommandlet;
79

@@ -16,6 +18,8 @@ public class EditionSetCommandlet extends Commandlet {
1618
/** The edition to set. */
1719
public final EditionProperty edition;
1820

21+
public final EnumProperty<EnvironmentVariablesFiles> cfg;
22+
1923
/**
2024
* The constructor.
2125
*
@@ -27,6 +31,7 @@ public EditionSetCommandlet(IdeContext context) {
2731
addKeyword(getName());
2832
this.tool = add(new ToolProperty("", true, "tool"));
2933
this.edition = add(new EditionProperty("", true, "edition"));
34+
this.cfg = add(new EnumProperty<>("--cfg", false, null, EnvironmentVariablesFiles.class));
3035
}
3136

3237
@Override
@@ -41,7 +46,9 @@ public void run() {
4146
ToolCommandlet commandlet = this.tool.getValue();
4247
String edition = this.edition.getValue();
4348

44-
commandlet.setEdition(edition);
49+
EnvironmentVariablesFiles env = this.cfg.getValue();
50+
commandlet.setEdition(edition, true, env);
51+
4552
}
4653

4754
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.devonfw.tools.ide.commandlet;
22

33
import com.devonfw.tools.ide.context.IdeContext;
4+
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
5+
import com.devonfw.tools.ide.property.EnumProperty;
46
import com.devonfw.tools.ide.property.ToolProperty;
57
import com.devonfw.tools.ide.property.VersionProperty;
68
import com.devonfw.tools.ide.tool.ToolCommandlet;
@@ -19,6 +21,8 @@ public class VersionSetCommandlet extends Commandlet {
1921
/** The version to set. */
2022
public final VersionProperty version;
2123

24+
public final EnumProperty<EnvironmentVariablesFiles> cfg;
25+
2226
/**
2327
* The constructor.
2428
*
@@ -30,6 +34,7 @@ public VersionSetCommandlet(IdeContext context) {
3034
addKeyword(getName());
3135
this.tool = add(new ToolProperty("", true, "tool"));
3236
this.version = add(new VersionProperty("", true, "version"));
37+
this.cfg = add(new EnumProperty("--cfg", false, null, EnvironmentVariablesFiles.class));
3338
}
3439

3540
@Override
@@ -43,7 +48,8 @@ public void run() {
4348

4449
ToolCommandlet commandlet = this.tool.getValue();
4550
VersionIdentifier versionIdentifier = this.version.getValue();
46-
commandlet.setVersion(versionIdentifier, true);
51+
EnvironmentVariablesFiles env = this.cfg.getValue();
52+
commandlet.setVersion(versionIdentifier, true, env);
4753
}
4854

4955
@Override
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.devonfw.tools.ide.common;
2+
3+
/**
4+
* Interface for a data object that can be read from and written to JSON.
5+
*/
6+
public interface JsonVersionItem {
7+
8+
String version();
9+
10+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
165165
while (currentDir != null) {
166166
trace("Looking for IDE_HOME in {}", currentDir);
167167
if (isIdeHome(currentDir)) {
168-
if (FOLDER_WORKSPACES.equals(name1)) {
168+
if (FOLDER_WORKSPACES.equals(name1) && !name2.isEmpty()) {
169169
workspace = name2;
170170
}
171171
break;
@@ -1064,7 +1064,7 @@ private String findBashOnWindows() {
10641064
}
10651065
}
10661066
// no bash found
1067-
throw new IllegalStateException("Could not find Bash. Please install Git for Windows and rerun.");
1067+
return null;
10681068
}
10691069

10701070
@Override

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,23 @@ default void setIdeHome(Path ideHome) {
531531
*/
532532
String findBash();
533533

534+
/**
535+
* Finds the path to the Bash executable.
536+
*
537+
* @return the {@link String} to the Bash executable. Throws an {@link IllegalStateException} if no bash was found.
538+
*/
539+
default String findBashRequired() {
540+
String bash = findBash();
541+
if (bash == null) {
542+
String message = "Could not find bash what is a prerequisite of IDEasy.";
543+
if (getSystemInfo().isWindows()) {
544+
message = message + "\nPlease install Git for Windows and rerun.";
545+
}
546+
throw new IllegalStateException(message);
547+
}
548+
return bash;
549+
}
550+
534551
/**
535552
* @return the {@link WindowsPathSyntax} used for {@link Path} conversion or {@code null} for no such conversion (typically if not on Windows).
536553
*/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.devonfw.tools.ide.environment;
2+
3+
/**
4+
* The subset of {@link EnvironmentVariables} types to be used for settings files.
5+
*
6+
* @see EnvironmentVariables#getType()
7+
*/
8+
public enum EnvironmentVariablesFiles {
9+
/**
10+
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getUserHome() users HOME directory}.
11+
*/
12+
USER,
13+
14+
/**
15+
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getSettingsPath() settings directory}.
16+
*/
17+
SETTINGS,
18+
19+
/**
20+
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getWorkspacePath() workspace directory}.
21+
*/
22+
WORKSPACE,
23+
24+
/**
25+
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getConfPath() conf directory}. Allows the user to override or
26+
* customize project specific variables.
27+
*/
28+
CONF;
29+
30+
private EnvironmentVariablesType type;
31+
32+
static {
33+
USER.type = EnvironmentVariablesType.USER;
34+
SETTINGS.type = EnvironmentVariablesType.SETTINGS;
35+
WORKSPACE.type = EnvironmentVariablesType.WORKSPACE;
36+
CONF.type = EnvironmentVariablesType.CONF;
37+
}
38+
39+
/**
40+
* @return the corresponding {@link EnvironmentVariablesType}
41+
*/
42+
public EnvironmentVariablesType toType() {
43+
return type;
44+
}
45+
46+
}
Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,16 @@
11
package com.devonfw.tools.ide.github;
22

3+
import com.devonfw.tools.ide.common.JsonVersionItem;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45

56
/**
67
* JSON data object for a github tag ref.
78
*/
8-
public class GithubTag {
9+
public record GithubTag(@JsonProperty("ref") String ref) implements JsonVersionItem {
910

10-
private String ref;
11+
@Override
12+
public String version() {
1113

12-
/**
13-
* The constructor.
14-
*/
15-
public GithubTag() {
16-
17-
super();
18-
}
19-
20-
/**
21-
* The constructor.
22-
*
23-
* @param ref the {@link #getRef() ref}.
24-
*/
25-
public GithubTag(String ref) {
26-
27-
super();
28-
this.ref = ref;
29-
}
30-
31-
/**
32-
* @return the tag reference (e.g. "refs/tags/v1.0").
33-
*/
34-
@JsonProperty("ref")
35-
public String getRef() {
36-
37-
return this.ref;
38-
}
39-
40-
/**
41-
* @param ref the new value of {@link #getRef()}.
42-
*/
43-
@JsonProperty("ref")
44-
public void setRef(String ref) {
45-
46-
this.ref = ref;
14+
return ref().replace("refs/tags/", "");
4715
}
4816
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.devonfw.tools.ide.npm;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* JSON data object for a version of Npm. We map only properties that we are interested in and let jackson ignore all others.
7+
*
8+
* @see NpmJsonObject#versions()
9+
*/
10+
public record NpmJsonDist(@JsonProperty("tarball") String tarball) {
11+
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.devonfw.tools.ide.npm;
2+
3+
import com.devonfw.tools.ide.common.JsonObject;
4+
5+
/**
6+
* {@link JsonObject} for Npm.
7+
*/
8+
public record NpmJsonObject(NpmJsonVersions versions) implements JsonObject {
9+
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.devonfw.tools.ide.npm;
2+
3+
import com.devonfw.tools.ide.common.JsonVersionItem;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
/**
7+
* JSON data object for a version of Npm. We map only properties that we are interested in and let jackson ignore all others.
8+
*
9+
* @see NpmJsonObject#versions()
10+
*/
11+
public record NpmJsonVersion(@JsonProperty("version") String version, @JsonProperty("dist") NpmJsonDist dist) implements JsonVersionItem {
12+
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.devonfw.tools.ide.npm;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.devonfw.tools.ide.common.JsonObject;
7+
import com.fasterxml.jackson.annotation.JsonAnySetter;
8+
9+
/**
10+
* {@link JsonObject} for {@link NpmJsonVersion}.
11+
*/
12+
public class NpmJsonVersions {
13+
14+
private Map<String, NpmJsonVersion> versions;
15+
16+
@JsonAnySetter
17+
public void setDetails(String key, NpmJsonVersion val) {
18+
19+
if (this.versions == null) {
20+
this.versions = new HashMap<>();
21+
}
22+
this.versions.put(key, val);
23+
}
24+
25+
/**
26+
* @return the {@link Map} of {@link NpmJsonVersion}s.
27+
*/
28+
public Map<String, NpmJsonVersion> getVersionMap() {
29+
30+
return this.versions;
31+
}
32+
}

cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private String addExecutable(String exec, List<String> args) {
271271
}
272272
if (isBashScript) {
273273
interpreter = "bash";
274-
args.add(this.context.findBash());
274+
args.add(this.context.findBashRequired());
275275
}
276276
if ("msi".equalsIgnoreCase(fileExtension)) {
277277
args.add(0, "/i");

cli/src/main/java/com/devonfw/tools/ide/tool/GlobalToolCommandlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected boolean runWithPackageManager(boolean silent, List<PackageManagerComma
7878
*/
7979
private boolean executePackageManagerCommand(PackageManagerCommand pmCommand, boolean silent) {
8080

81-
String bashPath = this.context.findBash();
81+
String bashPath = this.context.findBashRequired();
8282
for (String command : pmCommand.commands()) {
8383
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(bashPath)
8484
.addArgs("-c", command);

cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.devonfw.tools.ide.common.Tags;
1111
import com.devonfw.tools.ide.context.IdeContext;
1212
import com.devonfw.tools.ide.environment.EnvironmentVariables;
13-
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
13+
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
1414
import com.devonfw.tools.ide.nls.NlsBundle;
1515
import com.devonfw.tools.ide.os.MacOsHelper;
1616
import com.devonfw.tools.ide.process.ProcessContext;
@@ -277,12 +277,28 @@ public void setVersion(String version) {
277277
*/
278278
public void setVersion(VersionIdentifier version, boolean hint) {
279279

280+
setVersion(version, hint, null);
281+
}
282+
283+
/**
284+
* Sets the tool version in the environment variable configuration file.
285+
*
286+
* @param version the version to set. May also be a {@link VersionIdentifier#isPattern() version pattern}.
287+
* @param hint - {@code true} to print the installation hint, {@code false} otherwise.
288+
* @param destination - the destination for the property to be set
289+
*/
290+
public void setVersion(VersionIdentifier version, boolean hint, EnvironmentVariablesFiles destination) {
291+
280292
String edition = getConfiguredEdition();
281293
this.context.getUrls()
282294
.getVersionFolder(this.tool, edition, version); // CliException is thrown if the version is not existing
283295

284296
EnvironmentVariables variables = this.context.getVariables();
285-
EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS);
297+
if (destination == null) {
298+
//use default location
299+
destination = EnvironmentVariablesFiles.SETTINGS;
300+
}
301+
EnvironmentVariables settingsVariables = variables.getByType(destination.toType());
286302
String name = EnvironmentVariables.getToolVersionVariable(this.tool);
287303
VersionIdentifier resolvedVersion = this.context.getUrls().getVersion(this.tool, edition, version);
288304
if (version.isPattern()) {
@@ -320,16 +336,32 @@ public void setEdition(String edition) {
320336
*/
321337
public void setEdition(String edition, boolean hint) {
322338

339+
setEdition(edition, hint, null);
340+
}
341+
342+
/**
343+
* Sets the tool edition in the environment variable configuration file.
344+
*
345+
* @param edition the edition to set
346+
* @param hint - {@code true} to print the installation hint, {@code false} otherwise.
347+
* @param destination - the destination for the property to be set
348+
*/
349+
public void setEdition(String edition, boolean hint, EnvironmentVariablesFiles destination) {
350+
323351
if ((edition == null) || edition.isBlank()) {
324352
throw new IllegalStateException("Edition has to be specified!");
325353
}
326354

355+
if (destination == null) {
356+
//use default location
357+
destination = EnvironmentVariablesFiles.SETTINGS;
358+
}
327359
if (!Files.exists(this.context.getUrls().getEdition(getName(), edition).getPath())) {
328360
this.context.warning("Edition {} seems to be invalid", edition);
329361

330362
}
331363
EnvironmentVariables variables = this.context.getVariables();
332-
EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS);
364+
EnvironmentVariables settingsVariables = variables.getByType(destination.toType());
333365
String name = EnvironmentVariables.getToolEditionVariable(this.tool);
334366
settingsVariables.set(name, edition, false);
335367
settingsVariables.save();

0 commit comments

Comments
 (0)