aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-11-13 23:30:52 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-11-13 23:30:52 +0100
commit751e580672cc384e20f62e9440d44bdcb04f1ef0 (patch)
tree1ba5c28d6281770687ebdb73e2981a4954eae760
parent40dd47a3997fdf830fc45bce9c4a387ef3fb4e94 (diff)
downloadesper-testing-751e580672cc384e20f62e9440d44bdcb04f1ef0.tar.gz
esper-testing-751e580672cc384e20f62e9440d44bdcb04f1ef0.tar.bz2
esper-testing-751e580672cc384e20f62e9440d44bdcb04f1ef0.tar.xz
esper-testing-751e580672cc384e20f62e9440d44bdcb04f1ef0.zip
o Adding Jenkins code.
-rw-r--r--pom.xml5
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java61
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java30
3 files changed, 96 insertions, 0 deletions
diff --git a/pom.xml b/pom.xml
index 64fabf8..72db7a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,11 @@
<version>1.6.1</version>
</dependency>
<dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+ <dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
<version>0.7.1.RELEASE</version>
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
new file mode 100644
index 0000000..ddf040c
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java
@@ -0,0 +1,61 @@
+package io.trygvis.esper.testing.jenkins;
+
+import static org.apache.commons.lang.StringUtils.*;
+import org.codehaus.httpcache4j.*;
+import org.codehaus.httpcache4j.cache.*;
+import org.codehaus.httpcache4j.util.*;
+import org.jdom2.*;
+import org.jdom2.input.*;
+
+import javax.xml.stream.*;
+import java.net.*;
+import java.util.*;
+
+public class JenkinsClient {
+ private static final XMLInputFactory xmlReader = XMLInputFactory.newFactory();
+ private static final StAXStreamBuilder streamBuilder = new StAXStreamBuilder();
+ private final HTTPCache http;
+ private final URI apiXmlUri;
+
+ public JenkinsClient(HTTPCache http, URI jenkinsUri) {
+ this.http = http;
+ this.apiXmlUri = URIBuilder.fromURI(jenkinsUri).addRawPath("api/xml").toURI();
+ }
+
+ public List<JenkinsJobXml> fetchJobs() throws XMLStreamException, JDOMException {
+ HTTPResponse response = http.execute(new HTTPRequest(apiXmlUri));
+
+ if (response.getStatus().getCode() != 200) {
+ throw new RuntimeException("Did not get 200 back, got " + response.getStatus().getCode());
+ }
+
+ Element doc = streamBuilder.build(xmlReader.createXMLStreamReader(response.getPayload().getInputStream())).getRootElement();
+
+ List<JenkinsJobXml> jobs = new ArrayList<>();
+ for (Element job : doc.getChildren("job")) {
+ String name = trimToNull(job.getChildText("name"));
+ String url = trimToNull(job.getChildText("url"));
+ String color = trimToNull(job.getChildText("color"));
+
+ if (name == null || url == null || color == null) {
+ continue;
+ }
+
+ jobs.add(new JenkinsJobXml(name, url, color));
+ }
+
+ return jobs;
+ }
+}
+
+class JenkinsJobXml {
+ public final String name;
+ public final String url;
+ public final String color;
+
+ JenkinsJobXml(String name, String url, String color) {
+ this.name = name;
+ this.url = url;
+ this.color = color;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
new file mode 100644
index 0000000..942aa15
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsImporter.java
@@ -0,0 +1,30 @@
+package io.trygvis.esper.testing.jenkins;
+
+import io.trygvis.esper.testing.*;
+import org.codehaus.httpcache4j.cache.*;
+import org.codehaus.httpcache4j.client.*;
+
+import java.net.*;
+import java.util.*;
+
+public class JenkinsImporter {
+ private final JenkinsClient jenkinsClient;
+
+ public static void main(String[] args) throws Exception {
+ Main.configureLog4j();
+ new JenkinsImporter().work();
+ }
+
+ public JenkinsImporter() {
+ HTTPCache http = new HTTPCache(new MemoryCacheStorage(), HTTPClientResponseResolver.createMultithreadedInstance());
+ jenkinsClient = new JenkinsClient(http, URI.create("https://builds.apache.org"));
+ }
+
+ private void work() throws Exception {
+ List<JenkinsJobXml> jobs = jenkinsClient.fetchJobs();
+
+ for (JenkinsJobXml job : jobs) {
+ System.out.println("job.name = " + job.name);
+ }
+ }
+}