Repository navigation
[maven-3.10.x] Replace the 3.10 MessageBuilderFactory with the Maven 4 API - #13919
slachiewicz merged 2 commits into
Conversation
org.apache.maven.message.MessageBuilderFactory was never visible to plugins: core exports org.apache.maven.* only for that exact package. Rather than export it, maven-core now carries Java 8 copies of org.apache.maven.api.services.MessageBuilder and MessageBuilderFactory from maven-api-core, with the annotations they use and Constants reduced to the style names, and Maven uses those itself. A plugin compiled against maven-api-core 4.x injects the same factory on 3.10 as on Maven 4. maven-jline now generates its Sisu index, so the JLine factory wins over the uncoloured default for every injection, Maven's own included. See apache#13917.
9731ca4 to
cc9a4e4
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Well-structured backport of the Maven 4 MessageBuilderFactory API to Maven 3.10.x. The Sisu index fix for maven-jline is the key correctness improvement — without it, sisu-maven-plugin consumers couldn't discover the new service. Package rename from org.apache.maven.message to org.apache.maven.api.services is binary-incompatible but defensible since the old package was never accessible to plugins through classworlds. Two minor documentation items below, plus an incomplete @Nonnull annotation pass.
Question: Is the binary-incompatible package rename from org.apache.maven.message to org.apache.maven.api.services acceptable on the 3.10.x maintenance branch? The old classes were internal (not in classworlds exports), but the rename may affect consumers using maven-core directly on the classpath. Worth explicitly addressing in the PR description.
Question: maven-jline/src/main/resources/META-INF/sisu/javax.inject.Named now exports DefaultMessageBuilderFactory — is this the right format for the Sisu index? Maven 4 uses javax.inject.Named entries for Sisu DI discovery. This looks correct, but deserves explicit confirmation that the entry format matches what sisu-maven-plugin expects for 3.10.x.
Note — @Nonnull on abstract methods: This PR adds @Nonnull to the default/concrete methods in MessageBuilder, but the three abstract methods style(String), resetStyle(), and setLength(int) are still missing the annotation. Since the goal is consistent null-safety, these should be annotated as well (even though they weren't modified by this PR, it's the same pattern applied incompletely).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
On the package move: On the index: On |
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — all 3 previous findings have been addressed in this update:
@since 3.10.1onMessageBuilder.java— ✅ addressed (changed from3.10.0)@since 3.10.1onMessageBuilderFactory.java— ✅ addressed (changed from3.10.0)- Class-level
@since 3.10.1onConstants.java— ✅ addressed
The rest of the changes look solid:
- The classworlds export entries (
org.apache.maven.api.*,org.apache.maven.api.annotations.*,org.apache.maven.api.services.*) correctly make the new API types visible to plugins — the existingorg.apache.maven.*wildcard does not recursively cover subpackages in this format, so the explicit entries are necessary. - The
sisu-maven-pluginaddition tomaven-jline/pom.xmlis the right fix forJLineMessageBuilderFactorybeing bypassed at injection time. - The
DefaultMessageBuilderFactoryTestcorrectly validates the API surface under@PlexusTest(no JLine context), and thesetLength(0)call is defined on the interface. - One note for downstream embedders:
org.apache.maven.message.MessageBuilderandorg.apache.maven.message.MessageBuilderFactoryno longer exist in 3.10.1 (they moved toorg.apache.maven.api.services.*). The PR body already documents this migration requirement. No further action needed here — just flagging it for the release notes.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Plugins compiled against
maven-api-core4.x can injectorg.apache.maven.api.services.MessageBuilderFactoryon Maven 3.10 as they do on Maven 4, as proposed in #13917.org.apache.maven.message.MessageBuilderandMessageBuilderFactoryare replaced by Java 8 copies of the Maven 4 interfaces, which Maven itself now uses. The 3.10 types were never usable by plugins: core exportsorg.apache.maven.*, which classworlds matches for that exact package only, so a mojo injecting them failed withNoClassDefFoundError. The two interfaces are identical apart from the package,@Nonnullandextends Service. Code that embedsmaven-coreand used them directly changes the import.maven-corealso carriesService(the factory's supertype, so the copied hierarchy matches Maven 4), theNonnull,ExperimentalandThreadSafeannotations, andorg.apache.maven.api.Constantsreduced to the style names. All of its fields areStringconstants, which callers inline, so plugins compiled against the full class never read the missing ones.org.apache.maven.api.*,org.apache.maven.api.annotations.*andorg.apache.maven.api.services.*. A plugin that bundles othermaven-api-*classes keeps loading them from its own jar.JLineMessageBuilderFactorywas in no Sisu index, so every injection gotDefaultMessageBuilderFactory, which never colours.maven-jlinenow generates its index, and its@Priority(10)factory wins.Behaviour change: Maven's own messages built through the injected factory (
MojoExecutor,LifecycleDependencyResolver,DeprecatedPluginValidator,DefaultMojoExecutionConfigurator,LifecycleExecutionException) are now coloured on a terminal, like the rest of the output; with-B,-l,--color=neveror piped output they stay plain.Verified:
mvn verify -pl maven-core,maven-jline,maven-embedder→ 430, 10 and 55 tests pass; one mojo binary compiled with--release 8againstmaven-api-core4.0.0-rc-7 getsJLineMessageBuilderFactoryon the built distribution and on Maven 4.0.0-rc-7 and prints identical output on both, coloured under--color=alwaysand a pseudo-terminal, plain when piped or with-B;javadocon the copied sources reports no errors.Supersedes #13918.