make/langtools/src/classes/build/tools/symbolgenerator/ProbeModular.java
author ihse
Mon, 03 Dec 2018 18:33:11 +0100
branchihse-manpages-branch
changeset 57051 d8697832a650
parent 47703 dbfac941197a
permissions -rw-r--r--
Add html filter script from Jon.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47703
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     1
/*
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     4
 *
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    10
 *
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    16
 *
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    20
 *
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    23
 * questions.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    24
 */
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    25
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    26
package build.tools.symbolgenerator;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    27
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    28
import com.sun.source.util.JavacTask;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    29
import com.sun.tools.javac.api.JavacTool;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    30
import com.sun.tools.javac.util.Context;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    31
import java.io.BufferedInputStream;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    32
import java.io.ByteArrayOutputStream;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    33
import java.io.File;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    34
import java.io.FileOutputStream;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    35
import java.io.IOException;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    36
import java.io.InputStream;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    37
import java.io.OutputStream;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    38
import java.nio.charset.Charset;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    39
import java.util.Arrays;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    40
import java.util.EnumSet;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    41
import java.util.List;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    42
import java.util.Set;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    43
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    44
import javax.tools.JavaFileManager;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    45
import javax.tools.JavaFileManager.Location;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    46
import javax.tools.JavaFileObject;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    47
import javax.tools.JavaFileObject.Kind;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    48
import javax.tools.StandardLocation;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    49
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    50
/**A tool to dump the content of the default javac's bootclasspath. This tool should not use any
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    51
 * features not available on the oldest supported target JDK, or not available in the boot JDK.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    52
 *
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    53
 * For more information on use of this site, please see CreateSymbols.
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    54
 */
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    55
public class ProbeModular {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    56
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    57
    public static void main(String... args) throws IOException {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    58
        if (args.length != 1) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    59
            System.err.println("Not enough arguments.");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    60
            System.err.println("Usage:");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    61
            System.err.println("    java " +
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    62
                               ProbeModular.class.getName() +
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    63
                               " <output-file>");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    64
            return ;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    65
        }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    66
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    67
        File outFile = new File(args[0]);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    68
        Charset cs = Charset.forName("UTF-8");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    69
        JavacTool tool = JavacTool.create();
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    70
        Context ctx = new Context();
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    71
        String version = System.getProperty("java.specification.version");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    72
        JavacTask task = tool.getTask(null, null, null,
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    73
                                      Arrays.asList("--release", version),
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    74
                                      null, null, ctx);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    75
        task.getElements().getTypeElement("java.lang.Object");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    76
        JavaFileManager fm = ctx.get(JavaFileManager.class);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    77
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    78
        try (OutputStream out = new FileOutputStream(outFile)) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    79
            for (Location modLoc : LOCATIONS) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    80
                for (Set<JavaFileManager.Location> module :
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    81
                        fm.listLocationsForModules(modLoc)) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    82
                    for (JavaFileManager.Location loc : module) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    83
                        Iterable<JavaFileObject> files =
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    84
                                fm.list(loc,
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    85
                                        "",
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    86
                                        EnumSet.of(Kind.CLASS),
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    87
                                        true);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    88
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    89
                        for (JavaFileObject jfo : files) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    90
                            try (InputStream is = jfo.openInputStream();
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    91
                                 InputStream in =
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    92
                                         new BufferedInputStream(is)) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    93
                                ByteArrayOutputStream baos =
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    94
                                        new ByteArrayOutputStream();
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    95
                                StringBuilder textual = new StringBuilder();
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    96
                                int read;
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    97
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    98
                                while ((read = in.read()) != (-1)) {
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
    99
                                    baos.write(read);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   100
                                    String hex = String.format("%02x", read);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   101
                                    textual.append(hex);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   102
                                }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   103
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   104
                                textual.append("\n");
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   105
                                out.write(textual.toString().getBytes(cs));
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   106
                            }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   107
                        }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   108
                    }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   109
                }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   110
            }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   111
        }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   112
    }
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   113
    //where:
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   114
        private static final List<StandardLocation> LOCATIONS =
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   115
                Arrays.asList(StandardLocation.SYSTEM_MODULES,
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   116
                              StandardLocation.UPGRADE_MODULE_PATH);
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   117
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents:
diff changeset
   118
}