Skip to content

Conversation

@arturobernalg
Copy link
Member

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

  • [X ] Your pull request should address just one issue, without pulling in other changes.
  • [ X] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [ X] 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.
  • [X ] 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.
  • [X ] 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 Core IT successfully.

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.

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTempFileService.class);

// System property to keep temp material for diagnostics.
private static final String KEEP_PROP = "maven.tempfile.keep";
Copy link
Member

Choose a reason for hiding this comment

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

This should go (along with added doco) to Constants maybe?

@cstamas
Copy link
Member

cstamas commented Nov 5, 2025

@gnodet @desruisseaux I like the idea!

@desruisseaux
Copy link
Contributor

It would be for temporary files having a longer lifetime than what we can manage with tryfinally? I have no objection, but just curious at what are the use cases?

@cstamas
Copy link
Member

cstamas commented Nov 5, 2025

On a related note: in resolver I found this pattern quite useful (to perform cleanup immediately when tmp file was not needed anymore, but in Maven that can happen at session end I guess?):
https://github.com/apache/maven-resolver/blob/master/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/io/PathProcessor.java#L180-L210

Basically, the collocated temp file is mostly used, as it creates a temp file "next to target", and after you wrote to it, on close it will be atomically moved to it's place. As this is ideal pattern to "pub-unpub" files on modern FS, like "move to place" and "remove from place", and there are no partial reads possible.

() -> Collections.newSetFromMap(new ConcurrentHashMap<Path, Boolean>());

@Inject
public DefaultTempFileService() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This empty constructor is not needed.

}

@Override
public Path createTempFile(final Session session, final String prefix, final String suffix) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use final on arguments or variables.

* Service to create and track temporary files/directories for a Maven build.
* All created paths are deleted automatically when the session ends.
*/
public interface TempFileService {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to extend Service

* Service to create and track temporary files/directories for a Maven build.
* All created paths are deleted automatically when the session ends.
*/
public interface TempFileService {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add @Nonnull for parameters and return types on all methods.

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Some adjustments, but the idea is definitely interesting.

@gnodet
Copy link
Contributor

gnodet commented Nov 6, 2025

Also, I think we should retarget to master branch.

@gnodet gnodet added this to the 4.1.0 milestone Nov 6, 2025
} catch (final IOException e) {
if (first == null) {
first = e;
}
Copy link
Member

Choose a reason for hiding this comment

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

The other exceptions could be added as suppressed ones to the first.

Auto-clean temp files/dirs on afterSessionEnd; opt-out via -Dmaven.tempfile.keep
Add tests and minimal SessionData map stub
@arturobernalg
Copy link
Member Author

I did all the requested change and also add a new pr for master. Keep this in case you want to push it to 4.x #11405

@gnodet
Copy link
Contributor

gnodet commented Nov 18, 2025

I'd rather target 4.1

@gnodet gnodet closed this Nov 18, 2025
@github-actions github-actions bot removed this from the 4.1.0 milestone Nov 18, 2025
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.

5 participants