private String parseHostAndPort()

in maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java [351:383]


    private String parseHostAndPort(RepositoryUrl repoUrl, String url) throws ScmException {

        repoUrl.setPort("");
        repoUrl.setHost("");

        if (PROTOCOL_FILE.equals(repoUrl.getProtocol())) {
            // a file:// URL doesn't need any further parsing as it cannot contain a port, etc
            return url;
        } else {

            Matcher hostAndPortMatcher = HOST_AND_PORT_EXTRACTOR.matcher(url);
            if (hostAndPortMatcher.matches()) {
                if (hostAndPortMatcher.groupCount() > 1 && hostAndPortMatcher.group(1) != null) {
                    repoUrl.setHost(hostAndPortMatcher.group(1));
                }
                if (hostAndPortMatcher.groupCount() > 2 && hostAndPortMatcher.group(2) != null) {
                    repoUrl.setPort(hostAndPortMatcher.group(2));
                }

                StringBuilder computedUrl = new StringBuilder();
                if (hostAndPortMatcher.group(hostAndPortMatcher.groupCount() - 1) != null) {
                    computedUrl.append(hostAndPortMatcher.group(hostAndPortMatcher.groupCount() - 1));
                }
                if (hostAndPortMatcher.group(hostAndPortMatcher.groupCount()) != null) {
                    computedUrl.append(hostAndPortMatcher.group(hostAndPortMatcher.groupCount()));
                }
                return computedUrl.toString();
            } else {
                // Pattern doesn't match, let's return the original url
                return url;
            }
        }
    }