test/jdk/tools/pack200/TimeStamp.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6323
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     1
/*
28255
ddb0157601ed 8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents: 19374
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
6323
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     4
 *
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     8
 *
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    13
 * accompanied this code).
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    14
 *
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    18
 *
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    21
 * questions.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    22
 */
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    23
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    24
import java.io.File;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    25
import java.io.FileOutputStream;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    26
import java.io.IOException;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    27
import java.util.ArrayList;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    28
import java.util.Collections;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    29
import java.util.HashMap;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    30
import java.util.List;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    31
import java.util.TimeZone;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    32
import java.util.jar.JarEntry;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    33
import java.util.jar.JarFile;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    34
import java.util.jar.JarOutputStream;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    35
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    36
/*
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    37
 * @test
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    38
 * @bug 6966740
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    39
 * @summary verify identical timestamps, unpacked in any timezone
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    40
 * @compile -XDignore.symbol.file Utils.java TimeStamp.java
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    41
 * @run main/othervm TimeStamp
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    42
 * @author ksrini
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    43
 */
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    44
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    45
/**
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    46
 * First we pack the file in some time zone say India, then we unpack the  file
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    47
 * in the current time zone, and ensure the timestamp recorded in the unpacked
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    48
 * jar are the same.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    49
 */
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    50
public class TimeStamp {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    51
    static final TimeZone tz = TimeZone.getDefault();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    52
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    53
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    54
    public static void main(String... args) throws IOException {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    55
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    56
        // make a local copy of our test file
28255
ddb0157601ed 8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents: 19374
diff changeset
    57
        File srcFile = Utils.getGoldenJar();
6323
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    58
        File goldenFile = new File("golden.jar");
9009
e7036c254324 7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents: 6323
diff changeset
    59
        Utils.copyFile(srcFile, goldenFile);
6323
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    60
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    61
        JarFile goldenJarFile = new JarFile(goldenFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    62
        File packFile = new File("golden.pack");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    63
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    64
        // set the test timezone and pack the file
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    65
        TimeZone.setDefault(TimeZone.getTimeZone("IST"));
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    66
        Utils.pack(goldenJarFile, packFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    67
        TimeZone.setDefault(tz);   // reset the timezone
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    68
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    69
        // unpack in the  test timezone
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    70
        File istFile = new File("golden.jar.java.IST");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    71
        unpackJava(packFile, istFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    72
        verifyJar(goldenFile, istFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    73
        istFile.delete();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    74
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    75
        // unpack in some other timezone
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    76
        File pstFile = new File("golden.jar.java.PST");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    77
        unpackJava(packFile, pstFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    78
        verifyJar(goldenFile, pstFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    79
        pstFile.delete();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    80
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    81
        // repeat the test for unpack200 tool.
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    82
        istFile = new File("golden.jar.native.IST");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    83
        unpackNative(packFile, istFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    84
        verifyJar(goldenFile, istFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    85
        istFile.delete();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    86
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    87
        pstFile = new File("golden.jar.native.PST");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    88
        unpackNative(packFile, pstFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    89
        verifyJar(goldenFile, pstFile);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    90
        pstFile.delete();
19374
6773349693eb 8015666: test/tools/pack200/TimeStamp.java failing
sherman
parents: 18594
diff changeset
    91
        Utils.cleanup();
6323
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    92
    }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    93
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    94
    static void unpackNative(File packFile, File outFile) {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    95
        String name = outFile.getName();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    96
        String tzname = name.substring(name.lastIndexOf(".") + 1);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    97
        HashMap<String, String> env = new HashMap<>();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    98
        switch(tzname) {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
    99
            case "PST":
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   100
                env.put("TZ", "US/Pacific");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   101
                break;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   102
            case "IST":
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   103
                env.put("TZ", "Asia/Calcutta");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   104
                break;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   105
            default:
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   106
                throw new RuntimeException("not implemented: " + tzname);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   107
        }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   108
        List<String> cmdsList = new ArrayList<>();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   109
        cmdsList.add(Utils.getUnpack200Cmd());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   110
        cmdsList.add(packFile.getName());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   111
        cmdsList.add(outFile.getName());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   112
        Utils.runExec(cmdsList, env);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   113
    }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   114
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   115
    static void unpackJava(File packFile, File outFile) throws IOException {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   116
        String name = outFile.getName();
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   117
        String tzname = name.substring(name.lastIndexOf(".") + 1);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   118
        JarOutputStream jos = null;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   119
        try {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   120
            TimeZone.setDefault(TimeZone.getTimeZone(tzname));
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   121
            jos = new JarOutputStream(new FileOutputStream(outFile));
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   122
            System.out.println("Using timezone: " + TimeZone.getDefault());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   123
            Utils.unpackj(packFile, jos);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   124
        } finally {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   125
            Utils.close(jos);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   126
            TimeZone.setDefault(tz); // always reset
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   127
        }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   128
    }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   129
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   130
    static void verifyJar(File f1, File f2) throws IOException {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   131
        int errors = 0;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   132
        JarFile jf1 = null;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   133
        JarFile jf2 = null;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   134
        try {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   135
            jf1 = new JarFile(f1);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   136
            jf2 = new JarFile(f2);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   137
            System.out.println("Verifying: " + f1 + " and " + f2);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   138
            for (JarEntry je1 : Collections.list(jf1.entries())) {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   139
                JarEntry je2 = jf2.getJarEntry(je1.getName());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   140
                if (je1.getTime() != je2.getTime()) {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   141
                    System.out.println("Error:");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   142
                    System.out.println("  expected:" + jf1.getName() + ":"
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   143
                            + je1.getName() + ":" + je1.getTime());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   144
                    System.out.println("  obtained:" + jf2.getName() + ":"
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   145
                            + je2.getName() + ":" + je2.getTime());
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   146
                    errors++;
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   147
                }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   148
            }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   149
        } finally {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   150
            Utils.close(jf1);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   151
            Utils.close(jf2);
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   152
        }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   153
        if (errors > 0) {
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   154
            throw new RuntimeException("FAIL:" + errors + " error(s) encounted");
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   155
        }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   156
    }
1cdec3dff0a3 6966740: (pack200) need to add the timezone regression test
ksrini
parents:
diff changeset
   157
}