Skip to content

Use custom doclet to extract configuration metadata with the help of#1965

Open
kwin wants to merge 5 commits into
masterfrom
feature/doclet-for-config-documentation
Open

Use custom doclet to extract configuration metadata with the help of#1965
kwin wants to merge 5 commits into
masterfrom
feature/doclet-for-config-documentation

Conversation

@kwin

@kwin kwin commented Jul 16, 2026

Copy link
Copy Markdown
Member

javadoc

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@kwin kwin requested a review from cstamas July 16, 2026 08:17
Comment thread maven-resolver-tools/pom.xml

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Nice work, @kwin! Replacing the Roaster + ASM dependencies with a standard JDK javadoc doclet is a clean architectural improvement. The intermediate properties file format provides good separation between metadata extraction and rendering, and the fileContains pre-filtering to avoid classpath resolution issues is a smart optimization. The behavioral equivalence with the old code looks correct — e.g., the Long suffix stripping is correctly omitted since VariableElement.getConstantValue() returns a proper Long object.

Two minor observations on the new code:

Low Severity

  1. Redundant BufferedWriter wrapping — In ConfigurationCollectorDoclet.java, Files.newBufferedWriter() already returns a BufferedWriter, so the outer new BufferedWriter(...) wrapper is unnecessary. Harmless, but an extra allocation:

    try (Writer writer = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) {
    
  2. Broad exception catch in fileContains — In CollectConfiguration.java, the fileContains method catches Exception instead of IOException. Since Files.readString() only throws IOException as a checked exception, catching the broader Exception could mask programming errors (e.g., NullPointerException) by silently returning false. Consider narrowing to IOException.

Notes

  • The PR title appears truncated: "Use custom doclet to extract configuration metadata with the help of" — consider completing it.
  • CI checks are still pending at time of review.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@cstamas

cstamas commented Jul 16, 2026

Copy link
Copy Markdown
Member

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Review

Thanks for the quick update, @kwin! Both findings from the initial review have been addressed in the new commit:

  • ✅ Redundant BufferedWriter wrapping removed
  • ✅ Broad Exception catch narrowed to IOException

The new enum resolution logic is well-structured — the fallback chain from compile-time constant → enum constant kind → initializer expression analysis covers the practical cases nicely. The test fixture exercises both indirect enum references (DEFAULT_ENUM = SampleEnum.VALUE_A) and direct enum constant references (SampleEnum#VALUE_B), which is good coverage.

Three minor observations on the new code (all low severity):

  1. Stale assertion messageassertEquals(4, ...) says "expected three configuration keys" (see inline)
  2. Redundant docTrees.getTree(field) call — called twice in resolveEnumReference, could use Java 16+ pattern matching instanceof (see inline)
  3. Theoretical null from docTrees.getPath()resolveReferencedField passes the result of docTrees.getPath(contextField) directly to new DocTreePath(...) without a null check. In practice this is very unlikely since the doclet only processes included source elements, but a null guard would be more defensive.

None of these are blocking — the PR looks good overall.


This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

runDoclet(sourceFile, output);

Map<String, Map<String, String>> keys = readKeys(output);
assertEquals(4, keys.size(), "expected three configuration keys");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the assertion expects 4 keys but the failure message still says "three":

Suggested change
assertEquals(4, keys.size(), "expected three configuration keys");
assertEquals(4, keys.size(), "expected four configuration keys");

if (!(docTrees.getTree(field) instanceof VariableTree)) {
return null;
}
ExpressionTree initializer = ((VariableTree) docTrees.getTree(field)).getInitializer();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: docTrees.getTree(field) is called twice — once for the instanceof guard and again for the cast. Since the project targets Java 17+, pattern matching instanceof eliminates the redundant call:

Suggested change
ExpressionTree initializer = ((VariableTree) docTrees.getTree(field)).getInitializer();
private String resolveEnumReference(VariableElement field) {
if (!(docTrees.getTree(field) instanceof VariableTree variableTree)) {
return null;
}
ExpressionTree initializer = variableTree.getInitializer();

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Review (commits 3 & 4)

Thanks for applying the suggestions from the last review, @kwin — commit 4 (727e16bf) correctly adopts pattern matching instanceof and fixes the assertion message. Both look good.

Regarding commit 3 ("Restore maven mode"), the dual-mode architecture is clean — the split into processResolverField / processMavenField keeps the two code paths well-separated, and the @Config annotation attribute reading is correct. The mode is properly threaded from picocli CLI through to the doclet. A few observations:

Medium

  1. No test coverage for Maven mode — The existing test only exercises the resolver path (Javadoc block tags). The Maven mode has meaningfully different logic (annotation-based metadata extraction), and without a test fixture that includes an @Config-annotated field, regressions in processMavenField / getAnnotation would go undetected. Consider adding a second fixture and test method similar to the existing one but with --mode=maven.

Low

  1. No mode validation in doclet — The mode field is a raw String set by the --mode option. An invalid value (e.g. --mode=typo) silently falls through to resolver mode since doRun checks "maven".equals(mode) and treats everything else as resolver. Practical risk is low because CollectConfiguration validates via the picocli Mode enum, but if the doclet is ever invoked standalone, this could be surprising.

  2. Dead null check on description — In processMavenField, the if (description != null) guard on the replace("*", ...) call is unreachable: when docComment != null, renderContent(getFullBody()) returns a non-null String; when docComment == null, description is "". Harmless, but slightly misleading.

Notes

  • The PR description still says "Remove unused 'maven' mode" — consider updating it to reflect that Maven mode is now restored.
  • Good use of Locale.ROOT in source.toLowerCase() — an improvement over the default-locale alternative.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@kwin

kwin commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Long term I would rather move the Maven specific part to https://github.com/apache/maven so that it does not need to use reflection (to prevent dependencies from Resolver to Maven). Therefore I wouldn't spend time here now to add additional tests for Maven. For example https://maven.apache.org/ref/4.0.0-rc-5/maven-configuration.html still emits system_properties as source, as there is no mapping defined for all source enums (

).

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review #4 — commit 154e76df (mode validation & cleanup)

Nice work — this commit addresses two of the three findings from the previous round:

Mode validation (previously flagged): The explicit "resolver".equals(mode) check with else throw IllegalArgumentException correctly prevents unknown modes from silently falling through to resolver processing. The exception is caught by the RuntimeException handler in run() and properly reported.

Dead null check (previously flagged): The if (description != null) guard was correctly removed — the ternary always produces a non-null string.

system_properties source: Good addition completing the enum mapping alongside model and user_properties.

One low-severity observation (not blocking): The mode validation happens inside the field iteration loop (line 157). If scanned sources happened to contain no constant fields, the loop body would never execute and an invalid mode would silently succeed. In practice this is unreachable because CollectConfiguration constrains the mode to valid enum values and pre-filters sources to those containing configuration markers — but moving the validation to the top of doRun() (alongside the existing output == null check) would make the invariant self-documenting.

Still open from prior rounds: No test coverage for the maven mode path or the new IllegalArgumentException path. Not blocking for this commit.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@kwin

kwin commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

This requires some more work for error reporting and also for emitting types (should be FQCN for non simple types)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants