Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #190

Closed
wants to merge 2 commits into from
Closed

Fixes #190

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -111,6 +110,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 @@ -702,11 +703,6 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
*/
private String filteredPomPrefix = "interpolated-";

/**
* The format for elapsed build time.
*/
private final DecimalFormat secFormat = new DecimalFormat("(0.0 s)", new DecimalFormatSymbols(Locale.ENGLISH));

/**
* The version of Maven which is used to run the builds
*/
Expand Down Expand Up @@ -1534,7 +1530,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 +1542,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 All @@ -1558,13 +1554,15 @@ private void runBuild(
buildJob.setResult(BuildJob.Result.SUCCESS);

if (!suppressSummaries) {
getLog().info(pad(buildJob).success("SUCCESS").a(' ') + formatTime(buildJob.getTime()));
getLog().info(pad(buildJob).success("SUCCESS").a(' ') + "("
+ formatElapsedTime(buildJob.getTime()) + ")");
}
} else {
buildJob.setResult(BuildJob.Result.SKIPPED);

if (!suppressSummaries) {
getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + formatTime(buildJob.getTime()));
getLog().info(pad(buildJob).warning("SKIPPED").a(' ') + "("
+ formatElapsedTime(buildJob.getTime()) + ")");
}
}
} else {
Expand Down Expand Up @@ -1604,7 +1602,8 @@ private void runBuild(

if (!suppressSummaries) {
getLog().info(" " + e.getMessage());
getLog().info(pad(buildJob).failure("FAILED").a(' ') + formatTime(buildJob.getTime()));
getLog().info(pad(buildJob).failure("FAILED").a(' ') + "(" + formatElapsedTime(buildJob.getTime())
+ ")");
}
} finally {
deleteInterpolatedPomFile(interpolatedPomFile);
Expand Down Expand Up @@ -1697,7 +1696,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 +1728,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 +1754,20 @@ 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 formatElapsedTime(float time) {
/*
* Rationale: The idea is to always display four digits for visually consistent output
* Important: Keep in sync with src/main/resources/invoker-report.properties
*/
final MessageFormat elapsedTimeFormat = new MessageFormat(
"{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s",
Locale.ROOT);
return elapsedTimeFormat.format(new Object[] {time});
}

/**
Expand Down Expand Up @@ -1882,8 +1888,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