Skip to content

Commit

Permalink
Fixed #309 - Added better support for Maven Modules
Browse files Browse the repository at this point in the history
 - slight modifications based on removement of Guava
  • Loading branch information
Jakub Zacek authored and khmarbaise committed May 25, 2019
1 parent c4f5953 commit 5807954
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 21 deletions.
9 changes: 8 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Release 0.4.0 (NOT RELEASED YET)

* [Fixed Issue 309][issue-309]

* Added possibility to get mode detailed data from Maven Modules from Jobs/Builds

Thanks for that to [Jakub Zacek](https://github.com/dawon).

* [Fixed Issue 395][issue-395]

* Remove google guava lib
Expand Down Expand Up @@ -187,7 +193,7 @@
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)

Thanks for that to [Chids](https://github.com/Chids-gs).

## Release 0.3.7

* Changed Eclipse Formatting configuration.
Expand Down Expand Up @@ -1140,6 +1146,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport();
[issue-291]: https://github.com/jenkinsci/java-client-api/issues/291
[issue-298]: https://github.com/jenkinsci/java-client-api/issues/298
[issue-301]: https://github.com/jenkinsci/java-client-api/issues/301
[issue-309]: https://github.com/jenkinsci/java-client-api/issues/309
[issue-394]: https://github.com/jenkinsci/java-client-api/issues/394
[issue-395]: https://github.com/jenkinsci/java-client-api/issues/395
[issue-396]: https://github.com/jenkinsci/java-client-api/issues/396
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.offbytwo.jenkins.model;

import com.offbytwo.jenkins.client.JenkinsHttpConnection;
import java.util.function.Predicate;

/**
* The base model.
Expand All @@ -17,8 +18,7 @@ public class BaseModel {
* The class.
*/
private String _class;



/**
* Get the class.
* @return class
Expand Down Expand Up @@ -47,4 +47,9 @@ public BaseModel setClient(final JenkinsHttpConnection client) {
this.client = client;
return this;
}

protected static Predicate<? super Build> isBuildNumberEqualTo(int buildNumber) {
return build -> build.getNumber() == buildNumber;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxExc
"");
return client.getFile(artifactUri);
}

/**
* Returns {@link MavenModuleWithDetails} based on its name
*
* @param name module name
* @return {@link MavenModuleWithDetails}
* @throws IOException in case of error.
*/
public MavenModuleWithDetails getModule(String name) throws IOException {
return client.get(getUrl() + name, MavenModuleWithDetails.class);
}

@Override
public boolean equals(Object obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

package com.offbytwo.jenkins.model;

import static org.apache.commons.lang.StringUtils.join;

import com.offbytwo.jenkins.client.util.EncodingUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;

import com.offbytwo.jenkins.client.util.EncodingUtils;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -186,4 +183,6 @@ public String apply(Map.Entry<String, String> entry) {
return EncodingUtils.formParameter(entry.getKey()) + "=" + EncodingUtils.formParameter(entry.getValue());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT;
import static java.util.stream.Collectors.toList;
Expand All @@ -31,7 +30,7 @@ public class JobWithDetails extends Job {

private boolean buildable;

private List<Build> builds;
private List<Build> builds = Collections.emptyList();

private Build firstBuild;

Expand Down Expand Up @@ -438,10 +437,6 @@ public List<Job> getUpstreamProjects() {
}
}

private static Predicate<? super Build> isBuildNumberEqualTo(int buildNumber) {
return build -> build.getNumber() == buildNumber;
}

public QueueItem getQueueItem() {
return this.queueItem;
}
Expand All @@ -456,6 +451,18 @@ public QueueItem getQueueItem() {
public Optional<Build> getBuildByNumber(final int buildNumber) {
return builds.stream().filter(isBuildNumberEqualTo(buildNumber)).findFirst();
}

/**
* Get a module of a {@link Job}
*
* @param moduleName name of the {@link MavenModule}
* @return The {@link MavenModuleWithDetails} selected by the given module name
* @throws java.io.IOException in case of errors.
*
*/
public MavenModuleWithDetails getModule(String moduleName) throws IOException {
return client.get(getUrl() + moduleName, MavenModuleWithDetails.class);
}

/**
* Empty description to be used for {@link #updateDescription(String)} or
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.offbytwo.jenkins.model;

import com.offbytwo.jenkins.client.util.EncodingUtils;
import com.offbytwo.jenkins.helper.FunctionalHelper;
import com.offbytwo.jenkins.helper.Range;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpResponseException;
Expand All @@ -10,7 +9,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -276,11 +274,7 @@ public List<Job> getUpstreamProjects() {
}
}

private static Predicate<MavenBuild> isBuildNumberEqualTo(int buildNumber) {
return build -> build.getNumber() == buildNumber;
}

/**
/**
* @param buildNumber The build you would like to select.
* @return Optional which contains the {@link MavenBuild}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
/*
* Copyright (c) 2018 Cosmin Stejerean, Karl Heinz Marbaise, and contributors.
*
* Distributed under the MIT license: http://opensource.org/licenses/MIT
*/
package com.offbytwo.jenkins.model;

import java.io.IOException;
import java.util.List;

/**
*
* @author Karl Heinz Marbaise, Ricardo Zanini, René Scheibe, Jakub Zacek
*/
public class MavenModule extends BaseModel {

private List<MavenModuleRecord> moduleRecords;
private String name;
private String url;
private String color;
private String displayName;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public MavenModuleWithDetails details() throws IOException {
return client.get(url, MavenModuleWithDetails.class);
}

public List<MavenModuleRecord> getModuleRecords() {
return moduleRecords;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2018 Cosmin Stejerean, Karl Heinz Marbaise, and contributors.
*
* Distributed under the MIT license: http://opensource.org/licenses/MIT
*/
package com.offbytwo.jenkins.model;

import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT;
import static java.util.stream.Collectors.toList;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Model Class for Maven Modules
*
* @author Jakub Zacek
*/
public class MavenModuleWithDetails extends BaseModel {

private List<Build> builds = Collections.emptyList();
private List actions = Collections.emptyList();
private String displayName;
private BuildResult result;
private String url;
private long duration;
private long timestamp;

public List getActions() {
return actions;
}

public void setActions(List actions) {
this.actions = actions;
}

public void setBuilds(List<Build> builds) {
this.builds = builds;
}

public List<Build> getBuilds() {
return builds.stream()
.map(SET_CLIENT(this.getClient()))
.collect(toList());
}

public Build getBuildByNumber(final int buildNumber) {
return builds.stream()
.filter(isBuildNumberEqualTo(buildNumber))
.map(SET_CLIENT(this.getClient()))
.findFirst()
.orElse(Build.BUILD_HAS_NEVER_RUN);
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public BuildResult getResult() {
return result;
}

public void setResult(BuildResult result) {
this.result = result;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public long getDuration() {
return duration;
}

public void setDuration(long duration) {
this.duration = duration;
}

public String getConsoleOutputText() throws IOException {
return client.get(getUrl() + "/logText/progressiveText");
}

public TestReport getTestReport() throws IOException {
return client.get(this.getUrl() + "/testReport/?depth=1", TestReport.class);
}

}

0 comments on commit 5807954

Please sign in to comment.