package com.tikal.jenkins.plugins.multijob;

import hudson.console.HyperlinkNote;
import hudson.model.Cause;
import hudson.model.Run;
import hudson.model.TaskListener;

public class ResumeCause extends Cause.UpstreamCause {

	private Boolean afterRestart;

	public ResumeCause(Run<?, ?> up) {
		super(up);
		this.afterRestart = false;
	}

	public ResumeCause(Run<?, ?> up, Boolean afterRestart) {
		this(up);
		this.afterRestart = null != afterRestart ? afterRestart : false;
	}

	@Override
	public String getShortDescription() {
		if (afterRestart) {
			return Messages.ResumeCauseAfterRestart_ShortDescription(getUpstreamBuild(), getUpstreamUrl());
		}
		return Messages.ResumeCause_ShortDescription(getUpstreamBuild(), getUpstreamUrl());
	}

	@Override
	public void print(TaskListener listener) {
		StringBuilder sb = new StringBuilder();
		sb.append("[MultiJob] Resume build ");
		sb.append(HyperlinkNote.encodeTo(getUpstreamUrl(), "#" + String.valueOf(getUpstreamBuild())));
		listener.getLogger().println(sb.toString());
		if (afterRestart) {
			sb.append(" after Jenkins restart");
		}
	}
}

@@ -977,55 +977,8 @@
 ));%0A
-%09%09listener.getLogger().println(sb.toString());%0A
 %09%09if
@@ -1039,13 +1039,60 @@
 %22);%0A%09%09%7D%0A
+%09%09listener.getLogger().println(sb.toString());%0A
 %09%7D%0A%7D%0A

Fix message