--- a/jdk/test/java/net/URLClassLoader/closetest/GetResourceAsStream.java Fri May 26 16:35:45 2017 +0200
+++ b/jdk/test/java/net/URLClassLoader/closetest/GetResourceAsStream.java Tue May 30 07:03:33 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,15 +25,24 @@
* @test
* @bug 6899919
* @library /lib/testlibrary
- * @build jdk.testlibrary.FileUtils
- * @run shell build2.sh
+ * @modules jdk.compiler
+ * @build jdk.testlibrary.FileUtils JarUtils CompilerUtils
* @run main/othervm GetResourceAsStream
*/
-import java.io.*;
-import java.net.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
public class GetResourceAsStream extends Common {
+ private static final String WORK_DIR = System.getProperty("user.dir");
/*
* We simply test various scenarios with class/resource files
@@ -42,35 +51,30 @@
* on Windows. It will still run correctly on other platforms
*/
public static void main (String args[]) throws Exception {
-
- String workdir = System.getProperty("test.classes");
- if (workdir == null) {
- workdir = args[0];
- }
+ setup();
/* the jar we copy for each test */
- File srcfile = new File (workdir, "foo.jar");
+ File srcfile = new File(WORK_DIR, "foo.jar");
/* the jar we use for the test */
- File testfile = new File (workdir, "test.jar");
+ File testfile = new File(WORK_DIR, "test.jar");
- copyFile (srcfile, testfile);
- test (testfile, false, false);
+ copyFile(srcfile, testfile);
+ test(testfile, false, false);
- copyFile (srcfile, testfile);
- test (testfile, true, false);
+ copyFile(srcfile, testfile);
+ test(testfile, true, false);
- copyFile (srcfile, testfile);
- test (testfile, true, true);
+ copyFile(srcfile, testfile);
+ test(testfile, true, true);
// repeat test using a directory of files
- File testdir= new File (workdir, "testdir");
- File srcdir= new File (workdir, "test3");
+ File testdir = new File(WORK_DIR, "testdir");
+ File srcdir = new File(WORK_DIR, "test3");
- copyDir (srcdir, testdir);
- test (testdir, true, false);
-
+ copyDir(srcdir, testdir);
+ test(testdir, true, false);
}
// create a loader on jarfile (or directory)
@@ -82,7 +86,7 @@
static void test (File file, boolean loadclass, boolean readall)
throws Exception
{
- URL[] urls = new URL[] {file.toURL()};
+ URL[] urls = new URL[] {file.toURI().toURL()};
System.out.println ("Doing tests with URL: " + urls[0]);
URLClassLoader loader = new URLClassLoader (urls);
if (loadclass) {
@@ -97,7 +101,7 @@
loader.close ();
- // shouuld not find bye.txt now
+ // should not find bye.txt now
InputStream s1 = loader.getResourceAsStream("bye.txt");
if (s1 != null) {
throw new RuntimeException ("closed loader returned resource");
@@ -107,4 +111,26 @@
rm_minus_rf (file);
System.out.println (" ... OK");
}
+
+ /**
+ * Prepare jars files for the tests
+ */
+ private static void setup () throws IOException {
+ Path classes = Paths.get(WORK_DIR);
+ Path testSrc = Paths.get(System.getProperty("test.src"),
+ "test1", "com", "foo", "TestClass.java");
+ Path targetDir = classes.resolve("test3");
+ Path testTarget = targetDir.resolve("TestClass.java");
+ Files.createDirectories(targetDir);
+ Files.copy(testSrc, testTarget, StandardCopyOption.REPLACE_EXISTING);
+ // Compile sources for corresponding test
+ CompilerUtils.compile(targetDir, targetDir);
+ // Prepare txt files
+ Files.write(targetDir.resolve("hello.txt"), "Hello world".getBytes(),
+ StandardOpenOption.CREATE);
+ Files.write(targetDir.resolve("bye.txt"), "Bye world".getBytes(),
+ StandardOpenOption.CREATE);
+ // Create jar
+ JarUtils.createJarFile(classes.resolve("foo.jar"), targetDir);
+ }
}