make/langtools/src/classes/build/tools/symbolgenerator/TransitiveDependencies.java
author ihse
Mon, 03 Dec 2018 18:33:11 +0100
branchihse-manpages-branch
changeset 57051 d8697832a650
parent 50027 69aadf0c1e69
permissions -rw-r--r--
Add html filter script from Jon.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     1
/*
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     4
 *
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    10
 *
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    16
 *
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    20
 *
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    23
 * questions.
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    24
 */
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    25
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    26
package build.tools.symbolgenerator;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    27
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    28
import java.io.IOException;
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    29
import java.io.PrintWriter;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    30
import java.io.Writer;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    31
import java.nio.charset.Charset;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    32
import java.nio.file.Files;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    33
import java.nio.file.Path;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    34
import java.nio.file.Paths;
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    35
import java.util.ArrayDeque;
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    36
import java.util.Arrays;
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    37
import java.util.Deque;
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    38
import java.util.HashSet;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    39
import java.util.LinkedList;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    40
import java.util.List;
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    41
import java.util.Locale;
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    42
import java.util.Set;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    43
import java.util.stream.Collectors;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    44
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    45
import javax.lang.model.element.ModuleElement.RequiresDirective;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    46
import javax.lang.model.util.Elements;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    47
import javax.tools.JavaCompiler;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    48
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    49
import com.sun.tools.javac.api.JavacTaskImpl;
47364
6b3389375f31 8189094: Change required boot jdk to JDK 9
erikj
parents: 47275
diff changeset
    50
import com.sun.tools.javac.api.JavacTool;
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    51
import com.sun.tools.javac.code.Source;
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    52
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    53
import com.sun.tools.javac.jvm.Target;
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    54
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    55
/**
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    56
 * Write reflexive transitive closure of the given modules along their requires transitive edges into
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    57
 * file <version>/system-modules in the specified directory.
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    58
 */
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    59
public class TransitiveDependencies {
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    60
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    61
    private static void help() {
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    62
        System.err.println("java TransitiveDependencies <target-directory> <module-source-path> <root-modules>");
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    63
    }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    64
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    65
    public static void main(String... args) throws IOException {
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    66
        if (args.length < 2) {
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    67
            help();
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    68
            return ;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    69
        }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    70
47364
6b3389375f31 8189094: Change required boot jdk to JDK 9
erikj
parents: 47275
diff changeset
    71
        JavaCompiler compiler = JavacTool.create();
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    72
        List<String> options = List.of("-source", Source.DEFAULT.name,
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    73
                                       "-target", Target.DEFAULT.name,
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    74
                                       "-proc:only",
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    75
                                       "--system", "none",
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    76
                                       "--module-source-path", args[1],
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    77
                                       "--add-modules", Arrays.stream(args)
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    78
                                                              .skip(2)
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    79
                                                              .collect(Collectors.joining(",")));
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    80
        List<String> jlObjectList = List.of("java.lang.Object");
45910
c7092e4591b2 8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents: 45156
diff changeset
    81
        JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, options, jlObjectList, null);
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    82
        task.enter();
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    83
        Elements elements = task.getElements();
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    84
        Deque<String> todo = new ArrayDeque<>();
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    85
        Arrays.stream(args).skip(2).forEach(todo::add);
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    86
        Set<String> allModules = new HashSet<>();
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    87
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    88
        while (!todo.isEmpty()) {
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
    89
            String current = todo.removeFirst();
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    90
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    91
            if (!allModules.add(current))
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    92
                continue;
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    93
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    94
            ModuleSymbol mod = (ModuleSymbol) elements.getModuleElement(current);
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    95
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    96
            if (mod == null) {
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    97
                throw new IllegalStateException("Missing: " + current);
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    98
            }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
    99
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   100
             //use the internal structure to avoid unnecesarily completing the symbol using the UsesProvidesVisitor:
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   101
            for (RequiresDirective rd : mod.requires) {
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   102
                if (rd.isTransitive()) {
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   103
                    todo.offerLast(rd.getDependency().getQualifiedName().toString());
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   104
                }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   105
            }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   106
        }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   107
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   108
        allModules.add("java.base");
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   109
        allModules.add("jdk.unsupported");
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   110
50027
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   111
        String version =
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   112
                Integer.toString(Integer.parseInt(Source.DEFAULT.name), Character.MAX_RADIX);
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   113
        version = version.toUpperCase(Locale.ROOT);
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   114
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   115
        Path targetFile = Paths.get(args[0]).resolve(version).resolve("system-modules");
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   116
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   117
        Files.createDirectories(targetFile.getParent());
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   118
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   119
        try (Writer w = Files.newBufferedWriter(targetFile);
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   120
             PrintWriter out = new PrintWriter(w)) {
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   121
            allModules.stream()
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   122
                      .sorted()
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   123
                      .forEach(out::println);
69aadf0c1e69 8202387: javac --release 11 not supported
jlahoda
parents: 47364
diff changeset
   124
        }
45156
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   125
    }
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   126
001f73134346 8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
diff changeset
   127
}