test/langtools/tools/javac/launcher/src/CLTest.java
changeset 51871 8f66a57054b7
parent 51662 fe4349d27282
equal deleted inserted replaced
51870:cdfabab3413f 51871:8f66a57054b7
    41 import java.net.*;
    41 import java.net.*;
    42 import java.util.*;
    42 import java.util.*;
    43 import com.sun.tools.classfile.ClassFile;
    43 import com.sun.tools.classfile.ClassFile;
    44 
    44 
    45 public class CLTest {
    45 public class CLTest {
    46         public static void main(String... args) throws Exception {
    46     public static void main(String... args) throws Exception {
    47                 try {
    47         try {
    48                         new CLTest().run();
    48             new CLTest().run();
    49                 } catch (Throwable t) {
    49         } catch (Throwable t) {
    50                         t.printStackTrace();
    50             t.printStackTrace();
    51                         System.exit(1);
    51             System.exit(1);
    52                 }
    52         }
       
    53     }
       
    54 
       
    55     void run() throws Exception {
       
    56         String[] names = {
       
    57                 "p/q/CLTest.class",
       
    58                 "p/q/CLTest$Inner.class",
       
    59                 "p/q/CLTest2.class",
       
    60                 "java/lang/Object.class",
       
    61                 "UNKNOWN.class",
       
    62                 "UNKNOWN"
       
    63         };
       
    64 
       
    65         for (String name : names) {
       
    66             testGetResource(name);
       
    67             testGetResources(name);
       
    68             testGetResourceAsStream(name);
    53         }
    69         }
    54 
    70 
    55         void run() throws Exception {
    71         if (errors > 0) {
    56                 String[] names = {
    72             throw new Exception(errors + " errors found");
    57                                 "p/q/CLTest.class",
       
    58                                 "p/q/CLTest$Inner.class",
       
    59                                 "p/q/CLTest2.class",
       
    60                                 "java/lang/Object.class",
       
    61                                 "UNKNOWN.class",
       
    62                                 "UNKNOWN"
       
    63                 };
       
    64 
       
    65                 for (String name : names) {
       
    66                         testGetResource(name);
       
    67                         testGetResources(name);
       
    68                         testGetResourceAsStream(name);
       
    69                 }
       
    70 
       
    71                 if (errors > 0) {
       
    72                         throw new Exception(errors + " errors found");
       
    73                 }
       
    74         }
    73         }
       
    74     }
    75 
    75 
    76     void testGetResource(String name) {
    76     void testGetResource(String name) {
    77                 System.err.println("testGetResource: " + name);
    77         System.err.println("testGetResource: " + name);
    78         try {
    78         try {
    79             ClassLoader cl = getClass().getClassLoader();
    79             ClassLoader cl = getClass().getClassLoader();
    80             URL u = cl.getResource(name);
    80             URL u = cl.getResource(name);
    81             if (u == null) {
    81             if (u == null) {
    82                 if (!name.contains("UNKNOWN")) {
    82                 if (!name.contains("UNKNOWN")) {
    93             error("unexpected exception: " + t);
    93             error("unexpected exception: " + t);
    94         }
    94         }
    95     }
    95     }
    96 
    96 
    97     void testGetResources(String name) {
    97     void testGetResources(String name) {
    98                 System.err.println("testGetResources: " + name);
    98         System.err.println("testGetResources: " + name);
    99         try {
    99         try {
   100             ClassLoader cl = getClass().getClassLoader();
   100             ClassLoader cl = getClass().getClassLoader();
   101             Enumeration<URL> e = cl.getResources(name);
   101             Enumeration<URL> e = cl.getResources(name);
   102             List<URL> list = new ArrayList<>();
   102             List<URL> list = new ArrayList<>();
   103             while (e.hasMoreElements()) {
   103             while (e.hasMoreElements()) {