1 /*
2  * Copyright (c) 2016, 2018, 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  * @modules java.base/jdk.internal.misc
33  *          java.management
34  *          jdk.jartool/sun.tools.jar
35  * @requires os.family != "mac"
36  * @compile test-classes/Hello.java
37  * @run main CaseSensitiveClassPath
38  */
39 
40 import java.nio.file.FileAlreadyExistsException;
41 import java.nio.file.Files;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.nio.file.StandardCopyOption;
45 import jdk.test.lib.Platform;
46 import jdk.test.lib.process.OutputAnalyzer;
47 
48 
49 // Excluded from running on MAC: a more comprehensive case sensitivity detection
50 // and fix mechanism is needed, which is planned to be implemented in the future.
51 public class CaseSensitiveClassPath {
main(String[] args)52     public static void main(String[] args) throws Exception {
53         String appJar = JarBuilder.getOrCreateHelloJar();
54         String appJarUpper = appJar.replace("hello", "Hello");
55 
56         OutputAnalyzer out = TestCommon.dump(appJar, TestCommon.list("Hello"));
57         TestCommon.checkDump(out);
58 
59         Path jarPath = Paths.get(appJar);
60         Path jarPathUpper = null;
61 
62         boolean fileExists = false;
63         try {
64             jarPathUpper = Files.createFile(Paths.get(appJarUpper));
65         } catch (FileAlreadyExistsException faee) {
66             fileExists = true;
67         }
68 
69         if (!fileExists) {
70             try {
71                 Files.copy(jarPath, jarPathUpper, StandardCopyOption.REPLACE_EXISTING);
72             } catch (Exception e) {
73                 throw new java.lang.RuntimeException(
74                     "Failed copying file from " + appJar + " to " + appJarUpper + ".", e);
75             }
76         } else {
77             jarPathUpper = Paths.get(appJarUpper);
78         }
79         boolean isSameFile = Files.isSameFile(jarPath, jarPathUpper);
80 
81         TestCommon.run("-cp", appJarUpper, "Hello", "-Xlog:class+path=info",
82                        "-Xlog:cds")
83             .ifNoMappingFailure(output -> {
84                     if (isSameFile) {
85                         output.shouldContain("Hello World");
86                     } else {
87                         output.shouldContain("shared class paths mismatch");
88                         output.shouldHaveExitValue(1);
89                     }
90                 });
91     }
92 }
93