From e16e32c653cda7e47a6b9dc8515f187658549921 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 10 Dec 2012 15:16:36 +0100 Subject: o Adding some utilities. --- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 30 ++++++++++++++-------- .../esper/testing/jenkins/JenkinsServerActor.java | 17 ++++++++++-- 2 files changed, 35 insertions(+), 12 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java index bd99768..0195900 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -18,11 +18,11 @@ public class JenkinsDao { private final Connection c; - private static final String JENKINS_SERVER = "uuid, created_date, url"; + public static final String JENKINS_SERVER = "uuid, created_date, url"; - private static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name"; + public static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name"; - private static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp"; + public static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp"; public JenkinsDao(Connection c) { this.c = c; @@ -36,6 +36,14 @@ public class JenkinsDao { URI.create(rs.getString(i))); } + public List toServerList(ResultSet rs) throws SQLException { + List list = new ArrayList<>(); + while (rs.next()) { + list.add(jenkinsServer(rs)); + } + return list; + } + private JenkinsJobDto jenkinsJob(ResultSet rs) throws SQLException { int i = 1; return new JenkinsJobDto( @@ -46,6 +54,14 @@ public class JenkinsDao { fromNull(rs.getString(i))); } + public List toJobList(ResultSet rs) throws SQLException { + List list = new ArrayList<>(); + while (rs.next()) { + list.add(jenkinsJob(rs)); + } + return list; + } + private JenkinsBuildDto jenkinsBuild(ResultSet rs) throws SQLException { int i = 1; return new JenkinsBuildDto( @@ -65,13 +81,7 @@ public class JenkinsDao { where += enabledOnly ? "enabled=true" : ""; try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_SERVER + " FROM jenkins_server " + where)) { - ResultSet rs = s.executeQuery(); - - List servers = new ArrayList<>(); - while (rs.next()) { - servers.add(jenkinsServer(rs)); - } - return servers; + return toServerList(s.executeQuery()); } } 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 fa30f14..4bbc007 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -56,7 +56,7 @@ public class JenkinsServerActor implements TransactionalActor { JenkinsBuildXml build = buildXmlOption.some(); - URI jobUrl = createJobUrl(build.url.toASCIIString()); + URI jobUrl = extrapolateJobUrlFromBuildUrl(build.url.toASCIIString()); Option jobDtoOption = dao.selectJobByUrl(jobUrl); @@ -102,7 +102,7 @@ public class JenkinsServerActor implements TransactionalActor { /** * This sucks, a build should really include the URL to the job. */ - public static URI createJobUrl(String u) { + public static URI extrapolateJobUrlFromBuildUrl(String u) { if (!u.matches(".*/[0-9]*/")) { throw new RuntimeException("Not a valid build url: " + u); } @@ -112,4 +112,17 @@ public class JenkinsServerActor implements TransactionalActor { return URI.create(u); } + + public static String extrapolateMavenModuleFromMavenModuleSetUrl(String u) { + int i = u.lastIndexOf("/"); + if (i == -1) { + throw new RuntimeException("Illegal URL"); + } + u = u.substring(0, i); + i = u.lastIndexOf("/"); + if (i == -1) { + throw new RuntimeException("Illegal URL"); + } + return u.substring(0, i + 1); + } } -- cgit v1.2.3