Skip to content

Commit

Permalink
Use FullDisplayName for 'cb' command, too, if available [JENKINS-6560]
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed Jan 6, 2015
1 parent f08b787 commit 4ca5e97
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/hudson/plugins/im/bot/CurrentlyBuildingCommand.java
Expand Up @@ -2,10 +2,12 @@

import hudson.Extension;
import hudson.Util;
import hudson.model.Item;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Hudson;
import hudson.model.Queue.Executable;
import hudson.model.queue.SubTask;
import hudson.plugins.im.IMChat;
import hudson.plugins.im.IMException;
import hudson.plugins.im.IMMessage;
Expand All @@ -14,6 +16,8 @@
import java.util.Arrays;
import java.util.Collection;

import jenkins.model.Jenkins;

/**
* CurrentlyBuilding command for instant messaging plugin.
*
Expand All @@ -24,8 +28,6 @@
@Extension
public class CurrentlyBuildingCommand extends BotCommand {

private static final String HELP_MESSAGE = " - list jobs which are currently in progress";

@Override
public Collection<String> getCommandNames() {
return Arrays.asList("currentlyBuilding", "cb");
Expand All @@ -37,17 +39,24 @@ public void executeCommand(Bot bot, IMChat chat, IMMessage message,
StringBuffer msg = new StringBuffer();
msg.append("Currently building:");
boolean currentlyJobsInProgess = false;
for (Computer computer : Hudson.getInstance().getComputers()) {
for (Computer computer : Jenkins.getInstance().getComputers()) {
for (Executor executor : computer.getExecutors()) {
Executable currentExecutable = executor.getCurrentExecutable();
if (currentExecutable != null) {
currentlyJobsInProgess = true;

SubTask task = currentExecutable.getParent();
Item item = null;
if (task instanceof Item) {
item = (Item) task;
}

msg.append("\n- ");
msg.append(computer.getDisplayName());
msg.append("#");
msg.append(executor.getNumber());
msg.append(": ");
msg.append(currentExecutable.getParent().getDisplayName());
msg.append(item != null ? item.getFullDisplayName() : task.getDisplayName());
msg.append(" (Elapsed time: ");
msg.append(Util.getTimeSpanString(executor.getElapsedTime()));
msg.append(", Estimated remaining time: ");
Expand All @@ -66,7 +75,7 @@ public void executeCommand(Bot bot, IMChat chat, IMMessage message,

@Override
public String getHelp() {
return HELP_MESSAGE;
return " - list jobs which are currently in progress";
}

}

0 comments on commit 4ca5e97

Please sign in to comment.