hudson.scm.SubversionMailAddressResolverImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of subversion Show documentation
Show all versions of subversion Show documentation
Integrates Hudson with Subversion SCM
package hudson.scm;
import hudson.tasks.MailAddressResolver;
import hudson.Extension;
import hudson.model.User;
import hudson.model.AbstractProject;
import java.util.Map;
import java.util.HashMap;
import java.util.regex.Pattern;
/**
* {@link MailAddressResolver} that checks for well-known repositories that and computes user e-mail address.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class SubversionMailAddressResolverImpl extends MailAddressResolver {
public String findMailAddressFor(User u) {
for (AbstractProject,?> p : u.getProjects()) {
SCM scm = p.getScm();
if (scm instanceof SubversionSCM) {
SubversionSCM svn = (SubversionSCM) scm;
for (SubversionSCM.ModuleLocation loc : svn.getLocations(p.getLastBuild())) {
String s = findMailAddressFor(u,loc.remote);
if(s!=null) return s;
}
}
}
// didn't hit any known rules
return null;
}
/**
*
* @param scm
* String that represents SCM connectivity.
*/
protected String findMailAddressFor(User u, String scm) {
for (Map.Entry e : RULE_TABLE.entrySet())
if(e.getKey().matcher(scm).matches())
return u.getId()+e.getValue();
return null;
}
private static final Map RULE_TABLE = new HashMap();
static {
{// java.net
Pattern svnurl = Pattern.compile("https://[^.]+.dev.java.net/svn/([^/]+)(/.*)?");
RULE_TABLE.put(svnurl,"@dev.java.net");
}
{// source forge
Pattern svnUrl = Pattern.compile("(http|https)://[^.]+.svn.(sourceforge|sf).net/svnroot/([^/]+)(/.*)?");
RULE_TABLE.put(svnUrl,"@users.sourceforge.net");
}
// TODO: read some file under $HUDSON_HOME?
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy