
com.clarolab.entities.JenkinsBuild Maven / Gradle / Ivy
package com.clarolab.entities;
import com.clarolab.http.client.HttpClient;
import com.clarolab.http.utils.UrlUtils;
import com.clarolab.utils.JenkinsConstants;
import com.google.common.collect.Lists;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.java.Log;
import java.util.List;
import java.util.stream.Collectors;
@Getter
@Setter
@Log
@ToString
public class JenkinsBuild extends JenkinsBase{
private String id;
@Getter(AccessLevel.PRIVATE)
@ToString.Exclude
private HttpClient httpClient;
private String fullDisplayName;
private String displayName;
private long duration;
private int number;
private int queueId;
private String url;
private String result;
private long timestamp;
private List artifacts = Lists.newArrayList();;
public JenkinsBuild setHttpClient(HttpClient httpClient){
this.httpClient = httpClient;
return this;
}
public JenkinsBuild getDetails() throws Exception {
JenkinsBuild jenkinsBuild = httpClient.get(UrlUtils.getEndpoint(url).toString() + JenkinsConstants.JENKINS_API_JSON_PRETTY_ENDPOINT, JenkinsBuild.class);
id = jenkinsBuild.getId();
fullDisplayName = jenkinsBuild.getFullDisplayName();
displayName = jenkinsBuild.getDisplayName();
duration = jenkinsBuild.getDuration();
number = jenkinsBuild.getNumber();
queueId = jenkinsBuild.getQueueId();
url = jenkinsBuild.getUrl();
result = jenkinsBuild.getResult();
timestamp = jenkinsBuild.getTimestamp();
artifacts = jenkinsBuild.getArtifacts();
artifacts.forEach(artifact -> artifact.setHttpClient(httpClient).setJobUrl(this.url));
return this;
}
public String getArtifactContent(String artifactFileName) {
JenkinsArtifact artifact = artifacts.stream().filter(a -> a.getFileName().equals(artifactFileName)).findFirst().orElse(null);
if (artifact != null)
return artifact.getContent();
return null;
}
List getUsefulFileArtifacts(){
return getArtifacts().stream().filter(element -> !element.isNotUsefulFile()).collect(Collectors.toList());
}
public List getArtifactsWithRobotReports(){
return getUsefulFileArtifacts().stream().filter(element -> element.getFileName().equals(JenkinsConstants.JENKINS_REPORT_NAME_ROBOT)).collect(Collectors.toList());
}
public List getArtifactsWithCucumberReports(){
return getUsefulFileArtifacts().stream().filter(element -> element.getFileName().matches(JenkinsConstants.JENKINS_REPORT_NAME_CUCUMBER) && !element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_ALLURE) && !element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_CYPRESS)&& !element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_JEST))
.collect(Collectors.toList());
}
public List getArtifactsWithJunitReports(){
return getUsefulFileArtifacts().stream().filter(element -> element.getFileName().matches(JenkinsConstants.JENKINS_REPORT_NAME_JUNIT)).collect(Collectors.toList());
}
public List getArtifactsWithTestNGReports(){
return getUsefulFileArtifacts().stream().filter(element -> element.getFileName().equals(JenkinsConstants.JENKINS_REPORT_NAME_TESTNG)).collect(Collectors.toList());
}
public List getArtifactsWithAllureReports(){
return getUsefulFileArtifacts().stream().filter(element -> element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_ALLURE)).collect(Collectors.toList());
}
public List getArtifactsWithCypressReports() {
return getUsefulFileArtifacts().stream().filter(element -> element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_CYPRESS)).collect(Collectors.toList());
}
public List getArtifactsWithJestReports() {
return getUsefulFileArtifacts().stream().filter(element -> element.getRelativePath().contains(JenkinsConstants.JENKINS_REPORT_NAME_JEST)).collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy