Skip to content

Commit

Permalink
Merge branch 'main' into devonfw#589-fix-nls-bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeilex authored Nov 20, 2024
2 parents 428d3b6 + a7279d6 commit a2681cc
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions cli/src/main/java/com/devonfw/tools/ide/context/GitUrlSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,51 @@ public enum GitUrlSyntax {
/**
* The DEFAULT Git URL syntax
*/
DEFAULT(""),
DEFAULT("") {
@Override
public GitUrl format(GitUrl gitUrl) {
return gitUrl; // No conversion for DEFAULT
}
},
/**
* The SSH Git URL syntax (e.g., [email protected]:user/repo.git).
*/
SSH("git@"),
SSH("git@") {
@Override
public GitUrl format(GitUrl gitUrl) {
String url = gitUrl.url();
if (isDomainWithNoConversion(url.toLowerCase())) {
return gitUrl;
}
if (url.startsWith(HTTPS.prefix)) {
int index = url.indexOf("/", HTTPS.prefix.length());
if (index > 0) {
url = SSH.prefix + url.substring(HTTPS.prefix.length(), index) + ":" + url.substring(index + 1);
}
}
return new GitUrl(url, gitUrl.branch());
}
},

/**
* The HTTPS Git URL syntax (e.g., https://github.com/user/repo.git).
*/
HTTPS("https://");
HTTPS("https://") {
@Override
public GitUrl format(GitUrl gitUrl) {
String url = gitUrl.url();
if (isDomainWithNoConversion(url.toLowerCase())) {
return gitUrl;
}
if (url.startsWith(SSH.prefix)) {
int index = url.indexOf(":");
if (index > 0) {
url = HTTPS.prefix + url.substring(SSH.prefix.length(), index) + "/" + url.substring(index + 1);
}
}
return new GitUrl(url, gitUrl.branch());
}
};

private final String prefix;

Expand All @@ -40,41 +75,9 @@ public enum GitUrlSyntax {
* @return the formatted {@link GitUrl} according to this syntax.
* @throws IllegalArgumentException if the protocol is not supported.
*/
public GitUrl format(GitUrl gitUrl) {
if (this == DEFAULT) {
return gitUrl;
}
String url = gitUrl.url();

// Prevent conversion for domains in the no-conversion list
if (isDomainWithNoConversion(url.toLowerCase())) {
return gitUrl;
}

switch (this) {
case SSH -> {
if (url.startsWith(HTTPS.prefix)) {
int index = url.indexOf("/", HTTPS.prefix.length());
if (index > 0) {
url = SSH.prefix + url.substring(HTTPS.prefix.length(), index) + ":" + url.substring(index + 1);
}
}
}
case HTTPS -> {
if (url.startsWith(SSH.prefix)) {
int index = url.indexOf(":");
if (index > 0) {
url = HTTPS.prefix + url.substring(SSH.prefix.length(), index) + "/" + url.substring(index + 1);
}
}
}
default -> throw new IllegalArgumentException("Unsupported protocol: " + this);
}

return new GitUrl(url, gitUrl.branch());
}
public abstract GitUrl format(GitUrl gitUrl);

private boolean isDomainWithNoConversion(String url) {
private static boolean isDomainWithNoConversion(String url) {

for (String domain : DOMAINS_WITH_NO_CONVERSION) {
// Check if it's an HTTPS URL for the domain
Expand Down

0 comments on commit a2681cc

Please sign in to comment.