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

devonfw / IDEasy / 13327588889

14 Feb 2025 10:44AM UTC coverage: 67.947% (-0.5%) from 68.469%
13327588889

Pull #1021

github

web-flow
Merge d03159bfe into 52609dacb
Pull Request #1021: #786: support ide upgrade to automatically update to the latest version of IDEasy

2964 of 4791 branches covered (61.87%)

Branch coverage included in aggregate %.

7688 of 10886 relevant lines covered (70.62%)

3.07 hits per line

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

72.73
cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlChecksum.java
1
package com.devonfw.tools.ide.url.model.file;
2

3
import java.io.BufferedWriter;
4
import java.io.IOException;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import java.nio.file.StandardOpenOption;
8
import java.util.Iterator;
9
import java.util.Objects;
10

11
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
12
import com.devonfw.tools.ide.util.SingleElementIterator;
13

14
/**
15
 * {@link AbstractUrlFile} for the checksum of a binary download file.
16
 */
17
public class UrlChecksum extends AbstractUrlFile<UrlVersion> implements UrlGenericChecksum, UrlChecksums {
18

19
  /** The file extension of the checksum file (including the dot). */
20
  public static final String EXTENSION = ".sha256";
21

22
  /** The hash algorithm to use ({@value}). */
23
  public static final String HASH_ALGORITHM = "SHA-256";
24

25
  private String checksum;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param parent the {@link #getParent() parent folder}.
31
   * @param name the {@link #getName() filename}.
32
   */
33
  public UrlChecksum(UrlVersion parent, String name) {
34

35
    super(parent, name);
4✔
36
  }
1✔
37

38
  @Override
39
  public String getChecksum() {
40

41
    load(false);
3✔
42
    return this.checksum;
3✔
43
  }
44

45
  /**
46
   * @param checksum the new value of {@link #getChecksum()}.
47
   */
48
  public void setChecksum(String checksum) {
49

50
    if (Objects.equals(this.checksum, checksum)) {
5✔
51
      return;
1✔
52
    }
53
    this.checksum = checksum;
3✔
54
    this.modified = true;
3✔
55
  }
1✔
56

57
  @Override
58
  public String getHashAlgorithm() {
59

60
    return HASH_ALGORITHM;
×
61
  }
62

63
  @Override
64
  protected void doLoad() {
65

66
    Path path = getPath();
3✔
67
    try {
68
      String cs = Files.readString(path).trim();
4✔
69
      setChecksum(cs);
3✔
70
    } catch (IOException e) {
×
71
      throw new IllegalStateException("Failed to load file " + path, e);
×
72
    }
1✔
73
  }
1✔
74

75
  @Override
76
  protected void doSave() {
77

78
    if ((this.checksum == null) || this.checksum.isEmpty()) {
7!
79
      return;
×
80
    }
81
    Path path = getPath();
3✔
82
    try (BufferedWriter bw = Files.newBufferedWriter(path, StandardOpenOption.TRUNCATE_EXISTING,
17✔
83
        StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
84
      bw.write(this.checksum + "\n");
5✔
85

86
    } catch (IOException e) {
×
87
      throw new IllegalStateException("Failed to save file " + path, e);
×
88
    }
1✔
89
  }
1✔
90

91
  @Override
92
  public Iterator<UrlGenericChecksum> iterator() {
93

94
    return new SingleElementIterator<>(this);
×
95
  }
96

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