Skip to content

#309 - added better support for Maven Modules #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
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).

* [Fixed Issue 309](https://github.com/jenkinsci/java-client-api/issues/309)

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

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

## Release 0.3.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,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 @@ -477,6 +477,18 @@ public Job apply(Job job) {
return job;
}
}

/**
* 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,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,128 @@
/*
* 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 com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import static com.google.common.collect.Lists.transform;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

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

private List<Build> builds;
private List actions;
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() {
if (builds == null) {
return Collections.emptyList();
} else {
return transform(builds, new Function<Build, Build>() {
@Override
public Build apply(Build from) {
return buildWithClient(from);
}
});
}
}

public Build getBuildByNumber(final int buildNumber) {

Predicate<Build> isMatchingBuildNumber = new Predicate<Build>() {
@Override
public boolean apply(Build input) {
return input.getNumber() == buildNumber;
}
};

Optional<Build> optionalBuild = Iterables.tryFind(builds, isMatchingBuildNumber);
// TODO: Check if we could use Build#NO...instead of Null?
return optionalBuild.orNull() == null ? null : buildWithClient(optionalBuild.orNull());
}

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);
}

private Build buildWithClient(Build from) {
Build ret = from;
if (from != null) {
ret = new Build(from);
ret.setClient(client);
}
return ret;
}

}