Skip to content

Commit

Permalink
Fix JENKINS-13563
Browse files Browse the repository at this point in the history
Added support for content tokens in the attachments area. The
generated string must still be an ANT pattern.
  • Loading branch information
slide committed Jun 1, 2012
1 parent 5fc0aab commit 9c0b900
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/main/java/hudson/plugins/emailext/AttachmentUtils.java
Expand Up @@ -7,6 +7,10 @@
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;

import hudson.plugins.emailext.plugins.ContentBuilder;

import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -67,7 +71,7 @@ public String getName() {
}
}

private List<MimeBodyPart> getAttachments(final AbstractBuild<?, ?> build, final BuildListener listener)
private List<MimeBodyPart> getAttachments(ExtendedEmailPublisher publisher, final AbstractBuild<?, ?> build, final BuildListener listener)
throws MessagingException, InterruptedException, IOException {
List<MimeBodyPart> attachments = null;
FilePath ws = build.getWorkspace();
Expand All @@ -76,9 +80,10 @@ private List<MimeBodyPart> getAttachments(final AbstractBuild<?, ?> build, final
ExtendedEmailPublisher.DESCRIPTOR.getMaxAttachmentSize();
if(ws == null) {
listener.error("Error: No workspace found!");
} else if(attachmentsPattern != null && attachmentsPattern.trim().length() > 0) {
} else if(!StringUtils.isBlank(attachmentsPattern)) {
attachments = new ArrayList<MimeBodyPart>();
FilePath[] files = ws.list(attachmentsPattern);

FilePath[] files = ws.list(new ContentBuilder().transformText(attachmentsPattern, publisher, null, build, listener));

for(FilePath file : files) {
if(maxAttachmentSize > 0 &&
Expand Down Expand Up @@ -107,9 +112,9 @@ private List<MimeBodyPart> getAttachments(final AbstractBuild<?, ?> build, final
return attachments;
}

public void attach(Multipart multipart, AbstractBuild<?,?> build, BuildListener listener) {
public void attach(Multipart multipart, ExtendedEmailPublisher publisher, AbstractBuild<?,?> build, BuildListener listener) {
try {
List<MimeBodyPart> attachments = getAttachments(build, listener);
List<MimeBodyPart> attachments = getAttachments(publisher, build, listener);
if(attachments != null) {
for(MimeBodyPart attachment : attachments) {
multipart.addBodyPart(attachment);
Expand Down
Expand Up @@ -362,8 +362,8 @@ private MimeMessage createMail(EmailType type, AbstractBuild<?, ?> build, BuildL
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(getContent(type, build, msg, listener, charset));
AttachmentUtils attachments = new AttachmentUtils(attachmentsPattern);
attachments.attach(multipart, build, listener);
msg.setContent(multipart);
attachments.attach(multipart, this, build, listener);
msg.setContent(multipart);
EnvVars env = null;
try {
env = build.getEnvironment(listener);
Expand Down

0 comments on commit 9c0b900

Please sign in to comment.