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

devonfw / IDEasy / 22283847745

22 Feb 2026 07:34PM UTC coverage: 70.75% (+0.3%) from 70.474%
22283847745

Pull #1714

github

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

4064 of 6348 branches covered (64.02%)

Branch coverage included in aggregate %.

10635 of 14428 relevant lines covered (73.71%)

3.1 hits per line

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

66.2
cli/src/main/java/com/devonfw/tools/ide/network/NetworkStatusImpl.java
1
package com.devonfw.tools.ide.network;
2

3
import java.io.IOException;
4
import java.net.URL;
5
import java.net.URLConnection;
6
import java.util.concurrent.Callable;
7
import javax.net.ssl.SSLException;
8

9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

12
import com.devonfw.tools.ide.cache.CachedValue;
13
import com.devonfw.tools.ide.cli.CliOfflineException;
14
import com.devonfw.tools.ide.context.AbstractIdeContext;
15
import com.devonfw.tools.ide.log.IdeLogLevel;
16

17
/**
18
 * Implementation of {@link NetworkStatus}.
19
 */
20
public class NetworkStatusImpl implements NetworkStatus {
21

22
  private static final Logger LOG = LoggerFactory.getLogger(NetworkStatusImpl.class);
4✔
23

24
  private final AbstractIdeContext context;
25

26
  private NetworkProxy networkProxy;
27

28
  private final String onlineCheckUrl;
29

30
  protected final CachedValue<Throwable> onlineCheck;
31

32
  /**
33
   * @param ideContext the {@link AbstractIdeContext}.
34
   */
35
  public NetworkStatusImpl(AbstractIdeContext ideContext) {
36
    this(ideContext, null, CachedValue.DEFAULT_RETENTION);
×
37
  }
×
38

39
  /**
40
   * @param context the {@link AbstractIdeContext}.
41
   * @param onlineCheckUrl the URL to test for the online-check.
42
   * @param retention the retention of the {@link CachedValue}.
43
   */
44
  protected NetworkStatusImpl(AbstractIdeContext context, String onlineCheckUrl, long retention) {
2✔
45
    this.context = context;
3✔
46
    if (onlineCheckUrl == null) {
2✔
47
      onlineCheckUrl = "https://www.github.com";
2✔
48
    }
49
    this.onlineCheckUrl = onlineCheckUrl;
3✔
50
    this.onlineCheck = new CachedValue<>(this::doOnlineCheck, retention);
8✔
51
  }
1✔
52

53
  @Override
54
  public boolean isOfflineMode() {
55

56
    return this.context.isOfflineMode();
4✔
57
  }
58

59
  @Override
60
  public boolean isOnline() {
61

62
    return getError() == null;
7✔
63
  }
64

65
  @Override
66
  public Throwable getError() {
67

68
    return this.onlineCheck.get();
5✔
69
  }
70

71
  private Throwable doOnlineCheck() {
72
    configureNetworkProxy();
×
73
    try {
74
      int timeout = 1000;
×
75
      //open a connection to URL and try to retrieve data
76
      //getContent fails if there is no connection
77
      URLConnection connection = new URL(this.onlineCheckUrl).openConnection();
×
78
      connection.setConnectTimeout(timeout);
×
79
      connection.getContent();
×
80
      return null;
×
81
    } catch (Exception e) {
×
82
      if (LOG.isDebugEnabled()) {
×
83
        LOG.debug("Error when trying to connect to {}", this.onlineCheckUrl, e);
×
84
      }
85
      return e;
×
86
    }
87
  }
88

89
  private void configureNetworkProxy() {
90

91
    if (this.networkProxy == null) {
3✔
92
      this.networkProxy = new NetworkProxy(this.context);
7✔
93
      this.networkProxy.configure();
3✔
94
    }
95
  }
1✔
96

97
  @Override
98
  public void logStatusMessage() {
99

100
    if (isOfflineMode()) {
3✔
101
      LOG.warn("You are offline because you have enabled offline mode via CLI option.");
3✔
102
      return;
1✔
103
    }
104
    Throwable error = getError();
3✔
105
    if (error == null) {
2✔
106
      LOG.info(IdeLogLevel.INTERACTION.getSlf4jMarker(), "You are online.");
5✔
107
      return;
1✔
108
    }
109
    String message = "You are offline because of the following error:";
2✔
110
    if (LOG.isDebugEnabled()) {
3!
111
      LOG.error(message, error);
5✔
112
    } else {
113
      LOG.error(message);
×
114
      LOG.error(error.toString());
×
115
    }
116
    if (error instanceof SSLException) {
3✔
117
      LOG.warn(
3✔
118
          "You are having TLS issues. We guess you are forced to use a VPN tool breaking end-to-end encryption causing this effect. As a workaround you can create and configure a truststore as described here:");
119
      LOG.info(IdeLogLevel.INTERACTION.getSlf4jMarker(), "https://github.com/devonfw/IDEasy/blob/main/documentation/proxy-support.adoc#tls-certificate-issues");
6✔
120
    } else {
121
      LOG.info(IdeLogLevel.INTERACTION.getSlf4jMarker(),
5✔
122
          "Please check potential proxy settings, ensure you are properly connected to the internet and retry this operation.");
123
    }
124
  }
1✔
125

126
  @Override
127
  public <T> T invokeNetworkTask(Callable<T> callable, String uri) {
128

129
    if (isOfflineMode()) {
3!
130
      throw CliOfflineException.ofDownloadViaUrl(uri);
×
131
    }
132
    configureNetworkProxy();
2✔
133
    try {
134
      return callable.call();
3✔
135
    } catch (IOException e) {
×
136
      this.onlineCheck.set(e);
×
137
      throw new IllegalStateException("Network error whilst communicating to " + uri, e);
×
138
    } catch (Exception e) {
×
139
      throw new IllegalStateException("Unexpected checked exception whilst communicating to " + uri, e);
×
140
    }
141
  }
142
}
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