langtools/test/tools/javac/T6705935.java
changeset 6932 ded41b98a923
parent 5520 86e4b9a9da40
child 7681 1f0819a3341f
equal deleted inserted replaced
6931:d6339142c51f 6932:ded41b98a923
    29 
    29 
    30 import java.io.*;
    30 import java.io.*;
    31 import java.util.*;
    31 import java.util.*;
    32 import javax.tools.*;
    32 import javax.tools.*;
    33 import com.sun.tools.javac.file.*;
    33 import com.sun.tools.javac.file.*;
       
    34 import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
       
    35 import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject;
    34 
    36 
    35 public class T6705935 {
    37 public class T6705935 {
    36     public static void main(String... args) throws Exception {
    38     public static void main(String... args) throws Exception {
    37         new T6705935().run();
    39         new T6705935().run();
    38     }
    40     }
    41         File java_home = new File(System.getProperty("java.home"));
    43         File java_home = new File(System.getProperty("java.home"));
    42         if (java_home.getName().equals("jre"))
    44         if (java_home.getName().equals("jre"))
    43             java_home = java_home.getParentFile();
    45             java_home = java_home.getParentFile();
    44 
    46 
    45         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    47         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    46         JavaFileManager fm = c.getStandardFileManager(null, null, null);
    48         StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
       
    49         //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
       
    50 
    47         for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
    51         for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
    48                                         "java.lang",
    52                                         "java.lang",
    49                                         Collections.singleton(JavaFileObject.Kind.CLASS),
    53                                         Collections.singleton(JavaFileObject.Kind.CLASS),
    50                                         false)) {
    54                                         false)) {
       
    55             test++;
       
    56 
       
    57             if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
       
    58                 System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
       
    59                 skip++;
       
    60                 continue;
       
    61             }
       
    62 
       
    63             //System.err.println(fo.getName());
    51             String p = fo.getName();
    64             String p = fo.getName();
    52             int bra = p.indexOf("(");
    65             int bra = p.indexOf("(");
    53             int ket = p.indexOf(")");
    66             int ket = p.indexOf(")");
    54             //System.err.println(bra + "," + ket + "," + p.length());
    67             //System.err.println(bra + "," + ket + "," + p.length());
    55             if (bra == -1 || ket != p.length() -1)
    68             if (bra == -1 || ket != p.length() -1)
    59             //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
    72             //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
    60             if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
    73             if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
    61                 throw new Exception("bad path: " + p);
    74                 throw new Exception("bad path: " + p);
    62 
    75 
    63         }
    76         }
       
    77 
       
    78         if (test == 0)
       
    79             throw new Exception("no files found");
       
    80 
       
    81         if (skip == 0)
       
    82             System.out.println(test + " files found");
       
    83         else
       
    84             System.out.println(test + " files found, " + skip + " files skipped");
       
    85 
       
    86         if (test == skip)
       
    87             System.out.println("Warning: all files skipped; no platform classes found in zip files.");
    64     }
    88     }
       
    89 
       
    90     private <T> List<T> asList(Iterable<? extends T> items) {
       
    91         List<T> list = new ArrayList<T>();
       
    92         for (T item: items)
       
    93             list.add(item);
       
    94         return list;
       
    95      }
       
    96 
       
    97     private int skip;
       
    98     private int test;
    65 }
    99 }