test/langtools/tools/javac/T6942649.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 36526 langtools/test/tools/javac/T6942649.java@3b41f1c69604
child 55420 bc5a0508253c
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     4
 *
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     8
 *
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    13
 * accompanied this code).
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    14
 *
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    21
 * questions.
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    22
 */
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    23
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    24
/*
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    25
 * @test
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    26
 * @bug 6942649
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    27
 * @summary add hidden option to identify location and version of javac classes
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
    28
 * @modules jdk.compiler
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    29
 */
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    30
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    31
import java.io.*;
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    32
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    33
public class T6942649 {
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    34
    public static void main(String... args) throws Exception {
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    35
        new T6942649().run();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    36
    }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    37
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    38
    void run() throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    39
        test("-XDshowClass", "com.sun.tools.javac.Main", false);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    40
        test("-XDshowClass=com.sun.tools.javac.util.Log", "com.sun.tools.javac.util.Log", false);
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    41
    }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    42
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    43
    void test(String opt, String clazz, boolean checkLocation) throws Exception {
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    44
        System.err.println("test " + opt);
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    45
        StringWriter sw = new StringWriter();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    46
        PrintWriter pw = new PrintWriter(sw);
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    47
        int rc = com.sun.tools.javac.Main.compile(new String[] { opt }, pw);
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    48
        pw.close();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    49
        String out = sw.toString();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    50
        System.err.println("javac rc=" + rc + "\n" + out);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    51
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    52
        if (!out.contains(clazz))
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    53
            throw new Exception("class name not found in output");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    54
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    55
        // (JDK 9) We can no longer guarantee to be able to show a URL for the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    56
        // location of the class, especially when the class is in the system image
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    57
        if (checkLocation) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    58
            int lastDot = clazz.lastIndexOf(".");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    59
            if (!out.contains(clazz.substring(lastDot + 1) + ".class"))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    60
                throw new Exception("location of class not found in output");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    61
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    62
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    63
        if (!out.contains("MD5 checksum: "))
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    64
            throw new Exception("checksum not found in output");
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    65
    }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents:
diff changeset
    66
}