Skip to content
Permalink
Browse files

JENKINS-35365 EMail-Ext Extended Pipeline Support - Recipient Providers

fix for no options showing up on pipeline-syntax page
  • Loading branch information
davidvanlaatum committed Jun 13, 2016
1 parent c44674c commit 9982aea8c2d450ce547ac1480c23414382d2e839
@@ -132,6 +132,12 @@
<artifactId>workflow-step-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
@@ -6,6 +6,7 @@
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.RecipientProvider;
import hudson.plugins.emailext.plugins.RecipientProviderDescriptor;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution;
@@ -31,6 +32,7 @@ public EmailExtRecipientStep(List<RecipientProvider> recipientProviders) {
return recipientProviders;
}

@SuppressWarnings("WeakerAccess")
public static class Executor extends AbstractSynchronousNonBlockingStepExecution<String> {
private static final long serialVersionUID = 1L;

@@ -48,9 +50,13 @@ public EmailExtRecipientStep(List<RecipientProvider> recipientProviders) {

@Override
protected String run() throws Exception {
if (step.recipientProviders == null || step.recipientProviders.isEmpty()) {
throw new IllegalArgumentException("You must provide at least one recipient provider");
}
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, run, null, null, listener);
Set<InternetAddress> to = new HashSet<>();
RecipientProvider.checkAllSupport(step.recipientProviders, run.getParent().getClass());
for (RecipientProvider provider : step.recipientProviders) {
provider.addRecipients(context, env, to, to, to);
}
@@ -87,7 +93,7 @@ public String getDisplayName() {

@SuppressWarnings("unused")
public List<RecipientProviderDescriptor> getRecipientProvidersDescriptors() {
return RecipientProvider.allSupporting("org.jenkinsci.plugins.workflow.job.WorkflowJob");
return RecipientProvider.allSupporting(WorkflowJob.class);
}
}
}
@@ -15,6 +15,7 @@
import hudson.plugins.emailext.plugins.trigger.AlwaysTrigger;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution;
@@ -151,6 +152,7 @@ protected Void run() throws Exception {
AlwaysTrigger.DescriptorImpl descriptor = Jenkins.getActiveInstance().getDescriptorByType(AlwaysTrigger.DescriptorImpl.class);
EmailTrigger trigger = descriptor.createDefault();
if (step.recipientProviders != null) {
RecipientProvider.checkAllSupport(step.recipientProviders, run.getParent().getClass());
trigger.getEmail().addRecipientProviders(step.recipientProviders);
}
publisher.configuredTriggers.add(trigger);
@@ -208,7 +210,7 @@ public String getDisplayName() {

@SuppressWarnings("unused")
public List<RecipientProviderDescriptor> getRecipientProvidersDescriptors() {
return RecipientProvider.allSupporting("org.jenkinsci.plugins.workflow.job.WorkflowJob");
return RecipientProvider.allSupporting(WorkflowJob.class);
}
}
}
@@ -5,20 +5,26 @@
import hudson.model.Job;
import hudson.plugins.emailext.ExtendedEmailPublisherContext;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.mail.internet.InternetAddress;

import hudson.DescriptorExtensionList;
import hudson.model.AbstractDescribableImpl;
import jenkins.model.Jenkins;
import org.jsoup.helper.StringUtil;

/**
* Created by acearl on 12/24/13.
*/
public abstract class RecipientProvider extends AbstractDescribableImpl<RecipientProvider> implements ExtensionPoint {
private static final Logger LOG = Logger.getLogger(RecipientProvider.class.getName());

public static DescriptorExtensionList<RecipientProvider, RecipientProviderDescriptor> all() {
return Jenkins.getActiveInstance().getDescriptorList(RecipientProvider.class);
@@ -27,19 +33,30 @@
public static List<RecipientProviderDescriptor> allSupporting(Class<? extends Job> clazz) {
List<RecipientProviderDescriptor> rt = new ArrayList<>();
for (RecipientProviderDescriptor recipientProviderDescriptor : all()) {
if (recipientProviderDescriptor.isApplicable(clazz)) {
rt.add(recipientProviderDescriptor);
try {
if (recipientProviderDescriptor.isApplicable(clazz)) {
rt.add(recipientProviderDescriptor);
}
} catch (Exception ex) {
LOG.log(Level.WARNING, MessageFormat.format("Exception checking if {0} supports {1}, skipping",
recipientProviderDescriptor.getDisplayName(), clazz.getName()), ex);
}
}
return rt;
}

@SuppressWarnings("unchecked")
public static List<RecipientProviderDescriptor> allSupporting(String clazz) {
try {
return allSupporting((Class<? extends Job>) Class.forName(clazz));
} catch (ClassNotFoundException e) {
return Collections.emptyList();
public static void checkAllSupport(@Nonnull List<? extends RecipientProvider> providers, Class<? extends Job> clazz) {
Set<String> notSupported = new TreeSet<>();
for (RecipientProvider provider : providers) {
if (!provider.getDescriptor().isApplicable(clazz)) {
notSupported.add(provider.getClass().getName());
}
}

if (!notSupported.isEmpty()) {
throw new IllegalArgumentException(MessageFormat.
format("The following recipient providers do not support {0} {1}", clazz.getName(),
StringUtil.join(notSupported, ", ")));
}
}

0 comments on commit 9982aea

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