diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-11 18:26:30 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-12-11 18:26:30 +0100 |
commit | 17f6eaadeb91057cb37309271c0b6e79439f64aa (patch) | |
tree | 06d41bafd9aca824b8df7f4716e4a7c37db32f64 /src/main | |
parent | 91fbd12e13e16c4b163803e37ac24a0d1629d82d (diff) | |
download | esper-testing-17f6eaadeb91057cb37309271c0b6e79439f64aa.tar.gz esper-testing-17f6eaadeb91057cb37309271c0b6e79439f64aa.tar.bz2 esper-testing-17f6eaadeb91057cb37309271c0b6e79439f64aa.tar.xz esper-testing-17f6eaadeb91057cb37309271c0b6e79439f64aa.zip |
o Starting to parse out commit info from the Jenkins build too.
Diffstat (limited to 'src/main')
5 files changed, 283 insertions, 139 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildXml.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildXml.java new file mode 100755 index 0000000..e80097b --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildXml.java @@ -0,0 +1,173 @@ +package io.trygvis.esper.testing.jenkins; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.jdom2.Element; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fj.F; +import fj.data.Option; +import io.trygvis.esper.testing.Util; + +import static fj.data.List.iterableList; +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.data.Option.somes; +import static io.trygvis.esper.testing.Util.childText; +import static io.trygvis.esper.testing.jenkins.JenkinsBuildXml.ChangeSetItemXml.parseChangeSetItem; +import static io.trygvis.esper.testing.jenkins.JenkinsBuildXml.RevisionXml.parseRevision; + +public class JenkinsBuildXml { + private static final Logger logger = LoggerFactory.getLogger(JenkinsBuildXml.class); + + public final URI url; + + public final int number; + + public final Option<String> result; + + public final int duration; + + public final long timestamp; + + public final Option<ChangeSetXml> changeSet; + + JenkinsBuildXml(URI url, int number, Option<String> result, int duration, long timestamp, Option<ChangeSetXml> changeSet) { + this.url = url; + this.number = number; + this.result = result; + this.duration = duration; + this.timestamp = timestamp; + this.changeSet = changeSet; + } + + public static Option<JenkinsBuildXml> parse(Element root) { + Option<URI> url = childText(root, "url").bind(Util.parseUri); + Option<Integer> number = childText(root, "number").bind(Util.parseInt); + Option<String> result = childText(root, "result"); + Option<Integer> duration = childText(root, "duration").bind(Util.parseInt); + Option<Long> timestamp = childText(root, "timestamp").bind(Util.parseLong); + + if (url.isNone()) { + logger.warn("Missing required field: <url>"); + return none(); + } + if (number.isNone()) { + logger.warn("Missing required field: <number>"); + return none(); + } + if (duration.isNone()) { + logger.warn("Missing required field: <duration>"); + return none(); + } + if (timestamp.isNone()) { + logger.warn("Missing required field: <timestamp>"); + return none(); + } + + Option<ChangeSetXml> changeSet = none(); + Element e = root.getChild("changeSet"); + if (e != null) { + changeSet = ChangeSetXml.parse(e); + } + + return some(new JenkinsBuildXml(url.some(), number.some(), result, duration.some(), timestamp.some(), changeSet)); + } + + public static class ChangeSetXml { + public final List<ChangeSetItemXml> items; + + public final Option<RevisionXml> revision; + + public ChangeSetXml(List<ChangeSetItemXml> items, Option<RevisionXml> revision) { + this.items = items; + this.revision = revision; + } + + public static Option<ChangeSetXml> parse(Element changeSet) { + + List<ChangeSetItemXml> items = new ArrayList<>(somes(iterableList(changeSet.getChildren("item")).map(parseChangeSetItem)).toCollection()); + + Option<RevisionXml> revision = Option.fromNull(changeSet.getChild("revision")).bind(parseRevision); + + return some(new ChangeSetXml(items, revision)); + } + } + + public static class ChangeSetItemXml { + public final String commitId; + + public final DateTime date; + + public final String msg; + + /** + * Only subversion has this field + */ + public final Option<String> user; + + public ChangeSetItemXml(String commitId, DateTime date, String msg, Option<String> user) { + this.commitId = commitId; + this.date = date; + this.msg = msg; + this.user = user; + } + + private static final F<String, Option<DateTime>> parseDate = new F<String, Option<DateTime>>() { + DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z"); + + public Option<DateTime> f(String s) { + try { + return some(parser.parseDateTime(s)); + } catch (IllegalArgumentException e) { + return none(); + } + } + }; + + public static final F<Element, Option<ChangeSetItemXml>> parseChangeSetItem = new F<Element, Option<ChangeSetItemXml>>() { + public Option<ChangeSetItemXml> f(Element item) { + Option<String> commitId = childText(item, "commitId"); + Option<DateTime> date = childText(item, "date").bind(parseDate); + Option<String> msg = childText(item, "msg"); + Option<String> user = childText(item, "user"); + + if (commitId.isNone() || date.isNone() || msg.isNone()) { + return none(); + } + + return some(new ChangeSetItemXml(commitId.some(), date.some(), msg.some(), user)); + } + }; + } + + public static class RevisionXml { + public final String module; + + public final String revision; + + public RevisionXml(String module, String revision) { + this.module = module; + this.revision = revision; + } + + public static final F<Element, Option<RevisionXml>> parseRevision = new F<Element, Option<RevisionXml>>() { + public Option<RevisionXml> f(Element e) { + Option<String> module = childText(e, "module"); + Option<String> revision = childText(e, "revision"); + + if (module.isNone() || revision.isNone()) { + return none(); + } + + return some(new RevisionXml(module.some(), revision.some())); + } + }; + } +} 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 0aa63c1..39dfc66 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java @@ -2,7 +2,6 @@ package io.trygvis.esper.testing.jenkins; import fj.*; import fj.data.*; -import io.trygvis.esper.testing.*; import io.trygvis.esper.testing.jenkins.JenkinsJobXml.*; import io.trygvis.esper.testing.util.*; import org.apache.abdera.*; @@ -20,7 +19,6 @@ import java.util.*; import java.util.List; import static fj.data.Option.*; -import static io.trygvis.esper.testing.Util.*; import static io.trygvis.esper.testing.util.HttpClient.inputStreamOnly; import static java.lang.System.currentTimeMillis; import static org.apache.commons.lang.StringUtils.*; @@ -80,12 +78,12 @@ public class JenkinsClient { if (d.isNone()) { Option<String> n = Option.none(); - return new JenkinsXml(n, n, n, Collections.<JenkinsJobEntryXml>emptyList()); + return new JenkinsXml(n, n, n, Collections.<JenkinsXml.JobXml>emptyList()); } Element root = d.some().getRootElement(); - List<JenkinsJobEntryXml> jobs = new ArrayList<>(); + List<JenkinsXml.JobXml> jobs = new ArrayList<>(); for (Element job : root.getChildren("job")) { String name = trimToNull(job.getChildText("name")); String u = trimToNull(job.getChildText("url")); @@ -95,7 +93,7 @@ public class JenkinsClient { continue; } - jobs.add(new JenkinsJobEntryXml(name, u, color)); + jobs.add(new JenkinsXml.JobXml(name, u, color)); } return new JenkinsXml( @@ -155,53 +153,7 @@ public class JenkinsClient { } } - public static class JenkinsBuildXml { - - public final URI url; - public final int number; - public final String result; - public final int duration; - public final long timestamp; - - JenkinsBuildXml(URI url, int number, String result, int duration, long timestamp) { - this.url = url; - this.number = number; - this.result = result; - this.duration = duration; - this.timestamp = timestamp; - } - - public static Option<JenkinsBuildXml> parse(Element root) { - Option<URI> url = childText(root, "url").bind(Util.parseUri); - Option<Integer> number = childText(root, "number").bind(Util.parseInt); - Option<String> result = childText(root, "result"); - Option<Integer> duration = childText(root, "duration").bind(Util.parseInt); - Option<Long> timestamp = childText(root, "timestamp").bind(Util.parseLong); - - if(url.isNone()) { - logger.warn("Missing required field: <url>"); - return none(); - } - if(number.isNone()) { - logger.warn("Missing required field: <number>"); - return none(); - } - if(result.isNone()) { - logger.warn("Missing required field: <result>"); - return none(); - } - if(duration.isNone()) { - logger.warn("Missing required field: <duration>"); - return none(); - } - if(timestamp.isNone()) { - logger.warn("Missing required field: <timestamp>"); - return none(); - } - - return some(new JenkinsBuildXml(url.some(), number.some(), result.some(), duration.some(), timestamp.some())); - } - }} +} class JenkinsEntryXml { public final String id; @@ -219,99 +171,24 @@ class JenkinsXml { public final Option<String> nodeName; public final Option<String> nodeDescription; public final Option<String> description; - public final List<JenkinsJobEntryXml> jobs; + public final List<JobXml> jobs; - JenkinsXml(Option<String> nodeName, Option<String> nodeDescription, Option<String> description, List<JenkinsJobEntryXml> jobs) { + JenkinsXml(Option<String> nodeName, Option<String> nodeDescription, Option<String> description, List<JobXml> jobs) { this.nodeName = nodeName; this.nodeDescription = nodeDescription; this.description = description; this.jobs = jobs; } -} - -class JenkinsJobEntryXml { - public final String name; - public final String url; - public final String color; - - JenkinsJobEntryXml(String name, String url, String color) { - this.name = name; - this.url = url; - this.color = color; - } -} -class JenkinsJobXml { - enum JenkinsJobType { - FREE_STYLE, MAVEN_MODULE_SET, MAVEN_MODULE, MATRIX - } + public static class JobXml { + public final String name; + public final String url; + public final String color; - public final JenkinsJobType type; - public final Option<String> description; - public final Option<String> displayName; - public final Option<String> name; - public final URI url; - public final Option<String> color; - public final boolean buildable; - public final Option<BuildXml> lastBuild; - public final Option<BuildXml> lastCompletedBuild; - public final Option<BuildXml> lastFailedBuild; - public final Option<BuildXml> lastSuccessfulBuild; - public final Option<BuildXml> lastUnsuccessfulBuild; - - protected JenkinsJobXml(JenkinsJobType type, Option<String> description, Option<String> displayName, - Option<String> name, URI url, Option<String> color, boolean buildable, - Option<BuildXml> lastBuild, Option<BuildXml> lastCompletedBuild, - Option<BuildXml> lastFailedBuild, Option<BuildXml> lastSuccessfulBuild, - Option<BuildXml> 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; - } - - static class BuildXml { - public final int number; - public final URI url; - public static F<Element, Option<BuildXml>> buildXml = new F<Element, Option<BuildXml>>() { - public Option<BuildXml> f(Element element) { - Option<Integer> number = childText(element, "number").bind(Util.parseInt); - Option<URI> url = childText(element, "url").bind(Util.parseUri); - - if (number.isNone() || url.isNone()) { - return Option.none(); - } - - return some(new BuildXml(number.some(), url.some())); - } - }; - - BuildXml(int number, URI url) { - this.number = number; + JobXml(String name, String url, String color) { + this.name = name; this.url = url; + this.color = color; } } - - public static JenkinsJobXml parse(URI url, JenkinsJobType type, Element root) { - return new JenkinsJobXml(type, - childText(root, "description"), - childText(root, "displayName"), - childText(root, "name"), - childText(root, "url").bind(Util.parseUri).orSome(url), - childText(root, "color"), - childText(root, "buildable").bind(Util.parseBoolean).orSome(false), - 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)); - } } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobXml.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobXml.java new file mode 100755 index 0000000..8cbe049 --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobXml.java @@ -0,0 +1,88 @@ +package io.trygvis.esper.testing.jenkins; + +import java.net.URI; + +import org.jdom2.Element; + +import fj.F; +import fj.data.Option; +import io.trygvis.esper.testing.Util; + +import static fj.data.Option.some; +import static io.trygvis.esper.testing.Util.child; +import static io.trygvis.esper.testing.Util.childText; + +class JenkinsJobXml { + enum JenkinsJobType { + FREE_STYLE, MAVEN_MODULE_SET, MAVEN_MODULE, MATRIX + } + + public final JenkinsJobType type; + public final Option<String> description; + public final Option<String> displayName; + public final Option<String> name; + public final URI url; + public final Option<String> color; + public final boolean buildable; + public final Option<BuildXml> lastBuild; + public final Option<BuildXml> lastCompletedBuild; + public final Option<BuildXml> lastFailedBuild; + public final Option<BuildXml> lastSuccessfulBuild; + public final Option<BuildXml> lastUnsuccessfulBuild; + + protected JenkinsJobXml(JenkinsJobType type, Option<String> description, Option<String> displayName, + Option<String> name, URI url, Option<String> color, boolean buildable, + Option<BuildXml> lastBuild, Option<BuildXml> lastCompletedBuild, + Option<BuildXml> lastFailedBuild, Option<BuildXml> lastSuccessfulBuild, + Option<BuildXml> 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; + } + + static class BuildXml { + public final int number; + public final URI url; + public static F<Element, Option<BuildXml>> buildXml = new F<Element, Option<BuildXml>>() { + public Option<BuildXml> f(Element element) { + Option<Integer> number = childText(element, "number").bind(Util.parseInt); + Option<URI> url = childText(element, "url").bind(Util.parseUri); + + if (number.isNone() || url.isNone()) { + return Option.none(); + } + + return some(new BuildXml(number.some(), url.some())); + } + }; + + BuildXml(int number, URI url) { + this.number = number; + this.url = url; + } + } + + public static JenkinsJobXml parse(URI url, JenkinsJobType type, Element root) { + return new JenkinsJobXml(type, + childText(root, "description"), + childText(root, "displayName"), + childText(root, "name"), + childText(root, "url").bind(Util.parseUri).orSome(url), + childText(root, "color"), + childText(root, "buildable").bind(Util.parseBoolean).orSome(false), + 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)); + } +} diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java index 4bbc007..ebc46ce 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -46,7 +46,7 @@ public class JenkinsServerActor implements TransactionalActor { continue; } - logger.info("New build: " + entry.id + ", fetching info"); + logger.debug("Build: " + entry.id + ", fetching info"); Option<JenkinsBuildXml> buildXmlOption = client.fetchBuild(apiXml(entry.url)); @@ -56,6 +56,12 @@ public class JenkinsServerActor implements TransactionalActor { JenkinsBuildXml build = buildXmlOption.some(); + if(build.result.isNone()) { + logger.debug("Not done building, <result> is not available."); + continue; + } + String result = build.result.some(); + URI jobUrl = extrapolateJobUrlFromBuildUrl(build.url.toASCIIString()); Option<JenkinsJobDto> jobDtoOption = dao.selectJobByUrl(jobUrl); @@ -86,7 +92,7 @@ public class JenkinsServerActor implements TransactionalActor { job, entry.id, build.url, - build.result, + result, build.number, build.duration, build.timestamp); diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerOld.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerOld.java index 7e1dc9a..cfd9939 100644..100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerOld.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerOld.java @@ -86,7 +86,7 @@ public class JenkinsServerOld implements Closeable { JenkinsXml xml = client.fetchJobs(url); List<URI> jobUris = new ArrayList<>(xml.jobs.size()); - for (JenkinsJobEntryXml job : xml.jobs) { + for (JenkinsXml.JobXml job : xml.jobs) { jobUris.add(URI.create(job.url)); } |