changeset 19350:c9294b00cc92

Minor clean-up of ClassLoader.getResource test
author alanb
date Sun, 19 Mar 2017 11:58:46 +0000
parents 3e030cff43b1
children b657b9585c94
files test/java/lang/ClassLoader/getResource/automaticmodules/Driver.java test/java/lang/ClassLoader/getResource/automaticmodules/p/Dummy.java
diffstat 2 files changed, 12 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/lang/ClassLoader/getResource/automaticmodules/Driver.java	Sun Mar 19 11:48:14 2017 +0000
+++ b/test/java/lang/ClassLoader/getResource/automaticmodules/Driver.java	Sun Mar 19 11:58:46 2017 +0000
@@ -24,7 +24,7 @@
 /**
  * @test
  * @library /lib/testlibrary
- * @build Driver Main p.Dummy JarUtils jdk.testlibrary.ProcessTools
+ * @build Driver Main JarUtils jdk.testlibrary.ProcessTools
  * @run main Driver
  * @summary Test ClassLoader.getResourceXXX to locate resources in an automatic
  *          module
@@ -41,7 +41,7 @@
 import jdk.testlibrary.ProcessTools;
 
 /**
- * The driver creates a JAR file containing p/Dummy.class, p/foo.properties,
+ * The driver creates a JAR file containing p/Foo.class, p/foo.properties,
  * and p/resources/bar.properties. This ensures there are is a resource in
  * a module package and a resource that is not in the module package. The
  * test is then launched to locate every resource in the JAR file.
@@ -49,28 +49,23 @@
 
 public class Driver {
 
+    private static final String TEST_CLASSES = System.getProperty("test.classes");
+
     public static void main(String[] args) throws Exception {
-        Path classes = Paths.get(System.getProperty("test.classes"));
-        Path p = classes.resolve("p");
-        if (Files.notExists(p) || Files.notExists(p.resolve("Dummy.class")))
-            throw new RuntimeException("Dummy class missing?");
-
-        // create resource files
-        Path foo = Files.createFile(p.resolve("foo.properties"));
+        // create content for JAR file
+        Path dir = Files.createTempDirectory("classes");
+        Path p = Files.createDirectory(dir.resolve("p"));
+        Files.createFile(p.resolve("Foo.class"));
+        Files.createFile(p.resolve("foo.properties"));
         Path resources = Files.createDirectory(p.resolve("resources"));
-        Path bar = Files.createFile(resources.resolve("bar.properties"));
+        Files.createFile(resources.resolve("bar.properties"));
 
         // create the JAR file, including a manifest
         Path jarFile = Paths.get("library-1.0.jar");
         Manifest man = new Manifest();
         Attributes attrs = man.getMainAttributes();
         attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
-        JarUtils.createJarFile(jarFile, man, classes, p);
-
-        // delete the resources so they cannot be located on the class path
-        Files.delete(foo);
-        Files.delete(bar);
-        Files.delete(resources);
+        JarUtils.createJarFile(jarFile, man, dir, p);
 
         // get the module name
         ModuleFinder finder = ModuleFinder.of(jarFile);
@@ -82,7 +77,7 @@
         // launch the test with the JAR file on the module path
         if (ProcessTools.executeTestJava("-p", jarFile.toString(),
                                          "--add-modules", name,
-                                         "-cp", classes.toString(),
+                                         "-cp", TEST_CLASSES,
                                          "Main", name)
                 .outputTo(System.out)
                 .errorTo(System.out)
--- a/test/java/lang/ClassLoader/getResource/automaticmodules/p/Dummy.java	Sun Mar 19 11:48:14 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package p;
-
-class Dummy { }