From d19eb9bbc1930511abf8fcf6c0c3939219c0d5a3 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Fri, 8 Feb 2013 20:08:59 +1100 Subject: [PATCH 01/19] Add IDEA files to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 8bec788..651f8fb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ target .settings bin work + +# IDEA files +.idea/ +*.iml From 56e09bf245b711b28d3d5200cb069bd0e166aed4 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Fri, 8 Feb 2013 20:09:36 +1100 Subject: [PATCH 02/19] Update Jenkins version and add Mustache in POM Updated to use Jenkins 1.500 and added the Java implementation of Mustache from https://github.com/spullara/mustache.java --- pom.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 61f1707..fef1b57 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.jenkins-ci.plugins plugin - 1.447 + 1.500 @@ -77,6 +77,11 @@ 1.0.4 provided + + com.github.spullara.mustache.java + compiler + 0.8.9 + From 910a92677f4098bfdaebfb0c25b114bf58805e0d Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 12:48:12 +1100 Subject: [PATCH 03/19] Use Mustache templates to generate notifications The plugin will now use Mustache template from configuration when creating HipChat notifications. This allows you to use any values available in the build / project configuration, including your own custom parameters. --- .../plugins/hipchat/ActiveNotifier.java | 78 ++++++++++++----- .../plugins/hipchat/HipChatNotifier.java | 87 +++++++++++++++++-- .../HipChatJobProperty/config.jelly | 12 +++ .../hipchat/HipChatNotifier/global.jelly | 8 ++ 4 files changed, 160 insertions(+), 25 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index c0918b3..8dbbf48 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -1,5 +1,8 @@ package jenkins.plugins.hipchat; +import com.github.mustachejava.DefaultMustacheFactory; +import com.github.mustachejava.Mustache; +import com.github.mustachejava.MustacheFactory; import hudson.Util; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; @@ -10,10 +13,9 @@ import hudson.scm.ChangeLogSet.Entry; import org.apache.commons.lang.StringUtils; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.*; import java.util.logging.Logger; @SuppressWarnings("rawtypes") @@ -22,10 +24,12 @@ public class ActiveNotifier implements FineGrainedNotifier { private static final Logger logger = Logger.getLogger(HipChatListener.class.getName()); HipChatNotifier notifier; + MustacheFactory mustacheFactory; public ActiveNotifier(HipChatNotifier notifier) { super(); this.notifier = notifier; + this.mustacheFactory = new DefaultMustacheFactory(); } private HipChatService getHipChat(AbstractBuild r) { @@ -41,15 +45,19 @@ public void started(AbstractBuild build) { String changes = getChanges(build); CauseAction cause = build.getAction(CauseAction.class); - if (changes != null) { - notifyStart(build, changes); - } else if (cause != null) { - MessageBuilder message = new MessageBuilder(notifier, build); - message.append(cause.getShortDescription()); - notifyStart(build, message.appendOpenLink().toString()); - } else { - notifyStart(build, getBuildStatusMessage(build)); + Map messageParams = new HashMap(); + messageParams.put("build", build); + messageParams.put("changes", changes); + messageParams.put("link", MessageBuilder.getOpenLink(notifier, build)); + + if (notifier.getMessageTemplateStarted() == null) + { + logger.warning("Started message template is not set!"); + notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); + return; } + + notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams)); } private void notifyStart(AbstractBuild build, String message) { @@ -69,6 +77,13 @@ public void completed(AbstractBuild r) { || (result == Result.NOT_BUILT && jobProperty.getNotifyNotBuilt()) || (result == Result.SUCCESS && jobProperty.getNotifySuccess()) || (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) { + + if (notifier.getMessageTemplateCompleted() == null) + { + logger.warning("Completed message template is not set!"); + notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}"); + } + getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r)); } @@ -97,12 +112,12 @@ String getChanges(AbstractBuild r) { authors.add(entry.getAuthor().getDisplayName()); } MessageBuilder message = new MessageBuilder(notifier, r); - message.append("Started by changes from "); + message.append("by changes from "); message.append(StringUtils.join(authors, ", ")); message.append(" ("); message.append(files.size()); message.append(" file(s) changed)"); - return message.appendOpenLink().toString(); + return message.toString(); } static String getBuildColor(AbstractBuild r) { @@ -116,13 +131,30 @@ static String getBuildColor(AbstractBuild r) { } } + String applyMessageTemplate(String messageTemplate, Map messageParams) + { + StringWriter messageWriter = new StringWriter(); + + String actualTemplate = messageTemplate; + if (notifier.getMessageTemplateSuffix() != null) + { + actualTemplate += " " + notifier.getMessageTemplateSuffix(); + } + + Mustache mustache = this.mustacheFactory.compile(new StringReader(actualTemplate), "message"); + mustache.execute(messageWriter, messageParams); + return messageWriter.toString(); + } + String getBuildStatusMessage(AbstractBuild r) { - MessageBuilder message = new MessageBuilder(notifier, r); - message.appendStatusMessage(); - message.appendDuration(); - return message.appendOpenLink().toString(); + Map messageParams = new HashMap(); + messageParams.put("build", r); + messageParams.put("status", MessageBuilder.getStatusMessage(r)); + + return applyMessageTemplate(notifier.getMessageTemplateCompleted(), messageParams); } + public static class MessageBuilder { private StringBuffer message; private HipChatNotifier notifier; @@ -171,9 +203,15 @@ private MessageBuilder startMessage() { return this; } - public MessageBuilder appendOpenLink() { + static String getOpenLink(HipChatNotifier notifier, AbstractBuild build) + { String url = notifier.getBuildServerUrl() + build.getUrl(); - message.append(" (Open)"); + return new StringBuilder("(Open)").toString(); + } + + public MessageBuilder appendOpenLink() { + + message.append(" " + getOpenLink(notifier, build)); return this; } diff --git a/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java b/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java index e0f83b3..de31916 100644 --- a/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java @@ -25,6 +25,9 @@ public class HipChatNotifier extends Notifier { private String buildServerUrl; private String room; private String sendAs; + private String messageTemplateStarted; + private String messageTemplateCompleted; + private String messageTemplateSuffix; @Override public DescriptorImpl getDescriptor() { @@ -63,13 +66,43 @@ public void setSendAs(final String sendAs) { this.sendAs = sendAs; } + public String getMessageTemplateStarted() { + return messageTemplateStarted; + } + + public void setMessageTemplateStarted(String messageTemplateStarted) { + this.messageTemplateStarted = messageTemplateStarted; + } + + public String getMessageTemplateCompleted() { + return messageTemplateCompleted; + } + + public void setMessageTemplateCompleted(String messageTemplateCompleted) { + this.messageTemplateCompleted = messageTemplateCompleted; + } + + public String getMessageTemplateSuffix() { + return messageTemplateSuffix; + } + + public void setMessageTemplateSuffix(String messageTemplateSuffix) { + this.messageTemplateSuffix = messageTemplateSuffix; + } + + + @DataBoundConstructor - public HipChatNotifier(final String authToken, final String room, String buildServerUrl, final String sendAs) { + public HipChatNotifier(final String authToken, final String room, String buildServerUrl, final String sendAs, + final String messageTemplateStarted, final String messageTemplateCompleted, final String messageTemplateSuffix) { super(); this.authToken = authToken; this.buildServerUrl = buildServerUrl; this.room = room; this.sendAs = sendAs; + this.messageTemplateStarted = messageTemplateStarted; + this.messageTemplateCompleted = messageTemplateCompleted; + this.messageTemplateSuffix = messageTemplateSuffix; } public BuildStepMonitor getRequiredMonitorService() { @@ -91,6 +124,9 @@ public static class DescriptorImpl extends BuildStepDescriptor { private String room; private String buildServerUrl; private String sendAs; + private String messageTemplateStarted; + private String messageTemplateCompleted; + private String messageTemplateSuffix; public DescriptorImpl() { load(); @@ -112,6 +148,18 @@ public String getSendAs() { return sendAs; } + public String getMessageTemplateStarted() { + return messageTemplateStarted; + } + + public String getMessageTemplateCompleted() { + return messageTemplateCompleted; + } + + public String getMessageTemplateSuffix() { + return messageTemplateSuffix; + } + public boolean isApplicable(Class aClass) { return true; } @@ -122,7 +170,10 @@ public HipChatNotifier newInstance(StaplerRequest sr) { if (buildServerUrl == null) buildServerUrl = sr.getParameter("hipChatBuildServerUrl"); if (room == null) room = sr.getParameter("hipChatRoom"); if (sendAs == null) sendAs = sr.getParameter("hipChatSendAs"); - return new HipChatNotifier(token, room, buildServerUrl, sendAs); + if (messageTemplateStarted == null) messageTemplateStarted = sr.getParameter("hipChatMessageTemplateStarted"); + if (messageTemplateCompleted == null) messageTemplateCompleted = sr.getParameter("hipChatMessageTemplateCompleted"); + if (messageTemplateSuffix == null) messageTemplateSuffix = sr.getParameter("hipChatMessageTemplateSuffix"); + return new HipChatNotifier(token, room, buildServerUrl, sendAs, messageTemplateStarted, messageTemplateCompleted, messageTemplateSuffix); } @Override @@ -131,11 +182,14 @@ public boolean configure(StaplerRequest sr, JSONObject formData) throws FormExce room = sr.getParameter("hipChatRoom"); buildServerUrl = sr.getParameter("hipChatBuildServerUrl"); sendAs = sr.getParameter("hipChatSendAs"); + messageTemplateStarted = sr.getParameter("hipChatMessageTemplateStarted"); + messageTemplateCompleted = sr.getParameter("hipChatMessageTemplateCompleted"); + if (buildServerUrl != null && !buildServerUrl.endsWith("/")) { buildServerUrl = buildServerUrl + "/"; } try { - new HipChatNotifier(token, room, buildServerUrl, sendAs); + new HipChatNotifier(token, room, buildServerUrl, sendAs, messageTemplateStarted, messageTemplateCompleted, messageTemplateSuffix); } catch (Exception e) { throw new FormException("Failed to initialize notifier - check your global notifier configuration settings", e, ""); } @@ -157,11 +211,16 @@ public static class HipChatJobProperty extends hudson.model.JobProperty build, BuildListener listener) { if (startNotification) { @@ -233,6 +307,9 @@ public boolean isApplicable(Class jobType) { @Override public HipChatJobProperty newInstance(StaplerRequest sr, JSONObject formData) throws hudson.model.Descriptor.FormException { return new HipChatJobProperty(sr.getParameter("hipChatProjectRoom"), + sr.getParameter("hipChatMessageTemplateStarted"), + sr.getParameter("hipChatMessageTemplateCompleted"), + sr.getParameter("hipChatMessageTemplateSuffix"), sr.getParameter("hipChatStartNotification") != null, sr.getParameter("hipChatNotifyAborted") != null, sr.getParameter("hipChatNotifyFailure") != null, diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly index 31ebf5c..929e660 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly @@ -5,6 +5,18 @@ + + + + + + + + + + + + diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index 9d84395..a56dedf 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -24,5 +24,13 @@ + + + + + + From 7eafa590fa0486ff8319d2c8518bab1d5de23613 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 12:51:21 +1100 Subject: [PATCH 04/19] Update version to 0.1.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fef1b57..00d971f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.jvnet.hudson.plugins hipchat hpi - 0.1.2-SNAPSHOT + 0.1.3-SNAPSHOT Jenkins HipChat Plugin A Build status publisher that notifies channels on a HipChat server http://wiki.jenkins-ci.org/display/JENKINS/HipChat+Plugin From 2ad438fb99f31ce7457bec21c7090b60c6980525 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:02:09 +1100 Subject: [PATCH 05/19] Add link to completed message --- src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java | 3 ++- .../jenkins/plugins/hipchat/HipChatNotifier/global.jelly | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 8dbbf48..690a69b 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -81,7 +81,7 @@ public void completed(AbstractBuild r) { if (notifier.getMessageTemplateCompleted() == null) { logger.warning("Completed message template is not set!"); - notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}"); + notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); } getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r)); @@ -150,6 +150,7 @@ String getBuildStatusMessage(AbstractBuild r) { Map messageParams = new HashMap(); messageParams.put("build", r); messageParams.put("status", MessageBuilder.getStatusMessage(r)); + messageParams.put("link", MessageBuilder.getOpenLink(notifier, r)); return applyMessageTemplate(notifier.getMessageTemplateCompleted(), messageParams); } diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index a56dedf..f579fb8 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -30,7 +30,7 @@ + default="{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}" /> From 313d5e8195f1801d063eeae019e2f051834eee8b Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:06:58 +1100 Subject: [PATCH 06/19] Update plugin version past what's on the plugin repo --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 00d971f..0cc7eac 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.jvnet.hudson.plugins hipchat hpi - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT Jenkins HipChat Plugin A Build status publisher that notifies channels on a HipChat server http://wiki.jenkins-ci.org/display/JENKINS/HipChat+Plugin From 2e336051b92ade31c3c6ce7299814e726a09255f Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:07:20 +1100 Subject: [PATCH 07/19] Update README with info about using Mustache --- README.markdown | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 760dc2c..f3b72a0 100644 --- a/README.markdown +++ b/README.markdown @@ -2,4 +2,38 @@ Started with a fork of the Campfire plugin: -https://github.com/jgp/hudson_campfire_plugin \ No newline at end of file +https://github.com/jgp/hudson_campfire_plugin + +## Mustache template updates + +The plugin has been updated to use [Mustache.java](https://github.com/spullara/mustache.java) to +generate the HipChat notifications - this allows for easier customisation, as well as adding custom + build variables to be output. + + The default templates are: + + * Start message: ```{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}``` + * Complete message: ```{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}``` + + There is also a per-Job configurable "Message suffix" - this is also a Mustache template and is + used when you want to keep the same template overall and just override something that gets appended + to the default messages. + + **Note** that if you change the messages in the global config you'll have to re-save any Jobs using + the default for them to pick up the change! + + ### Available parameters + + #### Start message + + * **build** - instance of [AbstractBuild](http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html) - + most of the information comes from this object (eg. ```{{build.project.displayName}}```) + * **cause** - the "cause" string as to why the build was started + * **changes** - a string describing the changes that caused the build to start + * **link** - link to the build in Jenkins - note the triple-bracket to prevent HTML from being escaped + + #### Completed message + + * **build** - see above + * **status** - string describing the state of the build (eg. success, fail, etc) + * **link** - link to the build in Jenkins \ No newline at end of file From 333d376c19b2136456f126bf631ff102aa061383 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:18:42 +1100 Subject: [PATCH 08/19] Fix empty message issues When there is no config set there was an empty message being sent, instead make sure the defaults are used. --- .../java/jenkins/plugins/hipchat/ActiveNotifier.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 690a69b..432ac19 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -50,11 +50,10 @@ public void started(AbstractBuild build) { messageParams.put("changes", changes); messageParams.put("link", MessageBuilder.getOpenLink(notifier, build)); - if (notifier.getMessageTemplateStarted() == null) + if (notifier.getMessageTemplateStarted() == null || "".equals(notifier.getMessageTemplateStarted())) { - logger.warning("Started message template is not set!"); + logger.warning("Started message template is not set, using default"); notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); - return; } notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams)); @@ -78,9 +77,9 @@ public void completed(AbstractBuild r) { || (result == Result.SUCCESS && jobProperty.getNotifySuccess()) || (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) { - if (notifier.getMessageTemplateCompleted() == null) + if (notifier.getMessageTemplateCompleted() == null || "".equals(notifier.getMessageTemplateCompleted())) { - logger.warning("Completed message template is not set!"); + logger.warning("Completed message template is not set, using default"); notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); } From 3f0f322d82162b4864439e3881c5adbab5fae3f4 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:26:35 +1100 Subject: [PATCH 09/19] Update README with custom var info --- README.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f3b72a0..5177b93 100644 --- a/README.markdown +++ b/README.markdown @@ -36,4 +36,9 @@ generate the HipChat notifications - this allows for easier customisation, as we * **build** - see above * **status** - string describing the state of the build (eg. success, fail, etc) - * **link** - link to the build in Jenkins \ No newline at end of file + * **link** - link to the build in Jenkins + + ### Using custom build parameters + + Custom build parameters are available through ```{{build.buildVariables}}``` - for example if you have + a parameter called ENVIRONMENT then you would use ```{{build.buildVariables.ENVIRONMENT}}```. \ No newline at end of file From 80ffae38f63e4de1a8f903b462e5bbfd8244b02d Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:33:26 +1100 Subject: [PATCH 10/19] Remove MessageBuilder MessageBuilder is no longer required since we now generate messages using Mustache. --- .../plugins/hipchat/ActiveNotifier.java | 91 ++++--------------- 1 file changed, 19 insertions(+), 72 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 432ac19..2ef26fa 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -48,7 +48,7 @@ public void started(AbstractBuild build) { Map messageParams = new HashMap(); messageParams.put("build", build); messageParams.put("changes", changes); - messageParams.put("link", MessageBuilder.getOpenLink(notifier, build)); + messageParams.put("link", getOpenLink(build)); if (notifier.getMessageTemplateStarted() == null || "".equals(notifier.getMessageTemplateStarted())) { @@ -110,7 +110,7 @@ String getChanges(AbstractBuild r) { for (Entry entry : entries) { authors.add(entry.getAuthor().getDisplayName()); } - MessageBuilder message = new MessageBuilder(notifier, r); + StringBuilder message = new StringBuilder(); message.append("by changes from "); message.append(StringUtils.join(authors, ", ")); message.append(" ("); @@ -148,81 +148,28 @@ String applyMessageTemplate(String messageTemplate, Map messagePa String getBuildStatusMessage(AbstractBuild r) { Map messageParams = new HashMap(); messageParams.put("build", r); - messageParams.put("status", MessageBuilder.getStatusMessage(r)); - messageParams.put("link", MessageBuilder.getOpenLink(notifier, r)); + messageParams.put("status", getStatusMessage(r)); + messageParams.put("link", getOpenLink(r)); return applyMessageTemplate(notifier.getMessageTemplateCompleted(), messageParams); } - - public static class MessageBuilder { - private StringBuffer message; - private HipChatNotifier notifier; - private AbstractBuild build; - - public MessageBuilder(HipChatNotifier notifier, AbstractBuild build) { - this.notifier = notifier; - this.message = new StringBuffer(); - this.build = build; - startMessage(); - } - - public MessageBuilder appendStatusMessage() { - message.append(getStatusMessage(build)); - return this; - } - - static String getStatusMessage(AbstractBuild r) { - if (r.isBuilding()) { - return "Starting..."; - } - Result result = r.getResult(); - if (result == Result.SUCCESS) return "Success"; - if (result == Result.FAILURE) return "FAILURE"; - if (result == Result.ABORTED) return "ABORTED"; - if (result == Result.NOT_BUILT) return "Not built"; - if (result == Result.UNSTABLE) return "Unstable"; - return "Unknown"; - } - - public MessageBuilder append(String string) { - message.append(string); - return this; - } - - public MessageBuilder append(Object string) { - message.append(string.toString()); - return this; - } - - private MessageBuilder startMessage() { - message.append(build.getProject().getDisplayName()); - message.append(" - "); - message.append(build.getDisplayName()); - message.append(" "); - return this; - } - - static String getOpenLink(HipChatNotifier notifier, AbstractBuild build) - { - String url = notifier.getBuildServerUrl() + build.getUrl(); - return new StringBuilder("(Open)").toString(); - } - - public MessageBuilder appendOpenLink() { - - message.append(" " + getOpenLink(notifier, build)); - return this; - } - - public MessageBuilder appendDuration() { - message.append(" after "); - message.append(build.getDurationString()); - return this; + private String getStatusMessage(AbstractBuild r) { + if (r.isBuilding()) { + return "Starting..."; } + Result result = r.getResult(); + if (result == Result.SUCCESS) return "Success"; + if (result == Result.FAILURE) return "FAILURE"; + if (result == Result.ABORTED) return "ABORTED"; + if (result == Result.NOT_BUILT) return "Not built"; + if (result == Result.UNSTABLE) return "Unstable"; + return "Unknown"; + } - public String toString() { - return message.toString(); - } + private String getOpenLink(AbstractBuild build) + { + String url = notifier.getBuildServerUrl() + build.getUrl(); + return new StringBuilder("(Open)").toString(); } } From e1bb9074c1cd850cc0fed5f881b74e5b81dacf62 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 13:59:14 +1100 Subject: [PATCH 11/19] Make sure "Cause" is available to Mustache And some minor fixes to ensure there's no doubling up of "Started" text. --- src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java | 5 +++-- .../jenkins/plugins/hipchat/HipChatNotifier/global.jelly | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 2ef26fa..f2ca41d 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -47,13 +47,14 @@ public void started(AbstractBuild build) { Map messageParams = new HashMap(); messageParams.put("build", build); + messageParams.put("cause", cause); messageParams.put("changes", changes); messageParams.put("link", getOpenLink(build)); if (notifier.getMessageTemplateStarted() == null || "".equals(notifier.getMessageTemplateStarted())) { logger.warning("Started message template is not set, using default"); - notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); + notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); } notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams)); @@ -111,7 +112,7 @@ String getChanges(AbstractBuild r) { authors.add(entry.getAuthor().getDisplayName()); } StringBuilder message = new StringBuilder(); - message.append("by changes from "); + message.append("Started by changes from "); message.append(StringUtils.join(authors, ", ")); message.append(" ("); message.append(files.size()); diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index f579fb8..4ea9d42 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -26,7 +26,7 @@ + default="{{build.project.displayName}} - {{build.displayName}}: {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}" /> Date: Sat, 9 Feb 2013 14:41:55 +1100 Subject: [PATCH 12/19] Fix notifier so that is uses job properties Previous code was incorrectly getting message templates from the global notifier instead of using the JobProperties object --- .../plugins/hipchat/ActiveNotifier.java | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index f2ca41d..af5d81c 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -51,13 +51,12 @@ public void started(AbstractBuild build) { messageParams.put("changes", changes); messageParams.put("link", getOpenLink(build)); - if (notifier.getMessageTemplateStarted() == null || "".equals(notifier.getMessageTemplateStarted())) - { - logger.warning("Started message template is not set, using default"); - notifier.setMessageTemplateStarted("{{build.project.displayName}} - {{build.displayName}}: {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}"); - } + HipChatNotifier.HipChatJobProperty jobProperty = getJobPropertyForBuild(build); + String messageTemplate = getMessageTemplate(jobProperty.getMessageTemplateStarted(), + jobProperty.getMessageTemplateSuffix(), + "{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}}"); - notifyStart(build, applyMessageTemplate(notifier.getMessageTemplateStarted(), messageParams)); + notifyStart(build, applyMessageTemplate(messageTemplate, messageParams)); } private void notifyStart(AbstractBuild build, String message) { @@ -78,18 +77,27 @@ public void completed(AbstractBuild r) { || (result == Result.SUCCESS && jobProperty.getNotifySuccess()) || (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) { - if (notifier.getMessageTemplateCompleted() == null || "".equals(notifier.getMessageTemplateCompleted())) - { - logger.warning("Completed message template is not set, using default"); - notifier.setMessageTemplateCompleted("{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); - } + String messageTemplate = getMessageTemplate(jobProperty.getMessageTemplateCompleted(), + jobProperty.getMessageTemplateSuffix(), + "{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); + + Map messageParams = new HashMap(); + messageParams.put("build", r); + messageParams.put("status", getStatusMessage(r)); + messageParams.put("link", getOpenLink(r)); - getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r)); + getHipChat(r).publish(applyMessageTemplate(messageTemplate, messageParams), getBuildColor(r)); } } - String getChanges(AbstractBuild r) { + private HipChatNotifier.HipChatJobProperty getJobPropertyForBuild(AbstractBuild r) + { + AbstractProject project = r.getProject(); + return project.getProperty(HipChatNotifier.HipChatJobProperty.class); + } + + private String getChanges(AbstractBuild r) { if (!r.hasChangeSetComputed()) { logger.info("No change set computed..."); return null; @@ -131,28 +139,28 @@ static String getBuildColor(AbstractBuild r) { } } - String applyMessageTemplate(String messageTemplate, Map messageParams) + private String getMessageTemplate(String baseTemplate, String suffixTemplate, String defaultTemplate) { - StringWriter messageWriter = new StringWriter(); - - String actualTemplate = messageTemplate; - if (notifier.getMessageTemplateSuffix() != null) + StringBuilder template = new StringBuilder(); + if (baseTemplate == null || "".equals(baseTemplate)) { - actualTemplate += " " + notifier.getMessageTemplateSuffix(); + template.append(defaultTemplate); } - - Mustache mustache = this.mustacheFactory.compile(new StringReader(actualTemplate), "message"); - mustache.execute(messageWriter, messageParams); - return messageWriter.toString(); + if (suffixTemplate != null && !"".equals(suffixTemplate)) { + template.append(" "); + template.append(suffixTemplate); + } + return template.toString(); } - String getBuildStatusMessage(AbstractBuild r) { - Map messageParams = new HashMap(); - messageParams.put("build", r); - messageParams.put("status", getStatusMessage(r)); - messageParams.put("link", getOpenLink(r)); - return applyMessageTemplate(notifier.getMessageTemplateCompleted(), messageParams); + String applyMessageTemplate(String messageTemplate, Map messageParams) + { + StringWriter messageWriter = new StringWriter(); + + Mustache mustache = this.mustacheFactory.compile(new StringReader(messageTemplate), "message"); + mustache.execute(messageWriter, messageParams); + return messageWriter.toString(); } private String getStatusMessage(AbstractBuild r) { From f1ad64e6ecd11553530502095c5322973db4d2cf Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 14:43:00 +1100 Subject: [PATCH 13/19] Simplify the "started" template Use a single "trigger" string that's the same as the non-Mustache version's string instead of separate cause & changes strings which could cause duplications. --- README.markdown | 6 +++--- .../jenkins/plugins/hipchat/ActiveNotifier.java | 17 +++++++++++++++-- .../hipchat/HipChatNotifier/global.jelly | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.markdown b/README.markdown index 5177b93..4d92e1a 100644 --- a/README.markdown +++ b/README.markdown @@ -12,7 +12,7 @@ generate the HipChat notifications - this allows for easier customisation, as we The default templates are: - * Start message: ```{{build.project.displayName}} - {{build.displayName}}: Started {{#cause}}{{cause.shortDescription}}{{/cause}} {{#changes}}{{changes}}{{/changes}} {{{link}}}``` + * Start message: ```{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}}``` * Complete message: ```{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}``` There is also a per-Job configurable "Message suffix" - this is also a Mustache template and is @@ -28,8 +28,8 @@ generate the HipChat notifications - this allows for easier customisation, as we * **build** - instance of [AbstractBuild](http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html) - most of the information comes from this object (eg. ```{{build.project.displayName}}```) - * **cause** - the "cause" string as to why the build was started - * **changes** - a string describing the changes that caused the build to start + * **trigger** - a string describing why the build was started - tries to use the "changes" if available, otherwise + the "cause", and finally falls back to the string "Started..." * **link** - link to the build in Jenkins - note the triple-bracket to prevent HTML from being escaped #### Completed message diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index af5d81c..65c8fb5 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -45,10 +45,23 @@ public void started(AbstractBuild build) { String changes = getChanges(build); CauseAction cause = build.getAction(CauseAction.class); + String trigger; + if (changes != null) + { + trigger = changes; + } + else if (cause != null) + { + trigger = cause.getShortDescription(); + } + else + { + trigger = "Starting..."; + } + Map messageParams = new HashMap(); messageParams.put("build", build); - messageParams.put("cause", cause); - messageParams.put("changes", changes); + messageParams.put("trigger", trigger); messageParams.put("link", getOpenLink(build)); HipChatNotifier.HipChatJobProperty jobProperty = getJobPropertyForBuild(build); diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index 4ea9d42..66ae1b6 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -26,7 +26,7 @@ + default="{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}}" /> Date: Sat, 9 Feb 2013 15:02:42 +1100 Subject: [PATCH 14/19] Clean up config panels and add help files --- .../HipChatJobProperty/config.jelly | 6 +++--- .../plugins/hipchat/HipChatNotifier/global.jelly | 4 ++-- ...obalConfig-hipChatMessageTemplateCompleted.html | 14 ++++++++++++++ ...globalConfig-hipChatMessageTemplateStarted.html | 14 ++++++++++++++ ...jectConfig-hipChatMessageTemplateCompleted.html | 12 ++++++++++++ ...rojectConfig-hipChatMessageTemplateStarted.html | 12 ++++++++++++ ...projectConfig-hipChatMessageTemplateSuffix.html | 13 +++++++++++++ 7 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 src/main/webapp/help-globalConfig-hipChatMessageTemplateCompleted.html create mode 100644 src/main/webapp/help-globalConfig-hipChatMessageTemplateStarted.html create mode 100644 src/main/webapp/help-projectConfig-hipChatMessageTemplateCompleted.html create mode 100644 src/main/webapp/help-projectConfig-hipChatMessageTemplateStarted.html create mode 100644 src/main/webapp/help-projectConfig-hipChatMessageTemplateSuffix.html diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly index 929e660..31686b4 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/HipChatJobProperty/config.jelly @@ -5,15 +5,15 @@ - + - + - + diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index 66ae1b6..dc588a0 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -24,11 +24,11 @@ - + - + diff --git a/src/main/webapp/help-globalConfig-hipChatMessageTemplateCompleted.html b/src/main/webapp/help-globalConfig-hipChatMessageTemplateCompleted.html new file mode 100644 index 0000000..e11be7f --- /dev/null +++ b/src/main/webapp/help-globalConfig-hipChatMessageTemplateCompleted.html @@ -0,0 +1,14 @@ +
+

Specify a Mustache template that will be used to generate the + notification message sent to HipChat when a build is completed

+

Available parameters are: +

    +
  • build: the AbstractBuild + instance referring to the build - contains useful properties such as build.project.displayName
  • +
  • status: a string representing the build completion status
  • +
  • link: a link to the Jenkins build
  • +
+

+

You can set a global template here, or specify a template per-job. If neither is specified then a default will + be used.

+
\ No newline at end of file diff --git a/src/main/webapp/help-globalConfig-hipChatMessageTemplateStarted.html b/src/main/webapp/help-globalConfig-hipChatMessageTemplateStarted.html new file mode 100644 index 0000000..1e54a0b --- /dev/null +++ b/src/main/webapp/help-globalConfig-hipChatMessageTemplateStarted.html @@ -0,0 +1,14 @@ +
+

Specify a Mustache template that will be used to generate the + notification message sent to HipChat when a build is started

+

Available parameters are: +

    +
  • build: the AbstractBuild + instance referring to the build - contains useful properties such as build.project.displayName
  • +
  • trigger: a string representing why the build was started
  • +
  • link: a link to the Jenkins build
  • +
+

+

You can set a global template here, or specify a template per-job. If neither is specified then a default will + be used.

+
\ No newline at end of file diff --git a/src/main/webapp/help-projectConfig-hipChatMessageTemplateCompleted.html b/src/main/webapp/help-projectConfig-hipChatMessageTemplateCompleted.html new file mode 100644 index 0000000..15567b7 --- /dev/null +++ b/src/main/webapp/help-projectConfig-hipChatMessageTemplateCompleted.html @@ -0,0 +1,12 @@ +
+

Specify a Mustache template that will be used to generate the + notification message sent to HipChat when a build is completed

+

Available parameters are: +

    +
  • build: the AbstractBuild + instance referring to the build - contains useful properties such as build.project.displayName
  • +
  • status: a string representing the build completion status
  • +
  • link: a link to the Jenkins build
  • +
+

+
\ No newline at end of file diff --git a/src/main/webapp/help-projectConfig-hipChatMessageTemplateStarted.html b/src/main/webapp/help-projectConfig-hipChatMessageTemplateStarted.html new file mode 100644 index 0000000..9c331ec --- /dev/null +++ b/src/main/webapp/help-projectConfig-hipChatMessageTemplateStarted.html @@ -0,0 +1,12 @@ +
+

Specify a Mustache template that will be used to generate the + notification message sent to HipChat when a build is started

+

Available parameters are: +

    +
  • build: the AbstractBuild + instance referring to the build - contains useful properties such as build.project.displayName
  • +
  • trigger: a string representing why the build was started
  • +
  • link: a link to the Jenkins build
  • +
+

+
\ No newline at end of file diff --git a/src/main/webapp/help-projectConfig-hipChatMessageTemplateSuffix.html b/src/main/webapp/help-projectConfig-hipChatMessageTemplateSuffix.html new file mode 100644 index 0000000..835203f --- /dev/null +++ b/src/main/webapp/help-projectConfig-hipChatMessageTemplateSuffix.html @@ -0,0 +1,13 @@ +
+

Specify a Mustache template that will be appended to the end of the + Build Started and Build Completed templates.

+ +

This can be used when you want a global base default template but just want to configure the last part of a + template on a per-job basis. This is particularly useful when you want to include build parameters in the status + messages.

+ +

The variables available to this template is the same as for the template it is appended to (eg. Start or Complete). Of particular + use might be build parameters which are available via build.buildVariables + (eg. build.buildVariables.ENVIRONMENT)

+ +
\ No newline at end of file From be9091cc26aa2059009f02e081234487ce81874d Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 15:04:09 +1100 Subject: [PATCH 15/19] Readme update --- README.markdown | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.markdown b/README.markdown index 4d92e1a..c763bbc 100644 --- a/README.markdown +++ b/README.markdown @@ -19,9 +19,6 @@ generate the HipChat notifications - this allows for easier customisation, as we used when you want to keep the same template overall and just override something that gets appended to the default messages. - **Note** that if you change the messages in the global config you'll have to re-save any Jobs using - the default for them to pick up the change! - ### Available parameters #### Start message From d873c955080249c52c9fd335e2ac45d8220f2f57 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 9 Feb 2013 15:12:54 +1100 Subject: [PATCH 16/19] Fix README indentation --- README.markdown | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/README.markdown b/README.markdown index c763bbc..f8b4635 100644 --- a/README.markdown +++ b/README.markdown @@ -8,34 +8,34 @@ https://github.com/jgp/hudson_campfire_plugin The plugin has been updated to use [Mustache.java](https://github.com/spullara/mustache.java) to generate the HipChat notifications - this allows for easier customisation, as well as adding custom - build variables to be output. +build variables to be output. - The default templates are: +The default templates are: - * Start message: ```{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}}``` - * Complete message: ```{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}``` +* Start message: ```{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}}``` +* Complete message: ```{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}}``` - There is also a per-Job configurable "Message suffix" - this is also a Mustache template and is - used when you want to keep the same template overall and just override something that gets appended - to the default messages. +There is also a per-Job configurable "Message suffix" - this is also a Mustache template and is +used when you want to keep the same template overall and just override something that gets appended +to the default messages. - ### Available parameters +### Available parameters - #### Start message +#### Start message - * **build** - instance of [AbstractBuild](http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html) - +* **build** - instance of [AbstractBuild](http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html) - most of the information comes from this object (eg. ```{{build.project.displayName}}```) - * **trigger** - a string describing why the build was started - tries to use the "changes" if available, otherwise +* **trigger** - a string describing why the build was started - tries to use the "changes" if available, otherwise the "cause", and finally falls back to the string "Started..." - * **link** - link to the build in Jenkins - note the triple-bracket to prevent HTML from being escaped +* **link** - link to the build in Jenkins - note the triple-bracket to prevent HTML from being escaped - #### Completed message +#### Completed message - * **build** - see above - * **status** - string describing the state of the build (eg. success, fail, etc) - * **link** - link to the build in Jenkins +* **build** - see above +* **status** - string describing the state of the build (eg. success, fail, etc) +* **link** - link to the build in Jenkins - ### Using custom build parameters +### Using custom build parameters - Custom build parameters are available through ```{{build.buildVariables}}``` - for example if you have - a parameter called ENVIRONMENT then you would use ```{{build.buildVariables.ENVIRONMENT}}```. \ No newline at end of file +Custom build parameters are available through ```{{build.buildVariables}}``` - for example if you have +a parameter called ENVIRONMENT then you would use ```{{build.buildVariables.ENVIRONMENT}}```. From 16f705c4f74814a7fca918610d8fa92335121763 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Wed, 13 Feb 2013 15:24:54 +1100 Subject: [PATCH 17/19] Update default completion msg to allow html If the build fails then the completion message may contain HTML. This means the default message needs to triple 'stache "status" so that the correct output is generated. --- src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java | 2 +- .../jenkins/plugins/hipchat/HipChatNotifier/global.jelly | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 65c8fb5..5d558b0 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -92,7 +92,7 @@ public void completed(AbstractBuild r) { String messageTemplate = getMessageTemplate(jobProperty.getMessageTemplateCompleted(), jobProperty.getMessageTemplateSuffix(), - "{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} {{{link}}}"); + "{{build.project.displayName}} - {{build.displayName}}: {{{status}}} after {{build.durationString}} {{{link}}}"); Map messageParams = new HashMap(); messageParams.put("build", r); diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index dc588a0..92c6214 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -30,7 +30,7 @@
+ default="{{build.project.displayName}} - {{build.displayName}}: {{{status}}} after {{build.durationString}} {{{link}}}" /> From 91c54893e47fe5fa8c12261889478f96846eb71c Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sun, 31 Mar 2013 20:32:34 +1100 Subject: [PATCH 18/19] Use StringBuilder properly in getOpenLink Inefficient use of concatenated strings with String builder when creating the link to the build job. --- src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index 5d558b0..ebd11cb 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -191,7 +191,10 @@ private String getStatusMessage(AbstractBuild r) { private String getOpenLink(AbstractBuild build) { - String url = notifier.getBuildServerUrl() + build.getUrl(); - return new StringBuilder("(Open)").toString(); + StringBuilder builder = new StringBuilder("(Open)"); + return builder.toString(); } } From 81d3b1f58c5c31805c2fba131b962e33133f9a20 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sun, 31 Mar 2013 20:33:24 +1100 Subject: [PATCH 19/19] Use StringUtils to check for blank strings Style fix to check for blank strings based on feedback. --- src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java index ebd11cb..5db8c87 100644 --- a/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java @@ -155,11 +155,11 @@ static String getBuildColor(AbstractBuild r) { private String getMessageTemplate(String baseTemplate, String suffixTemplate, String defaultTemplate) { StringBuilder template = new StringBuilder(); - if (baseTemplate == null || "".equals(baseTemplate)) + if (baseTemplate == null || StringUtils.isBlank(baseTemplate)) { template.append(defaultTemplate); } - if (suffixTemplate != null && !"".equals(suffixTemplate)) { + if (suffixTemplate != null && StringUtils.isNotBlank(suffixTemplate)) { template.append(" "); template.append(suffixTemplate); }