Skip to content
Permalink
Browse files

Fix JENKINS-28212

Serialize the descriptor id's instead of the descriptors themselves.
  • Loading branch information...
slide committed May 13, 2015
1 parent d5af533 commit faac7b4b7da32c1c45748629631a76989628a3cb
@@ -165,11 +165,11 @@ public static void addAddressesFromRecipientList(Set<InternetAddress> to, Set<In
try {
Set<InternetAddress> internetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.TO);
to.addAll(internetAddresses);
if(bcc != null) {
if(bcc != null && bcc.size() > 0) {
Set<InternetAddress> bccInternetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.BCC);
bcc.addAll(bccInternetAddresses);
}
if(cc != null) {
if(cc != null && cc.size() > 0) {
Set<InternetAddress> ccInternetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.CC);
cc.addAll(ccInternetAddresses);
}
@@ -101,8 +101,10 @@

private List<GroovyScriptPath> defaultClasspath = new ArrayList<GroovyScriptPath>();

private List<EmailTriggerDescriptor> defaultTriggers = new ArrayList<EmailTriggerDescriptor>();

private transient List<EmailTriggerDescriptor> defaultTriggers = new ArrayList<EmailTriggerDescriptor>();

private List<String> defaultTriggerIds = new ArrayList<String>();

/**
* This is the global emergency email address
*/
@@ -330,11 +332,11 @@ public String getDefaultPresendScript() {
return defaultClasspath;
}

public List<EmailTriggerDescriptor> getDefaultTriggers() {
if(defaultTriggers.isEmpty()) {
defaultTriggers.add((EmailTriggerDescriptor)Jenkins.getInstance().getDescriptor(FailureTrigger.class));
public List<String> getDefaultTriggerIds() {
if(defaultTriggerIds.isEmpty()) {
defaultTriggerIds.add(Jenkins.getInstance().getDescriptor(FailureTrigger.class).getId());
}
return defaultTriggers;
return defaultTriggerIds;
}

public ExtendedEmailPublisherDescriptor() {
@@ -416,23 +418,21 @@ public boolean configure(StaplerRequest req, JSONObject formData)
listId = null;
}

List<String> classes = new ArrayList<String>();
List<String> ids = new ArrayList<String>();
if(formData.optJSONArray("defaultTriggers") != null) {
for(Object tName : formData.getJSONArray("defaultTriggers")) {
String triggerName = tName.toString();
classes.add(triggerName);
for(Object id : formData.getJSONArray("defaultTriggers")) {
ids.add(id.toString());
}
} else if(StringUtils.isNotEmpty(formData.optString("defaultTriggers"))) {
String triggerName = formData.getString("defaultTriggers");
classes.add(triggerName);
ids.add(formData.getString("defaultTriggers"));
}

if(!classes.isEmpty()) {
defaultTriggers.clear();
for(String triggerName : classes) {
EmailTriggerDescriptor d = (EmailTriggerDescriptor)Jenkins.getInstance().getDescriptorByName(triggerName);
if(!ids.isEmpty()) {
defaultTriggerIds.clear();
for(String id : ids) {
EmailTriggerDescriptor d = (EmailTriggerDescriptor)Jenkins.getInstance().getDescriptor(id);
if(d != null) {
defaultTriggers.add(d);
defaultTriggerIds.add(id);
}
}
}
@@ -447,7 +447,7 @@ private String nullify(String v) {
}
return v;
}

public Object readResolve() {
if (!this.overrideGlobalSettings) {
// need to get the plugin info from Mailer
@@ -463,6 +463,16 @@ public Object readResolve() {
this.charset = Mailer.descriptor().getCharset();
this.overrideGlobalSettings = true;
}

if(!this.defaultTriggers.isEmpty()) {
defaultTriggerIds.clear();
for(EmailTriggerDescriptor t : this.defaultTriggers) {
if(!defaultTriggerIds.contains(t.getId())) {
defaultTriggerIds.add(t.getId());
}
}
}

return this;
}

@@ -76,13 +76,12 @@ f.advanced(title: _("Advanced Settings")) {
if(instance != null) {
configuredTriggers = instance.configuredTriggers
} else {
jenkins.model.Jenkins.instance.getDescriptor(hudson.plugins.emailext.ExtendedEmailPublisher).defaultTriggers.each { t ->
configuredTriggers << t.createDefault()
jenkins.model.Jenkins.instance.getDescriptor(hudson.plugins.emailext.ExtendedEmailPublisher).defaultTriggerIds.each { t ->
def desc = jenkins.model.Jenkins.instance.getDescriptor(t)
configuredTriggers << desc.createDefault()
}
}

//def configuredTriggers = instance != null ? instance.configuredTriggers : [jenkins.model.Jenkins.instance.getDescriptor(hudson.plugins.emailext.plugins.trigger.FailureTrigger.class).createDefault()]

f.entry(title: _("Triggers"), help: "/plugin/email-ext/help/projectConfig/addATrigger.html") {
f.hetero_list(name: "project_triggers", hasHeader: true, descriptors: triggers, items: configuredTriggers, addCaption:_("Add Trigger"), deleteCaption: _("Remove Trigger"))
}
@@ -88,7 +88,7 @@ f.section(title: _("Extended E-mail Notification")) {
f.advanced(title: _("Default Triggers")) {
f.entry(title: _("Default Triggers"), help: "/plugin/email-ext/help/globalConfig/defaultTriggers.html") {
hudson.plugins.emailext.plugins.EmailTrigger.all().each { t ->
f.checkbox(name: "defaultTriggers", title: t.displayName, checked: descriptor.defaultTriggers.contains(t), json: t.clazz.name)
f.checkbox(name: "defaultTriggers", title: t.displayName, checked: descriptor.defaultTriggerIds.contains(t.id), json: t.id)
br()
}
}

2 comments on commit faac7b4

@jglick

This comment has been minimized.

Copy link
Member

jglick replied May 14, 2015

I have to say this is still pretty odd. I would expect defaultTriggers to be a List<EmailTrigger>, rather than relying on createDefault().

@slide

This comment has been minimized.

Copy link
Member Author

slide replied May 14, 2015

There was a reason I didn't do it that way, but I don't remember what it was. I have to have a createDefault at some level though because the triggers themselves can have a different constructor for additional UI elements. So, I can't just call the constructor with known parameters, especially since other plugins can provide EmailTrigger implementations via Extensions.

Please sign in to comment.
You can’t perform that action at this time.