Skip to content

Commit f05e7eb

Browse files
author
Jakub Zacek
committed
#309 - added better support for Maven Modules
1 parent 0af41dc commit f05e7eb

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,18 @@ public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxExc
541541
"");
542542
return client.getFile(artifactUri);
543543
}
544+
545+
/**
546+
* Returns {@link MavenModuleWithDetails} based on its name
547+
*
548+
* @param name module name
549+
* @return {@link MavenModuleWithDetails}
550+
* @throws IOException in case of error.
551+
*/
552+
public MavenModuleWithDetails getModule(String name) throws IOException {
553+
System.out.println(getUrl() + name);
554+
return client.get(getUrl() + name, MavenModuleWithDetails.class);
555+
}
544556

545557
@Override
546558
public boolean equals(Object obj) {

jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobWithDetails.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,18 @@ public Job apply(Job job) {
477477
return job;
478478
}
479479
}
480+
481+
/**
482+
* Get a module of a {@link Job}
483+
*
484+
* @param moduleName name of the {@link MavenModule}
485+
* @return The {@link MavenModuleWithDetails} selected by the given module name
486+
* @throws java.io.IOException in case of errors.
487+
*
488+
*/
489+
public MavenModuleWithDetails getModule(String moduleName) throws IOException {
490+
return client.get(getUrl() + moduleName, MavenModuleWithDetails.class);
491+
}
480492

481493
/**
482494
* Empty description to be used for {@link #updateDescription(String)} or

jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModule.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
11
package com.offbytwo.jenkins.model;
22

3+
import java.io.IOException;
34
import java.util.List;
45

56
public class MavenModule extends BaseModel {
67

78
private List<MavenModuleRecord> moduleRecords;
9+
private String name;
10+
private String url;
11+
private String color;
12+
private String displayName;
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
22+
public String getUrl() {
23+
return url;
24+
}
25+
26+
public void setUrl(String url) {
27+
this.url = url;
28+
}
29+
30+
public String getColor() {
31+
return color;
32+
}
33+
34+
public void setColor(String color) {
35+
this.color = color;
36+
}
37+
38+
public String getDisplayName() {
39+
return displayName;
40+
}
41+
42+
public void setDisplayName(String displayName) {
43+
this.displayName = displayName;
44+
}
45+
46+
public MavenModuleWithDetails details() throws IOException {
47+
return client.get(url, MavenModuleWithDetails.class);
48+
}
849

950
public List<MavenModuleRecord> getModuleRecords() {
1051
return moduleRecords;
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package com.offbytwo.jenkins.model;
2+
3+
import com.google.common.base.Function;
4+
import com.google.common.base.Optional;
5+
import com.google.common.base.Predicate;
6+
import com.google.common.collect.Iterables;
7+
import static com.google.common.collect.Lists.transform;
8+
import java.io.IOException;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
*
14+
* @author zacekj1
15+
*/
16+
public class MavenModuleWithDetails extends BaseModel {
17+
18+
private List<Build> builds;
19+
private List actions;
20+
private String displayName;
21+
private BuildResult result;
22+
private String url;
23+
private long duration;
24+
private long timestamp;
25+
26+
public List getActions() {
27+
return actions;
28+
}
29+
30+
public void setActions(List actions) {
31+
this.actions = actions;
32+
}
33+
34+
public void setBuilds(List<Build> builds) {
35+
this.builds = builds;
36+
}
37+
38+
public List<Build> getBuilds() {
39+
if (builds == null) {
40+
return Collections.emptyList();
41+
} else {
42+
return transform(builds, new Function<Build, Build>() {
43+
@Override
44+
public Build apply(Build from) {
45+
return buildWithClient(from);
46+
}
47+
});
48+
}
49+
}
50+
51+
public Build getBuildByNumber(final int buildNumber) {
52+
53+
Predicate<Build> isMatchingBuildNumber = new Predicate<Build>() {
54+
@Override
55+
public boolean apply(Build input) {
56+
return input.getNumber() == buildNumber;
57+
}
58+
};
59+
60+
Optional<Build> optionalBuild = Iterables.tryFind(builds, isMatchingBuildNumber);
61+
// TODO: Check if we could use Build#NO...instead of Null?
62+
return optionalBuild.orNull() == null ? null : buildWithClient(optionalBuild.orNull());
63+
}
64+
65+
public String getDisplayName() {
66+
return displayName;
67+
}
68+
69+
public void setDisplayName(String displayName) {
70+
this.displayName = displayName;
71+
}
72+
73+
public BuildResult getResult() {
74+
return result;
75+
}
76+
77+
public void setResult(BuildResult result) {
78+
this.result = result;
79+
}
80+
81+
public String getUrl() {
82+
return url;
83+
}
84+
85+
public void setUrl(String url) {
86+
this.url = url;
87+
}
88+
89+
public long getTimestamp() {
90+
return timestamp;
91+
}
92+
93+
public void setTimestamp(long timestamp) {
94+
this.timestamp = timestamp;
95+
}
96+
97+
public long getDuration() {
98+
return duration;
99+
}
100+
101+
public void setDuration(long duration) {
102+
this.duration = duration;
103+
}
104+
105+
public String getConsoleOutputText() throws IOException {
106+
return client.get(getUrl() + "/logText/progressiveText");
107+
}
108+
109+
public TestReport getTestReport() throws IOException {
110+
return client.get(this.getUrl() + "/testReport/?depth=1", TestReport.class);
111+
}
112+
113+
private Build buildWithClient(Build from) {
114+
Build ret = from;
115+
if (from != null) {
116+
ret = new Build(from);
117+
ret.setClient(client);
118+
}
119+
return ret;
120+
}
121+
122+
}

0 commit comments

Comments
 (0)