Skip to content

Commit fa1d489

Browse files
JENKINS-56448 Introduce a report of the time spent in each phase of the Maven build (compile, test...)
1 parent 638895d commit fa1d489

File tree

18 files changed

+726
-29
lines changed

18 files changed

+726
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.jenkinsci.plugins.pipeline.maven.model;
2+
3+
import java.io.Serializable;
4+
import java.time.ZonedDateTime;
5+
import java.util.SortedSet;
6+
import java.util.TreeSet;
7+
8+
import javax.annotation.Nonnull;
9+
10+
/**
11+
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
12+
*/
13+
public class MavenExecutionDetails implements Comparable<MavenExecutionDetails>, Serializable {
14+
15+
private static final long serialVersionUID = 1L;
16+
17+
private SortedSet<MavenProjectExecutionDetails> mavenProjectExecutionDetails = new TreeSet<>();
18+
19+
@Nonnull
20+
private final ZonedDateTime start;
21+
@Nonnull
22+
private ZonedDateTime stop;
23+
@Nonnull
24+
private MavenExecutionStatus status;
25+
26+
public MavenExecutionDetails(@Nonnull ZonedDateTime start) {
27+
this.start = start;
28+
this.stop = stop;
29+
}
30+
31+
public SortedSet<MavenProjectExecutionDetails> getMavenProjectExecutionDetails() {
32+
return mavenProjectExecutionDetails;
33+
}
34+
35+
@Nonnull
36+
public ZonedDateTime getStart() {
37+
return start;
38+
}
39+
40+
@Nonnull
41+
public ZonedDateTime getStop() {
42+
return stop;
43+
}
44+
45+
@Nonnull
46+
public MavenExecutionStatus getStatus() {
47+
return status;
48+
}
49+
50+
public void setStop(@Nonnull ZonedDateTime stop, @Nonnull MavenExecutionStatus status) {
51+
this.stop = stop;
52+
this.status = status;
53+
}
54+
55+
@Override
56+
public int compareTo(MavenExecutionDetails o) {
57+
return this.start.compareTo(o.start);
58+
}
59+
60+
/**
61+
* it's a poor comparison but there is no risk of having 2 builds starting at the same time
62+
*
63+
* @param o
64+
* @return
65+
*/
66+
@Override
67+
public boolean equals(Object o) {
68+
if (this == o) return true;
69+
if (o == null || getClass() != o.getClass()) return false;
70+
71+
MavenExecutionDetails that = (MavenExecutionDetails) o;
72+
73+
return start.equals(that.start);
74+
}
75+
76+
@Override
77+
public int hashCode() {
78+
return start.hashCode();
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.jenkinsci.plugins.pipeline.maven.model;
2+
3+
/**
4+
* See {@code org.apache.maven.execution.ExecutionEvent.Type}
5+
*/
6+
public enum MavenExecutionEventType {
7+
ProjectDiscoveryStarted,
8+
SessionStarted,
9+
SessionEnded,
10+
ProjectSkipped,
11+
ProjectStarted,
12+
ProjectSucceeded,
13+
ProjectFailed,
14+
MojoSkipped,
15+
MojoStarted,
16+
MojoSucceeded,
17+
MojoFailed,
18+
ForkStarted,
19+
ForkSucceeded,
20+
ForkFailed,
21+
ForkedProjectStarted,
22+
ForkedProjectSucceeded,
23+
ForkedProjectFailed
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.jenkinsci.plugins.pipeline.maven.model;
2+
3+
/**
4+
* See {@code org.apache.maven.execution.BuildSuccess} and {@code org.apache.maven.execution.BuildFailure}
5+
*/
6+
public enum MavenExecutionStatus {Success, Failure}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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.util.SortedSet;
9+
import java.util.TreeSet;
10+
11+
import javax.annotation.Nonnull;
12+
13+
/**
14+
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
15+
*/
16+
public class MavenProjectExecutionDetails implements Comparable<MavenProjectExecutionDetails>, Serializable {
17+
private static final long serialVersionUID = 1L;
18+
19+
@Nonnull
20+
private MavenArtifact project;
21+
@Nonnull
22+
private SortedSet<MavenMojoExecutionDetails> mojoExecutionDetails = new TreeSet<>();
23+
24+
public MavenProjectExecutionDetails(@Nonnull MavenArtifact project) {
25+
this.project = project;
26+
}
27+
28+
/**
29+
* See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoStarted}
30+
*/
31+
@Nonnull
32+
public ZonedDateTime getStart() {
33+
return mojoExecutionDetails.first().getStart();
34+
}
35+
36+
/**
37+
* See {@code org.apache.maven.execution.ExecutionEvent.Type#MojoSucceeded} and {@code org.apache.maven.execution.ExecutionEvent.Type#MojoFailed}
38+
*/
39+
@Nonnull
40+
public ZonedDateTime getStop() {
41+
return mojoExecutionDetails.last().getStop();
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return "MavenProjectExecutionDetails{" +
47+
"artifact=" + project +
48+
", start=" + getStart() +
49+
", stop=" + getStop() +
50+
'}';
51+
}
52+
53+
@Override
54+
public int compareTo(MavenProjectExecutionDetails other) {
55+
int comparison = this.getStart().compareTo(other.getStart());
56+
57+
if (comparison == 0) {
58+
comparison = this.getStop().compareTo(other.getStop());
59+
}
60+
return comparison;
61+
}
62+
63+
@Nonnull
64+
public MavenArtifact getProject() {
65+
return project;
66+
}
67+
68+
@Nonnull
69+
public SortedSet<MavenMojoExecutionDetails> getMojoExecutionDetails() {
70+
return mojoExecutionDetails;
71+
}
72+
73+
public void add(@Nonnull MavenMojoExecutionDetails timer) {
74+
mojoExecutionDetails.add(timer);
75+
}
76+
77+
@Nonnull
78+
public String getDuration() {
79+
return Duration.between(getStart(), getStop()).getSeconds() + "s";
80+
}
81+
82+
@Override
83+
public boolean equals(Object o) {
84+
if (this == o) return true;
85+
if (o == null || getClass() != o.getClass()) return false;
86+
87+
MavenProjectExecutionDetails that = (MavenProjectExecutionDetails) o;
88+
89+
return project.equals(that.project);
90+
}
91+
92+
@Override
93+
public int hashCode() {
94+
return project.hashCode();
95+
}
96+
}

0 commit comments

Comments
 (0)