< prev index next >

test/tools/launcher/modules/patch/basic/PatchTest.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @library /lib/testlibrary
  27  * @modules jdk.compiler
  28  * @build PatchTest CompilerUtils JarUtils jdk.testlibrary.*

  29  * @run testng PatchTest
  30  * @summary Basic test for --patch-module
  31  */
  32 
  33 import java.io.File;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;
  37 import java.util.stream.Collectors;
  38 import java.util.stream.Stream;
  39 
  40 import static jdk.testlibrary.ProcessTools.*;
  41 
  42 import org.testng.annotations.BeforeTest;
  43 import org.testng.annotations.Test;
  44 import static org.testng.Assert.*;
  45 
  46 
  47 /**
  48  * Compiles and launches a test that uses --patch-module with two directories
  49  * of classes to override existing classes and add new classes to modules in
  50  * the boot layer.
  51  *
  52  * The classes overridden or added via --patch-module all define a public
  53  * no-arg constructor and override toString to return "hi". This allows the
  54  * launched test to check that the overridden classes are loaded.
  55  */
  56 
  57 @Test
  58 public class PatchTest {
  59 
  60     // top-level source directory


 113             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 114             assertTrue(compiled, "classes did not compile");
 115             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-1.jar"), output);
 116         }
 117 
 118         // javac -Xmodule:$MODULE -d patches2/$MODULE patches2/$MODULE/**
 119         // jar cf patches/$MODULE-2.jar -C patches2/$MODULE .
 120         for (Path src : Files.newDirectoryStream(SRC2_DIR)) {
 121             Path output = PATCHES2_DIR.resolve(src.getFileName());
 122             String mn = src.getFileName().toString();
 123             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 124             assertTrue(compiled, "classes did not compile");
 125             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-2.jar"), output);
 126         }
 127 
 128     }
 129 
 130     /**
 131      * Run test with patches to java.base, jdk.naming.dns and jdk.compiler
 132      */
 133     void runTest(String basePatches, String dnsPatches, String compilerPatches)
 134         throws Exception
 135     {
 136         // the argument to the test is the list of classes overridden or added
 137         String arg = Stream.of(CLASSES).collect(Collectors.joining(","));
 138 
 139         int exitValue
 140             =  executeTestJava("--patch-module", "java.base=" + basePatches,
 141                                "--patch-module", "jdk.naming.dns=" + dnsPatches,
 142                                "--patch-module", "jdk.compiler=" + compilerPatches,
 143                                "--add-exports", "java.base/java.lang2=test",
 144                                "--add-exports", "jdk.naming.dns/com.sun.jndi.dns=test",
 145                                "--add-exports", "jdk.naming.dns/com.sun.jndi.dns2=test",
 146                                "--add-exports", "jdk.compiler/com.sun.tools.javac2=test",
 147                                "--add-modules", "jdk.naming.dns,jdk.compiler",
 148                                "--module-path", MODS_DIR.toString(),
 149                                "-m", "test/jdk.test.Main", arg)
 150                 .outputTo(System.out)
 151                 .errorTo(System.out)
 152                 .getExitValue();
 153 
 154         assertTrue(exitValue == 0);
 155     }
 156 
 157 
 158     /**
 159      * Run test with ---patch-module and exploded patches
 160      */
 161     public void testWithExplodedPatches() throws Exception {
 162 
 163         // patches1/java.base:patches2/java.base
 164         String basePatches = PATCHES1_DIR.resolve("java.base")
 165                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 166 
 167         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 168                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns");
 169 
 170         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 171                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler");
 172 
 173         runTest(basePatches, dnsPatches, compilerPatches);
 174     }
 175 
 176 
 177     /**
 178      * Run test with ---patch-module and patches in JAR files
 179      */
 180     public void testWithJarPatches() throws Exception {
 181 
 182         // patches/java.base-1.jar:patches/java-base-2.jar
 183         String basePatches = PATCHES_DIR.resolve("java.base-1.jar")
 184                 + File.pathSeparator + PATCHES_DIR.resolve("java.base-2.jar");
 185 
 186         String dnsPatches = PATCHES_DIR.resolve("jdk.naming.dns-1.jar")
 187                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar");
 188 
 189         String compilerPatches = PATCHES_DIR.resolve("jdk.compiler-1.jar")
 190                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar");
 191 
 192         runTest(basePatches, dnsPatches, compilerPatches);
 193 
 194     }
 195 
 196 
 197     /**
 198      * Run test with ---patch-module and patches in JAR files and exploded patches
 199      */
 200     public void testWithJarAndExplodedPatches() throws Exception {
 201 
 202         // patches/java.base-1.jar:patches2/java.base
 203         String basePatches = PATCHES_DIR.resolve("java.base-1.jar")
 204                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 205 
 206         // patches1/jdk.naming.dns:patches/jdk.naming.dns-2.jar
 207         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 208                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar");
 209 
 210         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 211                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar");
 212 
 213         runTest(basePatches, dnsPatches, compilerPatches);
 214 
 215     }
 216 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @library /lib/testlibrary
  27  * @modules jdk.compiler
  28  *          java.naming
  29  * @build PatchTest CompilerUtils JarUtils jdk.testlibrary.tasks.JavaTask
  30  * @run testng PatchTest
  31  * @summary Basic test for --patch-module
  32  */
  33 
  34 import java.io.File;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.util.stream.Collectors;
  39 import java.util.stream.Stream;
  40 
  41 import jdk.testlibrary.tasks.JavaTask;
  42 
  43 import org.testng.annotations.BeforeTest;
  44 import org.testng.annotations.Test;
  45 import static org.testng.Assert.*;
  46 
  47 
  48 /**
  49  * Compiles and launches a test that uses --patch-module with two directories
  50  * of classes to override existing classes and add new classes to modules in
  51  * the boot layer.
  52  *
  53  * The classes overridden or added via --patch-module all define a public
  54  * no-arg constructor and override toString to return "hi". This allows the
  55  * launched test to check that the overridden classes are loaded.
  56  */
  57 
  58 @Test
  59 public class PatchTest {
  60 
  61     // top-level source directory


 114             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 115             assertTrue(compiled, "classes did not compile");
 116             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-1.jar"), output);
 117         }
 118 
 119         // javac -Xmodule:$MODULE -d patches2/$MODULE patches2/$MODULE/**
 120         // jar cf patches/$MODULE-2.jar -C patches2/$MODULE .
 121         for (Path src : Files.newDirectoryStream(SRC2_DIR)) {
 122             Path output = PATCHES2_DIR.resolve(src.getFileName());
 123             String mn = src.getFileName().toString();
 124             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 125             assertTrue(compiled, "classes did not compile");
 126             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-2.jar"), output);
 127         }
 128 
 129     }
 130 
 131     /**
 132      * Run test with patches to java.base, jdk.naming.dns and jdk.compiler
 133      */
 134     void runTest(String basePatches, String dnsPatches, String compilerPatches) {


 135         // the argument to the test is the list of classes overridden or added
 136         String arg = Stream.of(CLASSES).collect(Collectors.joining(","));
 137 
 138         new JavaTask()
 139             .patchModule("java.base", basePatches)
 140             .patchModule("jdk.naming.dns", dnsPatches)
 141             .patchModule("jdk.compiler", compilerPatches)
 142             .addExports("java.base", "java.lang2", "test")
 143             .addExports("jdk.naming.dns", "com.sun.jndi.dns", "test")
 144             .addExports("jdk.naming.dns", "com.sun.jndi.dns2", "test")
 145             .addExports("jdk.compiler", "com.sun.tools.javac2", "test")
 146             .addModules("jdk.naming.dns,jdk.compiler")
 147             .modulePath(MODS_DIR)
 148             .module("test", "jdk.test.Main")
 149             .classArgs(arg)
 150             .run();



 151     }
 152 
 153 
 154     /**
 155      * Run test with ---patch-module and exploded patches
 156      */
 157     public void testWithExplodedPatches() {
 158 
 159         // patches1/java.base:patches2/java.base
 160         String basePatches = PATCHES1_DIR.resolve("java.base")
 161                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 162 
 163         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 164                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns");
 165 
 166         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 167                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler");
 168 
 169         runTest(basePatches, dnsPatches, compilerPatches);
 170     }
 171 
 172 
 173     /**
 174      * Run test with ---patch-module and patches in JAR files
 175      */
 176     public void testWithJarPatches() {
 177 
 178         // patches/java.base-1.jar:patches/java-base-2.jar
 179         String basePatches = PATCHES_DIR.resolve("java.base-1.jar")
 180                 + File.pathSeparator + PATCHES_DIR.resolve("java.base-2.jar");
 181 
 182         String dnsPatches = PATCHES_DIR.resolve("jdk.naming.dns-1.jar")
 183                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar");
 184 
 185         String compilerPatches = PATCHES_DIR.resolve("jdk.compiler-1.jar")
 186                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar");
 187 
 188         runTest(basePatches, dnsPatches, compilerPatches);
 189 
 190     }
 191 
 192 
 193     /**
 194      * Run test with ---patch-module and patches in JAR files and exploded patches
 195      */
 196     public void testWithJarAndExplodedPatches() {
 197 
 198         // patches/java.base-1.jar:patches2/java.base
 199         String basePatches = PATCHES_DIR.resolve("java.base-1.jar")
 200                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 201 
 202         // patches1/jdk.naming.dns:patches/jdk.naming.dns-2.jar
 203         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 204                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.naming.dns-2.jar");
 205 
 206         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 207                 +  File.pathSeparator + PATCHES_DIR.resolve("jdk.compiler-2.jar");
 208 
 209         runTest(basePatches, dnsPatches, compilerPatches);
 210 
 211     }
 212 }
< prev index next >