Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config file as URL on Windows #254

Merged
merged 1 commit into from
Jun 1, 2018

Conversation

lutovich
Copy link
Contributor

Configuration for various formatter steps can be located in separate files. Such files might live in the local filesystem and be identified as simple paths. They can also be remote files identified by a URL. Both types of files are copied to the output directory using Maven's ResourceManager which can handle both local and remote files.

Previously, plugin tried to deduce the output file name based on the configured string. This was done using FileUtils#filename() method that expects to only work with system file separators. Issue occurred on Windows when URL was specified. Path separator on Windows is \ and in URL it is /. Code wasn't able to extract the last path of the URL that denotes the file name. Instead, it treated the whole URL as a file name. URLs contain chars invalid for Windows paths and an exception was thrown on attempt to create the file.

This PR fixes the problem by making code use predefined name pattern for all resolved resources. Name of the output file will not be guessed based on the configured path or URL. It will just be unique and have 'spotless-resource-' prefix.

Fixes #250

@lutovich lutovich requested review from nedtwigg and fvgh May 31, 2018 21:22
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

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

LGTM. My instinct is that hashing the URL's content might be a better naming convention, but that's harder, and it's a general problem for both the maven plugin and the gradle plugin that FileSignature can only take files. Probably this could be improved in the future for both Gradle and Maven with a better FileSignature class, but no reason to block "good" while we wait for "best".

Configuration for various formatter steps can be located in separate
files. Such files might live in the local filesystem and be identified
as simple paths. They can also be remote files identified by a URL.
Both types of files are copied to the output directory using Maven's
`ResourceManager` which can handle both local and remote files.

Previously, plugin tried to deduce the output file name based on the
configured string. This was done using `FileUtils#filename()` method
that expects to only work with system file separators. Issue occurred
on Windows when URL was specified. Path separator on Windows is `\`
and in URL it is `/`. Code wasn't able to extract the last path of
the URL that denotes the file name. Instead, it treated the whole URL
as a file name. URLs contain chars invalid for Windows paths and an
exception was thrown on attempt to create the file.

This commit fixes the problem by making code use predefined name
pattern for all resolved resources. Name of the output file will not
be guessed based on the configured path or URL. It will just be unique
and have 'spotless-resource-' prefix.
Copy link
Member

@fvgh fvgh left a comment

Choose a reason for hiding this comment

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

LTGM

@nedtwigg nedtwigg merged commit c6c32e3 into diffplug:master Jun 1, 2018
@lutovich lutovich deleted the win-file-name branch June 5, 2018 10:28
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.

[maven] using an url as file does not work on windows.
3 participants