Skip to content

Commit 1dbbcb5

Browse files
7903876: Improve the man page, with (more) examples
Reviewed-by: iris
1 parent 3495601 commit 1dbbcb5

File tree

3 files changed

+196
-39
lines changed

3 files changed

+196
-39
lines changed

src/share/classes/jdk/codetools/apidiff/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private Result run(List<String> args, Log log) {
176176
}
177177

178178
// TODO: when APIDiff moves to JDK 21, thia can trivially become SequencedSet,
179-
// which would be useful in varoius places, such as PageReporter.getResultGlyph
179+
// which would be useful in various places, such as PageReporter.getResultGlyph
180180
Set<API> apis = options.allAPIOptions.values().stream()
181181
.map(a -> API.of(a, s, ak, log, verboseOptions))
182182
.collect(Collectors.toCollection(LinkedHashSet::new));

src/share/classes/jdk/codetools/apidiff/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static class APIOptions {
9797
public String source;
9898

9999
/**
100-
* Whether or not {@code --enable-preview} has been specified.
100+
* Whether {@code --enable-preview} has been specified.
101101
*/
102102
public boolean enablePreview;
103103

src/share/doc/apidiff.md

Lines changed: 194 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,49 @@ an HTML report. The comparison includes:
5353

5454
## Options
5555

56-
`apidiff` provides different groups of options, to specify
57-
the [APIs](#the-apis) and
58-
the [elements in those APIs](#the-elements-to-be-compared) to be compared,
59-
[output options](#output-options) for the report to be generated, and
60-
[other options](#other-options).
56+
`apidiff` provides different groups of options, to specify:
57+
58+
* the [APIs](#the-apis) to be compared,
59+
* the [elements](#the-elements-to-be-compared) (declarations) in those APIs to be compared,
60+
* the [output options](#output-options) for the report to be generated, and
61+
* [other options](#other-options).
62+
63+
All options have a long form, beginning with `--`. Some options may have
64+
a single-letter form, beginning with just `-`. For those options that take
65+
an argument, the value may be separated from the option name by either white
66+
space or '='. In general, as is common with most JDK tools, if an option
67+
is repeated, the rule is "last one wins". This rule is modified for
68+
the options that specify the APIs to be compared, such that "last one wins"
69+
only applies within the group of API-specific options used to define each API.
70+
71+
To see detailed information about how the options are processed,
72+
use [`--verbose options`](#option-verbose).
6173

6274
### The APIs
6375

6476
To specify each of the APIs to be compared, use the `--api` _name_ option
65-
followed by a series of options that apply to that API. Most of the options are the
66-
same as the corresponding _javac_ option; see the _javac_ documentation for more details
67-
about those options.
77+
followed by a series of _API-specific options_ that apply to that API.
78+
79+
The API-specific options must at least include options to find the source
80+
or class files for the declarations to be compared. The options should
81+
also define the location of the generated documentation if that is to be
82+
included in the comparison. (When comparing the API documentation, it is
83+
not enough to just specify the location of that documentation.)
84+
85+
Note that the API-specific options for each API are separate and distinct
86+
from the API-specific options for any other API.
6887

6988
<a id="option-api">`--api` _name_</a>
7089
: Specifies a name for the API and sets the [current API](#the-current-api) for
7190
use by the API-specific options that immediately follow this option.
72-
The option, and the API-specific options that follow, should be provided for each API
73-
to be compared.
91+
The name will appear in the generated reports when identifying any differences.
92+
If the generated report will be publicly shared, it is recommended that
93+
the name should be reasonably meaningful to any readers.
94+
A longer, more descriptive label may also be given with the `--label` option.
95+
96+
The option, and the API-specific options that follow, should be provided for
97+
each API to be compared.
98+
7499
The order in which the `--api` options first appear on the command line determines
75100
the order in which any differences are reported. It is recommended to specify the
76101
options in chronological order, from the oldest version of the API to the most recent
@@ -81,20 +106,48 @@ about those options.
81106
If given, it should be the top-level directory of the documentation generated by
82107
the `javadoc` command for the API.
83108

84-
<a id="option-class-path">`--class-path` *path*, `-classpath` *path*, or `-cp` *path*</a>
85-
: Specifies where to find files for the class path for the [current API](#the-current-api).
86-
87-
<a id="option-enable-preview">`--enable-preview`</a>
88-
: Enables preview language features for the [current API](#the-current-api).
89-
90109
<a id="option-jdk-build">`--jdk-build` *directory*</a>
91110
: Specifies a directory containing a JDK build from which to infer values for
92-
various options. For example, *repository*`/build/`*configuration-name*
111+
various options. The builds can either be for default-named configurations in
112+
separate repositories or work areas, or for differently named configurations in
113+
the same repository. (To create different configurations within the same JDK
114+
repository, use the `--with-conf-name` option when running `sh ./configure`
115+
to create the configuration.)
116+
117+
It is a matter of personal preference whether to use separate repositories
118+
or separate configurations within a single repository for the instances
119+
of the API to be compared.
120+
121+
* Using separate repositories uses more disk space, but makes it more
122+
convenient to not have to specify the desired configuration every time
123+
you run `make`.
124+
* Using separate configurations in a single repository uses less disk space,
125+
but means that you will have to indicate which configuration to use
126+
every time you run `make`.
127+
128+
When using this option, it should not be necessary to give any additional
129+
`javac`-like options, like `--module-path` or `--release`.
130+
131+
For example,
132+
133+
* `--jdk-build` *repository*`/build/`*configuration-name*
134+
* `--jdk-build /Users/Duke/jdk-dev/build/macosx-aarch64`
135+
* `--jdk-build /Users/Duke/jdk-dev/build/macosx-aarch64-server-release`
136+
* `--jdk-build $HOME/OpenJDK/build/linux-x86_64-server-fastdebug`
93137

94138
<a id="option-label">`--label` *text*</a>
95139
: Specifies a short plain-text label for the API, to be included in the generated
96140
reports. For example, the full version string for the instance of the API being compared.
97141

142+
The following API options are similar to the corresponding `javac` option;
143+
see the `javac` documentation for more details about the arguments for those options.
144+
145+
<a id="option-class-path">`--class-path` *path*, `-classpath` *path*, or `-cp` *path*</a>
146+
: Specifies where to find files for the class path for the [current API](#the-current-api).
147+
148+
<a id="option-enable-preview">`--enable-preview`</a>
149+
: Enables preview language features for the [current API](#the-current-api).
150+
98151
<a id="option-module-path">`--module-path`</a> *path* or `-p` *path*</a>
99152
: Specifies where to find application modules for the [current API](#the-current-api).
100153

@@ -129,6 +182,13 @@ pairwise, with each of the older instances being compared against the newest ins
129182

130183
### The Elements to be Compared
131184

185+
The following options are used to specify the elements (declarations) to be compared
186+
within the [APIs](#the-apis), specified by the various `--api` options and associated
187+
API-specific options.
188+
189+
These options apply equally to all the APIs to be compared: there is no need
190+
to repeat these options for each API to be compared.
191+
132192
<a id="option-access">`--access` `public|protected|package|private`</a>
133193
: Specifies the access of the declarations to be compared. The default is `protected`.
134194

@@ -142,19 +202,20 @@ pairwise, with each of the older instances being compared against the newest ins
142202
methods and fields.
143203

144204
<a id="option-exclude">`--exclude` *pattern*</a>
145-
: Specifies the patterns for modules or packages to be excluded from the
146-
comparison.
205+
: Specifies the [patterns](#patterns) for modules or packages to be excluded
206+
from the comparison. The default is that none of the elements specified with
207+
`--include` options are excluded.
147208

148209
<a id="option-include">`--include` *pattern*</a>
149-
: Specifies the patterns for modules or packages to be included from the
150-
comparison.
210+
: Specifies the [patterns](#patterns) for modules or packages to be included
211+
in the comparison. There must be at least one `--include` option.
151212

152213
<a id="option-compare-api-descriptions">`--compare-api-descriptions` *boolean*</a>
153-
: Specifies that the API descriptions (as generated by javadoc) should be compared
214+
: Specifies that the API descriptions (as generated by `javadoc`) should be compared
154215
for each element being compared.
155-
The option defaults to `true` if documentation comments are not to be compared
156-
and if an API directory is given for each instance of the API to be
157-
compared. (See `--compare-doc-comments`).
216+
The option defaults to `true` if an API directory is given for each instance
217+
of the API to be compared and if documentation comments are not to be compared.
218+
(See `--compare-doc-comments`).
158219
When the option is enabled, either explicitly or by default,
159220
the API directory must be specified for each instance of the API
160221
to be compared, and set to the location of the files generated by `javadoc`
@@ -163,7 +224,7 @@ pairwise, with each of the older instances being compared against the newest ins
163224
option, or indirectly, with the `--jdk-build` and `--jdk-docs` options.
164225

165226
<a id="option-compare-api-descriptions-as-text">`--compare-api-descriptions-as-text` *boolean*</a>
166-
: Specifies that the HTML for the API descriptions (as generated by javadoc)
227+
: Specifies that the HTML for the API descriptions (as generated by `javadoc`)
167228
should be compared as plain text for each element being compared. If the argument is `true`,
168229
this option also implies `--compare-api-descriptions true`.
169230

@@ -178,6 +239,10 @@ pairwise, with each of the older instances being compared against the newest ins
178239
<a id="option-jdk-docs">`--jdk-docs` *name*</a>
179240
: In conjunction with the `--jdk-build` option, specifies the name of the
180241
documentation bundle to use when more than one is available.
242+
It need not be specified if all the APIs specified by `--jdk-build`
243+
have exactly one directory matching the name `images/*docs*`:
244+
this is typically the case when building the OpenJDK `docs` or `docs-jdk`
245+
targets.
181246
For example, `docs`, `javase-docs`, `reference-docs`.
182247

183248
### Output Options
@@ -232,13 +297,22 @@ pairwise, with each of the older instances being compared against the newest ins
232297

233298
<a id="option-verbose">`--verbose` _flag_[`,`_flag_]*</a>
234299
: Specifies the kinds of verbose output. _flag_ may be one of
235-
`all`, `none`, or one of the following, optionally preceded by `-`:
300+
`all`, `none`, or one of the following, optionally preceded by `-` to negate the flag:
236301
`module`, `package`, `type`, `time`, `options`.
237302

303+
| Flag | Description |
304+
|:----------|:---------------------------------------------------------------------------|
305+
| `module` | Report on the modules being compared |
306+
| `package` | Report on the modules and packages being compared |
307+
| `type` | Report on the modules, packages, and classes and interfaces being compared |
308+
| `time` | Report the time taken to perform the comparison and generate the reports |
309+
| `options` | Report how the command-line options are processed |
310+
238311
<a id="option-at">`@`*filename*</a>
239312
: Reads options from a file. To shorten or simplify the `apidiff` command, you can specify
240313
one or more files that contain arguments for the `apidiff` command. This lets you create
241-
`apidiff` commands of any length on any operating system.
314+
`apidiff` commands of any length on any operating system. The syntax for the contents
315+
of the file is similar to that for other JDK commands, like `javac` and `javadoc`.
242316

243317
## Exit Status
244318

@@ -256,7 +330,7 @@ The `--help` and `--version` options exit with a status of 0.
256330
## The Current API
257331

258332
The current API is the API specified by the most recent `--api` option on the command line,
259-
and is the API for which any API-specific options will apply.
333+
and is the API for which any subsequent API-specific options will apply.
260334

261335
The "current API" is cancelled when any option is given that is not specific to
262336
any one API. Additional options for an API can be given by repeating the `--api`
@@ -299,6 +373,16 @@ module part.
299373
in the unnamed module, and so either all patterns must include a module part,
300374
or none must.
301375

376+
For example,
377+
378+
* `java.base/java.nio.**` matches all types in the `java.nio` packages
379+
and corresponding subpackages, in the `java.base` module
380+
* `java.compiler/**` matches all packages and types in the `java.compiler`
381+
module
382+
383+
Depending on how you invoke `apidiff`, you may need to quote the pattern
384+
to prevent the `*` characters being interpreted by a command shell.
385+
302386
## Notes
303387

304388
A "notes" file is used to specify links to be injected into the generated report
@@ -395,11 +479,15 @@ as generated by the standard JDK makefiles.
395479

396480
In conjunction with this option, use the `jdk-docs` option to specify the name
397481
of the docs bundle to be compared, when there is more than one. Note this option
398-
applies to all instances to be compared, and is not specific to the
399-
[current API](#the-current-api). Use the `--compare-doc-comments` and
400-
`--compare-api-descriptions` as needed to indicate the comparisons to be included
401-
in the report. If neither are specified, `--compare-api-descriptions` is
402-
the default.
482+
applies to all instances to be compared, and need only be given once;
483+
it is not specific to the [current API](#the-current-api).
484+
Use the `--compare-doc-comments` and `--compare-api-descriptions` as needed
485+
to indicate the comparisons to be included in the report.
486+
If neither are specified, `--compare-api-descriptions` is the default.
487+
488+
While the `--jdk-build` option provides a convenient way to have the tool
489+
automatically generate the equivalent underlying options, you can instead
490+
specify those options directly.
403491

404492
* If you just want to compare some or all of the declarations in different
405493
instances of JDK, without comparing the documentation comments or API documentation,
@@ -456,7 +544,7 @@ can use `--verbose options`, possibly implicitly as part of `--verbose all`.
456544
When comparing any generated API documentation, the comparison is sensitive to any
457545
variations caused by the version of `javadoc` used to generate the documentation.
458546
Therefore, it is highly recommended to use the same version of `javadoc` to generate
459-
all the versions of the documentation to be compared. When building JDK, although
547+
the documentation for all the versions to be compared. When building JDK, although
460548
the standard `docs` and `docs-jdk` targets will use the version of `javadoc` in the
461549
same repository, you can specify the version of JDK to be used for targets like
462550
`docs-reference-api` with the `--with-docs-reference-jdk` option to `configure`,
@@ -470,6 +558,46 @@ CSR request, when there is no change in `javadoc` in the versions being compared
470558
it is reasonable to use the standard `docs` or `docs-jdk` targets to generate the API
471559
documentation to be compared.
472560

561+
### Comparing non-JDK APIs
562+
563+
If the API does not define any modules, use an appropriate combination of the
564+
`--source-path`, `--class-path`, and `--api-directory` options.
565+
You can put either the compiled classes or a JAR file on the class path.
566+
If you want to compare documentation comments, put the source files on the
567+
source path. If you want to compare the API documentation, use the
568+
`--api-directory` to specify the root directory of the documentation.
569+
570+
For example, to set up an API to be able to compare the API documentation
571+
associated with a JAR file:
572+
573+
--api before --class-path build/example.jar --api-directory build/docs/api
574+
575+
To set up an API to be able to compare the documentation comments for a project:
576+
577+
--api before --source-path src/main/java
578+
579+
In both cases, you can specify any additional dependencies on the class path.
580+
581+
If the API defines one or more modules, use an appropriate combination of the
582+
`--module-source-path`, `--module-path`, and `--api-directory` options.
583+
You can put either the module or a directory of modules on the module path,
584+
where a module is anything that can be recognized as such by `javac`.
585+
If you want to compare documentation comments, put the source files on the
586+
module source path. If you want to compare the API documentation, use the
587+
`--api-directory` to specify the root directory of the documentation.
588+
589+
For example, to set up an API to be able to compare the API documentation
590+
associated with the modules for a project:
591+
592+
--api before --module-path build/modules --api-directory build/docs/api
593+
594+
To set up an API to be able to compare the documentation comments for a
595+
project that defines a module called `com.example`:
596+
597+
--api before --module-source-path com.example=src/main/java
598+
599+
In both cases, you can specify any additional dependencies on the module path.
600+
473601
### Comparing documentation comments or API descriptions
474602

475603
As well as comparing the declarations found in source files or compiled class files,
@@ -510,9 +638,11 @@ The tool does _not_ attempt to run `javadoc` locally to generate the page on the
510638
[Java Language Model API]: https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/lang/model/package-summary.html
511639
[Compiler Tree API]: https://docs.oracle.com/en/java/javase/17/docs/api/jdk.compiler/com/sun/source/doctree/package-summary.html
512640

513-
## Example
641+
## Examples
514642

515-
To compare APIs in the `java.base` module in JDK builds `/local/baseline-jdk` and `/local/updated-jdk`, and place the result in the directory `out`, run the following command:
643+
To compare APIs in the `java.base` module in JDK builds `/local/baseline-jdk`
644+
and `/local/updated-jdk`, and place the result in the directory `out`,
645+
run the following command:
516646

517647
```
518648
bin/apidiff \
@@ -526,3 +656,30 @@ bin/apidiff \
526656
--include 'java.base/**'
527657
```
528658

659+
To compare the changes for the fix for an issue such as JDK-8330183,
660+
using two separate configurations in the same repo, use a command like this:
661+
662+
```
663+
apidiff \
664+
--api jdk24 --jdk-build build/baseline \
665+
--api 8330183 --jdk-build build/macosx-aarch64-server-release \
666+
--include 'java.compiler/**' \
667+
--output-directory build/apidiff
668+
```
669+
670+
While the previous example is minimal, it could be augmented by
671+
providing additional details to be included in the output, and
672+
additional options to be explicit about some of the desired settings.
673+
674+
```
675+
apidiff \
676+
--api jdk24 --jdk-build build/baseline --label "The baseline for the changes"\
677+
--api 8330183 --jdk-build build/macosx-aarch64-server-release --label "Add SourceVersion.RELEASE_24" \
678+
--include 'java.compiler/**' \
679+
--output-directory build/apidiff \
680+
--compare-api-descriptions true \
681+
--jdk-docs docs \
682+
--info-text top="This proposal is not yet final" \
683+
--title "Diffs for JDK-8330183 CSR" \
684+
--description "Generated by $USER at $(date -u)"
685+
```

0 commit comments

Comments
 (0)