test/jdk/tools/jar/JarEntryTime.java
author herrick
Fri, 21 Jun 2019 08:29:09 -0400
branchJDK-8200758-branch
changeset 57419 44c2481650ce
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225092: Several jpackage tests failes when run with jcov enabled Submitted-by: almatvee Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
6308
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
    26
 * @bug 4225317 6969651
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    27
 * @modules jdk.jartool
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Check extracted files have date as per those in the .jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.PrintWriter;
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    33
import java.nio.file.attribute.FileTime;
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    34
import java.util.Date;
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    35
import java.util.TimeZone;
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    36
import java.util.spi.ToolProvider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class JarEntryTime {
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    39
    static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    40
        .orElseThrow(() ->
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    41
            new RuntimeException("jar tool not found")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    42
        );
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
    43
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    44
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    45
    // ZipEntry's mod date has 2 seconds precision: give extra time to
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    46
    // allow for e.g. rounding/truncation and networked/samba drives.
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    47
    static final long PRECISION = 10000L;
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
    48
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    49
    static final TimeZone TZ = TimeZone.getDefault();
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    50
    static final boolean DST = TZ.inDaylightTime(new Date());
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static boolean cleanup(File dir) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        boolean rc = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        File[] x = dir.listFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (x != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            for (int i = 0; i < x.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                rc &= x[i].delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return rc & dir.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static void extractJar(File jarFile, boolean useExtractionTime) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        String javahome = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        String jarcmd = javahome + File.separator + "bin" + File.separator + "jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        String[] args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (useExtractionTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            args = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                jarcmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                "-J-Dsun.tools.jar.useExtractionTime=true",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                "xf",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                jarFile.getName() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            args = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                jarcmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                "xf",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                jarFile.getName() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Process p = Runtime.getRuntime().exec(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        check(p != null && (p.waitFor() == 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static void realMain(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        File dirOuter = new File("outer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        File dirInner = new File(dirOuter, "inner");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        File jarFile = new File("JarEntryTime.jar");
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    88
        File testFile = new File("JarEntryTimeTest.txt");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // Remove any leftovers from prior run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        cleanup(dirInner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        cleanup(dirOuter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        jarFile.delete();
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
    94
        testFile.delete();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        /* Create a directory structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * outer/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         *     inner/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         *         foo.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         * Set the lastModified dates so that outer is created now, inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * yesterday, and foo.txt created "earlier".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        check(dirOuter.mkdir());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        check(dirInner.mkdir());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        File fileInner = new File(dirInner, "foo.txt");
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   106
        try (PrintWriter pw = new PrintWriter(fileInner)) {
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   107
            pw.println("hello, world");
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   108
        }
6308
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   109
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   110
        // Get the "now" from the "last-modified-time" of the last file we
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   111
        // just created, instead of the "System.currentTimeMillis()", to
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   112
        // workaround the possible "time difference" due to nfs.
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   113
        final long now = fileInner.lastModified();
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   114
        final long earlier = now - (60L * 60L * 6L * 1000L);
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   115
        final long yesterday = now - (60L * 60L * 24L * 1000L);
7d860a571385 6969651: TEST_BUG: tools/jar/JarEntryTime.java failed on JDK7 when run on NFS
sherman
parents: 5506
diff changeset
   116
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   117
        check(dirOuter.setLastModified(now));
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   118
        check(dirInner.setLastModified(yesterday));
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   119
        check(fileInner.setLastModified(earlier));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // Make a jar file from that directory structure
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
   122
        check(JAR_TOOL.run(System.out, System.err,
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 36239
diff changeset
   123
                           "cf", jarFile.getName(), dirOuter.getName()) == 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        check(jarFile.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        check(cleanup(dirInner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        check(cleanup(dirOuter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // Extract and check that the last modified values are those specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // in the archive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        extractJar(jarFile, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        check(dirOuter.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        check(dirInner.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        check(fileInner.exists());
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   135
        checkFileTime(dirOuter.lastModified(), now);
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   136
        checkFileTime(dirInner.lastModified(), yesterday);
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   137
        checkFileTime(fileInner.lastModified(), earlier);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        check(cleanup(dirInner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        check(cleanup(dirOuter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   142
        try (PrintWriter pw = new PrintWriter(testFile)) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   143
            pw.println("hello, world");
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   144
        }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   145
        final long start = testFile.lastModified();
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   146
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // Extract and check the last modified values are the current times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        extractJar(jarFile, true);
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   149
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   150
        try (PrintWriter pw = new PrintWriter(testFile)) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   151
            pw.println("hello, world");
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   152
        }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   153
        final long end = testFile.lastModified();
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   154
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        check(dirOuter.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        check(dirInner.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        check(fileInner.exists());
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   158
        checkFileTime(start, dirOuter.lastModified(), end);
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   159
        checkFileTime(start, dirInner.lastModified(), end);
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   160
        checkFileTime(start, fileInner.lastModified(), end);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        check(cleanup(dirInner));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        check(cleanup(dirOuter));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        check(jarFile.delete());
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   166
        check(testFile.delete());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   169
    static void checkFileTime(long now, long original) {
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   170
        if (isTimeSettingChanged()) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   171
            return;
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   172
        }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   173
21811
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   174
        if (Math.abs(now - original) > PRECISION) {
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   175
            System.out.format("Extracted to %s, expected to be close to %s%n",
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   176
                FileTime.fromMillis(now), FileTime.fromMillis(original));
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   177
            fail();
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   178
        }
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   179
    }
4810bf82fa69 8028589: Instrument tools/jar/JarEntryTime.java to make it easier to diagnose failures
alanb
parents: 7668
diff changeset
   180
36239
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   181
    static void checkFileTime(long start, long now, long end) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   182
        if (isTimeSettingChanged()) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   183
            return;
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   184
        }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   185
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   186
        if (now < start || now > end) {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   187
            System.out.format("Extracted to %s, "
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   188
                              + "expected to be after %s and before %s%n",
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   189
                              FileTime.fromMillis(now),
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   190
                              FileTime.fromMillis(start),
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   191
                              FileTime.fromMillis(end));
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   192
            fail();
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   193
        }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   194
    }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   195
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   196
    private static boolean isTimeSettingChanged() {
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   197
        TimeZone currentTZ = TimeZone.getDefault();
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   198
        boolean currentDST = currentTZ.inDaylightTime(new Date());
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   199
        return (!currentTZ.equals(TZ) || currentDST != DST);
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   200
    }
dc69fcbb786f 8038330: tools/jar/JarEntryTime.java fails intermittently on checking extracted file last modified values are the current times
amlu
parents: 30820
diff changeset
   201
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        System.out.println("\nPassed = " + passed + " failed = " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (failed > 0) throw new AssertionError("Some tests failed");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
}