--- old/test/tools/jar/JarEntryTime.java 2016-03-01 13:21:28.000000000 +0800 +++ new/test/tools/jar/JarEntryTime.java 2016-03-01 13:21:27.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2016, 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 @@ -31,6 +31,8 @@ import java.io.File; import java.io.PrintWriter; import java.nio.file.attribute.FileTime; +import java.util.Date; +import java.util.TimeZone; import sun.tools.jar.Main; public class JarEntryTime { @@ -39,6 +41,9 @@ // allow for e.g. rounding/truncation and networked/samba drives. static final long PRECISION = 10000L; + static final TimeZone TZ = TimeZone.getDefault(); + static final boolean DST = TZ.inDaylightTime(new Date()); + static boolean cleanup(File dir) throws Throwable { boolean rc = true; File[] x = dir.listFiles(); @@ -75,10 +80,13 @@ File dirOuter = new File("outer"); File dirInner = new File(dirOuter, "inner"); File jarFile = new File("JarEntryTime.jar"); + File dirTemp = new File("tempdir"); + File fileTemp = new File(dirTemp, "tempfile.txt"); // Remove any leftovers from prior run cleanup(dirInner); cleanup(dirOuter); + cleanup(dirTemp); jarFile.delete(); /* Create a directory structure @@ -94,6 +102,7 @@ try (PrintWriter pw = new PrintWriter(fileInner)) { pw.println("hello, world"); } + check(dirTemp.mkdir()); // Get the "now" from the "last-modified-time" of the last file we // just created, instead of the "System.currentTimeMillis()", to @@ -129,30 +138,59 @@ check(cleanup(dirInner)); check(cleanup(dirOuter)); + try (PrintWriter pw = new PrintWriter(fileTemp)) { + pw.println("hello, world"); + } + final long start = fileTemp.lastModified(); + // Extract and check the last modified values are the current times. // See sun.tools.jar.Main extractJar(jarFile, true); + + try (PrintWriter pw = new PrintWriter(fileTemp)) { + pw.println("hello, world"); + } + final long end = fileTemp.lastModified(); + check(dirOuter.exists()); check(dirInner.exists()); check(fileInner.exists()); - checkFileTime(dirOuter.lastModified(), now); - checkFileTime(dirInner.lastModified(), now); - checkFileTime(fileInner.lastModified(), now); + checkFileTime(start, dirOuter.lastModified(), end); + checkFileTime(start, dirInner.lastModified(), end); + checkFileTime(start, fileInner.lastModified(), end); check(cleanup(dirInner)); check(cleanup(dirOuter)); + check(cleanup(dirTemp)); check(jarFile.delete()); } static void checkFileTime(long now, long original) { - if (Math.abs(now - original) > PRECISION) { - System.out.format("Extracted to %s, expected to be close to %s%n", - FileTime.fromMillis(now), FileTime.fromMillis(original)); + checkFileTime(now, now, original + PRECISION); + } + + static void checkFileTime(long start, long now, long end) { + if (isTimeSettingChanged()) { + return; + } + + if (!(Math.abs(now - start) >= 0L && Math.abs(end - now) >= 0L)) { + System.out.format("Extracted to %s, " + + "expected to be after %s and before %s%n", + FileTime.fromMillis(now), + FileTime.fromMillis(start), + FileTime.fromMillis(end)); fail(); } } + private static boolean isTimeSettingChanged() { + TimeZone currentTZ = TimeZone.getDefault(); + boolean currentDST = currentTZ.inDaylightTime(new Date()); + return (!currentTZ.equals(TZ) || currentDST != DST); + } + //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0; static void pass() {passed++;}