public static String basedir()

in wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java [265:348]


    public static String basedir(String url) {
        String protocol = PathUtils.protocol(url);

        String retValue = null;

        if (protocol.equalsIgnoreCase("scm")) {
            // skip over SCM bits
            if (url.regionMatches(true, 0, "scm:svn:", 0, 8)) {
                url = url.substring(url.indexOf(":", 4) + 1);
                protocol = PathUtils.protocol(url);
            }
        }

        if (protocol.equalsIgnoreCase("file")) {
            retValue = url.substring(protocol.length() + 1);
            retValue = decode(retValue);
            // special case: if omitted // on protocol, keep path as is
            if (retValue.startsWith("//")) {
                retValue = retValue.substring(2);

                if (retValue.length() >= 2 && (retValue.charAt(1) == '|' || retValue.charAt(1) == ':')) {
                    // special case: if there is a windows drive letter, then keep the original return value
                    retValue = retValue.charAt(0) + ":" + retValue.substring(2);
                } else {
                    // Now we expect the host
                    int index = retValue.indexOf("/");
                    if (index >= 0) {
                        retValue = retValue.substring(index + 1);
                    }

                    // special case: if there is a windows drive letter, then keep the original return value
                    if (retValue.length() >= 2 && (retValue.charAt(1) == '|' || retValue.charAt(1) == ':')) {
                        retValue = retValue.charAt(0) + ":" + retValue.substring(2);
                    } else if (index >= 0) {
                        // leading / was previously stripped
                        retValue = "/" + retValue;
                    }
                }
            }

            // special case: if there is a windows drive letter using |, switch to :
            if (retValue.length() >= 2 && retValue.charAt(1) == '|') {
                retValue = retValue.charAt(0) + ":" + retValue.substring(2);
            }
        } else {
            final String authorization = PathUtils.authorization(url);

            final int port = PathUtils.port(url);

            int pos = 0;

            if (protocol.equalsIgnoreCase("scm")) {
                pos = url.indexOf(":", 4) + 1;
                pos = url.indexOf(":", pos) + 1;
            } else {
                int index = url.indexOf("://");
                if (index != -1) {
                    pos = index + 3;
                }
            }

            pos += authorization.length();

            if (port != WagonConstants.UNKNOWN_PORT) {
                pos = pos + Integer.toString(port).length() + 1;
            }

            if (url.length() > pos) {
                retValue = url.substring(pos);
                if (retValue.startsWith(":")) {
                    // this is for :/ after the host
                    retValue = retValue.substring(1);
                }

                // one module may be allowed in the path in CVS
                retValue = retValue.replace(':', '/');
            }
        }

        if (retValue == null) {
            retValue = "/";
        }
        return retValue.trim();
    }