|
| 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