forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw#750: Created method implementation for each enum constant
Removed switch and created a method implementation for each enum constant instead and made it abstract
- Loading branch information
1 parent
2b473ff
commit eb9c1e0
Showing
1 changed file
with
33 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,45 @@ 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 (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 (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; | ||
|
||
|
@@ -40,39 +69,7 @@ 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) { | ||
|
||
|