test/jdk/tools/pack200/MultiRelease.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:
34323
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     1
/*
41752
0c5a98b2e56c 8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents: 34323
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
34323
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     4
 *
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     8
 *
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    13
 * accompanied this code).
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    14
 *
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 41752
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
34323
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    18
 *
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    21
 * questions.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    22
 */
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    23
import java.io.File;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    24
import java.io.IOException;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    25
import java.util.ArrayList;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    26
import java.util.List;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    27
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    28
/*
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    29
 * @test
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    30
 * @bug 8066272
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    31
 * @summary tests a simple multi-versioned jar file
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    32
 * @compile -XDignore.symbol.file Utils.java MultiRelease.java
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    33
 * @run main MultiRelease
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    34
 * @author ksrini
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    35
 */
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    36
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    37
public class MultiRelease {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    38
    private static final File cwd = new File(".");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    39
    private static int pass = 0;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    40
    private static int fail = 0;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    41
    // specify alternate name via arguments to verify
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    42
    // if permanent fix works
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    43
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    44
    private static final String PropKey = "pack200.MultiRelease.META-INF";
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    45
    private static final String MetaInfName = System.getProperty(PropKey, "META-INF");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    46
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    48
        new MultiRelease().run();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    49
    }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    50
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    51
    void run() throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    52
        List<TestCase> testCases = new ArrayList<>();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    53
        testCases.add(new TestCase1());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    54
        testCases.add(new TestCase2());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    55
        for (TestCase tc : testCases) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    56
            tc.run();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    57
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    58
        if (fail > 0) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    59
            throw new Exception(fail + "/" + testCases.size() + " tests fails");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    60
        } else {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    61
            System.out.println("All tests(" + pass + ") passes");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    62
        }
41752
0c5a98b2e56c 8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents: 34323
diff changeset
    63
        Utils.cleanup();
34323
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    64
    }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    65
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    66
    /*
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    67
     * An abstract class to eliminate test boiler plating.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    68
     */
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    69
    static abstract class TestCase {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    70
        final File tcwd;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    71
        final File metaInfDir;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    72
        final File versionsDir;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    73
        final File manifestFile;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    74
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    75
        TestCase(String directory) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    76
            System.out.println("initializing directories");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    77
            tcwd = new File(cwd, directory);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    78
            metaInfDir = mkdir(new File(tcwd, MetaInfName));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    79
            versionsDir = mkdir(new File(metaInfDir, "versions"));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    80
            manifestFile = new File(tcwd, "manifest.tmp");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    81
            List<String> scratch = new ArrayList<>();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    82
            scratch.add("Multi-Release: true");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    83
            Utils.createFile(manifestFile, scratch);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    84
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    85
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    86
        File mkdir(File f) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    87
            if (f.exists() && f.isDirectory() && f.canRead() && f.canWrite()) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    88
                return f;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    89
            }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    90
            if (!f.mkdirs()) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    91
               throw new IOException("mkdirs failed: " + f.getAbsolutePath());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    92
            }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    93
            return f;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    94
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    95
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    96
        abstract void emitClassFiles() throws Exception;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    97
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    98
        void run() {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
    99
            try {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   100
                emitClassFiles();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   101
                // jar the file up
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   102
                File testFile = new File(tcwd, "test" + Utils.JAR_FILE_EXT);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   103
                Utils.jar("cvfm",
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   104
                        testFile.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   105
                        manifestFile.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   106
                        "-C",
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   107
                        tcwd.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   108
                        ".");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   109
                File outFile = new File(tcwd, "test-repacked" + Utils.JAR_FILE_EXT);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   110
                List<String> cmdsList = new ArrayList<>();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   111
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   112
                cmdsList.add(Utils.getPack200Cmd());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   113
                cmdsList.add("-J-ea");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   114
                cmdsList.add("-J-esa");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   115
                cmdsList.add("-v");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   116
                cmdsList.add("--repack");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   117
                cmdsList.add(outFile.getAbsolutePath());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   118
                cmdsList.add(testFile.getAbsolutePath());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   119
                List<String> output = Utils.runExec(cmdsList);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   120
                Utils.doCompareVerify(testFile.getAbsoluteFile(), outFile.getAbsoluteFile());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   121
                pass++;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   122
            } catch (Exception e) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   123
                e.printStackTrace(System.err);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   124
                fail++;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   125
            }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   126
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   127
    }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   128
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   129
    static class TestCase1 extends TestCase {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   130
        private TestCase1(String directory) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   131
            super(directory);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   132
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   133
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   134
        public TestCase1() throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   135
            this("case1");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   136
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   137
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   138
        @Override
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   139
        void emitClassFiles() throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   140
            emitClassFile("");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   141
            emitClassFile("7");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   142
            emitClassFile("8");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   143
            emitClassFile("9");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   144
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   145
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   146
        /*
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   147
         * Adds different variants of types
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   148
         */
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   149
        void emitClassFile(String version) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   150
            final File outDir = mkdir(version.isEmpty()
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   151
                    ? tcwd
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   152
                    : new File(versionsDir, version));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   153
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   154
            final File srcDir = mkdir(version.isEmpty()
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   155
                            ? new File(tcwd, "src")
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   156
                            : new File(new File(versionsDir, version), "src"));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   157
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   158
            final String fname = "Foo";
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   159
            final File srcFile = new File(srcDir, fname + Utils.JAVA_FILE_EXT);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   160
            List<String> scratch = new ArrayList<>();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   161
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   162
            scratch.add("package pkg;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   163
            switch (version) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   164
                case "7":
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   165
                    scratch.add("public class Foo {");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   166
                    scratch.add("public static final class Bar {}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   167
                    break;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   168
                case "8":
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   169
                    scratch.add("public abstract class Foo {");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   170
                    scratch.add("public final class Bar {}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   171
                    break;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   172
                case "9":
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   173
                    scratch.add("public interface Foo {");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   174
                    scratch.add("public final class Bar {}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   175
                    break;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   176
                default:
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   177
                    scratch.add("public class Foo {");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   178
                    scratch.add("public final class Bar {}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   179
                    break;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   180
            }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   181
            scratch.add("}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   182
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   183
            Utils.createFile(srcFile, scratch);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   184
            Utils.compiler("-d",
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   185
                    outDir.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   186
                    srcFile.getAbsolutePath());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   187
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   188
    }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   189
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   190
    static class TestCase2 extends TestCase {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   191
        private TestCase2(String directory) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   192
            super(directory);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   193
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   194
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   195
        TestCase2() throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   196
            this("case2");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   197
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   198
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   199
        @Override
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   200
        void emitClassFiles() throws Exception {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   201
            emitClassFile("");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   202
            emitClassFile("8");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   203
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   204
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   205
        /*
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   206
         * Adds different variants of types and tries to invoke an
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   207
         * interface or concrete method defined by them.
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   208
         */
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   209
        void emitClassFile(String version) throws IOException {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   210
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   211
            final File outDir = mkdir(version.isEmpty()
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   212
                    ? tcwd
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   213
                    : new File(versionsDir, version));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   214
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   215
            final File srcDir = mkdir(version.isEmpty()
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   216
                    ? new File(tcwd, "src")
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   217
                    : new File(new File(versionsDir, version), "src"));
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   218
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   219
            List<String> scratch = new ArrayList<>();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   220
            final String fname1 = "Ab";
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   221
            final File srcFile1 = new File(srcDir, fname1 + Utils.JAVA_FILE_EXT);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   222
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   223
            final String fname2 = "AbNormal";
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   224
            final File srcFile2 = new File(srcDir, fname2 + Utils.JAVA_FILE_EXT);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   225
            switch (version) {
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   226
                case "8":
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   227
                    scratch.clear();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   228
                    scratch.add("import java.io.IOException;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   229
                    scratch.add("public interface " + fname1 + "{");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   230
                    scratch.add("    public abstract void close() throws IOException ;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   231
                    scratch.add("}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   232
                    Utils.createFile(srcFile1, scratch);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   233
                    break;
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   234
                default:
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   235
                    scratch.clear();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   236
                    scratch.add("import java.io.IOException;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   237
                    scratch.add("public abstract class " + fname1 + "{");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   238
                    scratch.add("    public abstract void close() throws IOException ;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   239
                    scratch.add("}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   240
                    Utils.createFile(srcFile1, scratch);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   241
            }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   242
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   243
            scratch.clear();
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   244
            scratch.add("import java.io.IOException;");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   245
            scratch.add("public class " + fname2 + "{");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   246
            scratch.add("    public void doSomething(Ab ab) throws IOException {");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   247
            scratch.add("       ab.close();");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   248
            scratch.add("    }");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   249
            scratch.add("}");
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   250
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   251
            Utils.createFile(srcFile2, scratch);
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   252
            Utils.compiler("-d",
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   253
                    outDir.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   254
                    srcFile1.getAbsolutePath(),
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   255
                    srcFile2.getAbsolutePath());
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   256
        }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   257
    }
8e42083c7bc8 8066272: pack200 must support Multi-Release Jars
ksrini
parents:
diff changeset
   258
}