Skip to content

Commit

Permalink
devonfw#778: add icd devonfw#779: use functions instead of alias devo…
Browse files Browse the repository at this point in the history
…nfw#810: setup in current shell devonfw#782: fix IDE_ROOT on linux/mac devonfw#774: fixed HTTP proxy support (devonfw#811)
  • Loading branch information
hohwille authored Nov 28, 2024
1 parent cfd61d5 commit c993397
Show file tree
Hide file tree
Showing 24 changed files with 754 additions and 491 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE

== 2024.12.001

NOTE: ATTENTION: When installing this release as an update, you need to manually remove IDEasy entries from `.bashrc` and if present also `.zshrc`.
Also you should delete all files from your `$IDE_ROOT/_ide` folder before extracting the new version to it.
Then run the `setup` and all should work fine.

Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/774[#774]: HTTP proxy support not working properly
* https://github.com/devonfw/IDEasy/issues/589[#589]: Fix NLS Bundles for Linux and MacOS
* https://github.com/devonfw/IDEasy/issues/778[#778]: Add icd command
* https://github.com/devonfw/IDEasy/issues/779[#779]: Consider functions instead of alias
* https://github.com/devonfw/IDEasy/issues/810[#810]: setup not adding IDEasy to current shell
* https://github.com/devonfw/IDEasy/issues/782[#782]: Fix IDE_ROOT variable on Linux
* https://github.com/devonfw/IDEasy/issues/637[#637]: Added option to disable updates
* https://github.com/devonfw/IDEasy/issues/764[#764]: IDEasy not working properly in CMD
* https://github.com/devonfw/IDEasy/issues/81[#81]: Implement Toolcommandlet for Kubernetes
Expand Down
24 changes: 17 additions & 7 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@
<version>1.5.3</version>
<!--optional>true</optional-->
</dependency>
<!-- Needed for WireMock test support -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
Expand All @@ -90,6 +83,21 @@
<artifactId>jansi</artifactId>
<version>${jansi.version}</version>
</dependency>
<!-- Test dependencies -->
<!-- Mockito for mocking -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<!-- Needed for WireMock test support -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- required for advanced mocking -->
<groupId>net.bytebuddy</groupId>
Expand All @@ -102,11 +110,13 @@
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj3</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import com.devonfw.tools.ide.environment.AbstractEnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.IdeSystem;
import com.devonfw.tools.ide.environment.IdeSystemImpl;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.FileAccessImpl;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.log.IdeLogger;
import com.devonfw.tools.ide.log.IdeSubLogger;
import com.devonfw.tools.ide.merge.DirectoryMerger;
import com.devonfw.tools.ide.network.ProxyContext;
import com.devonfw.tools.ide.network.NetworkProxy;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoImpl;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
Expand Down Expand Up @@ -124,6 +126,10 @@ public abstract class AbstractIdeContext implements IdeContext {

protected Boolean online;

protected IdeSystem system;

private NetworkProxy networkProxy;

/**
* The constructor.
*
Expand Down Expand Up @@ -202,8 +208,8 @@ private Path findIdeRoot(Path ideHomePath) {
return ideRootPath;
}

private static Path getIdeRootPathFromEnv() {
String root = System.getenv(IdeVariables.IDE_ROOT.getName());
private Path getIdeRootPathFromEnv() {
String root = getSystem().getEnv(IdeVariables.IDE_ROOT.getName());
if (root != null) {
Path rootPath = Path.of(root);
if (Files.isDirectory(rootPath)) {
Expand Down Expand Up @@ -242,7 +248,7 @@ public void setCwd(Path userDir, String workspace, Path ideHome) {
this.userHome = this.ideHome.resolve("home");
}
} else {
this.userHome = Path.of(System.getProperty("user.home"));
this.userHome = Path.of(getSystem().getProperty("user.home"));
}
this.userHomeIde = this.userHome.resolve(".ide");
this.downloadPath = this.userHome.resolve("Downloads/ide");
Expand All @@ -261,8 +267,8 @@ private String getMessageIdeHomeNotFound() {
return "You are not inside an IDE installation: " + this.cwd;
}

private static String getMessageIdeRootNotFound() {
String root = System.getenv("IDE_ROOT");
private String getMessageIdeRootNotFound() {
String root = getSystem().getEnv("IDE_ROOT");
if (root == null) {
return "The environment variable IDE_ROOT is undefined. Please reinstall IDEasy or manually repair IDE_ROOT variable.";
} else {
Expand Down Expand Up @@ -349,6 +355,8 @@ public SystemInfo getSystemInfo() {
@Override
public FileAccess getFileAccess() {

// currently FileAccess contains download method and requires network proxy to be configured. Maybe download should be moved to its own interface/class
configureNetworkProxy();
return this.fileAccess;
}

Expand Down Expand Up @@ -547,6 +555,7 @@ public boolean isSkipUpdatesMode() {
public boolean isOnline() {

if (this.online == null) {
configureNetworkProxy();
// we currently assume we have only a CLI process that runs shortly
// therefore we run this check only once to save resources when this method is called many times
try {
Expand All @@ -564,6 +573,13 @@ public boolean isOnline() {
return this.online.booleanValue();
}

private void configureNetworkProxy() {
if (this.networkProxy == null) {
this.networkProxy = new NetworkProxy(this);
this.networkProxy.configure();
}
}

@Override
public Locale getLocale() {

Expand Down Expand Up @@ -602,12 +618,6 @@ public void setDefaultExecutionDirectory(Path defaultExecutionDirectory) {
}
}

@Override
public ProxyContext getProxyContext() {

return new ProxyContext(this);
}

@Override
public GitContext getGitContext() {

Expand All @@ -624,6 +634,15 @@ public ProcessContext newProcess() {
return processContext;
}

@Override
public IdeSystem getSystem() {

if (this.system == null) {
this.system = new IdeSystemImpl(this);
}
return this.system;
}

/**
* @return a new instance of {@link ProcessContext}.
* @see #newProcess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import com.devonfw.tools.ide.common.SystemPath;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.IdeSystem;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.IdeProgressBar;
import com.devonfw.tools.ide.merge.DirectoryMerger;
import com.devonfw.tools.ide.network.ProxyContext;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
import com.devonfw.tools.ide.process.ProcessContext;
Expand Down Expand Up @@ -416,7 +416,10 @@ default Path getSettingsTemplatePath() {
*/
Path getDefaultExecutionDirectory();

ProxyContext getProxyContext();
/**
* @return the {@link IdeSystem} instance wrapping {@link System}.
*/
IdeSystem getSystem();

/**
* @return the {@link GitContext} used to run several git commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public EnvironmentVariablesType getType() {
@Override
protected Map<String, String> getVariables() {

return System.getenv();
return this.context.getSystem().getEnv();
}

/**
Expand Down
44 changes: 44 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/environment/IdeSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.devonfw.tools.ide.environment;

import java.util.Map;

/**
* Interface to abstract from {@link System}.
*/
public interface IdeSystem {

/**
* @param key the name of the requested system property.
* @return the {@link System#getProperty(String) value} of the requested system property.
* @see System#getProperty(String)
*/
String getProperty(String key);

/**
* @param key the name of the requested system property.
* @param fallback the value to return as default in case the requested system property is undefined.
* @return the {@link System#getProperty(String, String) value} of the requested system property.
* @see System#getProperty(String, String)
*/
String getProperty(String key, String fallback);

/**
* @param key the name of the system property to set.
* @param value the new value to {@link System#setProperty(String, String) set}.
* @see System#setProperty(String, String)
*/
void setProperty(String key, String value);

/**
* @param key the name of the requested environment variable.
* @return the {@link System#getenv(String) value} of the requested environment variable.
* @see System#getenv(String)
*/
String getEnv(String key);

/**
* @return the {@link System#getenv() environment variables}.
*/
Map<String, String> getEnv();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.devonfw.tools.ide.environment;

import java.util.Map;
import java.util.Objects;
import java.util.Properties;

import com.devonfw.tools.ide.log.IdeLogger;

/**
* Implementation of {@link IdeSystem}.
*/
public class IdeSystemImpl implements IdeSystem {

private final IdeLogger logger;

final Properties systemProperties;

final Map<String, String> environmentVariables;

/**
* @param logger the {@link IdeLogger}.
*/
public IdeSystemImpl(IdeLogger logger) {

this(logger, System.getProperties(), System.getenv());
}

/**
* @param logger the {@link IdeLogger}.
* @param systemProperties the {@link System#getProperties() system properties}.
* @param environmentVariables the {@link System#getenv() environment variables}.
*/
protected IdeSystemImpl(IdeLogger logger, Properties systemProperties, Map<String, String> environmentVariables) {

super();
this.logger = logger;
this.systemProperties = systemProperties;
this.environmentVariables = environmentVariables;
}

@Override
public String getProperty(String key) {

return this.systemProperties.getProperty(key);
}

@Override
public String getProperty(String key, String fallback) {

return this.systemProperties.getProperty(key, fallback);
}

@Override
public void setProperty(String key, String value) {

String old = getProperty(key);
if (Objects.equals(old, value)) {
this.logger.trace("System property was already set to {}={}", key, value);
} else {
this.systemProperties.put(key, value);
if (old == null) {
this.logger.trace("System property was set to {}={}", key, value);
} else {
this.logger.trace("System property was changed to {}={} from {}", key, value, old);
}
}
}

@Override
public String getEnv(String key) {

return this.environmentVariables.get(key);
}

@Override
public Map<String, String> getEnv() {

return this.environmentVariables;
}
}
10 changes: 0 additions & 10 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Redirect;
Expand Down Expand Up @@ -82,12 +79,6 @@ public FileAccessImpl(IdeContext context) {
private HttpClient createHttpClient(String url) {

HttpClient.Builder builder = HttpClient.newBuilder().followRedirects(Redirect.ALWAYS);
Proxy proxy = this.context.getProxyContext().getProxy(url);
if (proxy != Proxy.NO_PROXY) {
this.context.info("Downloading through proxy: " + proxy);
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
builder.proxy(ProxySelector.of(proxyAddress));
}
return builder.build();
}

Expand All @@ -105,7 +96,6 @@ public void download(String url, Path target) {
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).GET().build();
HttpClient client = createHttpClient(url);
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());

if (response.statusCode() == 200) {
downloadFileWithProgressBar(url, target, response);
}
Expand Down
Loading

0 comments on commit c993397

Please sign in to comment.