support system.setProperty style overriding of default provider
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 296
- Avg merge
- 9m
- Merged PRs (30d)
- 7
Description
> As a user writing a suite of unit tests against a file-IO heavy application, I would like to simply set the default file system provider via a call similar to `System.setProperty("java.nio.file.spi.DefaultFileSystemProvider", "com.google.common.jimfs.SystemJimfsFileSystemProvider")`, so that I can more easily apply JimFS as the systems file system.
So this is hopefully a fairly minor request:
the system property "java.nio.file.spi.DefaultFileSystemProvider" controls which FileSystemProvider is to be used as the default one. It works by specifying a fully-qualified class name as the value, which will be loaded on a call to `java.nio.file.FileSystems.DefaultFileSystemHolder#getDefaultProvider`. It does this by looking for a constructor _that takes a `FileSystemProvider` as its single argument_, effectively allowing you to chain-wrap file system providers.
So, if you guys could add another constructor to the `SystemFileSystemProvider`, that takes a provider as an argument and simply ignores it, I would be much appreciative.
##
Regarding
> I'd strongly recommend not using `Paths.get` to get a Path in your production code. It's convenient as a quick replacement for `new File(String)` when migrating from the old API, but that's about it. When using `java.nio.file`, methods that tie you to the default `FileSystem` are generally an anti-pattern.
I agree with the general principal but I'd appreciate a little trust in navigating this space myself. I think this is better expressed as a line in documentation rather than a hard requirement within your library.
In my particular case, some of my libraries are calling `Paths.get()` and the application I'm building is quite small, so I'm OK with using statics for testing here.
##
This issue relates to:
- a stack overflow question: http://stackoverflow.com/questions/25763620/set-defaultfilesystemprovider-for-testing
- issue #12
Contributor guide
Assessment
This issue has not been assessed yet.