1 /* 2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 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 26 /* 27 * @test 28 * @summary Test case sensitive aspect of comparing class paths 29 * between dump time and archive use time 30 * @requires vm.cds 31 * @library /test/lib 32 * @requires os.family != "mac" 33 * @compile test-classes/Hello.java 34 * @run driver CaseSensitiveClassPath 35 */ 36 37 import java.nio.file.FileAlreadyExistsException; 38 import java.nio.file.Files; 39 import java.nio.file.Path; 40 import java.nio.file.Paths; 41 import java.nio.file.StandardCopyOption; 42 import jdk.test.lib.Platform; 43 import jdk.test.lib.process.OutputAnalyzer; 44 45 46 // Excluded from running on MAC: a more comprehensive case sensitivity detection 47 // and fix mechanism is needed, which is planned to be implemented in the future. 48 public class CaseSensitiveClassPath { main(String[] args)49 public static void main(String[] args) throws Exception { 50 String appJar = JarBuilder.getOrCreateHelloJar(); 51 String appJarUpper = appJar.replace("hello", "Hello"); 52 53 OutputAnalyzer out = TestCommon.dump(appJar, TestCommon.list("Hello")); 54 TestCommon.checkDump(out); 55 56 Path jarPath = Paths.get(appJar); 57 Path jarPathUpper = null; 58 59 boolean fileExists = false; 60 try { 61 jarPathUpper = Files.createFile(Paths.get(appJarUpper)); 62 } catch (FileAlreadyExistsException faee) { 63 fileExists = true; 64 } 65 66 if (!fileExists) { 67 try { 68 Files.copy(jarPath, jarPathUpper, StandardCopyOption.REPLACE_EXISTING); 69 } catch (Exception e) { 70 throw new java.lang.RuntimeException( 71 "Failed copying file from " + appJar + " to " + appJarUpper + ".", e); 72 } 73 } else { 74 jarPathUpper = Paths.get(appJarUpper); 75 } 76 boolean isSameFile = Files.isSameFile(jarPath, jarPathUpper); 77 78 TestCommon.run("-Xlog:class+path=info,cds", "-cp", appJarUpper, "Hello") 79 .ifNoMappingFailure(output -> { 80 if (isSameFile) { 81 output.shouldContain("Hello World"); 82 } else { 83 output.shouldContain("shared class paths mismatch"); 84 output.shouldHaveExitValue(1); 85 } 86 }); 87 } 88 } 89