PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
24package hudson.tasks.mail.impl;
25
26import hudson.Util;
27import hudson.model.AbstractBuild;
28import hudson.model.AbstractProject;
29import hudson.model.BuildListener;
30import hudson.model.Result;
31import hudson.tasks.Messages;
32import java.util.List;
33import javax.mail.MessagingException;
34import javax.mail.internet.MimeMessage;
35
36/**
37 * Class used for the mail preparation if build is unstable.
38 */
39public class UnstableBuildMail extends BaseBuildResultMail {
40
41    public UnstableBuildMail(String recipients, boolean sendToIndividuals,
42                             List<AbstractProject> upstreamProjects, String charset) {
43        super(recipients, sendToIndividuals, upstreamProjects, charset);
44    }
45
46    /**
47     * @inheritDoc
48     */
49    public MimeMessage getMail(AbstractBuild<?, ?> build, BuildListener listener)
50        throws MessagingException, InterruptedException {
51        MimeMessage msg = createEmptyMail(build, listener);
52
53        String subject = Messages.MailSender_UnstableMail_Subject();
54
55        AbstractBuild<?, ?> prev = build.getPreviousBuild();
56        boolean still = false;
57        if (prev != null) {
58            if (prev.getResult() == Result.SUCCESS) {
59                subject = Messages.MailSender_UnstableMail_ToUnStable_Subject();
60            } else if (prev.getResult() == Result.UNSTABLE) {
61                subject = Messages.MailSender_UnstableMail_StillUnstable_Subject();
62                still = true;
63            }
64        }
65
66        msg.setSubject(getSubject(build, subject), getCharset());
67        StringBuilder buf = new StringBuilder();
68        // Link to project changes summary for "still unstable" if this or last build has changes
69        if (still && !(build.getChangeSet().isEmptySet() && prev.getChangeSet().isEmptySet())) {
70            appendUrl(Util.encode(build.getProject().getUrl()) + "changes", buf);
71        } else {
72            appendBuildUrl(build, buf);
73        }
74        appendFooter(buf);
75        msg.setText(buf.toString(), getCharset());
76
77        return msg;
78    }
79}