Skip to content

Parse and forward JavaC 'Note:' level messages - #312

Closed
gnodet wants to merge 2 commits into
codehaus-plexus:masterfrom
gnodet:infoLogs2
Closed

gnodet wants to merge 2 commits into
codehaus-plexus:masterfrom
gnodet:infoLogs2

Conversation

@gnodet

@gnodet gnodet commented Oct 27, 2023 •

Copy link
Copy Markdown
Member

Theses messages can be generated by annotation processors using
printMessage(Diagnostic.Kind.NOTE, "...").

@gnodet
gnodet force-pushed the infoLogs2 branch 3 times, most recently from 3f48996 to 1b578f4 Compare October 27, 2023 15:02
@gnodet
gnodet marked this pull request as draft October 27, 2023 18:25
@gnodet

gnodet commented Oct 27, 2023

Copy link
Copy Markdown
Member Author

This PR should also integrate #57
I'll remove the draft status when that's done.

@gnodet
gnodet marked this pull request as ready for review October 27, 2023 21:33
mensinda and others added 2 commits October 28, 2023 10:34
Theses messages can be generated by annotation processors using
`printMessage(Diagnostic.Kind.NOTE, "...")`.
If the -log argument is used, the resulting log file is scanned for compiler output, both text and xml formatting supported. Otherwise a temporary log file is used to capture compiler output.

* Unit tests refactored
* Output emitted as "INFO" are reported as Kind.NOTE
* Column count adjusted to be 1-based index
@gnodet

gnodet commented Oct 28, 2023

Copy link
Copy Markdown
Member Author

Actually, I'm not sure about including the -log eclipse compiler option the way it is.
I think it should be rather implemented as #296 or with a global option in the CompilerConfig to give a path to a directory or file to store the compiler output for later inspection. However, passing the argument directly to the compiler and have plexus-compiler parse the file after the compilation could definitely lead to problems in case the give log is an absolute path and use concurrently. I'd rather have direct compiler output not accessible and the mentioned option to write/move/copy the output after the compilation has been done and the output has been parsed.

@spadou

spadou commented Nov 27, 2023

Copy link
Copy Markdown

For info, in Java 21, a note was added that span multiple lines (see https://inside.java/2023/07/29/quality-heads-up/). This produce the following output from javac:

Note: Annotation processing is enabled because one or more processors were found
  on the class path. A future release of javac may disable annotation processing
  unless at least one processor is specified by name (-processor), or a search
  path is specified (--processor-path, --processor-module-path), or annotation
  processing is enabled explicitly (-proc:only, -proc:full).
  Use -Xlint:-options to suppress this message.
  Use -proc:none to disable annotation processing.

This should probably be handled in this PR when note level messages are parsed.

Not sure what is the plan to merge this, but it would be really useful to have at least the note parsing, to handle this case when compiling with Java 21. Currently note messages are skipped, but this also only handle single line messages, so only the first line is skipped and the remaining lines are prepended with the next warning which is not a good output.

@slachiewicz slachiewicz added the need-rebase Branch has conflicts and needs a rebase before it can merge label Dec 25, 2024
@slachiewicz slachiewicz added the enhancement New feature or request label Aug 16, 2026
@slachiewicz

Copy link
Copy Markdown
Member

Splitting this so the uncontroversial part can move: #496 takes the javac half. It is not the one-line change from here — @spadou's multi-line JDK 21 note needs its continuation lines consumed, otherwise they poison the unclassified buffer, and since 880da00 that buffer is reported as a compiler error when javac fails.

The other two commits here, #313 and #314, are long merged.

That leaves the eclipse -log half, which is where the design question you raised against your own patch still stands — a CompilerConfiguration option naming where to write compiler output, rather than passing -log through and parsing the file afterwards. Worth its own issue so the log parsers and fixtures in this branch are not lost.

This comment was created with AI assistance.

slachiewicz added a commit that referenced this pull request Aug 18, 2026
The two javac back-ends disagreed. In-process compilation maps
Diagnostic.Kind.NOTE to CompilerMessage.Kind.NOTE, so notes reach the build
log; the forked path threw them away with a comment about JDK 1.5 and
-Xlint:deprecation. Forwarding them makes the two agree and brings back the
"Recompile with -Xlint:deprecation for details" hints that #183 asks for.
The idea, and the one-line form of it, come from #312.

Notes cannot simply be emitted line by line. javac can wrap one over several
lines, indenting every line but the first:

    Note: Annotation processing is enabled because one or more processors
      were found on the class path. A future release of javac may disable
      ...

No classifier matches those continuation lines, so they landed in the
unclassified buffer, and once that buffer is non-empty every following line
joins it - which is why the note used to reappear glued to the front of the
next warning. Since 880da00 a failing compile reports that buffer as an
error, so a project with an annotation processor on the class path could get
a compiler error assembled out of note text. A note is therefore held back
until a line arrives that does not continue it.

That particular note belongs to JDK 21 and 22 only: JDK 23 made annotation
processing opt-in, and JDK 25 stays silent even with a processor on the
class path. The handling is general because nothing stops a future note from
wrapping.

Do not tighten the continuation test into a match against the note's own
wording, which is localised and changes between releases.

Verified: mvn clean install on JDK 25, whole reactor green.
slachiewicz added a commit that referenced this pull request Aug 18, 2026
The two javac back-ends disagreed. In-process compilation maps
Diagnostic.Kind.NOTE to CompilerMessage.Kind.NOTE, so notes reach the build
log; the forked path threw them away with a comment about JDK 1.5 and
-Xlint:deprecation. Forwarding them makes the two agree and brings back the
"Recompile with -Xlint:deprecation for details" hints that #183 asks for.
The idea, and the one-line form of it, come from #312.

Notes cannot simply be emitted line by line. javac can wrap one over several
lines, indenting every line but the first:

    Note: Annotation processing is enabled because one or more processors
      were found on the class path. A future release of javac may disable
      ...

No classifier matches those continuation lines, so they landed in the
unclassified buffer, and once that buffer is non-empty every following line
joins it - which is why the note used to reappear glued to the front of the
next warning. Since 880da00 a failing compile reports that buffer as an
error, so a project with an annotation processor on the class path could get
a compiler error assembled out of note text. A note is therefore held back
until a line arrives that does not continue it.

That particular note belongs to JDK 21 and 22 only: JDK 23 made annotation
processing opt-in, and JDK 25 stays silent even with a processor on the
class path. The handling is general because nothing stops a future note from
wrapping.

Do not tighten the continuation test into a match against the note's own
wording, which is localised and changes between releases.

Verified: mvn clean install on JDK 25, whole reactor green.
@slachiewicz

Copy link
Copy Markdown
Member

Issue #500 records the design question behind the -log half, so the log parsers and the 8 captured compiler logs in this branch have somewhere to go.

The javac half merged as #496.

This comment was created with AI assistance.

@slachiewicz

Copy link
Copy Markdown
Member

Closing as not planned: what this PR set out to do is on master, by other routes.

Two things here have no equivalent on master. Neither changes what a caller sees:

  • expectedNotes() in AbstractCompilerTest, so a TCK subclass can assert the number of notes rather than ignore them.
  • The EcjLogParser split with EcjTextLogParser, which parses ecj text logs. EclipseJavaCompiler requests -log ecjerr-*.xml, so nothing reaches that path today.

Either is welcome as its own change, and the work here is a good starting point for it. Thanks @gnodet, and sorry it sat this long.

This comment was created with AI assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request need-rebase Branch has conflicts and needs a rebase before it can merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output information needed to suppress Xlint warnings

5 participants