Skip to content

Commit

Permalink
[MINVOKER-341] Make elapsed time field type consistent with Maven Sur…
Browse files Browse the repository at this point in the history
…efire

This closes #191
  • Loading branch information
michael-o committed Jun 11, 2023
1 parent 6c0c181 commit 26f2dcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand All @@ -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 <code>null</code>.
*/
private String formatTime(double seconds) {
return secFormat.format(seconds);
private String formatTime(float time) {
return secFormat.format(time);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/mdo/invocation.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ under the License.
<name>time</name>
<version>1.0.0</version>
<required>true</required>
<type>double</type>
<type>float</type>
<description>The number of seconds that this build job took to complete.</description>
</field>
<field xml.attribute="true">
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 26f2dcf

Please sign in to comment.