|
7 | 7 | package com.offbytwo.jenkins.model; |
8 | 8 |
|
9 | 9 | import com.google.common.base.Predicate; |
| 10 | +import com.google.common.base.Strings; |
10 | 11 |
|
11 | 12 | import java.io.IOException; |
12 | 13 | import java.io.InputStream; |
|
16 | 17 |
|
17 | 18 | import static com.google.common.collect.Collections2.filter; |
18 | 19 |
|
| 20 | +/** |
| 21 | + * This class represents build information with |
| 22 | + * details about what has been done like |
| 23 | + * duration start and of course the build result. |
| 24 | + * |
| 25 | + */ |
19 | 26 | public class BuildWithDetails extends Build { |
20 | 27 |
|
21 | | - List actions; // Should be improved. |
22 | | - boolean building; |
23 | | - String description; |
24 | | - long duration; |
25 | | - long estimatedDuration; |
26 | | - String fullDisplayName; |
27 | | - String id; |
28 | | - long timestamp; |
29 | | - BuildResult result; |
30 | | - List<Artifact> artifacts; |
31 | | - String consoleOutputText; |
32 | | - String consoleOutputHtml; |
33 | | - BuildChangeSet changeSet; |
34 | | - String builtOn; |
35 | | - List<BuildChangeSetAuthor> culprits; |
| 28 | + private List actions; // TODO: Should be improved. |
| 29 | + private boolean building; |
| 30 | + private String description; |
| 31 | + private long duration; |
| 32 | + private long estimatedDuration; |
| 33 | + private String fullDisplayName; |
| 34 | + private String id; |
| 35 | + private long timestamp; |
| 36 | + private BuildResult result; |
| 37 | + private List<Artifact> artifacts; |
| 38 | + private String consoleOutputText; |
| 39 | + private String consoleOutputHtml; |
| 40 | + private BuildChangeSet changeSet; |
| 41 | + private String builtOn; |
| 42 | + private List<BuildChangeSetAuthor> culprits; |
36 | 43 |
|
37 | 44 | public List<Artifact> getArtifacts() { |
38 | 45 | return artifacts; |
@@ -61,21 +68,51 @@ public boolean apply(Map<String, Object> action) { |
61 | 68 | .get("causes"); |
62 | 69 | for (Map<String, Object> cause : causes_blob) { |
63 | 70 |
|
64 | | - BuildCause cause_object = new BuildCause(); |
65 | | - cause_object.setShortDescription((String) cause.get("shortDescription")); |
66 | | - cause_object.setUpstreamBuild((Integer) cause.get("upstreamBuild")); |
67 | | - cause_object.setUpstreamProject((String) cause.get("upstreamProject")); |
68 | | - cause_object.setUpstreamUrl((String) cause.get("upstreamUrl")); |
69 | | - cause_object.setUserId((String) cause.get("userId")); |
70 | | - cause_object.setUserName((String) cause.get("userName")); |
| 71 | + BuildCause convertToBuildCause = convertToBuildCause(cause); |
71 | 72 |
|
72 | | - result.add(cause_object); |
| 73 | + result.add(convertToBuildCause); |
73 | 74 | } |
74 | 75 | } |
75 | 76 |
|
76 | 77 | return result; |
77 | 78 | } |
78 | 79 |
|
| 80 | + private BuildCause convertToBuildCause(Map<String, Object> cause) { |
| 81 | + BuildCause cause_object = new BuildCause(); |
| 82 | + |
| 83 | + //TODO: Think about it. Can this be done more simpler? |
| 84 | + String description = (String) cause.get("shortDescription"); |
| 85 | + if (!Strings.isNullOrEmpty(description)) { |
| 86 | + cause_object.setShortDescription(description); |
| 87 | + } |
| 88 | + |
| 89 | + Integer upstreamBuild = (Integer) cause.get("upstreamBuild"); |
| 90 | + if (upstreamBuild != null) { |
| 91 | + cause_object.setUpstreamBuild(upstreamBuild); |
| 92 | + } |
| 93 | + |
| 94 | + String upstreamProject = (String) cause.get("upstreamProject"); |
| 95 | + if (!Strings.isNullOrEmpty(upstreamProject)) { |
| 96 | + cause_object.setUpstreamProject(upstreamProject); |
| 97 | + } |
| 98 | + |
| 99 | + String upstreamUrl = (String) cause.get("upstreamUrl"); |
| 100 | + if (!Strings.isNullOrEmpty(upstreamProject)) { |
| 101 | + cause_object.setUpstreamUrl(upstreamUrl); |
| 102 | + } |
| 103 | + |
| 104 | + String userId = (String) cause.get("userId"); |
| 105 | + if (!Strings.isNullOrEmpty(userId)) { |
| 106 | + cause_object.setUserId(userId); |
| 107 | + } |
| 108 | + |
| 109 | + String userName = (String) cause.get("userName"); |
| 110 | + if (!Strings.isNullOrEmpty(userName)) { |
| 111 | + cause_object.setUserName(userName); |
| 112 | + } |
| 113 | + return cause_object; |
| 114 | + } |
| 115 | + |
79 | 116 | public String getDescription() { |
80 | 117 | return description; |
81 | 118 | } |
@@ -166,8 +203,7 @@ public void setCulprits(List<BuildChangeSetAuthor> culprits) { |
166 | 203 |
|
167 | 204 | public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException { |
168 | 205 | // We can't just put the artifact's relative path at the end of the url |
169 | | - // string, |
170 | | - // as there could be characters that need to be escaped. |
| 206 | + // string, as there could be characters that need to be escaped. |
171 | 207 | URI uri = new URI(getUrl()); |
172 | 208 | String artifactPath = uri.getPath() + "artifact/" + a.getRelativePath(); |
173 | 209 | URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), artifactPath, "", |
|
0 commit comments