• 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

5.88
cli/src/main/java/com/devonfw/tools/ide/tool/docker/Docker.java
1
package com.devonfw.tools.ide.tool.docker;
2

3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Set;
6
import java.util.regex.Pattern;
7

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

11
import com.devonfw.tools.ide.common.Tag;
12
import com.devonfw.tools.ide.context.IdeContext;
13
import com.devonfw.tools.ide.os.SystemArchitecture;
14
import com.devonfw.tools.ide.os.WindowsHelper;
15
import com.devonfw.tools.ide.tool.GlobalToolCommandlet;
16
import com.devonfw.tools.ide.tool.NativePackageManager;
17
import com.devonfw.tools.ide.tool.PackageManagerCommand;
18
import com.devonfw.tools.ide.tool.repository.ToolRepository;
19
import com.devonfw.tools.ide.version.VersionIdentifier;
20

21
/**
22
 * {@link GlobalToolCommandlet} for <a href="https://www.docker.com/">docker</a> either as
23
 * <a href="https://rancherdesktop.io/">Rancher Desktop</a> or as
24
 * <a href="https://www.docker.com/products/docker-desktop/">Docker Desktop</a>.
25
 */
26
public class Docker extends GlobalToolCommandlet {
27

28
  private static final Logger LOG = LoggerFactory.getLogger(Docker.class);
3✔
29

30
  private static final String PODMAN = "podman";
31

32
  private static final Pattern RDCTL_CLIENT_VERSION_PATTERN = Pattern.compile("client version:\\s*v([\\d.]+)", Pattern.CASE_INSENSITIVE);
4✔
33

34
  private static final Pattern DOCKER_DESKTOP_LINUX_VERSION_PATTERN = Pattern.compile("^([0-9]+(?:\\.[0-9]+){1,2})");
4✔
35

36
  /**
37
   * The constructor.
38
   *
39
   * @param context the {@link IdeContext}.
40
   */
41
  public Docker(IdeContext context) {
42

43
    super(context, "docker", Set.of(Tag.DOCKER));
6✔
44
  }
1✔
45

46
  @Override
47
  public String getBinaryName() {
48
    return detectContainerRuntime();
×
49
  }
50

51
  private boolean isDockerInstalled() {
52
    return isCommandAvailable("docker");
×
53
  }
54

55
  private boolean isRancherDesktopInstalled() {
56
    return isCommandAvailable("rdctl");
×
57
  }
58

59
  private String detectContainerRuntime() {
60
    if (isCommandAvailable(this.tool)) {
×
61
      return this.tool;
×
62
    } else if (isCommandAvailable(PODMAN)) {
×
63
      return PODMAN;
×
64
    } else {
65
      return this.tool;
×
66
    }
67
  }
68

69
  @Override
70
  public boolean isExtract() {
71

72
    return switch (this.context.getSystemInfo().getOs()) {
×
73
      case WINDOWS -> false;
×
74
      case MAC -> this.context.getSystemInfo().getArchitecture().equals(SystemArchitecture.ARM64);
×
75
      case LINUX -> true;
×
76
    };
77
  }
78

79
  @Override
80
  protected List<PackageManagerCommand> getInstallPackageManagerCommands() {
81

82
    String edition = getConfiguredEdition();
×
83
    ToolRepository toolRepository = getToolRepository();
×
84
    VersionIdentifier configuredVersion = getConfiguredVersion();
×
85
    String resolvedVersion = toolRepository.resolveVersion(this.tool, edition, configuredVersion, this).toString();
×
86

87
    return List.of(new PackageManagerCommand(NativePackageManager.ZYPPER, List.of(
×
88
            "sudo zypper addrepo https://download.opensuse.org/repositories/isv:/Rancher:/stable/rpm/isv:Rancher:stable.repo",
89
            String.format("sudo zypper --no-gpg-checks install rancher-desktop=%s*", resolvedVersion))),
×
90
        new PackageManagerCommand(NativePackageManager.APT, List.of(
×
91
            "curl -s https://download.opensuse.org/repositories/isv:/Rancher:/stable/deb/Release.key | gpg --dearmor |"
92
                + " sudo dd status=none of=/usr/share/keyrings/isv-rancher-stable-archive-keyring.gpg",
93
            "echo 'deb [signed-by=/usr/share/keyrings/isv-rancher-stable-archive-keyring.gpg]"
94
                + " https://download.opensuse.org/repositories/isv:/Rancher:/stable/deb/ ./' |"
95
                + " sudo dd status=none of=/etc/apt/sources.list.d/isv-rancher-stable.list", "sudo apt update",
96
            String.format("sudo apt install -y --allow-downgrades rancher-desktop=%s*", resolvedVersion))));
×
97
  }
98

99
  @Override
100
  public VersionIdentifier getInstalledVersion() {
101

102
    if (!isDockerInstalled()) {
×
103
      LOG.error("Couldn't get installed version of " + this.getName());
×
104
      return null;
×
105
    }
106

107
    if (isRancherDesktopInstalled()) {
×
108
      return getRancherDesktopClientVersion();
×
109
    } else {
110
      VersionIdentifier parsedVersion = switch (this.context.getSystemInfo().getOs()) {
×
111
        case WINDOWS -> getDockerDesktopVersionWindows();
×
112
        case LINUX -> getDockerDesktopVersionLinux();
×
113
        default -> null;
×
114
      };
115

116
      if (parsedVersion == null) {
×
117
        LOG.error("Couldn't get installed version of " + this.getName());
×
118
      }
119

120
      return parsedVersion;
×
121
    }
122
  }
123

124
  private VersionIdentifier getDockerDesktopVersionWindows() {
125

126
    String registryPath = "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Docker Desktop";
×
127

128
    WindowsHelper windowsHelper = ((com.devonfw.tools.ide.context.AbstractIdeContext) this.context).getWindowsHelper();
×
129
    String version = windowsHelper.getRegistryValue(registryPath, "DisplayVersion");
×
130

131
    return VersionIdentifier.of(version);
×
132
  }
133

134
  private VersionIdentifier getDockerDesktopVersionLinux() {
135

136
    String dockerDesktopVersionLinuxCommand = "apt list --installed | grep docker-desktop | awk '{print $2}'";
×
137
    String output = this.context.newProcess().runAndGetSingleOutput("bash", "-lc", dockerDesktopVersionLinuxCommand);
×
138
    return super.resolveVersionWithPattern(output, DOCKER_DESKTOP_LINUX_VERSION_PATTERN);
×
139
  }
140

141
  private VersionIdentifier getRancherDesktopClientVersion() {
142

143
    String output = this.context.newProcess().runAndGetSingleOutput("rdctl", "version");
×
144
    return super.resolveVersionWithPattern(output, RDCTL_CLIENT_VERSION_PATTERN);
×
145
  }
146

147
  @Override
148
  public String getInstalledEdition() {
149

150
    if (!isDockerInstalled()) {
×
151
      LOG.error("Couldn't get installed edition of {}", this.getName());
×
152
      return null;
×
153
    }
154

155
    if (isRancherDesktopInstalled()) {
×
156
      return "rancher";
×
157
    } else {
158
      return "desktop";
×
159
    }
160
  }
161

162
  @Override
163
  public void uninstall() {
164

165
    if (this.context.getSystemInfo().isLinux()) {
×
166
      runWithPackageManager(false, getPackageManagerCommandsUninstall());
×
167
    } else {
168
      super.uninstall();
×
169
    }
170

171
  }
×
172

173
  private List<PackageManagerCommand> getPackageManagerCommandsUninstall() {
174

175
    List<PackageManagerCommand> pmCommands = new ArrayList<>();
×
176
    pmCommands.add(
×
177
        new PackageManagerCommand(NativePackageManager.ZYPPER, List.of("sudo zypper remove rancher-desktop")));
×
178
    pmCommands.add(
×
179
        new PackageManagerCommand(NativePackageManager.APT, List.of("sudo apt -y autoremove rancher-desktop")));
×
180

181
    return pmCommands;
×
182
  }
183

184
  @Override
185
  public String getToolHelpArguments() {
186

187
    return "help";
×
188
  }
189
}
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