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

devonfw / IDEasy / 10164154193

30 Jul 2024 02:20PM UTC coverage: 62.742% (+1.0%) from 61.738%
10164154193

push

github

web-flow
#437: and #458: Refactor JsonUrlUpdaters (#481)

2079 of 3645 branches covered (57.04%)

Branch coverage included in aggregate %.

5504 of 8441 relevant lines covered (65.21%)

2.87 hits per line

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

86.27
cli/src/main/java/com/devonfw/tools/ide/tool/python/PythonUrlUpdater.java
1
package com.devonfw.tools.ide.tool.python;
2

3
import java.util.Collection;
4
import java.util.List;
5

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

9
import com.devonfw.tools.ide.json.mapping.JsonMapping;
10
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
11
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
12
import com.devonfw.tools.ide.url.model.folder.UrlTool;
13
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
14
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;
15
import com.fasterxml.jackson.databind.ObjectMapper;
16

17
/**
18
 * The {@Link JsonUrlUpdater} for Python
19
 */
20
public class PythonUrlUpdater extends JsonUrlUpdater<PythonJsonObject, PythonRelease> {
2✔
21

22
  /**
23
   * The base Url of the Python versions Json
24
   */
25
  private String VERSION_BASE_URL = "https://raw.githubusercontent.com";
4✔
26

27
  private final static String VERSION_FILENAME = "actions/python-versions/main/versions-manifest.json";
28

29
  final static ObjectMapper MAPPER = JsonMapping.create();
2✔
30

31
  private static final Logger logger = LoggerFactory.getLogger(PythonUrlUpdater.class);
4✔
32

33
  @Override
34
  protected String getTool() {
35

36
    return "python";
2✔
37
  }
38

39
  @Override
40
  protected void addVersion(UrlVersion urlVersion, PythonRelease release) {
41

42
    String version = release.version();
3✔
43

44
    try {
45
      for (PythonFile download : release.files()) {
11✔
46
        if (download.getPlatform().equals("win32") && download.getArch().equals("x64")) {
10✔
47
          doAddVersion(urlVersion, download.getDownloadUrl(), WINDOWS, X64);
9✔
48
        } else if (download.getPlatform().equals("linux") && download.getArch().equals("x64")) {
10!
49
          doAddVersion(urlVersion, download.getDownloadUrl(), LINUX, X64);
9✔
50
        } else if (download.getPlatform().equals("darwin") && download.getArch().equals("arm64")) {
10✔
51
          doAddVersion(urlVersion, download.getDownloadUrl(), MAC, ARM64);
9✔
52
        } else {
53
          logger.info("Unknown architecture for tool {} version {} and download {}.", getToolWithEdition(), version,
17✔
54
              download.getDownloadUrl());
2✔
55
        }
56
      }
1✔
57
      urlVersion.save();
2✔
58
    } catch (Exception exp) {
×
59
      logger.error("For tool {} we failed to add version {}.", getToolWithEdition(), version, exp);
×
60
    }
1✔
61
  }
1✔
62

63
  /**
64
   * @return String of version base Url
65
   */
66
  protected String getVersionBaseUrl() {
67

68
    return this.VERSION_BASE_URL;
×
69
  }
70

71
  @Override
72
  protected String doGetVersionUrl() {
73

74
    return getVersionBaseUrl() + "/" + VERSION_FILENAME;
4✔
75
  }
76

77
  @Override
78
  protected Class<PythonJsonObject> getJsonObjectType() {
79

80
    return PythonJsonObject.class;
×
81
  }
82

83
  @Override
84
  public void update(UrlRepository urlRepository) {
85

86
    UrlTool tool = urlRepository.getOrCreateChild(getTool());
6✔
87
    UrlEdition edition = tool.getOrCreateChild(getEdition());
6✔
88
    updateExistingVersions(edition);
3✔
89
    try {
90
      String response = doGetResponseBodyAsString(doGetVersionUrl());
5✔
91

92
      PythonRelease[] res = MAPPER.readValue(response, PythonRelease[].class);
6✔
93

94
      PythonJsonObject jsonObj = new PythonJsonObject();
4✔
95
      jsonObj.setReleases(List.of(res));
4✔
96

97
      collectVersionsWithDownloadsFromJson(jsonObj, edition);
4✔
98

99
    } catch (Exception e) {
×
100
      throw new IllegalStateException("Error while getting versions from JSON API " + doGetVersionUrl(), e);
×
101
    }
1✔
102
  }
1✔
103

104
  @Override
105
  protected Collection<PythonRelease> getVersionItems(PythonJsonObject jsonObject) {
106

107
    return jsonObject.getReleases();
3✔
108
  }
109

110
}
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