Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6efee8179987a5a3ee0ecc16eff4796184045baa @philandstuff committed Feb 3, 2011
@@ -0,0 +1,6 @@
+.ipr
+.iml
+.iws
+.idea
+out
+.mp3
0 README
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 run
@@ -0,0 +1,2 @@
+#!/bin/bash
+java -cp lib/commons-codec-1.4.jar:lib/commons-httpclient-3.0.1.jar:lib/commons-io-1.4.jar:lib/commons-logging-1.1.1.jar:lib/customizer.jar:lib/dom4j-1.6.1.jar:lib/go-api-client-0.0.jar:lib/jaxen-1.1.1.jar:lib/jl1.0.jar:lib/jmf.jar:lib/joda-time-1.4.jar:lib/junit-4.7.jar:lib/mediaplayer.jar:lib/multiplayer.jar:lib/talk-to-go-0.0.jar:out/production/BuildMonitor/ com.thoughtworks.go.monitor.BuildStatusMonitor
@@ -0,0 +1 @@
+java -cp lib/commons-codec-1.4.jar;lib/commons-httpclient-3.0.1.jar;lib/commons-io-1.4.jar;lib/commons-logging-1.1.1.jar;lib/customizer.jar;lib/dom4j-1.6.1.jar;lib/go-api-client-0.0.jar;lib/jaxen-1.1.1.jar;lib/jl1.0.jar;lib/jmf.jar;lib/joda-time-1.4.jar;lib/junit-4.7.jar;lib/mediaplayer.jar;lib/multiplayer.jar;lib/talk-to-go-0.0.jar;out/production/BuildMonitor/ com.thoughtworks.go.monitor.BuildStatusMonitor
@@ -0,0 +1,2 @@
+ShilpaG=The_Day_That_Never_Comes.wav
+default=rickroll.mp3
@@ -0,0 +1,2 @@
+ShilpaG=Rainmaker.wav
+default=passed.mp3
@@ -0,0 +1,46 @@
+package com.thoughtworks.go.monitor;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ppotter
+ * Date: 02/02/2011
+ * Time: 20:06
+ * To change this template use File | Settings | File Templates.
+ */
+public class BlameMonitor {
+ private JFrame frame;
+ private JLabel label;
+
+ public void createWindow() {
+ frame = new JFrame("BlameMonitor");
+ label = new JLabel("Blame Monitor");
+ frame.getContentPane().add(label);
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.pack();
+ frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
+
+ label.setFont(new Font("Dialog",Font.PLAIN, 100));
+
+ frame.setVisible(true);
+
+ }
+
+ public void blame(String result, String user) {
+ setWindowTo(result.equals("Failed") ? Color.RED : Color.GREEN);
+ showUser(user);
+ }
+
+ private void setWindowTo(Color color) {
+ frame.setBackground(color);
+ }
+
+ private void showUser(String user) {
+ label.setText(user);
+ }
+
+
+}
@@ -0,0 +1,124 @@
+package com.thoughtworks.go.monitor;
+
+import com.thoughtworks.go.TalkToGo;
+import com.thoughtworks.go.TalkToGo2Dot1;
+import com.thoughtworks.go.domain.FeedEntry;
+import com.thoughtworks.go.domain.Material;
+import com.thoughtworks.go.domain.Pipeline;
+import com.thoughtworks.go.domain.Stage;
+import com.thoughtworks.go.http.HttpClientWrapper;
+import com.thoughtworks.go.visitor.StageVisitor;
+import com.thoughtworks.go.visitor.criteria.MatchingStageVisitor;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @understands Checking if a given stage broke.
+ */
+public class BuildStatusMonitor {
+ private String pipelineName;
+ private String stageName;
+ Set<String> visitedStages = new HashSet<String>();
+ private BlameMonitor blameMonitor = new BlameMonitor();
+ private final String GO_SERVER = "twu-ci";
+ private boolean borked = false;
+
+ public BuildStatusMonitor(String pipelineName, String stageName) {
+ this.pipelineName = pipelineName;
+ this.stageName = stageName;
+ blameMonitor.createWindow();
+ }
+
+ public boolean pollForNewCompletion() {
+ Stage stage = latestStage();
+ if (stage != null && !visitedStages.contains(stage.getStageLocator())) {
+ System.out.println("Found new stage with result " + stage.getResult());
+ visitedStages.add(stage.getStageLocator());
+
+ if (!isBroken(stage) && !wasFixed(stage)) {
+ return false;
+ }
+
+ List<String> users = checkinUsersForThisStage(stage);
+
+ blameMonitor.blame(stage.getResult(), checkinUsersForThisStage(stage).get(0));
+ SongPlayer.playSong(new NameToSongMapping(stage.getResult()).songForUser(users));
+
+ borked = isBroken(stage);
+ return true;
+ }
+ return false;
+ }
+
+ private boolean wasFixed(Stage stage) {
+ return borked && stage.getResult().equals("Passed");
+ }
+
+ private boolean isBroken(Stage stage) {
+ return stage.getResult().equals("Failed");
+ }
+
+ private List<String> checkinUsersForThisStage(Stage stage) {
+ Pipeline pipeline = stage.getPipeline();
+ List<String> users = new ArrayList<String>();
+ for (Material material : pipeline.materials()) {
+ for (Material.Change change : material.getChanges()) {
+ users.add(change.getUser());
+ }
+ }
+ return users;
+ }
+
+ private Stage latestStage() {
+ final List<Stage> stageListHack = new ArrayList<Stage>();
+ TalkToGo talkToGo = new TalkToGo2Dot1(pipelineName, new HttpClientWrapper(GO_SERVER, 8153), false);
+
+ talkToGo.visitStages(new StageVisitor() {
+ public void visitStage(Stage stage) {
+ if (!stage.getResult().equals("Cancelled")) {
+ stageListHack.add(stage);
+ }
+ }
+
+ public void visitPipeline(Pipeline pipeline) {
+ }
+ }, new StopAfterFirstMatchCriteria(stageName));
+ return stageListHack.isEmpty() ? null : stageListHack.get(0);
+ }
+
+ private class StopAfterFirstMatchCriteria extends MatchingStageVisitor {
+
+ private boolean visitedOnce;
+
+ public StopAfterFirstMatchCriteria(String stageName) {
+ super(stageName);
+ }
+
+ @Override
+ public boolean shouldVisit(FeedEntry feedEntry) {
+ return visitedOnce = super.shouldVisit(feedEntry);
+ }
+
+ @Override
+ public boolean shouldContinue() {
+ return !visitedOnce;
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException {
+ Thread.sleep(100);
+ BuildStatusMonitor monitor = new BuildStatusMonitor("all", "build");
+ while (true) {
+ try {
+ monitor.pollForNewCompletion();
+ Thread.sleep(10000);
+ System.out.println("Polling...");
+ } catch (Exception ignore) {
+ ignore.printStackTrace();
+ }
+ }
+ }
+}
@@ -0,0 +1,25 @@
+package com.thoughtworks.go.monitor;
+
+import java.util.List;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class NameToSongMapping {
+
+ private String type;
+
+ public NameToSongMapping(String type) {
+ this.type = type;
+ }
+
+ public String songForUser(List<String> users) {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(type + "_userToSongMapping");
+ for (String user : users) {
+ try {
+ return resourceBundle.getString(user);
+ } catch (MissingResourceException e) {
+ }
+ }
+ return resourceBundle.getString("default");
+ }
+}
@@ -0,0 +1,21 @@
+package com.thoughtworks.go.monitor;
+
+import javazoom.jl.player.advanced.AdvancedPlayer;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+
+public class SongPlayer {
+
+ public static void playSong(String songPath) {
+ try {
+ System.out.println("Playing song " + songPath);
+ FileInputStream soundFile = new FileInputStream(songPath);
+ BufferedInputStream bis = new BufferedInputStream(soundFile);
+ AdvancedPlayer player = new AdvancedPlayer(bis);
+ player.play(700);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}

0 comments on commit 6efee81

Please sign in to comment.