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 Handling of directories in -cp is based on the classlist 28 * @requires vm.cds 29 * @library /test/lib 30 * @run main DirClasspathTest 31 */ 32 33 import jdk.test.lib.Platform; 34 import jdk.test.lib.process.OutputAnalyzer; 35 import java.io.File; 36 import java.nio.file.Path; 37 import java.nio.file.Paths; 38 import java.util.Arrays; 39 40 public class DirClasspathTest { 41 private static final int MAX_PATH = 260; 42 43 public static void main(String[] args) throws Exception { 44 File dir = new File(System.getProperty("user.dir")); 45 File emptydir = new File(dir, "emptydir"); 46 emptydir.mkdir(); 47 48 ///////////////////////////////////////////////////////////////// 49 // The classlist only contains boot class in following test cases 50 ///////////////////////////////////////////////////////////////// 51 String bootClassList[] = {"java/lang/Object"}; 52 53 // Empty dir in -cp: should be OK 54 OutputAnalyzer output; 55 output = TestCommon.dump(emptydir.getPath(), bootClassList, "-Xlog:class+path=info"); 70 File subDir = new File(longDir, "subdir"); 71 subDir.mkdir(); 72 output = TestCommon.dump(subDir.getPath(), bootClassList, "-Xlog:class+path=info"); 73 TestCommon.checkDump(output); 74 75 // Non-empty dir in -cp: should be OK 76 // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir> 77 output = TestCommon.dump(dir.getPath(), bootClassList, "-Xlog:class+path=info"); 78 TestCommon.checkDump(output); 79 80 // Long path to non-empty dir in -cp: should be OK 81 // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir> 82 output = TestCommon.dump(longDir.getPath(), bootClassList, "-Xlog:class+path=info"); 83 TestCommon.checkDump(output); 84 85 ///////////////////////////////////////////////////////////////// 86 // The classlist contains non-boot class in following test cases 87 ///////////////////////////////////////////////////////////////// 88 String appClassList[] = {"java/lang/Object", "com/sun/tools/javac/Main"}; 89 90 // Non-empty dir in -cp: should report error 91 output = TestCommon.dump(dir.getPath(), appClassList, "-Xlog:class+path=info"); 92 output.shouldNotHaveExitValue(0); 93 output.shouldContain("Cannot have non-empty directory in paths"); 94 95 // Long path to non-empty dir in -cp: should report error 96 output = TestCommon.dump(longDir.getPath(), appClassList, "-Xlog:class+path=info"); 97 output.shouldNotHaveExitValue(0); 98 output.shouldContain("Cannot have non-empty directory in paths"); 99 } 100 } | 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 Handling of directories in -cp is based on the classlist 28 * @requires vm.cds 29 * @library /test/lib 30 * @compile test-classes/Hello.java 31 * @run main DirClasspathTest 32 */ 33 34 import jdk.test.lib.Platform; 35 import jdk.test.lib.process.OutputAnalyzer; 36 import java.io.File; 37 import java.nio.file.Files; 38 import java.nio.file.Path; 39 import java.nio.file.Paths; 40 import java.util.Arrays; 41 42 public class DirClasspathTest { 43 private static final int MAX_PATH = 260; 44 45 public static void main(String[] args) throws Exception { 46 File dir = new File(System.getProperty("user.dir")); 47 File emptydir = new File(dir, "emptydir"); 48 emptydir.mkdir(); 49 50 ///////////////////////////////////////////////////////////////// 51 // The classlist only contains boot class in following test cases 52 ///////////////////////////////////////////////////////////////// 53 String bootClassList[] = {"java/lang/Object"}; 54 55 // Empty dir in -cp: should be OK 56 OutputAnalyzer output; 57 output = TestCommon.dump(emptydir.getPath(), bootClassList, "-Xlog:class+path=info"); 72 File subDir = new File(longDir, "subdir"); 73 subDir.mkdir(); 74 output = TestCommon.dump(subDir.getPath(), bootClassList, "-Xlog:class+path=info"); 75 TestCommon.checkDump(output); 76 77 // Non-empty dir in -cp: should be OK 78 // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir> 79 output = TestCommon.dump(dir.getPath(), bootClassList, "-Xlog:class+path=info"); 80 TestCommon.checkDump(output); 81 82 // Long path to non-empty dir in -cp: should be OK 83 // <dir> is not empty because it has at least one subdirectory, i.e., <emptydir> 84 output = TestCommon.dump(longDir.getPath(), bootClassList, "-Xlog:class+path=info"); 85 TestCommon.checkDump(output); 86 87 ///////////////////////////////////////////////////////////////// 88 // The classlist contains non-boot class in following test cases 89 ///////////////////////////////////////////////////////////////// 90 String appClassList[] = {"java/lang/Object", "com/sun/tools/javac/Main"}; 91 92 // Non-empty dir in -cp: should be OK (as long as no classes were loaded from there) 93 output = TestCommon.dump(dir.getPath(), appClassList, "-Xlog:class+path=info"); 94 TestCommon.checkDump(output); 95 96 // Long path to non-empty dir in -cp: should be OK (as long as no classes were loaded from there) 97 output = TestCommon.dump(longDir.getPath(), appClassList, "-Xlog:class+path=info"); 98 TestCommon.checkDump(output); 99 100 ///////////////////////////////////////////////////////////////// 101 // Loading an app class from a directory 102 ///////////////////////////////////////////////////////////////// 103 String appClassList2[] = {"Hello", "java/lang/Object", "com/sun/tools/javac/Main"}; 104 // Non-empty dir in -cp: should report error if a class is loaded from it 105 output = TestCommon.dump(classDir.toString(), appClassList2, "-Xlog:class+path=info"); 106 output.shouldNotHaveExitValue(0); 107 output.shouldContain("Cannot have non-empty directory in paths"); 108 109 // Long path to non-empty dir in -cp: should report error if a class is loaded from it 110 File srcClass = new File(classDir.toFile(), "Hello.class"); 111 File destClass = new File(longDir, "Hello.class"); 112 Files.copy(srcClass.toPath(), destClass.toPath()); 113 output = TestCommon.dump(longDir.getPath(), appClassList2, "-Xlog:class+path=info"); 114 output.shouldNotHaveExitValue(0); 115 output.shouldContain("Cannot have non-empty directory in paths"); 116 } 117 } |