Fix resource leak in Maven plugin by lutovich · Pull Request #571 · diffplug/spotless

nedtwigg

@lutovich lutovich marked this pull request as ready for review

June 27, 2020 21:31
… file instead of the

whole node_modules directory.
The resource leak increased the number of threads with every execution of
Exclipse-based formatter step in a Maven module. It happened because the
`SpotlessCache` wasn't properly utilized. Every cache key was based on
randomized file names because Maven plugin relocates config files into
the target directory with a random file name. This resulted in all cache
accesses being cache misses.

This commit fixes the problem by:

 * making the Maven plugin use non-random file names for output files.
   `FileLocator` is changed to construct names based on a hash of the
   input path. Input path can be a URL, file in a JAR, or a regular
   local file

 * changing `FileSignature` (used for `SpotlessCache` keys) to use filenames
   instead of paths and file hashes instead of last modified timestamps

These two changes allow `FileSignature` to uniquely identify a set of files
by their content and not take file paths into account. As a result, created
keys for `SpotlessCache` are properly comparable which results in lots of
cache hits and decreased number of created threads.

Changed `FileSignature` only accepts files, not directories.

@nedtwigg

…performance based on lastModified that we had prior to this PR.
…le, once a file has changed, we can discard the old one.
where a FileSignature is generated for multiple files with the same filename.

@nedtwigg

@nedtwigg

@nedtwigg

@nedtwigg

lutovich

@nedtwigg

@nedtwigg

@lutovich lutovich deleted the fix-mvn-resource-usage branch

June 29, 2020 21:34