Skip to content

Commit 6512454

Browse files
author
Jakub Zacek
committed
Fixed #309 - Added better support for Maven Modules
1 parent 0af41dc commit 6512454

File tree

5 files changed

+207
-1
lines changed

5 files changed

+207
-1
lines changed

ReleaseNotes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
Added new methods to JenkinsServer for stopping and restarting Jenkins. The methods are restart(Boolean crumbFlag), safeRestart(Boolean crumbFlag), exit(Boolean crumbFlag) and safeExit(Boolean crumbFlag)
118118

119119
Thanks for that to [Chids](https://github.com/Chids-gs).
120+
121+
* [Fixed Issue 309](https://github.com/jenkinsci/java-client-api/issues/309)
122+
123+
Added possibility to get mode detailed data from Maven Modules from Jobs/Builds
124+
125+
Thanks for that to [Jakub Zacek](https://github.com/dawon).
120126

121127
## Release 0.3.7
122128

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,17 @@ 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+
return client.get(getUrl() + name, MavenModuleWithDetails.class);
554+
}
544555

545556
@Override
546557
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: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
1+
/*
2+
* Copyright (c) 2018 Cosmin Stejerean, Karl Heinz Marbaise, and contributors.
3+
*
4+
* Distributed under the MIT license: http://opensource.org/licenses/MIT
5+
*/
16
package com.offbytwo.jenkins.model;
27

8+
import java.io.IOException;
39
import java.util.List;
4-
10+
/**
11+
*
12+
* @author Karl Heinz Marbaise, Ricardo Zanini, René Scheibe, Jakub Zacek
13+
*/
514
public class MavenModule extends BaseModel {
615

716
private List<MavenModuleRecord> moduleRecords;
17+
private String name;
18+
private String url;
19+
private String color;
20+
private String displayName;
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
public String getUrl() {
31+
return url;
32+
}
33+
34+
public void setUrl(String url) {
35+
this.url = url;
36+
}
37+
38+
public String getColor() {
39+
return color;
40+
}
41+
42+
public void setColor(String color) {
43+
this.color = color;
44+
}
45+
46+
public String getDisplayName() {
47+
return displayName;
48+
}
49+
50+
public void setDisplayName(String displayName) {
51+
this.displayName = displayName;
52+
}
53+
54+
public MavenModuleWithDetails details() throws IOException {
55+
return client.get(url, MavenModuleWithDetails.class);
56+
}
857

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

0 commit comments

Comments
 (0)