|
| 1 | +package org.jenkinsci.plugins.pipeline.maven.model; |
| 2 | + |
| 3 | +import org.jenkinsci.plugins.pipeline.maven.MavenArtifact; |
| 4 | + |
| 5 | +import java.io.Serializable; |
| 6 | +import java.time.Duration; |
| 7 | +import java.time.ZonedDateTime; |
| 8 | +import java.time.temporal.ChronoUnit; |
| 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 String lifecyclePhase; |
| 29 | + @Nonnull |
| 30 | + private final ZonedDateTime start; |
| 31 | + @Nonnull |
| 32 | + private ZonedDateTime stop; |
| 33 | + @Nonnull |
| 34 | + private MavenExecutionEventType type; |
| 35 | + |
| 36 | + public MavenMojoExecutionDetails(@Nonnull MavenArtifact project, @Nonnull MavenArtifact plugin, @Nonnull String executionId, @Nonnull String lifecyclePhase, @Nonnull String goal, @Nonnull ZonedDateTime start, @Nonnull MavenExecutionEventType type) { |
| 37 | + this.project = project; |
| 38 | + this.plugin = plugin; |
| 39 | + this.executionId = executionId; |
| 40 | + this.lifecyclePhase = lifecyclePhase; |
| 41 | + this.goal = goal; |
| 42 | + this.start = start; |
| 43 | + this.stop = start; |
| 44 | + this.type = type; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoStarted} |
| 49 | + */ |
| 50 | + @Nonnull |
| 51 | + public ZonedDateTime getStart() { |
| 52 | + return start; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoSucceeded} and {@code org.apache.maven.execution.ExecutionEvent.Type#MojoFailed} |
| 57 | + */ |
| 58 | + @Nonnull |
| 59 | + public ZonedDateTime getStop() { |
| 60 | + return stop; |
| 61 | + } |
| 62 | + |
| 63 | + public void stop(@Nonnull ZonedDateTime stop, MavenExecutionEventType type) { |
| 64 | + this.stop = stop; |
| 65 | + this.type = type; |
| 66 | + } |
| 67 | + |
| 68 | + @Nonnull |
| 69 | + public MavenArtifact getProject() { |
| 70 | + return project; |
| 71 | + } |
| 72 | + |
| 73 | + @Nonnull |
| 74 | + public MavenArtifact getPlugin() { |
| 75 | + return plugin; |
| 76 | + } |
| 77 | + |
| 78 | + @Nonnull |
| 79 | + public String getExecutionId() { |
| 80 | + return executionId; |
| 81 | + } |
| 82 | + |
| 83 | + @Nonnull |
| 84 | + public String getLifecyclePhase() { |
| 85 | + return lifecyclePhase; |
| 86 | + } |
| 87 | + |
| 88 | + @Nonnull |
| 89 | + public String getGoal() { |
| 90 | + return goal; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public String toString() { |
| 95 | + return "MavenMojoExecutionDetails{" + |
| 96 | + "project=" + project.getId() + |
| 97 | + ", plugin=" + plugin.getId() + |
| 98 | + ", executionId='" + executionId + '\'' + |
| 99 | + ", lifecyclePhase='" + lifecyclePhase + '\'' + |
| 100 | + ", goal='" + goal + '\'' + |
| 101 | + ", start=" + start + |
| 102 | + ", stop=" + stop + |
| 103 | + ", type=" + type + |
| 104 | + '}'; |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public int compareTo(MavenMojoExecutionDetails other) { |
| 109 | + int comparison = this.getStart().compareTo(other.getStart()); |
| 110 | + |
| 111 | + if (comparison == 0) { |
| 112 | + comparison = this.getStop().compareTo(other.getStop()); |
| 113 | + } |
| 114 | + return comparison; |
| 115 | + } |
| 116 | + |
| 117 | + @Nonnull |
| 118 | + public String getDuration() { |
| 119 | + return Duration.between(start, stop).getSeconds() + "s"; |
| 120 | + } |
| 121 | + |
| 122 | + @Nonnull |
| 123 | + public long getDurationMillis() { |
| 124 | + return start.until(stop, ChronoUnit.MILLIS); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public boolean equals(Object o) { |
| 129 | + if (this == o) return true; |
| 130 | + if (o == null || getClass() != o.getClass()) return false; |
| 131 | + |
| 132 | + MavenMojoExecutionDetails that = (MavenMojoExecutionDetails) o; |
| 133 | + |
| 134 | + if (!project.equals(that.project)) return false; |
| 135 | + if (!plugin.equals(that.plugin)) return false; |
| 136 | + if (!executionId.equals(that.executionId)) return false; |
| 137 | + return goal.equals(that.goal); |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public int hashCode() { |
| 142 | + int result = project.hashCode(); |
| 143 | + result = 31 * result + plugin.hashCode(); |
| 144 | + result = 31 * result + executionId.hashCode(); |
| 145 | + result = 31 * result + goal.hashCode(); |
| 146 | + return result; |
| 147 | + } |
| 148 | +} |
0 commit comments