From 26f2dcfcb76b8e23f986954f4670c189f3ead153 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 11 Jun 2023 13:23:20 +0200 Subject: [PATCH] [MINVOKER-341] Make elapsed time field type consistent with Maven Surefire This closes #191 --- .../plugins/invoker/AbstractInvokerMojo.java | 24 ++++++++++--------- src/main/mdo/invocation.mdo | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index b297a2c4..bb51e1be 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -111,6 +111,8 @@ * @since 15-Aug-2009 09:09:29 */ public abstract class AbstractInvokerMojo extends AbstractMojo { + private static final float ONE_SECOND = 1000.0f; + /** * The zero-based column index where to print the invoker result. */ @@ -1534,7 +1536,7 @@ private void runBuild( try { int selection = getSelection(invokerProperties, actualJreVersion); if (selection == 0) { - long milliseconds = System.currentTimeMillis(); + long startTime = System.currentTimeMillis(); boolean executed; FileLogger buildLogger = setupBuildLogFile(basedir); @@ -1546,8 +1548,8 @@ private void runBuild( executed = runBuild( basedir, interpolatedPomFile, settingsFile, actualJavaHome, invokerProperties, buildLogger); } finally { - milliseconds = System.currentTimeMillis() - milliseconds; - buildJob.setTime(milliseconds / 1000.0); + long elapsedTime = System.currentTimeMillis() - startTime; + buildJob.setTime(elapsedTime / ONE_SECOND); if (buildLogger != null) { buildLogger.close(); @@ -1697,7 +1699,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj File reportFile = new File(reportsDirectory, "TEST-" + safeFileName + ".xml"); Xpp3Dom testsuite = new Xpp3Dom("testsuite"); testsuite.setAttribute("name", junitPackageName + "." + safeFileName); - testsuite.setAttribute("time", Double.toString(buildJob.getTime())); + testsuite.setAttribute("time", Float.toString(buildJob.getTime())); // set default value for required attributes testsuite.setAttribute("tests", "1"); @@ -1729,7 +1731,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj } testcase.setAttribute("classname", junitPackageName + "." + safeFileName); testcase.setAttribute("name", safeFileName); - testcase.setAttribute("time", Double.toString(buildJob.getTime())); + testcase.setAttribute("time", Float.toString(buildJob.getTime())); Xpp3Dom systemOut = new Xpp3Dom("system-out"); testcase.addChild(systemOut); @@ -1755,13 +1757,13 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj } /** - * Formats the specified build duration time. + * Formats the specified elapsed time. * - * @param seconds The duration of the build. + * @param time The eapsed time of the build. * @return The formatted time, never null. */ - private String formatTime(double seconds) { - return secFormat.format(seconds); + private String formatTime(float time) { + return secFormat.format(time); } /** @@ -1882,8 +1884,8 @@ private boolean runBuild( int getParallelThreadsCount() { if (parallelThreads.endsWith("C")) { - double parallelThreadsMultiple = - Double.parseDouble(parallelThreads.substring(0, parallelThreads.length() - 1)); + float parallelThreadsMultiple = + Float.parseFloat(parallelThreads.substring(0, parallelThreads.length() - 1)); return (int) (parallelThreadsMultiple * Runtime.getRuntime().availableProcessors()); } else { return Integer.parseInt(parallelThreads); diff --git a/src/main/mdo/invocation.mdo b/src/main/mdo/invocation.mdo index 6529e7c6..f4af4252 100644 --- a/src/main/mdo/invocation.mdo +++ b/src/main/mdo/invocation.mdo @@ -86,7 +86,7 @@ under the License. time 1.0.0 true - double + float The number of seconds that this build job took to complete. @@ -126,7 +126,7 @@ under the License. /** * Creates a new build job with the specified project path. - * + * * @param project The path to the project. */ public BuildJob( String project )