All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.SvnUrlWithUsernamePassword Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;

import com.databasesandlife.util.gwtsafe.ConfigurationException;

/**
 * Represents a SVN URL, username, password.
 *
 * @author This source is copyright Adrian Smith and licensed under the LGPL 3.
 * @see Project on GitHub
 */
public class SvnUrlWithUsernamePassword {

    public SVNURL url;
    public String username, password;

    /** @param pipeSeparated "url" or "url|username|password" */
    public static SvnUrlWithUsernamePassword parse(String pipeSeparated) throws ConfigurationException {
        var m = Pattern.compile("^([^|]+?)(\\|([^|]+)\\|([^|]+))?$").matcher(pipeSeparated);
        if (! m.matches()) throw new ConfigurationException("SVN '" + pipeSeparated + "' should have 'url|user|pw' form");
        try {
            var result = new SvnUrlWithUsernamePassword();
            result.url = SVNURL.parseURIEncoded(m.group(1));
            result.username = m.group(3);
            result.password = m.group(4);
            return result;
        }
        catch (SVNException e) { throw new ConfigurationException("SVN URL '" + m.group(1) + "' malformed: " + e.getMessage(), e); }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy