jdk/test/tools/pack200/Utils.java
changeset 28255 ddb0157601ed
parent 27565 729f9700483a
child 36111 00ec08e93b0c
equal deleted inserted replaced
28252:4673729e145d 28255:ddb0157601ed
    61             System.getProperty("java.home"));
    61             System.getProperty("java.home"));
    62     static final boolean IsWindows =
    62     static final boolean IsWindows =
    63             System.getProperty("os.name").startsWith("Windows");
    63             System.getProperty("os.name").startsWith("Windows");
    64     static final boolean Is64Bit =
    64     static final boolean Is64Bit =
    65             System.getProperty("sun.arch.data.model", "32").equals("64");
    65             System.getProperty("sun.arch.data.model", "32").equals("64");
    66     static final File   JavaSDK =  new File(JavaHome).getParentFile();
    66     static final File   JavaSDK =  new File(JavaHome);
    67 
    67 
    68     static final String PACK_FILE_EXT   = ".pack";
    68     static final String PACK_FILE_EXT   = ".pack";
    69     static final String JAVA_FILE_EXT   = ".java";
    69     static final String JAVA_FILE_EXT   = ".java";
    70     static final String CLASS_FILE_EXT  = ".class";
    70     static final String CLASS_FILE_EXT  = ".class";
    71     static final String JAR_FILE_EXT    = ".jar";
    71     static final String JAR_FILE_EXT    = ".jar";
    80 
    80 
    81     private static void init() throws IOException {
    81     private static void init() throws IOException {
    82         if (VerifierJar.exists()) {
    82         if (VerifierJar.exists()) {
    83             return;
    83             return;
    84         }
    84         }
    85         File srcDir = new File(TEST_SRC_DIR, VERIFIER_DIR_NAME);
    85         File srcDir = new File(getVerifierDir(), "src");
    86         if (!srcDir.exists()) {
       
    87             // if not available try one level above
       
    88             srcDir = new File(TEST_SRC_DIR.getParentFile(), VERIFIER_DIR_NAME);
       
    89         }
       
    90         List<File> javaFileList = findFiles(srcDir, createFilter(JAVA_FILE_EXT));
    86         List<File> javaFileList = findFiles(srcDir, createFilter(JAVA_FILE_EXT));
    91         File tmpFile = File.createTempFile("javac", ".tmp");
    87         File tmpFile = File.createTempFile("javac", ".tmp");
    92         XCLASSES.mkdirs();
    88         XCLASSES.mkdirs();
    93         FileOutputStream fos = null;
    89         FileOutputStream fos = null;
    94         PrintStream ps = null;
    90         PrintStream ps = null;
   113             "-C",
   109             "-C",
   114             XCLASSES.getName(),
   110             XCLASSES.getName(),
   115             ".");
   111             ".");
   116     }
   112     }
   117 
   113 
       
   114     private static File getVerifierDir() {
       
   115         File srcDir = new File(TEST_SRC_DIR, VERIFIER_DIR_NAME);
       
   116         if (!srcDir.exists()) {
       
   117             // if not available try one level above
       
   118             srcDir = new File(TEST_SRC_DIR.getParentFile(), VERIFIER_DIR_NAME);
       
   119         }
       
   120         return srcDir;
       
   121     }
       
   122 
       
   123     static File getGoldenJar() {
       
   124         return new File(new File(getVerifierDir(), "data"), "golden.jar");
       
   125     }
   118     static void dirlist(File dir) {
   126     static void dirlist(File dir) {
   119         File[] files = dir.listFiles();
   127         File[] files = dir.listFiles();
   120         System.out.println("--listing " + dir.getAbsolutePath() + "---");
   128         System.out.println("--listing " + dir.getAbsolutePath() + "---");
   121         for (File f : files) {
   129         for (File f : files) {
   122             StringBuffer sb = new StringBuffer();
   130             StringBuffer sb = new StringBuffer();
   562         runExec(cmdList);
   570         runExec(cmdList);
   563 
   571 
   564         File rtJar = new File("rt.jar");
   572         File rtJar = new File("rt.jar");
   565         cmdList.clear();
   573         cmdList.clear();
   566         cmdList.add(getJarCmd());
   574         cmdList.add(getJarCmd());
   567         cmdList.add("cvf");
   575         // cmdList.add("cvf"); too noisy
       
   576         cmdList.add("cf");
   568         cmdList.add(rtJar.getName());
   577         cmdList.add(rtJar.getName());
   569         cmdList.add("-C");
   578         cmdList.add("-C");
   570         cmdList.add("out");
   579         cmdList.add("out");
   571         cmdList.add(".");
   580         cmdList.add(".");
   572         runExec(cmdList);
   581         runExec(cmdList);
   573 
   582 
   574         recursiveDelete(new File("out"));
   583         recursiveDelete(new File("out"));
   575         return rtJar;
   584         return rtJar;
   576     }
   585     }
   577     private static List<File> locaterCache = null;
       
   578     // search the source dir and jdk dir for requested file and returns
       
   579     // the first location it finds.
       
   580     static File locateJar(String name) {
       
   581         try {
       
   582             if (locaterCache == null) {
       
   583                 locaterCache = new ArrayList<File>();
       
   584                 locaterCache.addAll(findFiles(TEST_SRC_DIR, createFilter(JAR_FILE_EXT)));
       
   585                 locaterCache.addAll(findFiles(JavaSDK, createFilter(JAR_FILE_EXT)));
       
   586             }
       
   587             for (File f : locaterCache) {
       
   588                 if (f.getName().equals(name)) {
       
   589                     return f;
       
   590                 }
       
   591             }
       
   592             throw new IOException("file not found: " + name);
       
   593         } catch (IOException e) {
       
   594             throw new RuntimeException(e);
       
   595         }
       
   596     }
       
   597 }
   586 }