Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove MessageBuilder

MessageBuilder is no longer required since we now generate messages
using Mustache.
  • Loading branch information...
commit 80ffae38f63e4de1a8f903b462e5bbfd8244b02d 1 parent 3f0f322
@marcins authored
Showing with 19 additions and 72 deletions.
  1. +19 −72 src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java
View
91 src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java
@@ -48,7 +48,7 @@ public void started(AbstractBuild build) {
Map<String, Object> messageParams = new HashMap<String,Object>();
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<String,Object> messagePa
String getBuildStatusMessage(AbstractBuild r) {
Map<String,Object> messageParams = new HashMap<String, Object>();
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 "<b>FAILURE</b>";
- 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("(<a href='").append(url).append("'>Open</a>)").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 "<b>FAILURE</b>";
+ 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("(<a href='").append(url).append("'>Open</a>)").toString();
}
}

3 comments on commit 80ffae3

@phil-schneider

Not really a nice solution.
The idea of the MessageBuilder was to have one StringBuffer to build to whole string.
You will create now one Stringbuffer and add a String which was the result of a 3part StringBuilder.
I would stick with the single MessageBuilder(Stringbuffer) which consumes less memory then your way

@marcins
Owner

Thanks for the feedback - I've rewritten getOpenLink to just use a single StringBuilder.

@phil-schneider

ahh sorry, now I get it.
You create the message with params. Then you create a map (messageParams) with the key/value, which will be replaced with the mustache template engine.

Please sign in to comment.
Something went wrong with that request. Please try again.