langtools/make/src/classes/build/tools/symbolgenerator/Probe.java
author stefank
Tue, 05 Apr 2016 10:41:52 +0200
changeset 37255 100d4a515df0
parent 31506 4e07f827a794
permissions -rw-r--r--
8152711: Create a non-template Log wrapper class Reviewed-by: kbarrett, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     1
/*
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     4
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    10
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    16
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    20
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    23
 * questions.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    24
 */
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    25
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    26
package build.tools.symbolgenerator;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    27
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    28
import java.io.BufferedInputStream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    29
import java.io.ByteArrayOutputStream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    30
import java.io.File;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    31
import java.io.FileOutputStream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    32
import java.io.IOException;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    33
import java.io.InputStream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    34
import java.io.OutputStream;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    35
import java.nio.charset.Charset;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    36
import java.util.EnumSet;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    37
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    38
import javax.tools.JavaCompiler;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    39
import javax.tools.JavaFileObject;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    40
import javax.tools.JavaFileObject.Kind;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    41
import javax.tools.StandardJavaFileManager;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    42
import javax.tools.StandardLocation;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    43
import javax.tools.ToolProvider;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    44
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    45
/**A tool to dump the content of the default javac's bootclasspath. This tool should not use any
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    46
 * features not available on the oldest supported target JDK, which is currently JDK 6.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    47
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    48
 * For more information on use of this site, please see CreateSymbols.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    49
 */
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    50
public class Probe {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    51
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    52
    public static void main(String... args) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    53
        if (args.length != 1) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    54
            System.err.println("Not enough arguments.");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    55
            System.err.println("Usage:");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    56
            System.err.println("    java " + Probe.class.getName() + " <output-file>");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    57
            return ;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    58
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    59
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    60
        File outFile = new File(args[0]);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    61
        Charset cs = Charset.forName("UTF-8");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    62
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    63
        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    64
        OutputStream out = new FileOutputStream(outFile);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    65
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    66
        try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    67
            Iterable<JavaFileObject> bcpFiles =
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    68
                    fm.list(StandardLocation.PLATFORM_CLASS_PATH, "", EnumSet.of(Kind.CLASS), true);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    69
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    70
            for (JavaFileObject jfo : bcpFiles) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    71
                InputStream in = new BufferedInputStream(jfo.openInputStream());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    72
                try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    73
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    74
                    StringBuilder textual = new StringBuilder();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    75
                    int read;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    76
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    77
                    while ((read = in.read()) != (-1)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    78
                        baos.write(read);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    79
                        textual.append(String.format("%02x", read));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    80
                    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    81
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    82
                    textual.append("\n");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    83
                    out.write(textual.toString().getBytes(cs));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    84
                } finally {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    85
                    in.close();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    86
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    87
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    88
        } finally {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    89
            out.close();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    90
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    91
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    92
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    93
}