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

devonfw / IDEasy / 11939433873

20 Nov 2024 06:23PM UTC coverage: 67.239% (-0.01%) from 67.249%
11939433873

push

github

web-flow
#750: Created method implementation for each enum constant (#762)

2457 of 3996 branches covered (61.49%)

Branch coverage included in aggregate %.

6395 of 9169 relevant lines covered (69.75%)

3.08 hits per line

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

84.0
cli/src/main/java/com/devonfw/tools/ide/context/GitUrlSyntax.java
1
package com.devonfw.tools.ide.context;
2

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

6
/**
7
 * Enum representing the syntax of Git URLs, either SSH or HTTPS. Provides methods to format and convert Git URLs based on the syntax.
8
 */
9
public enum GitUrlSyntax {
2✔
10

11
  /**
12
   * The DEFAULT Git URL syntax
13
   */
14
  DEFAULT("") {
13✔
15
    @Override
16
    public GitUrl format(GitUrl gitUrl) {
17
      return gitUrl; // No conversion for DEFAULT
2✔
18
    }
19
  },
20
  /**
21
   * The SSH Git URL syntax (e.g., git@github.com:user/repo.git).
22
   */
23
  SSH("git@") {
13✔
24
    @Override
25
    public GitUrl format(GitUrl gitUrl) {
26
      String url = gitUrl.url();
3✔
27
      if (isDomainWithNoConversion(url.toLowerCase())) {
4✔
28
        return gitUrl;
2✔
29
      }
30
      if (url.startsWith(HTTPS.prefix)) {
5!
31
        int index = url.indexOf("/", HTTPS.prefix.length());
7✔
32
        if (index > 0) {
2!
33
          url = SSH.prefix + url.substring(HTTPS.prefix.length(), index) + ":" + url.substring(index + 1);
15✔
34
        }
35
      }
36
      return new GitUrl(url, gitUrl.branch());
7✔
37
    }
38
  },
39

40
  /**
41
   * The HTTPS Git URL syntax (e.g., https://github.com/user/repo.git).
42
   */
43
  HTTPS("https://") {
13✔
44
    @Override
45
    public GitUrl format(GitUrl gitUrl) {
46
      String url = gitUrl.url();
3✔
47
      if (isDomainWithNoConversion(url.toLowerCase())) {
4!
48
        return gitUrl;
×
49
      }
50
      if (url.startsWith(SSH.prefix)) {
5!
51
        int index = url.indexOf(":");
4✔
52
        if (index > 0) {
2!
53
          url = HTTPS.prefix + url.substring(SSH.prefix.length(), index) + "/" + url.substring(index + 1);
15✔
54
        }
55
      }
56
      return new GitUrl(url, gitUrl.branch());
7✔
57
    }
58
  };
59

60
  private final String prefix;
61

62
  private static final List<String> DOMAINS_WITH_NO_CONVERSION = Arrays.asList("github.com");
9✔
63

64
  GitUrlSyntax(String prefix) {
4✔
65
    this.prefix = prefix;
3✔
66
  }
1✔
67

68
  /**
69
   * Formats the given Git URL according to the syntax represented by this enum constant.
70
   * <p>
71
   * Converts the URL between SSH and HTTPS formats. For example, an HTTPS URL can be converted to its corresponding SSH URL format, and vice versa.
72
   * </p>
73
   *
74
   * @param gitUrl the original {@link GitUrl} to be formatted.
75
   * @return the formatted {@link GitUrl} according to this syntax.
76
   * @throws IllegalArgumentException if the protocol is not supported.
77
   */
78
  public abstract GitUrl format(GitUrl gitUrl);
79

80
  private static boolean isDomainWithNoConversion(String url) {
81

82
    for (String domain : DOMAINS_WITH_NO_CONVERSION) {
10✔
83
      // Check if it's an HTTPS URL for the domain
84
      if (url.startsWith("https://" + domain + "/")) {
5✔
85
        return true;
2✔
86
      }
87

88
      // Check if it's an SSH URL for the domain
89
      if (url.startsWith("git@" + domain + ":")) {
5!
90
        return true;
×
91
      }
92
    }
1✔
93

94
    return false;
2✔
95
  }
96

97

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

© 2025 Coveralls, Inc