8248261: Add timestamps to jpackage and jpackage tests verbose output
Reviewed-by: herrick, asemenyuk
This commit is contained in:
parent
8f8ff52cae
commit
231a8408b2
@ -542,11 +542,11 @@ public class Arguments {
|
|||||||
Log.verbose(e);
|
Log.verbose(e);
|
||||||
} else {
|
} else {
|
||||||
String msg1 = e.getMessage();
|
String msg1 = e.getMessage();
|
||||||
Log.error(msg1);
|
Log.fatalError(msg1);
|
||||||
if (e.getCause() != null && e.getCause() != e) {
|
if (e.getCause() != null && e.getCause() != e) {
|
||||||
String msg2 = e.getCause().getMessage();
|
String msg2 = e.getCause().getMessage();
|
||||||
if (msg2 != null && !msg1.contains(msg2)) {
|
if (msg2 != null && !msg1.contains(msg2)) {
|
||||||
Log.error(msg2);
|
Log.fatalError(msg2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -45,7 +45,7 @@ public class JPackageToolProvider implements ToolProvider {
|
|||||||
try {
|
try {
|
||||||
return new jdk.incubator.jpackage.main.Main().execute(out, err, args);
|
return new jdk.incubator.jpackage.main.Main().execute(out, err, args);
|
||||||
} catch (RuntimeException re) {
|
} catch (RuntimeException re) {
|
||||||
Log.error(re.getMessage());
|
Log.fatalError(re.getMessage());
|
||||||
Log.verbose(re);
|
Log.verbose(re);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
package jdk.incubator.jpackage.internal;
|
package jdk.incubator.jpackage.internal;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log
|
* 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) {
|
public void error(String msg) {
|
||||||
|
msg = addTimestamp(msg);
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
err.println(msg);
|
err.println(msg);
|
||||||
} else {
|
} else {
|
||||||
@ -87,19 +98,28 @@ public class Log {
|
|||||||
|
|
||||||
public void verbose(Throwable t) {
|
public void verbose(Throwable t) {
|
||||||
if (out != null && verbose) {
|
if (out != null && verbose) {
|
||||||
|
out.print(addTimestamp(""));
|
||||||
t.printStackTrace(out);
|
t.printStackTrace(out);
|
||||||
} else if (verbose) {
|
} else if (verbose) {
|
||||||
|
System.out.print(addTimestamp(""));
|
||||||
t.printStackTrace(System.out);
|
t.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verbose(String msg) {
|
public void verbose(String msg) {
|
||||||
|
msg = addTimestamp(msg);
|
||||||
if (out != null && verbose) {
|
if (out != null && verbose) {
|
||||||
out.println(msg);
|
out.println(msg);
|
||||||
} else if (verbose) {
|
} else if (verbose) {
|
||||||
System.out.println(msg);
|
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;
|
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) {
|
public static void error(String msg) {
|
||||||
if (delegate != null) {
|
if (delegate != null) {
|
||||||
delegate.error(msg);
|
delegate.error(msg);
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -76,11 +76,11 @@ public class Main {
|
|||||||
try {
|
try {
|
||||||
newArgs = CommandLine.parse(args);
|
newArgs = CommandLine.parse(args);
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
Log.error(MessageFormat.format(I18N.getString(
|
Log.fatalError(MessageFormat.format(I18N.getString(
|
||||||
"ERR_CannotParseOptions"), fnfe.getMessage()));
|
"ERR_CannotParseOptions"), fnfe.getMessage()));
|
||||||
return 1;
|
return 1;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.error(ioe.getMessage());
|
Log.fatalError(ioe.getMessage());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +39,12 @@ import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
|
|||||||
import java.nio.file.WatchEvent;
|
import java.nio.file.WatchEvent;
|
||||||
import java.nio.file.WatchKey;
|
import java.nio.file.WatchKey;
|
||||||
import java.nio.file.WatchService;
|
import java.nio.file.WatchService;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -217,7 +219,14 @@ final public class TKit {
|
|||||||
return false;
|
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) {
|
static void log(String v) {
|
||||||
|
v = addTimestamp(v);
|
||||||
System.out.println(v);
|
System.out.println(v);
|
||||||
if (extraLogStream != null) {
|
if (extraLogStream != null) {
|
||||||
extraLogStream.println(v);
|
extraLogStream.println(v);
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -73,21 +73,21 @@ public class LinuxResourceTest {
|
|||||||
})
|
})
|
||||||
.addBundleVerifier((cmd, result) -> {
|
.addBundleVerifier((cmd, result) -> {
|
||||||
TKit.assertTextStream("Using custom package resource [DEB control file]")
|
TKit.assertTextStream("Using custom package resource [DEB control file]")
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(String.format(
|
TKit.assertTextStream(String.format(
|
||||||
"Expected value of \"Package\" property is [%s]. Actual value in output package is [dont-install-me]",
|
"Expected value of \"Package\" property is [%s]. Actual value in output package is [dont-install-me]",
|
||||||
LinuxHelper.getPackageName(cmd)))
|
LinuxHelper.getPackageName(cmd)))
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(
|
TKit.assertTextStream(
|
||||||
"Expected value of \"Version\" property is [1.0-1]. Actual value in output package is [1.2.3-R2]")
|
"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());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(String.format(
|
TKit.assertTextStream(String.format(
|
||||||
"Expected value of \"Architecture\" property is [%s]. Actual value in output package is [bar]",
|
"Expected value of \"Architecture\" property is [%s]. Actual value in output package is [bar]",
|
||||||
LinuxHelper.getDefaultPackageArch(cmd.packageType())))
|
LinuxHelper.getDefaultPackageArch(cmd.packageType())))
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
})
|
})
|
||||||
.forTypes(PackageType.LINUX_RPM)
|
.forTypes(PackageType.LINUX_RPM)
|
||||||
@ -116,20 +116,20 @@ public class LinuxResourceTest {
|
|||||||
})
|
})
|
||||||
.addBundleVerifier((cmd, result) -> {
|
.addBundleVerifier((cmd, result) -> {
|
||||||
TKit.assertTextStream("Using custom package resource [RPM spec file]")
|
TKit.assertTextStream("Using custom package resource [RPM spec file]")
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(String.format(
|
TKit.assertTextStream(String.format(
|
||||||
"Expected value of \"Name\" property is [%s]. Actual value in output package is [dont-install-me]",
|
"Expected value of \"Name\" property is [%s]. Actual value in output package is [dont-install-me]",
|
||||||
LinuxHelper.getPackageName(cmd)))
|
LinuxHelper.getPackageName(cmd)))
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(
|
TKit.assertTextStream(
|
||||||
"Expected value of \"Version\" property is [1.0]. Actual value in output package is [1.2.3]")
|
"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());
|
.apply(result.getOutput().stream());
|
||||||
TKit.assertTextStream(
|
TKit.assertTextStream(
|
||||||
"Expected value of \"Release\" property is [1]. Actual value in output package is [R2]")
|
"Expected value of \"Release\" property is [1]. Actual value in output package is [R2]")
|
||||||
.predicate(String::startsWith)
|
.predicate(String::contains)
|
||||||
.apply(result.getOutput().stream());
|
.apply(result.getOutput().stream());
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user