jdk/test/tools/pack200/RepackTest.java
author alanb
Mon, 21 Jan 2013 23:23:12 -0500
changeset 15684 e5b41bd22ec9
parent 13249 9f4bd1ab7873
child 18594 b6a3c9f71ac8
permissions -rw-r--r--
8004931: add/removePropertyChangeListener should not exist in subset Profiles of Java SE Reviewed-by: dholmes, mchung, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13249
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     1
/*
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     4
 *
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     8
 *
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    13
 * accompanied this code).
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    14
 *
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    18
 *
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    21
 * questions.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    22
 */
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    23
import java.io.File;
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    24
import java.io.IOException;
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    25
import java.util.ArrayList;
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    26
import java.util.List;
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    27
/*
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    28
 * @test
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    29
 * @bug 7184145
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    30
 * @summary tests repacking of a simple named jarfile.
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    31
 * @compile -XDignore.symbol.file Utils.java RepackTest.java
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    32
 * @run main RepackTest
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    33
 * @author ksrini
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    34
 */
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    35
public class RepackTest {
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    36
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    37
    public static void main(String... args) throws Exception {
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    38
        testRepack();
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    39
    }
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    40
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    41
    /*
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    42
     * there are two cases we need to test, where the file in question is
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    43
     * orpaned, ie. without a parent ie. not qualified by a parent path
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    44
     * relative nor absolute
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    45
     * case 1: src and dest are the same
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    46
     * case 2: src and dest are different
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    47
     */
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    48
    static void testRepack() throws IOException {
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    49
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    50
        // make a copy of the test specimen to local directory
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    51
        File testFile = new File("src_tools.jar");
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    52
        Utils.copyFile(Utils.locateJar("golden.jar"), testFile);
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    53
        List<String> cmdsList = new ArrayList<>();
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    54
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    55
        // case 1:
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    56
        cmdsList.add(Utils.getPack200Cmd());
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    57
        cmdsList.add("--repack");
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    58
        cmdsList.add(testFile.getName());
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    59
        Utils.runExec(cmdsList);
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    60
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    61
        // case 2:
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    62
        File dstFile = new File("dst_tools.jar");
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    63
        cmdsList.clear();
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    64
        cmdsList.add(Utils.getPack200Cmd());
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    65
        cmdsList.add("--repack");
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    66
        cmdsList.add(dstFile.getName());
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    67
        cmdsList.add(testFile.getName());
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    68
        Utils.runExec(cmdsList);
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    69
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    70
        // tidy up
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    71
        testFile.delete();
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    72
        dstFile.delete();
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    73
    }
9f4bd1ab7873 7184145: (pack200) pack200 --repack throws NullPointerException when JAR file specified without path
ksrini
parents:
diff changeset
    74
}