langtools/test/tools/jdeps/jdkinternals/ShowReplacement.java
author mchung
Thu, 29 Sep 2016 21:31:09 -0700
changeset 41251 6112540cd0c1
parent 40308 274367a99f98
child 41442 14db641d4a9f
permissions -rw-r--r--
8166238: Update jdeps for GNU-style long form options Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     1
/*
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     4
 *
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     8
 *
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    13
 * accompanied this code).
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    14
 *
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    18
 *
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    21
 * questions.
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    22
 */
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    23
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    24
/*
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    25
 * @test
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    26
 * @bug 8159524
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    27
 * @summary Tests JDK internal APIs with and without replacements
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    28
 * @library ../lib
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.jdeps
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    30
 * @build CompilerUtils JdepsUtil
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    31
 * @run testng ShowReplacement
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    32
 */
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    33
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    34
import java.nio.file.Path;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    35
import java.nio.file.Paths;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    36
import java.util.Map;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    37
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    38
import org.testng.annotations.BeforeTest;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    39
import org.testng.annotations.Test;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    40
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    41
import static org.testng.Assert.assertEquals;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    42
import static org.testng.Assert.assertTrue;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    43
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    44
public class ShowReplacement {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    45
    private static final String TEST_SRC = System.getProperty("test.src");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    46
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    47
    private static final Path CLASSES_DIR = Paths.get("classes");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    48
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    49
    private static final Map<String, String> REPLACEMENTS = Map.of(
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    50
        "sun.security.util.HostnameChecker",
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    51
        "Use javax.net.ssl.SSLParameters.setEndpointIdentificationAlgorithm(\"HTTPS\") @since 1.7",
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    52
        "",
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    53
        "or javax.net.ssl.HttpsURLConnection.setHostnameVerifier() @since 1.4");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    54
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    55
    /**
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    56
     * Compiles classes used by the test
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    57
     */
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    58
    @BeforeTest
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    59
    public void compileAll() throws Exception {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    60
        CompilerUtils.cleanDir(CLASSES_DIR);
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    61
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    62
        Path tmp = Paths.get("tmp");
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    63
        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "apple"), tmp));
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    64
        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "q"),
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    65
                                         CLASSES_DIR,
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    66
                                         "-cp", tmp.toString(),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 39671
diff changeset
    67
                                         "--add-exports=java.base/sun.security.util=ALL-UNNAMED"));
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    68
    }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    69
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    70
    @Test
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    71
    public void withReplacement() {
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    72
        Path file = Paths.get("q", "WithRepl.class");
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    73
        String[] output = JdepsUtil.jdeps("-jdkinternals", CLASSES_DIR.resolve(file).toString());
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    74
        int i = 0;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    75
        while (!output[i].contains("Suggested Replacement")) {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    76
            i++;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    77
        }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    78
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    79
        // must match the number of JDK internal APIs
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    80
        int count = output.length-i-2;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    81
        assertEquals(count, REPLACEMENTS.size());
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    82
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    83
        for (int j=i+2; j < output.length; j++) {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    84
            String line = output[j];
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    85
            int pos = line.indexOf("Use ");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    86
            if (pos < 0)
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    87
                pos = line.indexOf("or");
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    88
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    89
            assertTrue(pos > 0);
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    90
            String name = line.substring(0, pos).trim();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    91
            String repl = line.substring(pos, line.length()).trim();
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    92
            assertEquals(REPLACEMENTS.get(name), repl);
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    93
        }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    94
    }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    95
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    96
    /*
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    97
     * A JDK internal class has been removed while its package still exists.
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
    98
     */
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
    99
    @Test
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   100
    public void noReplacement() {
39671
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   101
        Path file = Paths.get("q", "NoRepl.class");
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   102
        String[] output = JdepsUtil.jdeps("-jdkinternals", CLASSES_DIR.resolve(file).toString());
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   103
        int i = 0;
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   104
        // expect no replacement
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   105
        while (i < output.length && !output[i].contains("Suggested Replacement")) {
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   106
            i++;
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   107
        }
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   108
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   109
        // no replacement
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   110
        assertEquals(output.length-i, 0);
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   111
    }
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   112
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   113
    /*
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   114
     * A JDK internal package has been removed.
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   115
     */
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   116
    @Test
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   117
    public void removedPackage() {
5a4b6a035514 8160398: (jdeps) Replace a list of JDK 8 internal API for detecting if it's removed in JDK 9 or later
mchung
parents: 39101
diff changeset
   118
        Path file = Paths.get("q", "RemovedPackage.class");
41251
6112540cd0c1 8166238: Update jdeps for GNU-style long form options
mchung
parents: 40308
diff changeset
   119
        String[] output = JdepsUtil.jdeps("--jdk-internals", CLASSES_DIR.resolve(file).toString());
39101
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   120
        int i = 0;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   121
        // expect no replacement
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   122
        while (i < output.length && !output[i].contains("Suggested Replacement")) {
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   123
            i++;
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   124
        }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   125
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   126
        // no replacement
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   127
        assertEquals(output.length-i, 0);
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   128
    }
fd8a6392b7ea 8159524: jdeps -jdkinternals throws NPE when no replacement is known
mchung
parents:
diff changeset
   129
}