Skip to content

Commit

Permalink
FIXED JENKINS-20265
Browse files Browse the repository at this point in the history
Added TRIGGER_NAME token
  • Loading branch information
slide committed Nov 6, 2013
1 parent c70cb54 commit a42c315
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 135 deletions.
59 changes: 35 additions & 24 deletions src/main/java/hudson/plugins/emailext/AttachmentUtils.java
Expand Up @@ -74,23 +74,23 @@ public String getName() {
}
}

private List<MimeBodyPart> getAttachments(final ExtendedEmailPublisher publisher, final AbstractBuild<?, ?> build, final BuildListener listener)
private List<MimeBodyPart> getAttachments(final ExtendedEmailPublisherContext context)
throws MessagingException, InterruptedException, IOException {
List<MimeBodyPart> attachments = null;
FilePath ws = build.getWorkspace();
FilePath ws = context.getBuild().getWorkspace();
long totalAttachmentSize = 0;
long maxAttachmentSize = publisher.getDescriptor().getMaxAttachmentSize();
long maxAttachmentSize = context.getPublisher().getDescriptor().getMaxAttachmentSize();
if (ws == null) {
listener.error("Error: No workspace found!");
context.getListener().error("Error: No workspace found!");
} else if (!StringUtils.isBlank(attachmentsPattern)) {
attachments = new ArrayList<MimeBodyPart>();

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

for (FilePath file : files) {
if (maxAttachmentSize > 0
&& (totalAttachmentSize + file.length()) >= maxAttachmentSize) {
listener.getLogger().println("Skipping `" + file.getName()
context.getListener().getLogger().println("Skipping `" + file.getName()
+ "' (" + file.length()
+ " bytes) - too large for maximum attachments size");
continue;
Expand All @@ -106,7 +106,7 @@ private List<MimeBodyPart> getAttachments(final ExtendedEmailPublisher publisher
attachments.add(attachmentPart);
totalAttachmentSize += file.length();
} catch (MessagingException e) {
listener.getLogger().println("Error adding `"
context.getListener().getLogger().println("Error adding `"
+ file.getName() + "' as attachment - "
+ e.getMessage());
}
Expand All @@ -116,41 +116,44 @@ private List<MimeBodyPart> getAttachments(final ExtendedEmailPublisher publisher
}

public void attach(Multipart multipart, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, BuildListener listener) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, listener);
attach(multipart, context);

}

public void attach(Multipart multipart, ExtendedEmailPublisherContext context) {
try {
List<MimeBodyPart> attachments = getAttachments(publisher, build, listener);

List<MimeBodyPart> attachments = getAttachments(context);
if (attachments != null) {
for (MimeBodyPart attachment : attachments) {
multipart.addBodyPart(attachment);
}
}
} catch (IOException e) {
listener.error("Error accessing files to attach: " + e.getMessage());
context.getListener().error("Error accessing files to attach: " + e.getMessage());
} catch (MessagingException e) {
listener.error("Error attaching items to message: " + e.getMessage());
context.getListener().error("Error attaching items to message: " + e.getMessage());
} catch (InterruptedException e) {
listener.error("Interrupted in processing attachments: " + e.getMessage());
}
context.getListener().error("Interrupted in processing attachments: " + e.getMessage());
}
}

/**
* Attaches the build log to the multipart item.
*/
public static void attachBuildLog(ExtendedEmailPublisher publisher, Multipart multipart, AbstractBuild<?, ?> build, BuildListener listener, boolean compress) {

public static void attachBuildLog(ExtendedEmailPublisherContext context, Multipart multipart, boolean compress) {
try {
File logFile = build.getLogFile();
long maxAttachmentSize =
publisher.getDescriptor().getMaxAttachmentSize();
File logFile = context.getBuild().getLogFile();
long maxAttachmentSize = context.getPublisher().getDescriptor().getMaxAttachmentSize();

if (maxAttachmentSize > 0 && logFile.length() >= maxAttachmentSize) {
listener.getLogger().println("Skipping build log attachment - "
context.getListener().getLogger().println("Skipping build log attachment - "
+ " too large for maximum attachments size");
return;
}

DataSource fileSource;
MimeBodyPart attachment = new MimeBodyPart();
if (compress) {
listener.getLogger().println("Request made to compress build log");
context.getListener().getLogger().println("Request made to compress build log");
fileSource = new ZipDataSource(logFile);
attachment.setFileName("build.zip");
} else {
Expand All @@ -160,9 +163,17 @@ public static void attachBuildLog(ExtendedEmailPublisher publisher, Multipart mu
attachment.setDataHandler(new DataHandler(fileSource));
multipart.addBodyPart(attachment);
} catch (MessagingException e) {
listener.error("Error attaching build log to message: " + e.getMessage());
context.getListener().error("Error attaching build log to message: " + e.getMessage());
} catch (IOException e) {
listener.error("Error attaching build log to message: " + e.getMessage());
context.getListener().error("Error attaching build log to message: " + e.getMessage());
}
}

/**
* Attaches the build log to the multipart item.
*/
public static void attachBuildLog(ExtendedEmailPublisher publisher, Multipart multipart, AbstractBuild<?, ?> build, BuildListener listener, boolean compress) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, listener);
attachBuildLog(context, multipart, compress);
}
}

0 comments on commit a42c315

Please sign in to comment.