Permalink
Browse files

tidy up a bit

  • Loading branch information...
1 parent 95718ea commit a22e61eead43ac76ffaae3a46406ecd9e0ba4c62 @philandstuff committed Feb 3, 2011
View
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="lib" level="project" />
+ </component>
+</module>
+
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -10,7 +10,7 @@
* Time: 20:06
* To change this template use File | Settings | File Templates.
*/
-public class BlameMonitor {
+public class BlameMonitor implements BuildMonitorListener {
private JFrame frame;
private JLabel label;
@@ -29,13 +29,19 @@ public void createWindow() {
}
- public void blame(String result, String user) {
- setWindowTo(result.equals("Failed") ? Color.RED : Color.GREEN);
+ public void brokeTheBuild(String user) {
+ frame.setBackground(Color.RED);
showUser(user);
}
- private void setWindowTo(Color color) {
- frame.setBackground(color);
+ public void fixedTheBuild(String user) {
+ frame.setBackground(Color.GREEN);
+ showUser(user);
+ }
+
+ public void pushedWorkingBuild(String user) {
+ frame.setBackground(Color.GREEN);
+ showUser(user);
}
private void showUser(String user) {
@@ -0,0 +1,9 @@
+package com.thoughtworks.go.monitor;
+
+public interface BuildMonitorListener {
+ void brokeTheBuild(String user);
+
+ void fixedTheBuild(String user);
+
+ void pushedWorkingBuild(String user);
+}
@@ -15,42 +15,64 @@
import java.util.List;
import java.util.Set;
-/**
- * @understands Checking if a given stage broke.
- */
public class BuildStatusMonitor {
- private String pipelineName;
- private String stageName;
+ private final String pipelineName;
+ private final String stageName;
+ private final String GO_SERVER;
+
Set<String> visitedStages = new HashSet<String>();
+
+ List<BuildMonitorListener> listeners = new ArrayList<BuildMonitorListener>();
+
private BlameMonitor blameMonitor = new BlameMonitor();
- private final String GO_SERVER = "twu-ci";
+ private SongListener songListener = new SongListener();
+
private boolean borked = false;
- public BuildStatusMonitor(String pipelineName, String stageName) {
+ public BuildStatusMonitor(String pipelineName, String stageName, String goServer) {
this.pipelineName = pipelineName;
this.stageName = stageName;
+ this.GO_SERVER = goServer;
+
+ BlameMonitor blameMonitor = new BlameMonitor();
+ blameMonitor.createWindow();
+ listeners.add(blameMonitor);
+ listeners.add(new SongListener());
+
blameMonitor.createWindow();
}
- public boolean pollForNewCompletion() {
+ public void pollForNewCompletion() {
Stage stage = latestStage();
- if (stage != null && !visitedStages.contains(stage.getStageLocator())) {
+ if (stage != null && !alreadySeen(stage)) {
System.out.println("Found new stage with result " + stage.getResult());
- visitedStages.add(stage.getStageLocator());
-
- if (!isBroken(stage) && !wasFixed(stage)) {
- return false;
- }
+ reportNewStage(stage);
+ }
+ }
- List<String> users = checkinUsersForThisStage(stage);
+ void reportNewStage(Stage stage) {
+ visitedStages.add(stage.getStageLocator());
- blameMonitor.blame(stage.getResult(), checkinUsersForThisStage(stage).get(0));
- SongPlayer.playSong(new NameToSongMapping(stage.getResult()).songForUser(users));
+ List<String> users = checkinUsersForThisStage(stage);
+ String user = users.get(0);
- borked = isBroken(stage);
- return true;
+ for (BuildMonitorListener listener : listeners) {
+ if (isBroken(stage)) {
+ listener.brokeTheBuild(user);
+ }
+ else if (wasFixed(stage)) {
+ listener.fixedTheBuild(user);
+ }
+ else {
+ listener.pushedWorkingBuild(user);
+ }
}
- return false;
+
+ borked = isBroken(stage);
+ }
+
+ private boolean alreadySeen(Stage stage) {
+ return visitedStages.contains(stage.getStageLocator());
}
private boolean wasFixed(Stage stage) {
@@ -110,7 +132,7 @@ public boolean shouldContinue() {
public static void main(String[] args) throws InterruptedException {
Thread.sleep(100);
- BuildStatusMonitor monitor = new BuildStatusMonitor("all", "build");
+ BuildStatusMonitor monitor = new BuildStatusMonitor("all", "build", "twu-ci");
while (true) {
try {
monitor.pollForNewCompletion();
@@ -5,9 +5,13 @@
import java.io.BufferedInputStream;
import java.io.FileInputStream;
-public class SongPlayer {
+public class SongListener implements BuildMonitorListener {
- public static void playSong(String songPath) {
+ private static final String BROKEN_SONG = "failed.mp3";
+ private static final String FIXED_SONG = "fixed.mp3";
+ private static final String PASSED_SONG = "passed.mp3";
+
+ public void playSong(String songPath) {
try {
System.out.println("Playing song " + songPath);
FileInputStream soundFile = new FileInputStream(songPath);
@@ -18,4 +22,16 @@ public static void playSong(String songPath) {
throw new RuntimeException(e);
}
}
+
+ public void brokeTheBuild(String user) {
+ playSong(BROKEN_SONG);
+ }
+
+ public void fixedTheBuild(String user) {
+ playSong(FIXED_SONG);
+ }
+
+ public void pushedWorkingBuild(String user) {
+ playSong(PASSED_SONG);
+ }
}
@@ -0,0 +1,9 @@
+package com.thoughtworks.go.monitor;
+
+public class BuildStatusMonitorTest {
+// @Test
+// public void shouldCallFixedBuild() {
+// BuildStatusMonitor monitor = new BuildStatusMonitor("pipe","stage","server");
+// monitor.reportNewStage(new Stage())
+// }
+}

0 comments on commit a22e61e

Please sign in to comment.