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