langtools/test/tools/jdeps/MultiReleaseJar.java
author hseigel
Tue, 26 Jul 2016 08:23:25 -0400
changeset 43178 6fb98b21d035
parent 41164 69167c89e68f
child 44182 ce2f0cbc81b9
permissions -rw-r--r--
8161218: Better bytecode loading Reviewed-by: acorn, mschoene, ctornqvi Contributed-by: harold.seigel@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41164
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     1
/*
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     4
 *
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     7
 * published by the Free Software Foundation.
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     8
 *
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    13
 * accompanied this code).
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    14
 *
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    18
 *
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    21
 * questions.
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    22
 */
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    23
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    24
/*
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    25
 * @test
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    26
 * @bug 8153654
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    27
 * @summary Tests for jdeps tool with multi-release jar files
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.jdeps
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    29
 * @library mrjar mrjar/base mrjar/9 mrjar/10 mrjar/v9 mrjar/v10
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    30
 * @build test.* p.* q.*
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    31
 * @run testng MultiReleaseJar
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    32
 */
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    33
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    34
import org.testng.Assert;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    35
import org.testng.annotations.AfterClass;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    36
import org.testng.annotations.BeforeClass;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    37
import org.testng.annotations.Test;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    38
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    39
import java.io.IOException;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    40
import java.io.InputStream;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    41
import java.nio.file.Path;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    42
import java.nio.file.Paths;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    43
import java.util.concurrent.TimeUnit;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    44
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    45
public class MultiReleaseJar {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    46
    Path mrjar;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    47
    String testJdk;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    48
    String fileSep;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    49
    Path cmdPath;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    50
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    51
    @BeforeClass
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    52
    public void initialize() throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    53
        mrjar = Paths.get(System.getProperty("test.classes", "."), "mrjar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    54
        testJdk = System.getProperty("test.jdk");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    55
        fileSep = System.getProperty("file.separator");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    56
        cmdPath = Paths.get(testJdk, "bin");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    57
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    58
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    59
    @Test
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    60
    public void basic() throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    61
        // build the jar file
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    62
        Result r = run("jar -cf Version.jar -C base test --release 9 -C 9 test --release 10 -C 10 test");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    63
        checkResult(r);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    64
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    65
        // try out a bunch of things
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    66
        r = run("jdeps --multi-release 9  -v missing.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    67
        checkResult(r, false, "Warning: Path does not exist: missing.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    68
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    69
        r = run("jdeps -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    70
        checkResult(r, false, "the --multi-release option is not set");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    71
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    72
        r = run("jdeps --multi-release base  -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    73
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    74
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    75
                "test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    76
                "test.Version"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    77
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    78
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    79
        r = run("jdeps --multi-release 9  -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    80
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    81
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    82
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    83
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    84
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    85
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    86
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    87
                "9/test.Version"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    88
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    89
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    90
        r = run("jdeps --multi-release 10  -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    91
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    92
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    93
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    94
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    95
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    96
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    97
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    98
                "9/test.NonPublic"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
    99
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   100
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   101
        r = run("jdeps --multi-release 8  -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   102
        checkResult(r, false, "Error: invalid argument for option: 8");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   103
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   104
        r = run("jdeps --multi-release 9.1  -v Version.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   105
        checkResult(r, false, "Error: invalid argument for option: 9.1");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   106
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   107
        r = run("jdeps -v -R -cp Version.jar test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   108
        checkResult(r, false, "the --multi-release option is not set");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   109
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   110
        r = run("jdeps -v -R -cp Version.jar -multi-release 9 test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   111
        checkResult(r, false,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   112
                "Error: unknown option: -multi-release",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   113
                "Usage: jdeps <options> <path",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   114
                "use -h, -?, -help, or --help"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   115
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   116
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   117
        r = run("jdeps -v -R -cp Version.jar --multi-release 9 test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   118
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   119
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   120
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   121
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   122
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   123
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   124
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   125
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   126
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   127
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   128
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   129
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   130
                "9/test.Version"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   131
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   132
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   133
        r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   134
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   135
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   136
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   137
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   138
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   139
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   140
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   141
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   142
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   143
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   144
                "10/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   145
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   146
                "9/test.NonPublic"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   147
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   148
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   149
        r = run("jdeps -v -R -cp Version.jar --multi-release base test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   150
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   151
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   152
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   153
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   154
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   155
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   156
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   157
                "test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   158
                "test.Version"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   159
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   160
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   161
        r = run("jdeps -v -R -cp Version.jar --multi-release 9.1 test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   162
        checkResult(r, false, "Error: invalid argument for option: 9.1");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   163
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   164
        // Rebuild jar without version 10
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   165
        r = run("jar -cf Version.jar -C base test --release 9 -C 9 test");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   166
        checkResult(r);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   167
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   168
        // but ask for version 10
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   169
        r = run("jdeps -v -R -cp Version.jar --multi-release 10 test/Main.class");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   170
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   171
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   172
                "Main.class ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   173
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   174
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   175
                "test.Main",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   176
                "Version.jar ->",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   177
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   178
                "9/test.NonPublic",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   179
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   180
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   181
                "9/test.Version",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   182
                "9/test.Version"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   183
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   184
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   185
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   186
    @Test
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   187
    public void ps_and_qs() throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   188
        // build the jar file
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   189
        Result r = run("jar -cf PQ.jar -C base p --release 9 -C v9 p -C v9 q --release 10 -C v10 q");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   190
        checkResult(r);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   191
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   192
        r = run("jdeps -v -R -cp PQ.jar --multi-release base PQ.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   193
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   194
                "PQ.jar -> java.base",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   195
                "p.Foo"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   196
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   197
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   198
        r = run("jdeps -v -R -cp PQ.jar --multi-release 9 PQ.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   199
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   200
                "PQ.jar -> java.base",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   201
                "9/p.Foo",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   202
                "9/p.Foo",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   203
                "9/q.Bar"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   204
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   205
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   206
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   207
        r = run("jdeps -v -R -cp PQ.jar --multi-release 10 PQ.jar");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   208
        checkResult(r, true,
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   209
                "PQ.jar -> java.base",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   210
                "10/q.Bar",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   211
                "10/q.Bar",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   212
                "10/q.Gee",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   213
                "9/p.Foo",
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   214
                "9/p.Foo"
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   215
        );
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   216
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   217
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   218
    static class Result {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   219
        final String cmd;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   220
        final int rc;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   221
        final String out;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   222
        final String err;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   223
        Result(String cmd, int rc, String out, String err) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   224
            this.cmd = cmd;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   225
            this.rc = rc;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   226
            this.out = out;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   227
            this.err = err;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   228
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   229
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   230
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   231
    Result run(String cmd) throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   232
        String[] cmds = cmd.split(" +");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   233
        cmds[0] = cmdPath.resolve(cmds[0]).toString();
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   234
        ProcessBuilder pb = new ProcessBuilder(cmds);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   235
        pb.directory(mrjar.toFile());
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   236
        Process p = pb.start();
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   237
        p.waitFor(10, TimeUnit.SECONDS);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   238
        String out;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   239
        try (InputStream is = p.getInputStream()) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   240
            out = new String(is.readAllBytes());
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   241
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   242
        String err;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   243
        try (InputStream is = p.getErrorStream()) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   244
            err = new String(is.readAllBytes());
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   245
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   246
        return new Result(cmd, p.exitValue(), out, err);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   247
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   248
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   249
    void checkResult(Result r) throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   250
        System.out.println(r.cmd);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   251
        System.out.println(r.out);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   252
        if (r.rc != 0) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   253
            System.out.println(r.err);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   254
            throw new Exception("rc=" + r.rc);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   255
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   256
        System.out.println();
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   257
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   258
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   259
    void checkResult(Result r, boolean checkrc, String... lines) throws Exception {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   260
        System.out.println(r.cmd);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   261
        System.out.println(r.out);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   262
        if (checkrc && r.rc != 0) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   263
            System.out.println(r.err);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   264
            throw new Exception("rc=" + r.rc);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   265
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   266
        String[] out = r.out.split("\r?\n");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   267
        Assert.assertEquals(out.length, lines.length);
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   268
        int n = 0;
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   269
        for (String line : lines) {
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   270
            Assert.assertTrue(out[n++].contains(line), "\"" + line + "\"");
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   271
        }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   272
        System.out.println();
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   273
    }
69167c89e68f 8153654: Update jdeps to be multi-release jar aware
sdrach
parents:
diff changeset
   274
}