langtools/test/tools/javah/T6994608.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 7078 17f1f2bdcb46
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7078
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     1
/*
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     4
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     8
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    13
 * accompanied this code).
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    14
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    18
 *
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    21
 * questions.
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    22
 */
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    23
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    24
/*
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    25
 * @test
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    26
 * @bug 6994608
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    27
 * @summary javah no longer accepts parameter files as input
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    28
 */
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    29
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    30
import java.io.*;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    31
import java.util.*;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    32
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    33
public class T6994608 {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    34
    public static void main(String... args) throws Exception {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    35
        new T6994608().run();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    36
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    37
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    38
    void run() throws Exception {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    39
        Locale prev = Locale.getDefault();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    40
        Locale.setDefault(Locale.ENGLISH);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    41
        try {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    42
            File f = writeFile(new File("classList"), "java.lang.Object");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    43
            test(Arrays.asList("@" + f.getPath()), 0, null);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    44
            test(Arrays.asList("@badfile"), 1, "Can't find file badfile");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    45
            if (errors > 0)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    46
                throw new Exception(errors + " errors occurred");
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    47
        } finally {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    48
            Locale.setDefault(prev);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    49
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    50
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    51
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    52
    void test(List<String> args, int expectRC, String expectOut) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    53
        System.err.println("Test: " + args
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    54
                + " rc:" + expectRC
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    55
                + ((expectOut != null) ? " out:" + expectOut : ""));
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    56
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    57
        StringWriter sw = new StringWriter();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    58
        PrintWriter pw = new PrintWriter(sw);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    59
        int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    60
        pw.close();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    61
        String out = sw.toString();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    62
        if (!out.isEmpty())
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    63
            System.err.println(out);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    64
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    65
        if (rc != expectRC)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    66
            error("Unexpected exit code: " + rc + "; expected: " + expectRC);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    67
        if (expectOut != null && !out.contains(expectOut))
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    68
            error("Expected string not found: " + expectOut);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    69
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    70
        System.err.println();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    71
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    72
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    73
    File writeFile(File f, String s) throws IOException {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    74
        if (f.getParentFile() != null)
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    75
            f.getParentFile().mkdirs();
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    76
        try (FileWriter out = new FileWriter(f)) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    77
            out.write(s);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    78
        }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    79
        return f;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    80
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    81
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    82
    void error(String msg) {
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    83
        System.err.println(msg);
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    84
        errors++;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    85
    }
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    86
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    87
    int errors;
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    88
}
17f1f2bdcb46 6994608: javah no longer accepts parameter files as input
jjg
parents:
diff changeset
    89