private String getUrl()

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 [218:277]


    private String getUrl(RepositoryUrl repoUrl) {
        StringBuilder urlSb = new StringBuilder(repoUrl.getProtocol());
        boolean urlSupportsUserInformation = false;

        if (PROTOCOL_SSH.equals(repoUrl.getProtocol())
                || PROTOCOL_RSYNC.equals(repoUrl.getProtocol())
                || PROTOCOL_GIT.equals(repoUrl.getProtocol())
                || PROTOCOL_HTTP.equals(repoUrl.getProtocol())
                || PROTOCOL_HTTPS.equals(repoUrl.getProtocol())
                || PROTOCOL_NONE.equals(repoUrl.getProtocol())) {
            urlSupportsUserInformation = true;
        }

        if (repoUrl.getProtocol() != null && repoUrl.getProtocol().length() > 0) {
            urlSb.append("://");
        }

        // add user information if given and allowed for the protocol
        if (urlSupportsUserInformation) {
            String userName = repoUrl.getUserName();
            // if specified on the commandline or other configuration, we take this.
            if (getUser() != null && getUser().length() > 0) {
                userName = getUser();
            }

            String password = repoUrl.getPassword();
            if (getPassword() != null && getPassword().length() > 0) {
                password = getPassword();
            }

            if (userName != null && userName.length() > 0) {
                String userInfo = userName;
                if (password != null && password.length() > 0) {
                    userInfo += ":" + password;
                }

                try {
                    URI uri = new URI(null, userInfo, "localhost", -1, null, null, null);
                    urlSb.append(uri.getRawUserInfo());
                } catch (URISyntaxException e) {
                    // Quite impossible...
                    // Otherwise throw a RTE since this method is also used by toString()
                    e.printStackTrace();
                }

                urlSb.append('@');
            }
        }

        // add host and port information
        urlSb.append(repoUrl.getHost());
        if (repoUrl.getPort() != null && repoUrl.getPort().length() > 0) {
            urlSb.append(':').append(repoUrl.getPort());
        }

        // finaly we add the path to the repo on the host
        urlSb.append(repoUrl.getPath());

        return urlSb.toString();
    }