1 /* 2 * Copyright (c) 2014, 2017, 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 * @test 27 * @summary Class-Path: attribute in MANIFEST file 28 * AppCDS does not support uncompressed oops 29 * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true) 30 * @library /test/lib 31 * @modules java.base/jdk.internal.misc 32 * java.management 33 * jdk.jartool/sun.tools.jar 34 * @run main ClassPathAttr 35 */ 36 37 import jdk.test.lib.process.OutputAnalyzer; 38 import java.io.File; 39 import java.nio.file.Files; 40 import java.nio.file.FileAlreadyExistsException; 41 import java.nio.file.StandardCopyOption; 42 import java.nio.file.Paths; 43 44 45 public class ClassPathAttr { 46 47 public static void main(String[] args) throws Exception { 48 buildCpAttr("cpattr1", "cpattr1.mf", "CpAttr1", "CpAttr1"); 49 buildCpAttr("cpattr1_long", "cpattr1_long.mf", "CpAttr1", "CpAttr1"); 50 buildCpAttr("cpattr2", "cpattr2.mf", "CpAttr2", "CpAttr2"); 51 buildCpAttr("cpattr3", "cpattr3.mf", "CpAttr3", "CpAttr2", "CpAttr3"); 52 buildCpAttr("cpattr4", "cpattr4.mf", "CpAttr4", 53 "CpAttr2", "CpAttr3", "CpAttr4", "CpAttr5"); 54 buildCpAttr("cpattr5_123456789_223456789_323456789_423456789_523456789_623456789", "cpattr5_extra_long.mf", "CpAttr5", "CpAttr5"); 55 56 for (int i=1; i<=2; i++) { 57 String jar1 = TestCommon.getTestJar("cpattr1.jar"); 58 String jar4 = TestCommon.getTestJar("cpattr4.jar"); 59 if (i == 2) { 60 // Test case #2 -- same as #1, except we use cpattr1_long.jar, which has a super-long 61 // Class-Path: attribute. 62 jar1 = TestCommon.getTestJar("cpattr1_long.jar"); 63 } 64 String cp = jar1 + File.pathSeparator + jar4; 65 66 TestCommon.testDump(cp, TestCommon.list("CpAttr1", 67 "CpAttr2", 68 "CpAttr3", 69 "CpAttr4", 70 "CpAttr5")); 71 72 OutputAnalyzer output = TestCommon.execCommon( 73 "-cp", cp, 74 "CpAttr1"); 75 TestCommon.checkExec(output); 76 77 // Logging test for class+path. 78 output = TestCommon.execCommon( 79 "-Xlog:class+path", 80 "-cp", cp, 81 "CpAttr1"); 82 if (!TestCommon.isUnableToMap(output)){ 83 output.shouldMatch("checking shared classpath entry: .*cpattr2.jar"); 84 output.shouldMatch("checking shared classpath entry: .*cpattr3.jar"); 85 } 86 // Make sure aliased TraceClassPaths still works 87 output = TestCommon.execCommon( 88 "-XX:+TraceClassPaths", 89 "-cp", cp, 90 "CpAttr1"); 91 if (!TestCommon.isUnableToMap(output)){ 92 output.shouldMatch("checking shared classpath entry: .*cpattr2.jar"); 93 output.shouldMatch("checking shared classpath entry: .*cpattr3.jar"); 94 } 95 } 96 } 97 98 private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception { 99 String jarClassesDir = System.getProperty("test.classes") + File.separator + jarName + "_classes"; 100 try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { } 101 102 JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator + 103 "test-classes" + File.separator + enclosingClassName + ".java"); 104 JarBuilder.buildWithManifest(jarName, manifest, jarClassesDir, testClassNames); 105 } 106 }