diff --git a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParser.java b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParser.java index 7ce83ee12e..6b416b48a5 100644 --- a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParser.java +++ b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParser.java @@ -51,6 +51,8 @@ public class AzureDevOpsURLParser { private final Pattern azureSSHDevOpsPattern; private final String azureSSHDevOpsPatternTemplate = "^git@ssh\\.%s:v3/(?.*)/(?.*)/(?.*)$"; + private final String azureSSHDevOpsServerPatternTemplate = + "^ssh://\\.%s(:d*)?/(?.*)/(?.*)/_git/(?.*)$"; private final String azureDevOpsPatternTemplate = "^https?://(?[^@]++)?@?%s/(?[^/]++)/((?[^/]++)/)?_git/" + "(?[^?]++)" @@ -71,15 +73,9 @@ public AzureDevOpsURLParser( this.azureDevOpsScmApiEndpointHost = trimEnd(azureDevOpsScmApiEndpoint, '/').replaceFirst("https?://", ""); this.azureDevOpsPattern = - compile( - format( - azureDevOpsPatternTemplate, - azureDevOpsScmApiEndpointHost)); + compile(format(azureDevOpsPatternTemplate, azureDevOpsScmApiEndpointHost)); this.azureSSHDevOpsPattern = - compile( - format( - azureSSHDevOpsPatternTemplate, - azureDevOpsScmApiEndpointHost)); + compile(format(azureSSHDevOpsPatternTemplate, azureDevOpsScmApiEndpointHost)); } public boolean isValid(@NotNull String url) { @@ -128,19 +124,17 @@ private Optional getServerUrl(String repositoryUrl) { } private Optional getPatternMatcherByUrl(String url) { - URI uri = - URI.create( - url.matches(format(azureSSHDevOpsPatternTemplate, ".*")) - ? "ssh://" + url.replace(":", "/") - : url); - String scheme = uri.getScheme(); - String host = uri.getHost(); - Matcher matcher = - compile(format(azureDevOpsPatternTemplate, scheme + "://" + host)).matcher(url); + String host = URI.create(url).getHost(); + Matcher matcher = compile(format(azureDevOpsPatternTemplate, host)).matcher(url); if (matcher.matches()) { return Optional.of(matcher); } else { matcher = compile(format(azureSSHDevOpsPatternTemplate, host)).matcher(url); + if (matcher.matches()) { + return Optional.of(matcher); + } else { + matcher = compile(format(azureSSHDevOpsServerPatternTemplate, host)).matcher(url); + } return matcher.matches() ? Optional.of(matcher) : Optional.empty(); } } @@ -164,7 +158,7 @@ public AzureDevOpsUrl parse(String url) { if (!matcher.matches()) { throw buildIllegalArgumentException(url); } - + String serverUrl = getServerUrl(url).orElseThrow(() -> buildIllegalArgumentException(url)); String repoName = matcher.group("repoName"); String project = matcher.group("project"); if (project == null) { @@ -203,6 +197,7 @@ public AzureDevOpsUrl parse(String url) { .withBranch(branch) .withTag(tag) .withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames()) + .withServerUrl(serverUrl) .withUrl(newUrl); } } diff --git a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsUrl.java b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsUrl.java index 6ae07240a6..3e1388f81f 100644 --- a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsUrl.java +++ b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsUrl.java @@ -43,6 +43,8 @@ public class AzureDevOpsUrl extends DefaultFactoryUrl { private String tag; + private String serverUrl; + private final List devfileFilenames = new ArrayList<>(); protected AzureDevOpsUrl() {} @@ -100,7 +102,7 @@ public AzureDevOpsUrl withBranch(String branch) { @Override public String getProviderUrl() { - return "https://" + hostName; + return isNullOrEmpty(serverUrl) ? "https://" + hostName : serverUrl; } protected AzureDevOpsUrl withDevfileFilenames(List devfileFilenames) { @@ -108,6 +110,11 @@ protected AzureDevOpsUrl withDevfileFilenames(List devfileFilenames) { return this; } + public AzureDevOpsUrl withServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + return this; + } + @Override public void setDevfileFilename(String devfileName) { this.devfileFilenames.clear();