/hudson-core/src/main/java/hudson/tasks/mail/impl/UnstableBuildMail.java

http://github.com/hudson/hudson · Java · 79 lines · 41 code · 8 blank · 30 comment · 11 complexity · 16f3832ed5ba175bed801db4bdc0d407 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2011, Oracle Corporation, Anton Kozak
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.tasks.mail.impl;
  25. import hudson.Util;
  26. import hudson.model.AbstractBuild;
  27. import hudson.model.AbstractProject;
  28. import hudson.model.BuildListener;
  29. import hudson.model.Result;
  30. import hudson.tasks.Messages;
  31. import java.util.List;
  32. import javax.mail.MessagingException;
  33. import javax.mail.internet.MimeMessage;
  34. /**
  35. * Class used for the mail preparation if build is unstable.
  36. */
  37. public class UnstableBuildMail extends BaseBuildResultMail {
  38. public UnstableBuildMail(String recipients, boolean sendToIndividuals,
  39. List<AbstractProject> upstreamProjects, String charset) {
  40. super(recipients, sendToIndividuals, upstreamProjects, charset);
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. public MimeMessage getMail(AbstractBuild<?, ?> build, BuildListener listener)
  46. throws MessagingException, InterruptedException {
  47. MimeMessage msg = createEmptyMail(build, listener);
  48. String subject = Messages.MailSender_UnstableMail_Subject();
  49. AbstractBuild<?, ?> prev = build.getPreviousBuild();
  50. boolean still = false;
  51. if (prev != null) {
  52. if (prev.getResult() == Result.SUCCESS) {
  53. subject = Messages.MailSender_UnstableMail_ToUnStable_Subject();
  54. } else if (prev.getResult() == Result.UNSTABLE) {
  55. subject = Messages.MailSender_UnstableMail_StillUnstable_Subject();
  56. still = true;
  57. }
  58. }
  59. msg.setSubject(getSubject(build, subject), getCharset());
  60. StringBuilder buf = new StringBuilder();
  61. // Link to project changes summary for "still unstable" if this or last build has changes
  62. if (still && !(build.getChangeSet().isEmptySet() && prev.getChangeSet().isEmptySet())) {
  63. appendUrl(Util.encode(build.getProject().getUrl()) + "changes", buf);
  64. } else {
  65. appendBuildUrl(build, buf);
  66. }
  67. appendFooter(buf);
  68. msg.setText(buf.toString(), getCharset());
  69. return msg;
  70. }
  71. }