1 import java.io.IOException;
2 import java.text.ParseException;
3 import java.text.SimpleDateFormat;
4
5 import org.apache.commons.httpclient.HttpClient;
6 import org.apache.commons.httpclient.HttpException;
7 import org.apache.commons.httpclient.HttpMethod;
8 import org.apache.commons.httpclient.methods.GetMethod;
9 import org.apache.commons.lang.StringUtils;
10
11 public class Deploy {
12 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd.hhmmss");
13
14 public static void main(String[] args) {
15 Deploy deploy = new Deploy();
16 deploy.run();
17 }
18
19 public void run() {
20 try {
21 String url = getCurlUrl();
22 System.out.println("\n" + url);
23 } catch (Throwable t) {
24 t.printStackTrace();
25 }
26 }
27
28 protected String getCurlUrl() throws Exception {
29 String url = getUrl("maven-metadata.xml");
30 String xml = getContents(url);
31 BuildInfo bi = getBuildInfo(xml);
32 String filename = getFilename(bi);
33 return getUrl(filename);
34 }
35
36 protected String getFilename(BuildInfo bi) {
37 StringBuffer sb = new StringBuffer();
38 sb.append(bi.getArtifactId());
39 sb.append("-");
40 String version = bi.getVersion();
41 if (version.endsWith("-SNAPSHOT")) {
42 version = StringUtils.replace(version, "-SNAPSHOT", "");
43 }
44 sb.append(version);
45 sb.append("-");
46 sb.append(sdf.format(bi.getTimestamp()));
47 sb.append("-");
48 sb.append(bi.getBuildNumber());
49 sb.append(".war");
50 return sb.toString();
51 }
52
53 protected BuildInfo getBuildInfo(String contents) throws ParseException {
54 String artifactId = StringUtils.substringBetween(contents, "<artifactId>", "</artifactId>");
55 String version = StringUtils.substringBetween(contents, "<version>", "</version>");
56 String buildNumber = StringUtils.substringBetween(contents, "<buildNumber>", "</buildNumber>");
57 String timestamp = StringUtils.substringBetween(contents, "<timestamp>", "</timestamp>");
58
59 BuildInfo bi = new BuildInfo();
60 bi.setArtifactId(artifactId);
61 bi.setVersion(version);
62 bi.setBuildNumber(new Integer(buildNumber));
63 bi.setTimestamp(sdf.parse(timestamp));
64 return bi;
65 }
66
67 protected String getUrl(String filename) {
68 String base = "http://maven.kuali.org/snapshot/org/kuali/student/web/ks-embedded/1.1.0-M9-SNAPSHOT/";
69 return base + filename;
70 }
71
72 protected String getContents(String url) throws IOException, HttpException {
73 HttpClient client = new HttpClient();
74 HttpMethod method = new GetMethod(url);
75 client.executeMethod(method);
76 return method.getResponseBodyAsString();
77 }
78
79 }