91 String dumptimeBootAppendOpt = "-Xbootclasspath/a:" + fake_modules; 92 { 93 ProcessBuilder pb = makeBuilder(java_home_src + "/bin/java", 94 "-Xshare:dump", 95 dumptimeBootAppendOpt, 96 jsaOpt); 97 TestCommon.executeAndLog(pb, "dump"); 98 } 99 { 100 String runtimeBootAppendOpt = dumptimeBootAppendOpt + System.getProperty("path.separator") + helloJar; 101 ProcessBuilder pb = makeBuilder(java_home_dst + "/bin/java", 102 "-Xshare:auto", 103 runtimeBootAppendOpt, 104 jsaOpt, 105 "-Xlog:class+path=info", 106 "-version"); 107 OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-dst"); 108 out.shouldNotContain("shared class paths mismatch"); 109 out.shouldNotContain("BOOT classpath mismatch"); 110 } 111 } 112 113 // Do a cheap clone of the JDK. Most files can be sym-linked. However, $JAVA_HOME/bin/java and $JAVA_HOME/lib/.../libjvm.so" 114 // must be copied, because the java.home property is derived from the canonicalized paths of these 2 files. 115 static void clone(File src, File dst) throws Exception { 116 if (dst.exists()) { 117 if (!dst.isDirectory()) { 118 throw new RuntimeException("Not a directory :" + dst); 119 } 120 } else { 121 if (!dst.mkdir()) { 122 throw new RuntimeException("Cannot create directory: " + dst); 123 } 124 } 125 for (String child : src.list()) { 126 if (child.equals(".") || child.equals("..")) { 127 continue; 128 } 129 130 File child_src = new File(src, child); 131 File child_dst = new File(dst, child); 132 if (child_dst.exists()) { 133 throw new RuntimeException("Already exists: " + child_dst); 134 } 135 if (child_src.isFile()) { 136 if (child.equals("libjvm.so") || child.equals("java")) { 137 Files.copy(child_src.toPath(), /* copy data to -> */ child_dst.toPath()); 138 } else { 139 Files.createSymbolicLink(child_dst.toPath(), /* link to -> */ child_src.toPath()); 140 } 141 } else { 142 clone(child_src, child_dst); 143 } 144 } 145 } 146 147 static ProcessBuilder makeBuilder(String... args) throws Exception { 148 System.out.print("["); 149 for (String s : args) { 150 System.out.print(" " + s); 151 } 152 System.out.println(" ]"); 153 return new ProcessBuilder(args); 154 } 155 156 private static String copyFakeModulesFromHelloJar() throws Exception { 157 String classDir = System.getProperty("test.classes"); 158 String newFile = "hello.modules"; 159 String path = classDir + File.separator + newFile; 160 161 Files.copy(Paths.get(classDir, "hello.jar"), 162 Paths.get(classDir, newFile), 163 StandardCopyOption.REPLACE_EXISTING); | 91 String dumptimeBootAppendOpt = "-Xbootclasspath/a:" + fake_modules; 92 { 93 ProcessBuilder pb = makeBuilder(java_home_src + "/bin/java", 94 "-Xshare:dump", 95 dumptimeBootAppendOpt, 96 jsaOpt); 97 TestCommon.executeAndLog(pb, "dump"); 98 } 99 { 100 String runtimeBootAppendOpt = dumptimeBootAppendOpt + System.getProperty("path.separator") + helloJar; 101 ProcessBuilder pb = makeBuilder(java_home_dst + "/bin/java", 102 "-Xshare:auto", 103 runtimeBootAppendOpt, 104 jsaOpt, 105 "-Xlog:class+path=info", 106 "-version"); 107 OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-dst"); 108 out.shouldNotContain("shared class paths mismatch"); 109 out.shouldNotContain("BOOT classpath mismatch"); 110 } 111 112 // Test with no modules image in the <java home>/lib directory 113 renameModulesFile(java_home_dst); 114 { 115 ProcessBuilder pb = makeBuilder(java_home_dst + "/bin/java", 116 "-version"); 117 OutputAnalyzer out = TestCommon.executeAndLog(pb, "exec-missing-modules"); 118 out.shouldHaveExitValue(1); 119 out.shouldContain("System boot class path should not be NULL"); 120 } 121 } 122 123 // Do a cheap clone of the JDK. Most files can be sym-linked. However, $JAVA_HOME/bin/java and $JAVA_HOME/lib/.../libjvm.so" 124 // must be copied, because the java.home property is derived from the canonicalized paths of these 2 files. 125 static void clone(File src, File dst) throws Exception { 126 if (dst.exists()) { 127 if (!dst.isDirectory()) { 128 throw new RuntimeException("Not a directory :" + dst); 129 } 130 } else { 131 if (!dst.mkdir()) { 132 throw new RuntimeException("Cannot create directory: " + dst); 133 } 134 } 135 for (String child : src.list()) { 136 if (child.equals(".") || child.equals("..")) { 137 continue; 138 } 139 140 File child_src = new File(src, child); 141 File child_dst = new File(dst, child); 142 if (child_dst.exists()) { 143 throw new RuntimeException("Already exists: " + child_dst); 144 } 145 if (child_src.isFile()) { 146 if (child.equals("libjvm.so") || child.equals("java")) { 147 Files.copy(child_src.toPath(), /* copy data to -> */ child_dst.toPath()); 148 } else { 149 Files.createSymbolicLink(child_dst.toPath(), /* link to -> */ child_src.toPath()); 150 } 151 } else { 152 clone(child_src, child_dst); 153 } 154 } 155 } 156 157 static void renameModulesFile(String javaHome) throws Exception { 158 String modulesDir = javaHome + File.separator + "lib"; 159 File origModules = new File(modulesDir, "modules"); 160 if (!origModules.exists()) { 161 throw new RuntimeException("modules file not found"); 162 } 163 164 File renamedModules = new File(modulesDir, "orig_modules"); 165 if (renamedModules.exists()) { 166 throw new RuntimeException("found orig_modules unexpectedly"); 167 } 168 169 boolean success = origModules.renameTo(renamedModules); 170 if (!success) { 171 throw new RuntimeException("rename modules file failed"); 172 } 173 } 174 175 static ProcessBuilder makeBuilder(String... args) throws Exception { 176 System.out.print("["); 177 for (String s : args) { 178 System.out.print(" " + s); 179 } 180 System.out.println(" ]"); 181 return new ProcessBuilder(args); 182 } 183 184 private static String copyFakeModulesFromHelloJar() throws Exception { 185 String classDir = System.getProperty("test.classes"); 186 String newFile = "hello.modules"; 187 String path = classDir + File.separator + newFile; 188 189 Files.copy(Paths.get(classDir, "hello.jar"), 190 Paths.get(classDir, newFile), 191 StandardCopyOption.REPLACE_EXISTING); |