author | alanb |
Sat, 23 Jun 2018 08:03:52 +0100 | |
changeset 50738 | 6cc2dc161c64 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
1 |
/* |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
4 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
10 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
16 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
20 |
* |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
23 |
* questions. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
24 |
*/ |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
25 |
|
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
26 |
package jdk.internal.module; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
27 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
28 |
import java.lang.module.ModuleDescriptor; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
29 |
import java.lang.module.ModuleFinder; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
30 |
import java.lang.module.ModuleReference; |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
31 |
import java.util.Set; |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
32 |
import java.util.stream.Collectors; |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
33 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
34 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
35 |
* Defines methods to compute the default set of root modules for the unnamed |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
36 |
* module. |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
37 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
38 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
39 |
public final class DefaultRoots { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
40 |
private DefaultRoots() { } |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
41 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
42 |
/** |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
43 |
* Returns the default set of root modules for the unnamed module from the |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
44 |
* modules observable with the intersection of two module finders. |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
45 |
* |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
46 |
* The first module finder should be the module finder that finds modules on |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
47 |
* the upgrade module path or among the system modules. The second module |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
48 |
* finder should be the module finder that finds all modules on the module |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
49 |
* path, or a subset of when using --limit-modules. |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
50 |
*/ |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
51 |
static Set<String> compute(ModuleFinder finder1, ModuleFinder finder2) { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
52 |
return finder1.findAll().stream() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
53 |
.filter(mref -> !ModuleResolution.doNotResolveByDefault(mref)) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
54 |
.map(ModuleReference::descriptor) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
55 |
.filter(descriptor -> finder2.find(descriptor.name()).isPresent() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
56 |
&& exportsAPI(descriptor)) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
57 |
.map(ModuleDescriptor::name) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
58 |
.collect(Collectors.toSet()); |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
59 |
} |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
60 |
|
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
61 |
/** |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
62 |
* Returns the default set of root modules for the unnamed module from the |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
63 |
* modules observable with the given module finder. |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
64 |
* |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
65 |
* This method is used by the jlink system modules plugin. |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
66 |
*/ |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
67 |
public static Set<String> compute(ModuleFinder finder) { |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
68 |
return compute(finder, finder); |
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
69 |
} |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
70 |
|
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
71 |
/** |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
72 |
* Returns true if the given module exports a package to all modules |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
73 |
*/ |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
74 |
private static boolean exportsAPI(ModuleDescriptor descriptor) { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
75 |
return descriptor.exports() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
76 |
.stream() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
77 |
.filter(e -> !e.isQualified()) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
78 |
.findAny() |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
79 |
.isPresent(); |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
47216
diff
changeset
|
80 |
} |
46096
62c77b334012
8185853: Generate readability graph at link time and other startup improvements
alanb
parents:
diff
changeset
|
81 |
} |