Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created P4UserProperty to store Email address.
P4UserProperty extends UserProperty to store the Perforce User’s email. Then retrieves it with P4AddressResolver by extending MailAddressResolver. JENKINS-28421
- Loading branch information
Showing
4 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/jenkinsci/plugins/p4/email/P4AddressResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
package org.jenkinsci.plugins.p4.email; | |||
|
|||
import hudson.model.User; | |||
import hudson.tasks.MailAddressResolver; | |||
|
|||
import java.util.logging.Logger; | |||
|
|||
public class P4AddressResolver extends MailAddressResolver { | |||
|
|||
private static Logger logger = Logger.getLogger(P4AddressResolver.class | |||
.getName()); | |||
|
|||
@Override | |||
public String findMailAddressFor(User user) { | |||
P4UserProperty prop = user.getProperty(P4UserProperty.class); | |||
if (prop != null) { | |||
String id = user.getId(); | |||
String email = prop.getEmail(); | |||
logger.info("MailAddressResolver: " + id + ":" + email); | |||
return email; | |||
} | |||
return null; | |||
} | |||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/jenkinsci/plugins/p4/email/P4UserProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
package org.jenkinsci.plugins.p4.email; | |||
|
|||
import hudson.Extension; | |||
import hudson.Util; | |||
import hudson.model.UserProperty; | |||
import hudson.model.UserPropertyDescriptor; | |||
import hudson.model.User; | |||
import net.sf.json.JSONObject; | |||
|
|||
import org.kohsuke.stapler.DataBoundConstructor; | |||
import org.kohsuke.stapler.StaplerRequest; | |||
import org.kohsuke.stapler.export.Exported; | |||
|
|||
public class P4UserProperty extends UserProperty { | |||
|
|||
private final String email; | |||
|
|||
@DataBoundConstructor | |||
public P4UserProperty(String email) { | |||
this.email = Util.fixEmptyAndTrim(email); | |||
} | |||
|
|||
@Extension | |||
public static class DescriptorImpl extends UserPropertyDescriptor { | |||
|
|||
@Override | |||
public UserProperty newInstance(User user) { | |||
return new P4UserProperty(null); | |||
} | |||
|
|||
@Override | |||
public String getDisplayName() { | |||
return "Perforce User Property"; | |||
} | |||
|
|||
@Override | |||
public UserProperty | |||
newInstance(StaplerRequest req, JSONObject formData) | |||
throws FormException { | |||
return new P4UserProperty(formData.optString("email")); | |||
} | |||
} | |||
|
|||
@Exported | |||
public String getEmail() { | |||
return email; | |||
} | |||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/org/jenkinsci/plugins/p4/email/P4UserProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | |||
<f:entry title="Perforce Email" description="ReadOnly: Defined in the Perforce User spec."> | |||
<f:readOnlyTextbox field="email"/> | |||
</f:entry> | |||
</j:jelly> |