|
| 1 | +package org.jenkinsci.plugins.pipeline.maven.model; |
| 2 | + |
| 3 | +import org.jenkinsci.plugins.pipeline.maven.MavenArtifact; |
| 4 | +import org.jenkinsci.plugins.pipeline.maven.publishers.MavenReport; |
| 5 | + |
| 6 | +import java.io.Serializable; |
| 7 | +import java.time.Duration; |
| 8 | +import java.time.ZonedDateTime; |
| 9 | + |
| 10 | +import javax.annotation.Nonnull; |
| 11 | + |
| 12 | +/** |
| 13 | + * @author <a href="mailto:[email protected]">Cyrille Le Clerc</a> |
| 14 | + */ |
| 15 | +public class MavenMojoExecutionDetails implements Comparable<MavenMojoExecutionDetails>, Serializable { |
| 16 | + |
| 17 | + private static final long serialVersionUID = 1L; |
| 18 | + |
| 19 | + @Nonnull |
| 20 | + private final MavenArtifact project; |
| 21 | + @Nonnull |
| 22 | + private final MavenArtifact plugin; |
| 23 | + @Nonnull |
| 24 | + private final String executionId; |
| 25 | + @Nonnull |
| 26 | + private final String goal; |
| 27 | + @Nonnull |
| 28 | + private final ZonedDateTime start; |
| 29 | + @Nonnull |
| 30 | + private ZonedDateTime stop; |
| 31 | + @Nonnull |
| 32 | + private MavenExecutionEventType type; |
| 33 | + |
| 34 | + public MavenMojoExecutionDetails(@Nonnull MavenArtifact project, @Nonnull MavenArtifact plugin, @Nonnull String executionId, @Nonnull String goal, @Nonnull ZonedDateTime start, @Nonnull MavenExecutionEventType type) { |
| 35 | + this.project = project; |
| 36 | + this.plugin = plugin; |
| 37 | + this.executionId = executionId; |
| 38 | + this.goal = goal; |
| 39 | + this.start = start; |
| 40 | + this.stop = start; |
| 41 | + this.type = type; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoStarted} |
| 46 | + */ |
| 47 | + @Nonnull |
| 48 | + public ZonedDateTime getStart() { |
| 49 | + return start; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoSucceeded} and {@code org.apache.maven.execution.ExecutionEvent.Type#MojoFailed} |
| 54 | + */ |
| 55 | + @Nonnull |
| 56 | + public ZonedDateTime getStop() { |
| 57 | + return stop; |
| 58 | + } |
| 59 | + |
| 60 | + public void stop(@Nonnull ZonedDateTime stop, MavenExecutionEventType type) { |
| 61 | + this.stop = stop; |
| 62 | + this.type = type; |
| 63 | + } |
| 64 | + |
| 65 | + @Nonnull |
| 66 | + public MavenArtifact getProject() { |
| 67 | + return project; |
| 68 | + } |
| 69 | + |
| 70 | + @Nonnull |
| 71 | + public MavenArtifact getPlugin() { |
| 72 | + return plugin; |
| 73 | + } |
| 74 | + |
| 75 | + @Nonnull |
| 76 | + public String getExecutionId() { |
| 77 | + return executionId; |
| 78 | + } |
| 79 | + |
| 80 | + @Nonnull |
| 81 | + public String getGoal() { |
| 82 | + return goal; |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public String toString() { |
| 87 | + return "MavenMojoExecutionDetails{" + |
| 88 | + "project=" + project.getId() + |
| 89 | + ", plugin=" + plugin.getId() + |
| 90 | + ", executionId='" + executionId + '\'' + |
| 91 | + ", goal='" + goal + '\'' + |
| 92 | + ", start=" + start + |
| 93 | + ", stop=" + stop + |
| 94 | + ", type=" + type + |
| 95 | + '}'; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public int compareTo(MavenMojoExecutionDetails other) { |
| 100 | + int comparison = this.getStart().compareTo(other.getStart()); |
| 101 | + |
| 102 | + if (comparison == 0) { |
| 103 | + comparison = this.getStop().compareTo(other.getStop()); |
| 104 | + } |
| 105 | + return comparison; |
| 106 | + } |
| 107 | + |
| 108 | + @Nonnull |
| 109 | + public String getDuration() { |
| 110 | + return Duration.between(start, stop).getSeconds() + "s"; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public boolean equals(Object o) { |
| 115 | + if (this == o) return true; |
| 116 | + if (o == null || getClass() != o.getClass()) return false; |
| 117 | + |
| 118 | + MavenMojoExecutionDetails that = (MavenMojoExecutionDetails) o; |
| 119 | + |
| 120 | + if (!project.equals(that.project)) return false; |
| 121 | + if (!plugin.equals(that.plugin)) return false; |
| 122 | + if (!executionId.equals(that.executionId)) return false; |
| 123 | + return goal.equals(that.goal); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public int hashCode() { |
| 128 | + int result = project.hashCode(); |
| 129 | + result = 31 * result + plugin.hashCode(); |
| 130 | + result = 31 * result + executionId.hashCode(); |
| 131 | + result = 31 * result + goal.hashCode(); |
| 132 | + return result; |
| 133 | + } |
| 134 | +} |
0 commit comments