Skip to content

Commit

Permalink
Merge branch 'master' into devonfw#1198-ability-to-download-custom-so…
Browse files Browse the repository at this point in the history
…ftware-from-mounted-filesystem
  • Loading branch information
alfeilex authored Aug 31, 2023
2 parents 36fc226 + 5f4cdde commit f5e77c9
Show file tree
Hide file tree
Showing 45 changed files with 1,375 additions and 665 deletions.
1 change: 1 addition & 0 deletions .github/workflows/update-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
with:
repository: devonfw/ide-urls
path: ide-urls
token: ${{ secrets.ACTION_PUSH_TOKEN }}
- name: Set up Java
uses: actions/setup-java@v3
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/ide[devonf

Release with new features and bugfixes:

* https://github.com/devonfw/ide/issues/1197[#1197]: Integrate Java Mission Control
* https://github.com/devonfw/ide/issues/1320[#1320]: Fix Bug in intellij documenation

The full list of changes for this release can be found in https://github.com/devonfw/ide/milestone/48?closed=1[milestone 2023.08.002].
Expand Down
16 changes: 16 additions & 0 deletions ide/src/main/java/com/devonfw/tools/ide/cli/CliAbortException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.devonfw.tools.ide.cli;

/**
* {@link CliException} that is thrown if the user aborted further processing due
*/
public final class CliAbortException extends CliException {

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

super("Aborted by end-user.", 22);
}

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

/**
* {@link RuntimeException} for to abort CLI process in expected situations. It allows to abort with a defined message
* for the end user and a defined exit code. Unlike other exceptions a {@link CliException} is not treated as technical
* error. Therefore by default (unless in debug mode) no stacktrace is printed.
*/
public class CliException extends RuntimeException {

private final int exitCode;

/**
* The constructor.
*
* @param message the {@link #getMessage() message}.
*/
public CliException(String message) {

this(message, 1);
}

/**
* The constructor.
*
* @param message the {@link #getMessage() message}.
* @param cause the {@link #getCause() cause}.
*/
public CliException(String message, Throwable cause) {

this(message, 1, cause);
}

/**
* The constructor.
*
* @param message the {@link #getMessage() message}.
* @param exitCode the {@link #getExitCode() exit code}.
*/
public CliException(String message, int exitCode) {

super(message);
this.exitCode = exitCode;
}

/**
* The constructor.
*
* @param message the {@link #getMessage() message}.
* @param exitCode the {@link #getExitCode() exit code}.
* @param cause the {@link #getCause() cause}.
*/
public CliException(String message, int exitCode, Throwable cause) {

super(message, cause);
this.exitCode = exitCode;
}

/**
* @return the exit code. Should not be zero.
*/
public int getExitCode() {

return this.exitCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void init(IdeContext ideContext) {

public static void doLicenseAgreement() {

File licenseAgreement = context.env().getUserHomeIde().resolve("license-agreement.txt").toFile();
File licenseAgreement = context.getUserHomeIde().resolve("license-agreement.txt").toFile();
if (!licenseAgreement.exists()) {
System.out.println();
logo();
Expand All @@ -61,7 +61,7 @@ public static void doLicenseAgreement() {
System.out.println("You are solely responsible for all risk implied by using this software.");
System.out.println("You will be able to find it in one of the following locations:");
System.out.println("https://github.com/devonfw/ide/blob/master/documentation/LICENSE.asciidoc");
System.out.println("Also it is included in " + context.env().getIdeHome() + "/devon-ide-doc.pdf");
System.out.println("Also it is included in " + context.getIdeHome() + "/devon-ide-doc.pdf");
System.out.println();
/*
* if (!isBatch()) { doOpen("https://github.com/devonfw/ide/blob/master/documentation/LICENSE.asciidoc"); }
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void downloadAndExtract(String software, String version, String ur
tmpFileObj.renameTo(targetFile);
System.out.println("Download of " + downloadFilename + " from " + url + " succeeded.");

String DEVON_SOFTWARE_DIR = context.env().getIdeHome().resolve("software").toString();
String DEVON_SOFTWARE_DIR = context.getIdeHome().resolve("software").toString();

extract(targetFolder + downloadFilename, DEVON_SOFTWARE_DIR + software);
createOrUpdateVersionFile(software, version, DEVON_SOFTWARE_DIR + software);
Expand Down Expand Up @@ -221,7 +221,7 @@ public static void setup(String url, String targetDir, String software, String v
if (version.isEmpty() || version == null) {
version = getLatestVersion(software, edition);
}
Path urlDirPath = context.env().getIdeRoot().resolve("urls/" + software + "/" + edition + "/" + version);
Path urlDirPath = context.getIdeRoot().resolve("urls/" + software + "/" + edition + "/" + version);
String downloadUrlFile = null;
try {
try (Stream<Path> paths = Files.list(urlDirPath)) {
Expand Down Expand Up @@ -356,16 +356,16 @@ public static void gitPullOrClone(String dir, String url) {

public static void updateUrls() {

String urlsDir = context.env().getDownloadMetadata().toString();
String devonUrls = context.env().getVariables().get("DEVON_URLS");
String urlsDir = context.getUrlsPath().toString();
String devonUrls = context.getVariables().get("DEVON_URLS");
String gitUrl = ((devonUrls != null) && !devonUrls.isEmpty()) ? devonUrls
: "https://github.com/devonfw/ide-urls.git";
gitPullOrClone(urlsDir, gitUrl);
}

public static String getLatestVersion(String software, String edition) {

Path urlsPath = context.env().getDownloadMetadata();
Path urlsPath = context.getUrlsPath();
Path toolPath = urlsPath.resolve(software);
Path editionPath = toolPath.resolve(edition);
if (!Files.exists(editionPath)) {
Expand Down Expand Up @@ -492,7 +492,7 @@ private static void extractZip(File file, Path targetPath) {

public static void verifyUrlsExistence() {

Path urlsPath = context.env().getDownloadMetadata();
Path urlsPath = context.getUrlsPath();
if (!Files.exists(urlsPath)) {
gitPullOrClone(urlsPath.toString(), "https://github.com/devonfw/ide-urls.git");
}
Expand All @@ -504,7 +504,7 @@ public static void listVersions(String software, String edition) {
if (edition == null || edition.isEmpty()) {
edition = software;
}
Path urlsPath = context.env().getDownloadMetadata();
Path urlsPath = context.getUrlsPath();
if (Files.isDirectory(urlsPath)) {
updateUrls();
Path toolPath = urlsPath.resolve(software);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.devonfw.tools.ide.commandlet;

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

import com.devonfw.tools.ide.environment.VariableLine;

import picocli.CommandLine;

Expand All @@ -16,10 +17,9 @@ private EnvironmentCommand() {
@Override
public void run() {

Map<String, String> map = new HashMap<>();
context().env().getVariables().collectVariables(map);
for (String line : map.values()) {
context().info(line);
Collection<VariableLine> variables = context().getVariables().collectVariables();
for (VariableLine line : variables) {
context().info(line.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.devonfw.tools.ide.commandlet;

import java.util.List;

import com.devonfw.tools.ide.cli.functions.Functions;
import com.devonfw.tools.ide.env.var.EnvironmentVariables;
import com.devonfw.tools.ide.env.var.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.version.VersionIdentifier;

import picocli.CommandLine;
Expand Down Expand Up @@ -64,15 +66,15 @@ public void run() {
*/
protected String getEdition() {

return context().env().getVariables().getToolEdition(getTool());
return context().getVariables().getToolEdition(getTool());
}

/**
* @return the {@link EnvironmentVariables#getToolVersion(String) tool version}.
*/
protected VersionIdentifier getVersion() {

return context().env().getVariables().getToolVersion(getTool());
return context().getVariables().getToolVersion(getTool());
}

protected void setup() {
Expand All @@ -82,33 +84,39 @@ protected void setup() {

protected void listVersions() {

Functions.listVersions(getTool(), getEdition());
List<VersionIdentifier> versions = context().getUrls().getSortedVersions(getTool(), getEdition());
for (VersionIdentifier vi : versions) {
context().info(vi.toString());
}
}

/**
* Sets the tool version in the environment variable configuration file.
*/
protected void setVersion() {

EnvironmentVariables variables = context().env().getVariables();
EnvironmentVariables variables = context().getVariables();
EnvironmentVariables settingsVariables = variables.getByType(EnvironmentVariablesType.SETTINGS);
String tool = getTool();
String edition = getEdition();
String name = EnvironmentVariables.getToolVersionVariable(tool);
String value = this.setVersion.version;
if ((value == null) || value.isBlank()) {
// TODO throw exception instead and implement proper exception handling
context().error("You have to specify the version you want to set.");
return;
}
VersionIdentifier configuredVersion;
if (value.equals("latest")) {
context().env().getDownloadMetadata();
String edition = getEdition();
if ((edition == null) || edition.isEmpty()) {
edition = tool;
}
value = Functions.getLatestVersion(tool, edition);
configuredVersion = VersionIdentifier.LATEST;
} else {
configuredVersion = VersionIdentifier.of(value);
}
VersionIdentifier resolvedVersion = context().getUrls().getVersion(tool, edition, configuredVersion);
if (configuredVersion.isPattern()) {
context().debug("Resolved version {} to {} for tool {}/{}", configuredVersion, resolvedVersion, tool, edition);
}
settingsVariables.set(name, value, false);
settingsVariables.set(name, resolvedVersion.toString(), false);
settingsVariables.save();
context().info("{}={} has been set in {}", name, value, settingsVariables.getSource());
EnvironmentVariables declaringVariables = variables.findVariable(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ protected String getTool() {
@Override
protected void startTool() {

String DEVON_SOFTWARE_DIR = context().env().getSoftwarePath().toString();
String DEVON_SOFTWARE_DIR = context().getSoftwarePath().toString();
Path pathToBinFolder = Functions.searchFolder(DEVON_SOFTWARE_DIR + getTool(), "bin");
if (pathToBinFolder != null) {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(getTool(), this.option);

try {
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
Expand Down
Loading

0 comments on commit f5e77c9

Please sign in to comment.