Skip to content

Commit

Permalink
Merge branch 'main' into feature/223-dynamic-wiremock-ports
Browse files Browse the repository at this point in the history
# Conflicts:
#	cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonUrlUpdaterTest.java
#	cli/src/test/resources/integrationtest/PythonJsonUrlUpdater/python-version.json
  • Loading branch information
slskiba committed Jul 31, 2024
2 parents c3b87e2 + 20888e2 commit eae1f77
Show file tree
Hide file tree
Showing 56 changed files with 1,234 additions and 559 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ jobs:
git tag -a "release/${next_version}" -m "tagged version ${next_version}"
export GPG_TTY=$TTY
mkdir -p ./cli/target/
mv ./natives/* ./cli/target/
mvn --settings .mvn/settings.xml -B -ntp deploy -Pdeploy -Dgpg.pin.entry.mode=loopback -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
import com.devonfw.tools.ide.property.EditionProperty;
import com.devonfw.tools.ide.property.EnumProperty;
import com.devonfw.tools.ide.property.ToolProperty;
import com.devonfw.tools.ide.tool.ToolCommandlet;

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

public final EnumProperty<EnvironmentVariablesFiles> cfg;

/**
* The constructor.
*
Expand All @@ -27,6 +31,7 @@ public EditionSetCommandlet(IdeContext context) {
addKeyword(getName());
this.tool = add(new ToolProperty("", true, "tool"));
this.edition = add(new EditionProperty("", true, "edition"));
this.cfg = add(new EnumProperty<>("--cfg", false, null, EnvironmentVariablesFiles.class));
}

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

commandlet.setEdition(edition);
EnvironmentVariablesFiles env = this.cfg.getValue();
commandlet.setEdition(edition, true, env);

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
import com.devonfw.tools.ide.property.EnumProperty;
import com.devonfw.tools.ide.property.ToolProperty;
import com.devonfw.tools.ide.property.VersionProperty;
import com.devonfw.tools.ide.tool.ToolCommandlet;
Expand All @@ -19,6 +21,8 @@ public class VersionSetCommandlet extends Commandlet {
/** The version to set. */
public final VersionProperty version;

public final EnumProperty<EnvironmentVariablesFiles> cfg;

/**
* The constructor.
*
Expand All @@ -30,6 +34,7 @@ public VersionSetCommandlet(IdeContext context) {
addKeyword(getName());
this.tool = add(new ToolProperty("", true, "tool"));
this.version = add(new VersionProperty("", true, "version"));
this.cfg = add(new EnumProperty("--cfg", false, null, EnvironmentVariablesFiles.class));
}

@Override
Expand All @@ -43,7 +48,8 @@ public void run() {

ToolCommandlet commandlet = this.tool.getValue();
VersionIdentifier versionIdentifier = this.version.getValue();
commandlet.setVersion(versionIdentifier, true);
EnvironmentVariablesFiles env = this.cfg.getValue();
commandlet.setVersion(versionIdentifier, true, env);
}

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

/**
* Interface for a data object that can be read from and written to JSON.
*/
public interface JsonVersionItem {

String version();

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
while (currentDir != null) {
trace("Looking for IDE_HOME in {}", currentDir);
if (isIdeHome(currentDir)) {
if (FOLDER_WORKSPACES.equals(name1)) {
if (FOLDER_WORKSPACES.equals(name1) && !name2.isEmpty()) {
workspace = name2;
}
break;
Expand Down Expand Up @@ -1064,7 +1064,7 @@ private String findBashOnWindows() {
}
}
// no bash found
throw new IllegalStateException("Could not find Bash. Please install Git for Windows and rerun.");
return null;
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ default void setIdeHome(Path ideHome) {
*/
String findBash();

/**
* Finds the path to the Bash executable.
*
* @return the {@link String} to the Bash executable. Throws an {@link IllegalStateException} if no bash was found.
*/
default String findBashRequired() {
String bash = findBash();
if (bash == null) {
String message = "Could not find bash what is a prerequisite of IDEasy.";
if (getSystemInfo().isWindows()) {
message = message + "\nPlease install Git for Windows and rerun.";
}
throw new IllegalStateException(message);
}
return bash;
}

/**
* @return the {@link WindowsPathSyntax} used for {@link Path} conversion or {@code null} for no such conversion (typically if not on Windows).
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.devonfw.tools.ide.environment;

/**
* The subset of {@link EnvironmentVariables} types to be used for settings files.
*
* @see EnvironmentVariables#getType()
*/
public enum EnvironmentVariablesFiles {
/**
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getUserHome() users HOME directory}.
*/
USER,

/**
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getSettingsPath() settings directory}.
*/
SETTINGS,

/**
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getWorkspacePath() workspace directory}.
*/
WORKSPACE,

/**
* Type of {@link EnvironmentVariables} from the {@link com.devonfw.tools.ide.context.IdeContext#getConfPath() conf directory}. Allows the user to override or
* customize project specific variables.
*/
CONF;

private EnvironmentVariablesType type;

static {
USER.type = EnvironmentVariablesType.USER;
SETTINGS.type = EnvironmentVariablesType.SETTINGS;
WORKSPACE.type = EnvironmentVariablesType.WORKSPACE;
CONF.type = EnvironmentVariablesType.CONF;
}

/**
* @return the corresponding {@link EnvironmentVariablesType}
*/
public EnvironmentVariablesType toType() {
return type;
}

}
42 changes: 5 additions & 37 deletions cli/src/main/java/com/devonfw/tools/ide/github/GithubTag.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
package com.devonfw.tools.ide.github;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* JSON data object for a github tag ref.
*/
public class GithubTag {
public record GithubTag(@JsonProperty("ref") String ref) implements JsonVersionItem {

private String ref;
@Override
public String version() {

/**
* The constructor.
*/
public GithubTag() {

super();
}

/**
* The constructor.
*
* @param ref the {@link #getRef() ref}.
*/
public GithubTag(String ref) {

super();
this.ref = ref;
}

/**
* @return the tag reference (e.g. "refs/tags/v1.0").
*/
@JsonProperty("ref")
public String getRef() {

return this.ref;
}

/**
* @param ref the new value of {@link #getRef()}.
*/
@JsonProperty("ref")
public void setRef(String ref) {

this.ref = ref;
return ref().replace("refs/tags/", "");
}
}
12 changes: 12 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/npm/NpmJsonDist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.devonfw.tools.ide.npm;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* JSON data object for a version of Npm. We map only properties that we are interested in and let jackson ignore all others.
*
* @see NpmJsonObject#versions()
*/
public record NpmJsonDist(@JsonProperty("tarball") String tarball) {

}
10 changes: 10 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/npm/NpmJsonObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.devonfw.tools.ide.npm;

import com.devonfw.tools.ide.common.JsonObject;

/**
* {@link JsonObject} for Npm.
*/
public record NpmJsonObject(NpmJsonVersions versions) implements JsonObject {

}
13 changes: 13 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/npm/NpmJsonVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.devonfw.tools.ide.npm;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* JSON data object for a version of Npm. We map only properties that we are interested in and let jackson ignore all others.
*
* @see NpmJsonObject#versions()
*/
public record NpmJsonVersion(@JsonProperty("version") String version, @JsonProperty("dist") NpmJsonDist dist) implements JsonVersionItem {

}
32 changes: 32 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/npm/NpmJsonVersions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.devonfw.tools.ide.npm;

import java.util.HashMap;
import java.util.Map;

import com.devonfw.tools.ide.common.JsonObject;
import com.fasterxml.jackson.annotation.JsonAnySetter;

/**
* {@link JsonObject} for {@link NpmJsonVersion}.
*/
public class NpmJsonVersions {

private Map<String, NpmJsonVersion> versions;

@JsonAnySetter
public void setDetails(String key, NpmJsonVersion val) {

if (this.versions == null) {
this.versions = new HashMap<>();
}
this.versions.put(key, val);
}

/**
* @return the {@link Map} of {@link NpmJsonVersion}s.
*/
public Map<String, NpmJsonVersion> getVersionMap() {

return this.versions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private String addExecutable(String exec, List<String> args) {
}
if (isBashScript) {
interpreter = "bash";
args.add(this.context.findBash());
args.add(this.context.findBashRequired());
}
if ("msi".equalsIgnoreCase(fileExtension)) {
args.add(0, "/i");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected boolean runWithPackageManager(boolean silent, List<PackageManagerComma
*/
private boolean executePackageManagerCommand(PackageManagerCommand pmCommand, boolean silent) {

String bashPath = this.context.findBash();
String bashPath = this.context.findBashRequired();
for (String command : pmCommand.commands()) {
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(bashPath)
.addArgs("-c", command);
Expand Down
38 changes: 35 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.devonfw.tools.ide.common.Tags;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.EnvironmentVariablesFiles;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.os.MacOsHelper;
import com.devonfw.tools.ide.process.ProcessContext;
Expand Down Expand Up @@ -277,12 +277,28 @@ public void setVersion(String version) {
*/
public void setVersion(VersionIdentifier version, boolean hint) {

setVersion(version, hint, null);
}

/**
* Sets the tool version in the environment variable configuration file.
*
* @param version the version to set. May also be a {@link VersionIdentifier#isPattern() version pattern}.
* @param hint - {@code true} to print the installation hint, {@code false} otherwise.
* @param destination - the destination for the property to be set
*/
public void setVersion(VersionIdentifier version, boolean hint, EnvironmentVariablesFiles destination) {

String edition = getConfiguredEdition();
this.context.getUrls()
.getVersionFolder(this.tool, edition, version); // CliException is thrown if the version is not existing

EnvironmentVariables variables = this.context.getVariables();
EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS);
if (destination == null) {
//use default location
destination = EnvironmentVariablesFiles.SETTINGS;
}
EnvironmentVariables settingsVariables = variables.getByType(destination.toType());
String name = EnvironmentVariables.getToolVersionVariable(this.tool);
VersionIdentifier resolvedVersion = this.context.getUrls().getVersion(this.tool, edition, version);
if (version.isPattern()) {
Expand Down Expand Up @@ -320,16 +336,32 @@ public void setEdition(String edition) {
*/
public void setEdition(String edition, boolean hint) {

setEdition(edition, hint, null);
}

/**
* Sets the tool edition in the environment variable configuration file.
*
* @param edition the edition to set
* @param hint - {@code true} to print the installation hint, {@code false} otherwise.
* @param destination - the destination for the property to be set
*/
public void setEdition(String edition, boolean hint, EnvironmentVariablesFiles destination) {

if ((edition == null) || edition.isBlank()) {
throw new IllegalStateException("Edition has to be specified!");
}

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

}
EnvironmentVariables variables = this.context.getVariables();
EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS);
EnvironmentVariables settingsVariables = variables.getByType(destination.toType());
String name = EnvironmentVariables.getToolEditionVariable(this.tool);
settingsVariables.set(name, edition, false);
settingsVariables.save();
Expand Down
Loading

0 comments on commit eae1f77

Please sign in to comment.