langtools/test/tools/javah/6572945/T6572945.java
author jjg
Mon, 04 Apr 2016 12:34:42 -0700
changeset 36991 7f814aac1f80
parent 30730 d3ce7619db2c
permissions -rw-r--r--
8153416: unexport javah from jdk.compiler module Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     1
/*
36991
7f814aac1f80 8153416: unexport javah from jdk.compiler module
jjg
parents: 30730
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     4
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     8
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    13
 * accompanied this code).
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    14
 *
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    21
 * questions.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    22
 */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    23
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    24
/*
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    25
 * @test
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    26
 * @bug 6572945
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    27
 * @summary rewrite javah as an annotation processor, instead of as a doclet
36991
7f814aac1f80 8153416: unexport javah from jdk.compiler module
jjg
parents: 30730
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javah
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    29
 * @build TestClass1 TestClass2 TestClass3
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    30
 * @run main T6572945
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    31
 */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    32
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    33
import java.io.*;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    34
import java.util.*;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    35
import com.sun.tools.javah.Main;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    36
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    37
public class T6572945
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    38
{
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    39
    static File testSrc = new File(System.getProperty("test.src", "."));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    40
    static File testClasses = new File(System.getProperty("test.classes", "."));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    41
    static boolean isWindows = System.getProperty("os.name").startsWith("Windows");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    42
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    43
    public static void main(String... args)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    44
        throws IOException, InterruptedException
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    45
    {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    46
        boolean ok = new T6572945().run(args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    47
        if (!ok)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    48
            throw new Error("Test Failed");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    49
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    50
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    51
    public boolean run(String[] args)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    52
        throws IOException, InterruptedException
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    53
    {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    54
        if (args.length == 1)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    55
            jdk = new File(args[0]);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    56
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    57
        test("-o", "jni.file.1",  "-jni", "TestClass1");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    58
        test("-o", "jni.file.2",  "-jni", "TestClass1", "TestClass2");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    59
        test("-d", "jni.dir.1",   "-jni", "TestClass1", "TestClass2");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    60
        test("-o", "jni.file.3",  "-jni", "TestClass3");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    61
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    62
        // The following tests are disabled because llni support has been
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    63
        // discontinued, and because bugs in old javah means that character
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    64
        // for character testing against output from old javah does not work.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    65
        // In fact, the LLNI impl in new javah is actually better than the
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    66
        // impl in old javah because of a couple of significant bug fixes.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    67
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    68
//        test("-o", "llni.file.1", "-llni", "TestClass1");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    69
//        test("-o", "llni.file.2", "-llni", "TestClass1", "TestClass2");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    70
//        test("-d", "llni.dir.1",  "-llni", "TestClass1", "TestClass2");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    71
//        test("-o", "llni.file.3", "-llni", "TestClass3");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    72
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    73
        return (errors == 0);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    74
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    75
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    76
    void test(String... args)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    77
        throws IOException, InterruptedException
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    78
    {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    79
        String[] cp_args = new String[args.length + 2];
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    80
        cp_args[0] = "-classpath";
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    81
        cp_args[1] = testClasses.getPath();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    82
        System.arraycopy(args, 0, cp_args, 2, args.length);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    83
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    84
        if (jdk != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    85
            init(cp_args);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    86
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    87
        File out = null;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    88
        for (int i = 0; i < args.length; i++) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    89
            if (args[i].equals("-o")) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    90
                out = new File(args[++i]);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    91
                break;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    92
            } else if (args[i].equals("-d")) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    93
                out = new File(args[++i]);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    94
                out.mkdirs();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    95
                break;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    96
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    97
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    98
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
    99
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   100
            System.out.println("test: " + Arrays.asList(cp_args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   101
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   102
//            // Uncomment and use the following lines to execute javah via the
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   103
//            // command line -- for example, to run old javah and set up the golden files
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   104
//            List<String> cmd = new ArrayList<String>();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   105
//            File javaHome = new File(System.getProperty("java.home"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   106
//            if (javaHome.getName().equals("jre"))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   107
//                javaHome = javaHome.getParentFile();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   108
//            File javah = new File(new File(javaHome, "bin"), "javah");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   109
//            cmd.add(javah.getPath());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   110
//            cmd.addAll(Arrays.asList(cp_args));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   111
//            ProcessBuilder pb = new ProcessBuilder(cmd);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   112
//            pb.redirectErrorStream(true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   113
//            pb.start();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   114
//            Process p = pb.start();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   115
//            String line;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   116
//            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   117
//            while ((line = in.readLine()) != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   118
//                System.err.println(line);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   119
//            in.close();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   120
//            int rc = p.waitFor();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   121
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   122
            // Use new javah
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   123
            PrintWriter err = new PrintWriter(System.err, true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   124
            int rc = Main.run(cp_args, err);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   125
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   126
            if (rc != 0) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   127
                error("javah failed: rc=" + rc);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   128
                return;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   129
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   130
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   131
            // The golden files use the LL suffix for long constants, which
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   132
            // is used on Linux and Solaris.   On Windows, the suffix is i64,
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   133
            // so compare will update the golden files on the fly before the
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   134
            // final comparison.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   135
            compare(new File(new File(testSrc, "gold"), out.getName()), out);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   136
        } catch (Throwable t) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   137
            t.printStackTrace();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   138
            error("javah threw exception");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   139
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   140
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   141
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   142
    void init(String[] args) throws IOException, InterruptedException {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   143
        String[] cmdArgs = new String[args.length + 1];
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   144
        cmdArgs[0] = new File(new File(jdk, "bin"), "javah").getPath();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   145
        System.arraycopy(args, 0, cmdArgs, 1, args.length);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   146
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   147
        System.out.println("init: " + Arrays.asList(cmdArgs));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   148
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   149
        ProcessBuilder pb = new ProcessBuilder(cmdArgs);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   150
        pb.directory(new File(testSrc, "gold"));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   151
        pb.redirectErrorStream(true);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   152
        Process p = pb.start();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   153
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   154
        String line;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   155
        while ((line = in.readLine()) != null)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   156
            System.out.println("javah: " + line);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   157
        int rc = p.waitFor();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   158
        if (rc != 0)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   159
            error("javah: exit code " + rc);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   160
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   161
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   162
    /** Compare two directories.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   163
     *  @param f1 The golden directory
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   164
     *  @param f2 The directory to be compared
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   165
     */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   166
    void compare(File f1, File f2) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   167
        compare(f1, f2, null);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   168
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   169
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   170
    /** Compare two files or directories
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   171
     *  @param f1 The golden directory
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   172
     *  @param f2 The directory to be compared
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   173
     *  @param p An optional path identifying a file within the two directories
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   174
     */
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   175
    void compare(File f1, File f2, String p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   176
        File f1p = (p == null ? f1 : new File(f1, p));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   177
        File f2p = (p == null ? f2 : new File(f2, p));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   178
        System.out.println("compare " + f1p + " " + f2p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   179
        if (f1p.isDirectory() && f2p.isDirectory()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   180
            Set<String> children = new HashSet<String>();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   181
            children.addAll(Arrays.asList(f1p.list()));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   182
            children.addAll(Arrays.asList(f2p.list()));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   183
            for (String c: children) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   184
                compare(f1, f2, new File(p, c).getPath()); // null-safe for p
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   185
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   186
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   187
        else if (f1p.isFile() && f2p.isFile()) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   188
            String s1 = read(f1p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   189
            if (isWindows) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   190
                // f1/s1 is the golden file
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   191
                // on Windows, long constants use the i64 suffix, not LL
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   192
                s1 = s1.replaceAll("( [0-9]+)LL\n", "$1i64\n");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   193
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   194
            String s2 = read(f2p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   195
            if (!s1.equals(s2)) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   196
                System.out.println("File: " + f1p + "\n" + s1);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   197
                System.out.println("File: " + f2p + "\n" + s2);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   198
                error("Files differ: " + f1p + " " + f2p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   199
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   200
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   201
        else if (f1p.exists() && !f2p.exists())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   202
            error("Only in " + f1 + ": " + p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   203
        else if (f2p.exists() && !f1p.exists())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   204
            error("Only in " + f2 + ": " + p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   205
        else
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   206
            error("Files differ: " + f1p + " " + f2p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   207
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   208
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   209
    private String read(File f) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   210
        try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   211
            BufferedReader in = new BufferedReader(new FileReader(f));
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   212
            try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   213
                StringBuilder sb = new StringBuilder((int) f.length());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   214
                String line;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   215
                while ((line = in.readLine()) != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   216
                    sb.append(line);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   217
                    sb.append("\n");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   218
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   219
                return sb.toString();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   220
            } finally {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   221
                try {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   222
                    in.close();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   223
                } catch (IOException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   224
                }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   225
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   226
        } catch (IOException e) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   227
            error("error reading " + f + ": " + e);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   228
            return "";
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   229
        }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   230
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   231
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   232
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   233
    private void error(String msg) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   234
        System.out.println(msg);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   235
        errors++;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   236
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   237
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   238
    private int errors;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   239
    private File jdk;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents:
diff changeset
   240
}