• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 22303886886

23 Feb 2026 11:19AM UTC coverage: 70.647% (+0.2%) from 70.474%
22303886886

Pull #1714

github

web-flow
Merge f1f7e1e61 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4069 of 6360 branches covered (63.98%)

Branch coverage included in aggregate %.

10644 of 14466 relevant lines covered (73.58%)

3.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
cli/src/main/java/com/devonfw/tools/ide/network/NetworkProxy.java
1
package com.devonfw.tools.ide.network;
2

3
import java.net.MalformedURLException;
4
import java.net.URL;
5
import java.util.Locale;
6

7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.environment.IdeSystem;
12

13
/**
14
 * Simple class to {@link #configure()} network proxy.
15
 */
16
public class NetworkProxy {
17

18
  private static final Logger LOG = LoggerFactory.getLogger(NetworkProxy.class);
4✔
19

20
  private static final String PROXY_DOCUMENTATION_PAGE = "https://github.com/devonfw/IDEasy/blob/main/documentation/proxy-support.adoc";
21

22
  private final IdeContext context;
23

24
  private String nonProxyHosts;
25

26
  private String allProxy;
27

28
  /**
29
   * @param context the {@link IdeContext}.
30
   */
31
  public NetworkProxy(IdeContext context) {
32

33
    super();
2✔
34
    this.context = context;
3✔
35
  }
1✔
36

37
  /**
38
   * Perform the actual {@link NetworkProxy} configuration.
39
   */
40
  public void configure() {
41

42
    setupNetworkProxy("http");
3✔
43
    setupNetworkProxy("https");
3✔
44
  }
1✔
45

46
  private void setupNetworkProxy(String protocol) {
47

48
    String systemPropertyProxyHost = protocol + ".proxyHost";
3✔
49
    String configuredValue = System.getProperty(systemPropertyProxyHost);
3✔
50
    if (configuredValue != null) {
2!
51
      LOG.trace("Proxy already configured via system property {}={}", systemPropertyProxyHost, configuredValue);
×
52
      return;
×
53
    }
54
    String proxyUrlString = getProxyUrlFromEnvironmentVariable(protocol);
4✔
55
    if (proxyUrlString == null) {
2✔
56
      LOG.trace("No {} proxy configured.", protocol);
4✔
57
      return;
1✔
58
    }
59
    try {
60
      URL proxyUrl = new URL(proxyUrlString);
5✔
61
      IdeSystem system = this.context.getSystem();
4✔
62
      system.setProperty(systemPropertyProxyHost, proxyUrl.getHost());
5✔
63
      int port = proxyUrl.getPort();
3✔
64
      if (port == -1) {
3✔
65
        String urlProtocol = proxyUrl.getProtocol().toLowerCase(Locale.ROOT);
5✔
66
        if ("http".equals(urlProtocol)) {
4✔
67
          port = 80;
3✔
68
        } else if ("https".equals(urlProtocol)) {
4!
69
          port = 443;
3✔
70
        } else if ("ftp".equals(urlProtocol)) {
×
71
          port = 21;
×
72
        }
73
      }
74
      system.setProperty(protocol + ".proxyPort", Integer.toString(port));
6✔
75
      if (this.nonProxyHosts == null) {
3✔
76
        this.nonProxyHosts = getEnvironmentVariableNonNull("no_proxy");
5✔
77
      }
78
      if (!this.nonProxyHosts.isEmpty()) {
4!
79
        system.setProperty(protocol + ".nonProxyHosts", this.nonProxyHosts);
6✔
80
      }
81
    } catch (MalformedURLException e) {
1✔
82
      LOG.warn("Invalid {} proxy configuration detected with URL {}. Proxy configuration will be skipped.\n"
17✔
83
          + "For further details, see " + PROXY_DOCUMENTATION_PAGE, protocol, proxyUrlString, e);
84
    }
1✔
85
  }
1✔
86

87
  private String getProxyUrlFromEnvironmentVariable(String protocol) {
88

89
    String proxyUrl = getEnvironmentVariableCaseInsensitive(protocol + "_proxy");
5✔
90
    if (proxyUrl == null) {
2✔
91
      if (this.allProxy == null) {
3✔
92
        this.allProxy = getEnvironmentVariableNonNull("all_proxy");
5✔
93
      }
94
      if (!this.allProxy.isEmpty()) {
4✔
95
        proxyUrl = this.allProxy;
3✔
96
      }
97
    }
98
    return proxyUrl;
2✔
99
  }
100

101
  private String getEnvironmentVariableNonNull(String nameLowerCase) {
102

103
    String value = getEnvironmentVariableCaseInsensitive(nameLowerCase);
4✔
104
    if (value == null) {
2✔
105
      return "";
2✔
106
    } else {
107
      return value.trim();
3✔
108
    }
109
  }
110

111
  private String getEnvironmentVariableCaseInsensitive(String nameLowerCase) {
112

113
    String value = getEnvironmentVariable(nameLowerCase);
4✔
114
    if (value == null) {
2✔
115
      value = getEnvironmentVariable(nameLowerCase.toUpperCase(Locale.ROOT));
6✔
116
    }
117
    return value;
2✔
118
  }
119

120
  private String getEnvironmentVariable(String name) {
121

122
    String value = this.context.getSystem().getEnv(name);
6✔
123
    if (value != null) {
2✔
124
      LOG.trace("Found environment variable {}={}", name, value);
5✔
125
    }
126
    return value;
2✔
127
  }
128

129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc