Skip to content

Commit 26f2dcf

Browse files
committed
[MINVOKER-341] Make elapsed time field type consistent with Maven Surefire
This closes #191
1 parent 6c0c181 commit 26f2dcf

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
* @since 15-Aug-2009 09:09:29
112112
*/
113113
public abstract class AbstractInvokerMojo extends AbstractMojo {
114+
private static final float ONE_SECOND = 1000.0f;
115+
114116
/**
115117
* The zero-based column index where to print the invoker result.
116118
*/
@@ -1534,7 +1536,7 @@ private void runBuild(
15341536
try {
15351537
int selection = getSelection(invokerProperties, actualJreVersion);
15361538
if (selection == 0) {
1537-
long milliseconds = System.currentTimeMillis();
1539+
long startTime = System.currentTimeMillis();
15381540
boolean executed;
15391541

15401542
FileLogger buildLogger = setupBuildLogFile(basedir);
@@ -1546,8 +1548,8 @@ private void runBuild(
15461548
executed = runBuild(
15471549
basedir, interpolatedPomFile, settingsFile, actualJavaHome, invokerProperties, buildLogger);
15481550
} finally {
1549-
milliseconds = System.currentTimeMillis() - milliseconds;
1550-
buildJob.setTime(milliseconds / 1000.0);
1551+
long elapsedTime = System.currentTimeMillis() - startTime;
1552+
buildJob.setTime(elapsedTime / ONE_SECOND);
15511553

15521554
if (buildLogger != null) {
15531555
buildLogger.close();
@@ -1697,7 +1699,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
16971699
File reportFile = new File(reportsDirectory, "TEST-" + safeFileName + ".xml");
16981700
Xpp3Dom testsuite = new Xpp3Dom("testsuite");
16991701
testsuite.setAttribute("name", junitPackageName + "." + safeFileName);
1700-
testsuite.setAttribute("time", Double.toString(buildJob.getTime()));
1702+
testsuite.setAttribute("time", Float.toString(buildJob.getTime()));
17011703

17021704
// set default value for required attributes
17031705
testsuite.setAttribute("tests", "1");
@@ -1729,7 +1731,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
17291731
}
17301732
testcase.setAttribute("classname", junitPackageName + "." + safeFileName);
17311733
testcase.setAttribute("name", safeFileName);
1732-
testcase.setAttribute("time", Double.toString(buildJob.getTime()));
1734+
testcase.setAttribute("time", Float.toString(buildJob.getTime()));
17331735
Xpp3Dom systemOut = new Xpp3Dom("system-out");
17341736
testcase.addChild(systemOut);
17351737

@@ -1755,13 +1757,13 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
17551757
}
17561758

17571759
/**
1758-
* Formats the specified build duration time.
1760+
* Formats the specified elapsed time.
17591761
*
1760-
* @param seconds The duration of the build.
1762+
* @param time The eapsed time of the build.
17611763
* @return The formatted time, never <code>null</code>.
17621764
*/
1763-
private String formatTime(double seconds) {
1764-
return secFormat.format(seconds);
1765+
private String formatTime(float time) {
1766+
return secFormat.format(time);
17651767
}
17661768

17671769
/**
@@ -1882,8 +1884,8 @@ private boolean runBuild(
18821884

18831885
int getParallelThreadsCount() {
18841886
if (parallelThreads.endsWith("C")) {
1885-
double parallelThreadsMultiple =
1886-
Double.parseDouble(parallelThreads.substring(0, parallelThreads.length() - 1));
1887+
float parallelThreadsMultiple =
1888+
Float.parseFloat(parallelThreads.substring(0, parallelThreads.length() - 1));
18871889
return (int) (parallelThreadsMultiple * Runtime.getRuntime().availableProcessors());
18881890
} else {
18891891
return Integer.parseInt(parallelThreads);

src/main/mdo/invocation.mdo

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ under the License.
8686
<name>time</name>
8787
<version>1.0.0</version>
8888
<required>true</required>
89-
<type>double</type>
89+
<type>float</type>
9090
<description>The number of seconds that this build job took to complete.</description>
9191
</field>
9292
<field xml.attribute="true">
@@ -126,7 +126,7 @@ under the License.
126126
127127
/**
128128
* Creates a new build job with the specified project path.
129-
*
129+
*
130130
* @param project The path to the project.
131131
*/
132132
public BuildJob( String project )

0 commit comments

Comments
 (0)