Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-9560] new bot command to show the currently building jobs
- Loading branch information
kutzi
committed
May 2, 2011
1 parent
0f27ccb
commit c2544d1
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/java/hudson/plugins/im/bot/CurrentlyBuildingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package hudson.plugins.im.bot; | ||
|
||
import hudson.Extension; | ||
import hudson.Util; | ||
import hudson.model.Computer; | ||
import hudson.model.Executor; | ||
import hudson.model.Hudson; | ||
import hudson.model.Queue.Executable; | ||
import hudson.plugins.im.IMChat; | ||
import hudson.plugins.im.IMException; | ||
import hudson.plugins.im.IMMessage; | ||
import hudson.plugins.im.Sender; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
/** | ||
* CurrentlyBuilding command for instant messaging plugin. | ||
* | ||
* Generates a list of jobs in progress. | ||
* | ||
* @author Bjoern Kasteleiner | ||
*/ | ||
@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"); | ||
} | ||
|
||
@Override | ||
public void executeCommand(Bot bot, IMChat chat, IMMessage message, | ||
Sender sender, String[] args) throws IMException { | ||
StringBuffer msg = new StringBuffer(); | ||
msg.append("Currently building:"); | ||
boolean currentlyJobsInProgess = false; | ||
for (Computer computer : Hudson.getInstance().getComputers()) { | ||
for (Executor executor : computer.getExecutors()) { | ||
Executable currentExecutable = executor.getCurrentExecutable(); | ||
if (currentExecutable != null) { | ||
currentlyJobsInProgess = true; | ||
msg.append("\n- "); | ||
msg.append(computer.getDisplayName()); | ||
msg.append("#"); | ||
msg.append(executor.getNumber()); | ||
msg.append(": "); | ||
msg.append(currentExecutable.getParent().getDisplayName()); | ||
msg.append(" (Elapsed time: "); | ||
msg.append(Util.getTimeSpanString(executor.getElapsedTime())); | ||
msg.append(", Estimated remaining time: "); | ||
msg.append(executor.getEstimatedRemainingTime()); | ||
msg.append(")"); | ||
} | ||
} | ||
} | ||
|
||
if (!currentlyJobsInProgess) { | ||
msg.append("\n- No jobs are running."); | ||
} | ||
|
||
chat.sendMessage(msg.toString()); | ||
} | ||
|
||
@Override | ||
public String getHelp() { | ||
return HELP_MESSAGE; | ||
} | ||
|
||
} |