hotspot/test/runtime/modules/Xpatch/XpatchTestJar.java
author lana
Thu, 12 May 2016 15:15:02 +0000
changeset 37915 be4ff50b6cb6
parent 37773 e5b3e9732c3c
permissions -rw-r--r--
Added tag jdk-9+118 for changeset cc643de7cb06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37773
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     1
/*
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     4
 *
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     8
 *
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    13
 * accompanied this code).
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    14
 *
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    18
 *
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    21
 * questions.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    22
 */
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    23
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    24
/*
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    25
 * @test
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    26
 * @summary Make sure -Xpatch works when a jar file is specified for a module
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    27
 * @library /testlibrary
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    29
 *          jdk.jartool/sun.tools.jar
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    30
 * @build BasicJarBuilder
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    31
 * @compile XpatchMain.java
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    32
 * @run main XpatchTestJar
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    33
 */
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    34
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    35
import jdk.test.lib.*;
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    36
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    37
public class XpatchTestJar {
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    38
    private static String moduleJar;
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    39
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    41
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    42
        // Create a class file in the module java.naming. This class file
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    43
        // will be put in the javanaming.jar file.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    44
        String source = "package javax.naming.spi; "                +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    45
                        "public class NamingManager { "             +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    46
                        "    static { "                             +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    47
                        "        System.out.println(\"I pass!\"); " +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    48
                        "    } "                                    +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    49
                        "}";
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    50
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    51
        ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    52
             InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "-Xmodule:java.naming"),
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    53
             System.getProperty("test.classes"));
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    54
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    55
        // Build the jar file that will be used for the module "java.naming".
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    56
        BasicJarBuilder.build("javanaming", "javax/naming/spi/NamingManager");
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    57
        moduleJar = BasicJarBuilder.getTestJar("javanaming.jar");
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    58
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    59
        // Just to make sure we are not fooled by the class file being on the
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    60
        // class path where all the test classes are stored, write the NamingManager.class
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    61
        // file out again with output that does not contain what OutputAnalyzer
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    62
        // expects. This will provide confidence that the contents of the class
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    63
        // is truly coming from the jar file and not the class file.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    64
        source =        "package javax.naming.spi; "                +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    65
                        "public class NamingManager { "             +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    66
                        "    static { "                             +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    67
                        "        System.out.println(\"Fail!\"); "   +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    68
                        "    } "                                    +
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    69
                        "}";
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    70
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    71
        ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    72
             InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "-Xmodule:java.naming"),
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    73
             System.getProperty("test.classes"));
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    74
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    75
        // Supply -Xpatch with the name of the jar file for the module java.naming.
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    76
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xpatch:java.naming=" + moduleJar,
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    77
             "XpatchMain", "javax.naming.spi.NamingManager");
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    78
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    79
        new OutputAnalyzer(pb.start())
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    80
            .shouldContain("I pass!")
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    81
            .shouldHaveExitValue(0);
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    82
    }
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    83
}