8248261: Add timestamps to jpackage and jpackage tests verbose output

Reviewed-by: herrick, asemenyuk
This commit is contained in:
Alexander Matveev 2020-07-13 12:04:58 -07:00
parent 8f8ff52cae
commit 231a8408b2
6 changed files with 51 additions and 16 deletions

View File

@ -542,11 +542,11 @@ public class Arguments {
Log.verbose(e);
} else {
String msg1 = e.getMessage();
Log.error(msg1);
Log.fatalError(msg1);
if (e.getCause() != null && e.getCause() != e) {
String msg2 = e.getCause().getMessage();
if (msg2 != null && !msg1.contains(msg2)) {
Log.error(msg2);
Log.fatalError(msg2);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,7 +45,7 @@ public class JPackageToolProvider implements ToolProvider {
try {
return new jdk.incubator.jpackage.main.Main().execute(out, err, args);
} catch (RuntimeException re) {
Log.error(re.getMessage());
Log.fatalError(re.getMessage());
Log.verbose(re);
return 1;
}

View File

@ -26,6 +26,8 @@
package jdk.incubator.jpackage.internal;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Log
@ -77,7 +79,16 @@ public class Log {
}
}
public void fatalError(String msg) {
if (err != null) {
err.println(msg);
} else {
System.err.println(msg);
}
}
public void error(String msg) {
msg = addTimestamp(msg);
if (err != null) {
err.println(msg);
} else {
@ -87,19 +98,28 @@ public class Log {
public void verbose(Throwable t) {
if (out != null && verbose) {
out.print(addTimestamp(""));
t.printStackTrace(out);
} else if (verbose) {
System.out.print(addTimestamp(""));
t.printStackTrace(System.out);
}
}
public void verbose(String msg) {
msg = addTimestamp(msg);
if (out != null && verbose) {
out.println(msg);
} else if (verbose) {
System.out.println(msg);
}
}
private String addTimestamp(String msg) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
Date time = new Date(System.currentTimeMillis());
return String.format("[%s] %s", sdf.format(time), msg);
}
}
private static Logger delegate = null;
@ -120,6 +140,12 @@ public class Log {
}
}
public static void fatalError(String msg) {
if (delegate != null) {
delegate.fatalError(msg);
}
}
public static void error(String msg) {
if (delegate != null) {
delegate.error(msg);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -76,11 +76,11 @@ public class Main {
try {
newArgs = CommandLine.parse(args);
} catch (FileNotFoundException fnfe) {
Log.error(MessageFormat.format(I18N.getString(
Log.fatalError(MessageFormat.format(I18N.getString(
"ERR_CannotParseOptions"), fnfe.getMessage()));
return 1;
} catch (IOException ioe) {
Log.error(ioe.getMessage());
Log.fatalError(ioe.getMessage());
return 1;
}

View File

@ -39,10 +39,12 @@ import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -217,7 +219,14 @@ final public class TKit {
return false;
}
private static String addTimestamp(String msg) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
Date time = new Date(System.currentTimeMillis());
return String.format("[%s] %s", sdf.format(time), msg);
}
static void log(String v) {
v = addTimestamp(v);
System.out.println(v);
if (extraLogStream != null) {
extraLogStream.println(v);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -73,21 +73,21 @@ public class LinuxResourceTest {
})
.addBundleVerifier((cmd, result) -> {
TKit.assertTextStream("Using custom package resource [DEB control file]")
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(String.format(
"Expected value of \"Package\" property is [%s]. Actual value in output package is [dont-install-me]",
LinuxHelper.getPackageName(cmd)))
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(
"Expected value of \"Version\" property is [1.0-1]. Actual value in output package is [1.2.3-R2]")
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(String.format(
"Expected value of \"Architecture\" property is [%s]. Actual value in output package is [bar]",
LinuxHelper.getDefaultPackageArch(cmd.packageType())))
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
})
.forTypes(PackageType.LINUX_RPM)
@ -116,20 +116,20 @@ public class LinuxResourceTest {
})
.addBundleVerifier((cmd, result) -> {
TKit.assertTextStream("Using custom package resource [RPM spec file]")
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(String.format(
"Expected value of \"Name\" property is [%s]. Actual value in output package is [dont-install-me]",
LinuxHelper.getPackageName(cmd)))
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(
"Expected value of \"Version\" property is [1.0]. Actual value in output package is [1.2.3]")
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
TKit.assertTextStream(
"Expected value of \"Release\" property is [1]. Actual value in output package is [R2]")
.predicate(String::startsWith)
.predicate(String::contains)
.apply(result.getOutput().stream());
})
.run();