jdk/test/tools/pack200/Utils.java
author ksrini
Fri, 20 Aug 2010 08:18:54 -0700
changeset 6314 8ab691ddb904
child 6320 6b48de58428e
permissions -rw-r--r--
6966737: (pack200) the pack200 regression tests need to be more robust. Reviewed-by: jrose, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6314
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     1
/*
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2007, 2010 Oracle and/or its affiliates. All rights reserved.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     4
 *
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     8
 *
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    13
 * accompanied this code).
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    14
 *
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    18
 *
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    21
 * questions.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    22
 */
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    23
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    24
import java.io.BufferedReader;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    25
import java.io.ByteArrayOutputStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    26
import java.io.Closeable;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    27
import java.io.File;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    28
import java.io.FileFilter;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    29
import java.io.FileInputStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    30
import java.io.FileOutputStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    31
import java.io.IOException;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    32
import java.io.InputStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    33
import java.io.InputStreamReader;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    34
import java.io.PrintStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    35
import java.nio.channels.FileChannel;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    36
import java.util.ArrayList;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    37
import java.util.Arrays;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    38
import java.util.Collections;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    39
import java.util.List;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    40
import java.util.Map;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    41
import java.util.jar.JarFile;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    42
import java.util.jar.JarOutputStream;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    43
import java.util.jar.Pack200;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    44
import java.util.zip.ZipEntry;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    45
import java.util.zip.ZipFile;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    46
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    47
/**
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    48
 *
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    49
 * @author ksrini
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    50
 */
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    51
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    52
/*
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    53
 * This class contains all the commonly used utilities used by various tests
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    54
 * in this directory.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    55
 */
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    56
class Utils {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    57
    static final String JavaHome = System.getProperty("test.java",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    58
            System.getProperty("java.home"));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    59
    static final boolean IsWindows =
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    60
            System.getProperty("os.name").startsWith("Windows");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    61
    static final boolean Is64Bit =
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    62
            System.getProperty("sun.arch.data.model", "32").equals("64");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    63
    static final File   JavaSDK =  new File(JavaHome).getParentFile();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    64
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    65
    static final String PACK_FILE_EXT   = ".pack";
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    66
    static final String JAVA_FILE_EXT   = ".java";
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    67
    static final String CLASS_FILE_EXT  = ".class";
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    68
    static final String JAR_FILE_EXT    = ".jar";
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    69
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    70
    static final File   TEST_SRC_DIR = new File(System.getProperty("test.src"));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    71
    static final String VERIFIER_DIR_NAME = "pack200-verifier";
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    72
    static final File   VerifierJar = new File(VERIFIER_DIR_NAME + JAR_FILE_EXT);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    73
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    74
    private Utils() {} // all static
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    75
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    76
    static {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    77
        if (!JavaHome.endsWith("jre")) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    78
            throw new RuntimeException("Error: requires an SDK to run");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    79
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    80
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    81
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    82
    private static void init() throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    83
        if (VerifierJar.exists()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    84
            return;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    85
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    86
        File srcDir = new File(TEST_SRC_DIR, VERIFIER_DIR_NAME);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    87
        List<File> javaFileList = findFiles(srcDir, createFilter(JAVA_FILE_EXT));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    88
        File tmpFile = File.createTempFile("javac", ".tmp");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    89
        File classesDir = new File("xclasses");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    90
        classesDir.mkdirs();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    91
        FileOutputStream fos = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    92
        PrintStream ps = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    93
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    94
            fos = new FileOutputStream(tmpFile);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    95
            ps = new PrintStream(fos);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    96
            for (File f : javaFileList) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    97
                ps.println(f.getAbsolutePath());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    98
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
    99
        } finally {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   100
            close(ps);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   101
            close(fos);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   102
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   103
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   104
        compiler("-d",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   105
                "xclasses",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   106
                "@" + tmpFile.getAbsolutePath());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   107
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   108
        jar("cvfe",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   109
            VerifierJar.getName(),
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   110
            "sun.tools.pack.verify.Main",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   111
            "-C",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   112
            "xclasses",
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   113
            ".");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   114
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   115
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   116
    static void dirlist(File dir) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   117
        File[] files = dir.listFiles();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   118
        System.out.println("--listing " + dir.getAbsolutePath() + "---");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   119
        for (File f : files) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   120
            StringBuffer sb = new StringBuffer();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   121
            sb.append(f.isDirectory() ? "d " : "- ");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   122
            sb.append(f.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   123
            System.out.println(sb);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   124
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   125
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   126
    static void doCompareVerify(File reference, File specimen) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   127
        init();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   128
        List<String> cmds = new ArrayList<String>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   129
        cmds.add(getJavaCmd());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   130
        cmds.add("-jar");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   131
        cmds.add(VerifierJar.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   132
        cmds.add(reference.getAbsolutePath());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   133
        cmds.add(specimen.getAbsolutePath());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   134
        cmds.add("-O");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   135
        runExec(cmds);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   136
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   137
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   138
    static void doCompareBitWise(File reference, File specimen)
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   139
            throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   140
        init();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   141
        List<String> cmds = new ArrayList<String>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   142
        cmds.add(getJavaCmd());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   143
        cmds.add("-jar");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   144
        cmds.add(VerifierJar.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   145
        cmds.add(reference.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   146
        cmds.add(specimen.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   147
        cmds.add("-O");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   148
        cmds.add("-b");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   149
        runExec(cmds);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   150
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   151
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   152
    static FileFilter createFilter(final String extension) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   153
        return new FileFilter() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   154
            @Override
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   155
            public boolean accept(File pathname) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   156
                String name = pathname.getName();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   157
                if (name.endsWith(extension)) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   158
                    return true;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   159
                }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   160
                return false;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   161
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   162
        };
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   163
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   164
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   165
    static final FileFilter DIR_FILTER = new FileFilter() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   166
        public boolean accept(File pathname) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   167
            if (pathname.isDirectory()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   168
                return true;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   169
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   170
            return false;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   171
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   172
    };
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   173
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   174
    static final FileFilter FILE_FILTER = new FileFilter() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   175
        public boolean accept(File pathname) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   176
            if (pathname.isFile()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   177
                return true;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   178
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   179
            return false;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   180
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   181
    };
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   182
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   183
    private static void setFileAttributes(File src, File dst) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   184
        dst.setExecutable(src.canExecute());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   185
        dst.setReadable(src.canRead());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   186
        dst.setWritable(src.canWrite());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   187
        dst.setLastModified(src.lastModified());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   188
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   189
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   190
    static void copyFile(File src, File dst) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   191
        if (src.isDirectory()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   192
            dst.mkdirs();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   193
            setFileAttributes(src, dst);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   194
            return;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   195
        } else {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   196
            File baseDirFile = dst.getParentFile();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   197
            if (!baseDirFile.exists()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   198
                baseDirFile.mkdirs();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   199
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   200
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   201
        FileInputStream in = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   202
        FileOutputStream out = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   203
        FileChannel srcChannel = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   204
        FileChannel dstChannel = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   205
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   206
            in = new FileInputStream(src);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   207
            out = new FileOutputStream(dst);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   208
            srcChannel = in.getChannel();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   209
            dstChannel = out.getChannel();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   210
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   211
            long retval = srcChannel.transferTo(0, src.length(), dstChannel);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   212
            if (src.length() != dst.length()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   213
                throw new IOException("file copy failed for " + src);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   214
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   215
        } finally {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   216
            close(srcChannel);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   217
            close(dstChannel);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   218
            close(in);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   219
            close(out);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   220
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   221
        setFileAttributes(src, dst);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   222
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   223
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   224
    /*
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   225
     * Suppose a path is provided which consists of a full path
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   226
     * this method returns the sub path for a full path ex: /foo/bar/baz/foobar.z
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   227
     * and the base path is /foo/bar it will will return baz/foobar.z.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   228
     */
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   229
    private static String getEntryPath(String basePath, String fullPath) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   230
        if (!fullPath.startsWith(basePath)) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   231
            return null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   232
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   233
        return fullPath.substring(basePath.length());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   234
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   235
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   236
    static String getEntryPath(File basePathFile, File fullPathFile) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   237
        return getEntryPath(basePathFile.toString(), fullPathFile.toString());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   238
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   239
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   240
    public static void recursiveCopy(File src, File dest) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   241
        if (!src.exists() || !src.canRead()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   242
            throw new IOException("file not found or readable: " + src);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   243
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   244
        if (dest.exists() && !dest.isDirectory() && !dest.canWrite()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   245
            throw new IOException("file not found or writeable: " + dest);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   246
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   247
        if (!dest.exists()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   248
            dest.mkdirs();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   249
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   250
        List<File> a = directoryList(src);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   251
        for (File f : a) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   252
            copyFile(f, new File(dest, getEntryPath(src, f)));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   253
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   254
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   255
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   256
    static List<File> directoryList(File dirname) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   257
        List<File>  dirList = new ArrayList<File>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   258
        return directoryList(dirname, dirList, null);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   259
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   260
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   261
    private static List<File> directoryList(File dirname, List<File> dirList,
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   262
            File[] dirs) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   263
        dirList.addAll(Arrays.asList(dirname.listFiles(FILE_FILTER)));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   264
        dirs = dirname.listFiles(DIR_FILTER);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   265
        for (File f : dirs) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   266
            if (f.isDirectory() && !f.equals(dirname)) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   267
                dirList.add(f);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   268
                directoryList(f, dirList, dirs);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   269
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   270
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   271
        return dirList;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   272
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   273
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   274
    static void recursiveDelete(File dir) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   275
        if (dir.isFile()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   276
            dir.delete();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   277
        } else if (dir.isDirectory()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   278
            File[] entries = dir.listFiles();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   279
            for (int i = 0; i < entries.length; i++) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   280
                if (entries[i].isDirectory()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   281
                    recursiveDelete(entries[i]);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   282
                }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   283
                entries[i].delete();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   284
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   285
            dir.delete();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   286
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   287
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   288
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   289
    static List<File> findFiles(File startDir, FileFilter filter)
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   290
            throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   291
        List<File> list = new ArrayList<File>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   292
        findFiles0(startDir, list, filter);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   293
        return list;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   294
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   295
    /*
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   296
     * finds files in the start directory using the the filter, appends
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   297
     * the files to the dirList.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   298
     */
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   299
    private static void findFiles0(File startDir, List<File> list,
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   300
                                    FileFilter filter) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   301
        File[] foundFiles = startDir.listFiles(filter);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   302
        list.addAll(Arrays.asList(foundFiles));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   303
        File[] dirs = startDir.listFiles(DIR_FILTER);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   304
        for (File dir : dirs) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   305
            findFiles0(dir, list, filter);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   306
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   307
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   308
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   309
    static void close(Closeable c) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   310
        if (c == null) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   311
            return;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   312
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   313
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   314
            c.close();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   315
        } catch (IOException ignore) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   316
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   317
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   318
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   319
    static void compiler(String... javacCmds) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   320
        if (com.sun.tools.javac.Main.compile(javacCmds) != 0) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   321
            throw new RuntimeException("compilation failed");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   322
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   323
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   324
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   325
    static void jar(String... jargs) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   326
        sun.tools.jar.Main jarTool =
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   327
                new sun.tools.jar.Main(System.out, System.err, "jartool");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   328
        if (!jarTool.run(jargs)) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   329
            throw new RuntimeException("jar command failed");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   330
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   331
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   332
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   333
    // given a jar file foo.jar will write to foo.pack
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   334
    static void pack(JarFile jarFile, File packFile) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   335
        Pack200.Packer packer = Pack200.newPacker();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   336
        Map<String, String> p = packer.properties();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   337
        // Take the time optimization vs. space
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   338
        p.put(packer.EFFORT, "1");  // CAUTION: do not use 0.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   339
        // Make the memory consumption as effective as possible
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   340
        p.put(packer.SEGMENT_LIMIT, "10000");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   341
        // ignore all JAR deflation requests to save time
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   342
        p.put(packer.DEFLATE_HINT, packer.FALSE);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   343
        // save the file ordering of the original JAR
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   344
        p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   345
        FileOutputStream fos = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   346
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   347
            // Write out to a jtreg scratch area
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   348
            fos = new FileOutputStream(packFile);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   349
            // Call the packer
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   350
            packer.pack(jarFile, fos);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   351
        } finally {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   352
            close(fos);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   353
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   354
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   355
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   356
    // uses java unpacker, slow but useful to discover issues with the packer
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   357
    static void unpackj(File inFile, JarOutputStream jarStream)
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   358
            throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   359
        unpack0(inFile, jarStream, true);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   360
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   361
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   362
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   363
    // uses native unpacker using the java APIs
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   364
    static void unpackn(File inFile, JarOutputStream jarStream)
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   365
            throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   366
        unpack0(inFile, jarStream, false);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   367
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   368
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   369
    // given a packed file, create the jar file in the current directory.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   370
    private static void unpack0(File inFile, JarOutputStream jarStream,
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   371
            boolean useJavaUnpack) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   372
        // Unpack the files
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   373
        Pack200.Unpacker unpacker = Pack200.newUnpacker();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   374
        Map<String, String> props = unpacker.properties();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   375
        if (useJavaUnpack) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   376
            props.put("com.sun.java.util.jar.pack.disable.native", "true");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   377
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   378
        // Call the unpacker
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   379
        unpacker.unpack(inFile, jarStream);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   380
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   381
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   382
    static byte[] getBuffer(ZipFile zf, ZipEntry ze) throws IOException {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   383
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   384
        byte buf[] = new byte[8192];
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   385
        InputStream is = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   386
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   387
            is = zf.getInputStream(ze);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   388
            int n = is.read(buf);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   389
            while (n > 0) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   390
                baos.write(buf, 0, n);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   391
                n = is.read(buf);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   392
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   393
            return baos.toByteArray();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   394
        } finally {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   395
            close(is);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   396
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   397
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   398
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   399
    static ArrayList<String> getZipFileEntryNames(ZipFile z) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   400
        ArrayList<String> out = new ArrayList<String>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   401
        for (ZipEntry ze : Collections.list(z.entries())) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   402
            out.add(ze.getName());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   403
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   404
        return out;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   405
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   406
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   407
    static List<String> runExec(List<String> cmdsList) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   408
        ArrayList<String> alist = new ArrayList<String>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   409
        ProcessBuilder pb =
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   410
                new ProcessBuilder(cmdsList);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   411
        Map<String, String> env = pb.environment();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   412
        pb.directory(new File("."));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   413
        dirlist(new File("."));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   414
        for (String x : cmdsList) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   415
            System.out.print(x + " ");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   416
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   417
        System.out.println("");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   418
        int retval = 0;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   419
        Process p = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   420
        InputStreamReader ir = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   421
        BufferedReader rd = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   422
        InputStream is = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   423
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   424
            pb.redirectErrorStream(true);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   425
            p = pb.start();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   426
            is = p.getInputStream();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   427
            ir = new InputStreamReader(is);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   428
            rd = new BufferedReader(ir, 8192);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   429
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   430
            String in = rd.readLine();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   431
            while (in != null) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   432
                alist.add(in);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   433
                System.out.println(in);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   434
                in = rd.readLine();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   435
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   436
            retval = p.waitFor();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   437
            if (retval != 0) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   438
                throw new RuntimeException("process failed with non-zero exit");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   439
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   440
        } catch (Exception ex) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   441
            throw new RuntimeException(ex.getMessage());
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   442
        } finally {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   443
            close(rd);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   444
            close(ir);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   445
            close(is);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   446
            if (p != null) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   447
                p.destroy();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   448
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   449
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   450
        return alist;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   451
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   452
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   453
    static String getUnpack200Cmd() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   454
        return getAjavaCmd("unpack200");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   455
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   456
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   457
    static String getPack200Cmd() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   458
        return getAjavaCmd("pack200");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   459
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   460
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   461
    static String getJavaCmd() {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   462
        return getAjavaCmd("java");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   463
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   464
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   465
    static String getAjavaCmd(String cmdStr) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   466
        File binDir = new File(JavaHome, "bin");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   467
        File unpack200File = IsWindows
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   468
                ? new File(binDir, cmdStr + ".exe")
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   469
                : new File(binDir, cmdStr);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   470
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   471
        String cmd = unpack200File.getAbsolutePath();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   472
        if (!unpack200File.canExecute()) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   473
            throw new RuntimeException("please check" +
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   474
                    cmd + " exists and is executable");
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   475
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   476
        return cmd;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   477
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   478
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   479
    private static List<File> locaterCache = null;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   480
    // search the source dir and jdk dir for requested file and returns
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   481
    // the first location it finds.
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   482
    static File locateJar(String name) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   483
        try {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   484
            if (locaterCache == null) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   485
                locaterCache = new ArrayList<File>();
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   486
                locaterCache.addAll(findFiles(TEST_SRC_DIR, createFilter(JAR_FILE_EXT)));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   487
                locaterCache.addAll(findFiles(JavaSDK, createFilter(JAR_FILE_EXT)));
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   488
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   489
            for (File f : locaterCache) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   490
                if (f.getName().equals(name)) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   491
                    return f;
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   492
                }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   493
            }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   494
            throw new IOException("file not found: " + name);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   495
        } catch (IOException e) {
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   496
            throw new RuntimeException(e);
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   497
        }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   498
    }
8ab691ddb904 6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff changeset
   499
}