Skip to content

Commit 254e1f5

Browse files
authored
Adjust jdk-api-extractor output to be compatible with the public-callers-finder (#135824)
This simplifies finding the transitive public surface of new additions that require entitlement instrumentation. Relates to ES-11757
1 parent 5024169 commit 254e1f5

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

libs/entitlement/tools/common/src/main/java/org/elasticsearch/entitlement/tools/ExternalAccess.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public static EnumSet<ExternalAccess> fromString(String accessAsString) {
5656
if ("PUBLIC".equals(accessAsString)) {
5757
return EnumSet.of(ExternalAccess.PUBLIC_CLASS, ExternalAccess.PUBLIC_METHOD);
5858
}
59+
// used by JDK public API extractor (only), describing protected method access
60+
// in this case public class access can be implied
61+
if ("PROTECTED".equals(accessAsString)) {
62+
return EnumSet.of(ExternalAccess.PUBLIC_CLASS, ExternalAccess.PROTECTED_METHOD);
63+
}
5964
if ("PUBLIC-METHOD".equals(accessAsString)) {
6065
return EnumSet.of(ExternalAccess.PUBLIC_METHOD);
6166
}

libs/entitlement/tools/jdk-api-extractor/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
This tool scans the JDK on which it is running to extract its public accessible API.
22
That is:
3-
- public methods (including constructors) of public, exported classes as well as protected methods of these if not final.
4-
- internal implementations (overwrites) of above.
3+
- public methods (including constructors) of public, exported classes as well as protected methods of non-final classes.
4+
- any overwrites of public methods of public, exported super classes and interfaces.
55

66
The output of this tool is meant to be diffed against the output for another JDK
77
version to identify changes that need to be reviewed for entitlements.
8+
The output is compatible with the `public-callers-finder` tool to calculate the
9+
public transitive surface of new additions. See the example below.
810

911
The following `TAB`-separated columns are written:
1012
1. module name
11-
2. fully qualified class name (ASM style, with `/` separators)
12-
3. method name
13-
4. method descriptor (ASM signature)
14-
5. visibility (`PUBLIC` / `PROTECTED`)
15-
6. `STATIC` modifier or empty
16-
7. `FINAL` modifier or empty
13+
2. unused / empty (for compatibility with `public-callers-finder`)
14+
3. unused / empty (for compatibility with `public-callers-finder`)
15+
4. fully qualified class name (ASM style, with `/` separators)
16+
5. method name
17+
6. method descriptor (ASM signature)
18+
7. visibility (`PUBLIC` / `PROTECTED`)
19+
8. `STATIC` modifier or empty
20+
9. `FINAL` modifier or empty
1721

1822
Usage example:
1923
```bash
2024
./gradlew :libs:entitlement:tools:jdk-api-extractor:run -Druntime.java=24 --args="api-jdk24.tsv"
2125
./gradlew :libs:entitlement:tools:jdk-api-extractor:run -Druntime.java=25 --args="api-jdk25.tsv"
26+
2227
# diff the public apis
2328
diff -u libs/entitlement/tools/jdk-api-extractor/api-jdk24.tsv libs/entitlement/tools/jdk-api-extractor/api-jdk25.tsv > libs/entitlement/tools/jdk-api-extractor/api.diff
29+
2430
# extract additions in the new JDK, these require the most careful review
2531
cat libs/entitlement/tools/jdk-api-extractor/api.diff | grep '^+[^+]' | sed 's/^+//' > api-jdk25-additions.tsv
32+
33+
# review new additions next for critical ones that should require entitlements
34+
# once done, remove all lines that are not considered critical and run the public-callers-finder to report
35+
# the transitive public surface for these additions
36+
./gradlew :libs:entitlement:tools:public-callers-finder:run -Druntime.java=25 --args="api-jdk25-additions.tsv true"
2637
```
2738

2839
### Optional arguments:

libs/entitlement/tools/jdk-api-extractor/src/main/java/org/elasticsearch/entitlement/tools/jdkapi/JdkApiExtractor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ CharSequence toLine(ModuleClass moduleClass) {
188188
return String.join(
189189
SEPARATOR,
190190
moduleClass.module,
191+
"", // compatibility with public-callers-finder
192+
"", // compatibility with public-callers-finder
191193
moduleClass.clazz,
192194
method,
193195
descriptor,

libs/entitlement/tools/public-callers-finder/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
This tool scans the JDK on which it is running. It takes a list of methods (compatible with the output of the `securitymanager-scanner` tool), and looks for the "public surface" of these methods (i.e. any class/method accessible from regular Java code that calls into the original list, directly or transitively).
1+
This tool scans the JDK on which it is running. It takes a list of methods (compatible with the output of the `securitymanager-scanner` and `jdk-api-extractor` tools),
2+
and looks for the "public surface" of these methods (i.e. any class/method accessible from regular Java code that calls into the original list, directly or transitively).
23

34
It acts basically as a recursive "Find Usages" in Intellij, stopping at the first fully accessible point (public method on a public class).
45
The tool scans every method in every class inside the same java module; e.g.
@@ -14,19 +15,18 @@ it treats calls to `super` in `S.m` as regular calls (e.g. `example() -> S.m() -
1415

1516
In order to run the tool, use:
1617
```shell
17-
./gradlew :libs:entitlement:tools:public-callers-finder:run <input-file> [<bubble-up-from-public>]
18+
./gradlew :libs:entitlement:tools:public-callers-finder:run -Druntime.java=25 --args="<input-file> [<bubble-up-from-public>]"
1819
```
1920
Where `input-file` is a CSV file (columns separated by `TAB`) that contains the following columns:
20-
Module name
21-
1. unused
21+
1. Module name
2222
2. unused
2323
3. unused
2424
4. Fully qualified class name (ASM style, with `/` separators)
2525
5. Method name
2626
6. Method descriptor (ASM signature)
2727
7. Visibility (PUBLIC/PUBLIC-METHOD/PRIVATE)
2828

29-
And `bubble-up-from-public` is a boolean (`true|false`) indicating if the code should stop at the first public method (`false`: default, recommended) or continue to find usages recursively even after reaching the "public surface".
29+
And `bubble-up-from-public` is a boolean (`true|false`) indicating if the code should stop at the first public method (`false`: default) or continue to find usages recursively even after reaching the "public surface".
3030

3131
The output of the tool is another CSV file, with one line for each entry-point, columns separated by `TAB`
3232

libs/entitlement/tools/public-callers-finder/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ repositories {
5151
}
5252

5353
dependencies {
54-
compileOnly(project(':libs:core'))
54+
implementation(project(':libs:core'))
5555
implementation 'org.ow2.asm:asm:9.8'
5656
implementation 'org.ow2.asm:asm-util:9.8'
5757
implementation(project(':libs:entitlement:tools:common'))

0 commit comments

Comments
 (0)