Introduce TempFileService and lifecycle cleanup participant - #11405
Introduce TempFileService and lifecycle cleanup participant#11405arturobernalg wants to merge 1 commit into
Conversation
…irs on afterSessionEnd; opt-out via -Dmaven.tempfile.keep Add tests and minimal SessionData map stub
|
It looks like a duplicate of #11389 ? |
Yes. one for master and the other for maven-4.X |
| * System property to keep temp material for diagnostics. | ||
| * | ||
| */ | ||
| public static final String KEEP_PROP = "maven.tempfile.keep"; |
There was a problem hiding this comment.
Rename to MAVEN_TEMPFILE_KEEP for consistency.
gnodet
left a comment
There was a problem hiding this comment.
Review: Introduce TempFileService and lifecycle cleanup participant
The concept is sound — providing a managed temp file service with automatic cleanup at session end is a useful addition. However, there are several API design issues that should be addressed before merging into the Maven 4 API.
High
@Nonnull on void return methods — TempFileService.register() and cleanup() have @Nonnull on their void return type. This is semantically meaningless — void methods have no return value to be null or non-null. Other services (e.g., ArtifactManager.setPath()) do not annotate void returns with @Nonnull. Remove @Nonnull from these two methods and instead annotate the parameters.
Medium
-
KEEP_PROPnaming convention (Constants.java) — Every other constant inConstants.javauses theMAVEN_prefix (113 occurrences). The new constant should follow suit:MAVEN_TEMPFILE_KEEPinstead ofKEEP_PROP. -
Missing
@Experimentalannotation (TempFileService.java) — Every otherServiceinterface inorg.apache.maven.api.servicescarries@Experimental(ArtifactResolver,ArtifactManager,Interpolator, etc.). This should too. -
Boolean.getBoolean(KEEP_PROP)reads JVM system property (DefaultTempFileService.java) —Boolean.getBoolean()only checksSystem.getProperty(), so the property cannot be set viapom.xml<properties>, profiles, orsettings.xml. Consider usingsession.getUserProperties()orsession.getSystemProperties()if this should be settable through Maven's property resolution. If this is intentionally a JVM-level diagnostic flag, that's fine — just document the rationale. -
Missing
@sinceand@Config(Constants.java) — All recent constant additions have@since 4.1.0and a@Configannotation (e.g.,MAVEN_CACHE_STATS,MAVEN_MODEL_PROCESSOR_POOLED_TYPES). Both are missing here.
Low
-
Parameters missing
@Nonnull/@Nullable(TempFileService.java) — Other services in this package annotate all parameters (Interpolator,ArtifactManager). Thesessionanddirectoryparameters should be@Nonnull; clarify whetherprefix/suffixaccept null (they do perjava.nio.file.Filescontract). -
Logger created inline (
TempFileCleanupParticipant.java) — The logger is created at the call site:LoggerFactory.getLogger(TempFileCleanupParticipant.class).warn(...). This is inconsistent withDefaultTempFileServicein the same PR, which correctly uses aprivate static final Logger LOGGERfield. Extract to a field. -
System.setPropertyin tests (DefaultTempFileServiceTest.java) —System.setPropertymutates global JVM state and can cause test pollution in parallel execution. Also, there is no test forTempFileCleanupParticipantitself. -
Raw type cast for
TMP_KEY(DefaultTempFileService.java) — The@SuppressWarnings({"unchecked", "rawtypes"})cast is acknowledged and documented. Consider a wrapper type to avoid the raw cast, or accept it as a known limitation ofSessionData.Keygenerics.
Notes
- The companion PR #11389 targeting
maven-4.Xis closed. Please confirm this is the intended target branch. - The PR description is minimal — for a new public API addition, documenting the motivation (what temp files are currently leaked, which plugins benefit) would help reviewers.
- Thread safety looks correct:
ConcurrentHashMap-backedSetandSessionData.computeIfAbsentprovide atomic initialization. - No new dependencies introduced.
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
Reviewed 3 PRs: apache#12454 (re-review), apache#11502 (new), apache#11405 (new). Added 2 new dependabot PRs to skip list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet
left a comment
There was a problem hiding this comment.
New TempFileService API with lifecycle cleanup — solid concept for managing build temp files. All findings below were independently verified (7/7 confirmed).
Note: a maintainer (gnodet) already submitted CHANGES_REQUESTED in November 2025, and these issues remain unaddressed after 8+ months.
Convention violations:
- @nonnull on void returns (high) —
register()andcleanup()apply@Nonnullto the void return type. Existing services apply it to parameters instead. - Missing @experimental (medium) — All 20+ Service interfaces carry
@Experimental. Also missing@since 4.1.0. - KEEP_PROP naming (medium) — All 113 other constants use the
MAVEN_prefix. Should beMAVEN_TEMPFILE_KEEP. Also missing@Configand@since 4.1.0. (Already noted by gnodet in Nov 2025 review.) - Boolean.getBoolean limitation (medium) — Only reads JVM
-Dproperties, not Maven session properties from pom.xml/profiles/settings.xml. Should be documented if intentional. - Inline logger (low) —
TempFileCleanupParticipantcreates logger inline;DefaultTempFileServiceuses standardprivate static final Logger. - Missing parameter annotations (low) —
session,directory,prefix,suffixparameters lack@Nonnull/@Nullable. - System.setProperty in test (low) — Mutates global JVM state;
@AfterEachcleanup present but can still cause flakiness under parallel execution. No test forTempFileCleanupParticipant.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
| * Registers an externally created path for cleanup at session end. | ||
| */ | ||
| @Nonnull | ||
| void register(Session session, Path path); |
There was a problem hiding this comment.
@Nonnull on a void return type is semantically meaningless. In existing services (ArtifactDeployer.deploy, ArtifactManager.setPath), @Nonnull is applied to parameters, not void returns.
Same issue on cleanup() below.
| void register(Session session, Path path); | |
| void register(@Nonnull Session session, @Nonnull Path path); |
| * System property to keep temp material for diagnostics. | ||
| * | ||
| */ | ||
| public static final String KEEP_PROP = "maven.tempfile.keep"; |
There was a problem hiding this comment.
All 113 other constants in this file use the MAVEN_ prefix (MAVEN_HOME, MAVEN_CACHE_STATS, MAVEN_REPO_LOCAL, etc.). This should be MAVEN_TEMPFILE_KEEP. Also missing @since 4.1.0 and @Config annotation (71 other constants have @Config).
| public static final String KEEP_PROP = "maven.tempfile.keep"; | |
| /** | |
| * System property to keep temp material for diagnostics. | |
| * | |
| * @since 4.1.0 | |
| */ | |
| @Config(type = "java.lang.Boolean", defaultValue = "false") | |
| public static final String MAVEN_TEMPFILE_KEEP = "maven.tempfile.keep"; |
Following this checklist to help us incorporate your
contribution quickly and easily:
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.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.