From 8029baf595ea247b29d928ca242e316583149f0b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 18 Nov 2012 17:23:27 +0100 Subject: o Adding "buildable" to the job status. --- .../java/io/trygvis/esper/testing/XmlUtil.java | 10 +++ .../esper/testing/jenkins/JenkinsClient.java | 94 ++++++++++------------ 2 files changed, 52 insertions(+), 52 deletions(-) (limited to 'src/main/java/io/trygvis') diff --git a/src/main/java/io/trygvis/esper/testing/XmlUtil.java b/src/main/java/io/trygvis/esper/testing/XmlUtil.java index 612667f..c2c571c 100644 --- a/src/main/java/io/trygvis/esper/testing/XmlUtil.java +++ b/src/main/java/io/trygvis/esper/testing/XmlUtil.java @@ -28,6 +28,16 @@ public class XmlUtil { } }; + public static F> parseBoolean = new F>() { + public Option f(String s) { + try { + return some(Boolean.parseBoolean(s)); + } catch (Throwable e) { + return none(); + } + } + }; + public static Option childText(Element e, String childName) { return fromNull(e.getChildText(childName)); } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java index f3d2941..dac79d9 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java @@ -4,6 +4,7 @@ import fj.*; import fj.data.*; import io.trygvis.esper.testing.*; import static io.trygvis.esper.testing.XmlUtil.*; +import io.trygvis.esper.testing.jenkins.JenkinsJobXml.*; import static java.lang.Integer.*; import static org.apache.commons.lang.StringUtils.*; import org.codehaus.httpcache4j.*; @@ -59,13 +60,15 @@ public class JenkinsClient { public JenkinsJobXml fetchJob(URI uri) throws IOException, JDOMException, XMLStreamException { Element root = fetchXml(uri).getRootElement(); - switch (root.getName()) { + String name = root.getName(); + + switch (name) { case "freeStyleProject": - return FreeStyleProjectXml.parse(root); + return JenkinsJobXml.parse(uri, JenkinsJobType.FREE_STYLE, root); case "mavenModuleSet": - return MavenModuleSetXml.parse(root); + return JenkinsJobXml.parse(uri, JenkinsJobType.MAVEN, root); default: - throw new IOException("Unknown project type: " + root.getName()); + throw new IOException("Unknown project type: " + name); } } @@ -138,86 +141,73 @@ class JenkinsJobEntryXml { } } -abstract class JenkinsJobXml { +class JenkinsJobXml { + enum JenkinsJobType { + MAVEN, FREE_STYLE + } + + public final JenkinsJobType type; public final Option description; public final Option displayName; public final Option name; - public final Option url; + public final URI url; public final Option color; + public final boolean buildable; public final Option lastBuild; public final Option lastCompletedBuild; public final Option lastFailedBuild; public final Option lastSuccessfulBuild; public final Option lastUnsuccessfulBuild; - protected JenkinsJobXml(Option description, Option displayName, Option name, Option url, Option color, Option lastBuild, Option lastCompletedBuild, Option lastFailedBuild, Option lastSuccessfulBuild, Option lastUnsuccessfulBuild) { + protected JenkinsJobXml(JenkinsJobType type, Option description, Option displayName, + Option name, URI url, Option color, boolean buildable, + Option lastBuild, Option lastCompletedBuild, + Option lastFailedBuild, Option lastSuccessfulBuild, + Option lastUnsuccessfulBuild) { + this.type = type; this.description = description; this.displayName = displayName; this.name = name; this.url = url; this.color = color; + this.buildable = buildable; this.lastBuild = lastBuild; this.lastCompletedBuild = lastCompletedBuild; this.lastFailedBuild = lastFailedBuild; this.lastSuccessfulBuild = lastSuccessfulBuild; this.lastUnsuccessfulBuild = lastUnsuccessfulBuild; } -} -class BuildXml { - public final int number; - public final URI url; - public static F> buildXml = new F>() { - public Option f(Element element) { - Option number = childText(element, "number").bind(XmlUtil.parseInt); - Option url = childText(element, "url").bind(parseUri); + static class BuildXml { + public final int number; + public final URI url; + public static F> buildXml = new F>() { + public Option f(Element element) { + Option number = childText(element, "number").bind(XmlUtil.parseInt); + Option url = childText(element, "url").bind(parseUri); + + if(number.isNone() || url.isNone()) { + return Option.none(); + } - if(number.isNone() || url.isNone()) { - return Option.none(); + return Option.some(new BuildXml(number.some(), url.some())); } + }; - return Option.some(new BuildXml(number.some(), url.some())); + BuildXml(int number, URI url) { + this.number = number; + this.url = url; } - }; - - BuildXml(int number, URI url) { - this.number = number; - this.url = url; - } -} - -class FreeStyleProjectXml extends JenkinsJobXml { - FreeStyleProjectXml(Option description, Option displayName, Option name, Option url, Option color, Option lastBuild, Option lastCompletedBuild, Option lastFailedBuild, Option lastSuccessfulBuild, Option lastUnsuccessfulBuild) { - super(description, displayName, name, url, color, lastBuild, lastCompletedBuild, lastFailedBuild, lastSuccessfulBuild, lastUnsuccessfulBuild); - } - - public static JenkinsJobXml parse(Element root) { - return new FreeStyleProjectXml( - childText(root, "description"), - childText(root, "displayName"), - childText(root, "name"), - childText(root, "url"), - childText(root, "color"), - child(root, "lastBuild").bind(BuildXml.buildXml), - child(root, "lastCompletedBuild").bind(BuildXml.buildXml), - child(root, "lastFailedBuild").bind(BuildXml.buildXml), - child(root, "lastSuccessfulBuild").bind(BuildXml.buildXml), - child(root, "lastUnsuccessfulBuild").bind(BuildXml.buildXml)); - } -} - -class MavenModuleSetXml extends JenkinsJobXml { - MavenModuleSetXml(Option description, Option displayName, Option name, Option url, Option color, Option lastBuild, Option lastCompletedBuild, Option lastFailedBuild, Option lastSuccessfulBuild, Option lastUnsuccessfulBuild) { - super(description, displayName, name, url, color, lastBuild, lastCompletedBuild, lastFailedBuild, lastSuccessfulBuild, lastUnsuccessfulBuild); } - public static JenkinsJobXml parse(Element root) { - return new MavenModuleSetXml( + public static JenkinsJobXml parse(URI uri, JenkinsJobType type, Element root) { + return new JenkinsJobXml(type, childText(root, "description"), childText(root, "displayName"), childText(root, "name"), - childText(root, "url"), + childText(root, "url").bind(parseUri).orSome(uri), childText(root, "color"), + childText(root, "buildable").bind(parseBoolean).orSome(false), child(root, "lastBuild").bind(BuildXml.buildXml), child(root, "lastCompletedBuild").bind(BuildXml.buildXml), child(root, "lastFailedBuild").bind(BuildXml.buildXml), -- cgit v1.2.3