* Total time: 3:14.025s
*/
public static Long extractTotalTime(String logs) {
- Pattern pattern = Pattern.compile(".*Total time: (\\d*:)?(\\d+).(\\d+)s.*");
+ Pattern pattern = Pattern.compile("^.*Total time: (\\d*:)?(\\d+).(\\d+)s.*$", Pattern.DOTALL);
Matcher matcher = pattern.matcher(logs);
if (matcher.matches()) {
String minutes = StringUtils.defaultIfBlank(StringUtils.removeEnd(matcher.group(1), ":"), "0");
return (Long.parseLong(minutes) * 60000) + (Long.parseLong(seconds) * 1000) + Long.parseLong(millis);
}
- return null;
+ throw new IllegalStateException("Maven logs do not contain \"Total time\"");
}
/**
public class MavenLogsTest {
@Test
public void testExtractTotalTime() throws Exception {
- assertThat(MavenLogs.extractTotalTime(" Total time: 6.015s ")).isEqualTo(6015);
- assertThat(MavenLogs.extractTotalTime(" Total time: 3:14.025s ")).isEqualTo(194025);
+ assertThat(MavenLogs.extractTotalTime(" \n Total time: 6.015s \n ")).isEqualTo(6015);
+ assertThat(MavenLogs.extractTotalTime(" \n Total time: 3:14.025s\n ")).isEqualTo(194025);
}
@Test