< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java

Print this page

  1 /*
  2  * Copyright (c) 2014, 2020, 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  *

100 
101     String cp = TestCommon.getTestJar("cpattr6.jar");
102     String nonExistPath = CDSTestUtils.getOutputDir() + File.separator + "cpattrX.jar";
103     (new File(nonExistPath)).delete();
104 
105     TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
106         "-Xlog:class+path");
107 
108     TestCommon.run(
109         "-Xlog:class+path",
110         "-cp", cp,
111         "CpAttr6")
112       .assertNormalExit(output -> {
113           output.shouldMatch("should be non-existent: .*cpattrX.jar");
114         });
115 
116     // Now make nonExistPath exist. CDS still loads, but archived non-system classes will not be used.
117     Files.copy(Paths.get(cp), Paths.get(nonExistPath),
118                StandardCopyOption.REPLACE_EXISTING);
119 
120     TestCommon.run(
121         "-Xlog:class+path",
122         "-cp", cp,
123         "CpAttr6")
124       .assertNormalExit(output -> {
125           output.shouldMatch("Archived non-system classes are disabled because the file .*cpattrX.jar exists");
126         });







127   }
128 
129   private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception {
130     String jarClassesDir = CDSTestUtils.getOutputDir() + File.separator + jarName + "_classes";
131     try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }
132 
133     JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator +
134         "test-classes" + File.separator + enclosingClassName + ".java");
135     JarBuilder.buildWithManifest(jarName, manifest, jarClassesDir, testClassNames);
136   }
137 }

  1 /*
  2  * Copyright (c) 2014, 2024, 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  *

100 
101     String cp = TestCommon.getTestJar("cpattr6.jar");
102     String nonExistPath = CDSTestUtils.getOutputDir() + File.separator + "cpattrX.jar";
103     (new File(nonExistPath)).delete();
104 
105     TestCommon.testDump(cp, TestCommon.list("CpAttr6"),
106         "-Xlog:class+path");
107 
108     TestCommon.run(
109         "-Xlog:class+path",
110         "-cp", cp,
111         "CpAttr6")
112       .assertNormalExit(output -> {
113           output.shouldMatch("should be non-existent: .*cpattrX.jar");
114         });
115 
116     // Now make nonExistPath exist. CDS still loads, but archived non-system classes will not be used.
117     Files.copy(Paths.get(cp), Paths.get(nonExistPath),
118                StandardCopyOption.REPLACE_EXISTING);
119 
120     CDSTestUtils.Result result = TestCommon.run(
121         "-Xlog:class+path",
122         "-cp", cp,
123         "CpAttr6");
124     if (CDSTestUtils.isAOTClassLinkingEnabled()) {
125         result.assertAbnormalExit(output -> {
126                 output.shouldMatch("CDS archive has aot-linked classes. It cannot be used because the file .*cpattrX.jar exists");
127             });
128 
129     } else {
130         result.assertNormalExit(output -> {
131                 output.shouldMatch("Archived non-system classes are disabled because the file .*cpattrX.jar exists");
132             });
133     }
134   }
135 
136   private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception {
137     String jarClassesDir = CDSTestUtils.getOutputDir() + File.separator + jarName + "_classes";
138     try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }
139 
140     JarBuilder.compile(jarClassesDir, System.getProperty("test.src") + File.separator +
141         "test-classes" + File.separator + enclosingClassName + ".java");
142     JarBuilder.buildWithManifest(jarName, manifest, jarClassesDir, testClassNames);
143   }
144 }
< prev index next >