Skip to content

Make MSBuildFileSystemBase non-abstract to remove versioning and usability constraints#6475

Merged
Forgind merged 3 commits intodotnet:mainfrom
ladipro:6068-MSBuildFileSystemBase
May 29, 2021
Merged

Make MSBuildFileSystemBase non-abstract to remove versioning and usability constraints#6475
Forgind merged 3 commits intodotnet:mainfrom
ladipro:6068-MSBuildFileSystemBase

Conversation

@ladipro
Copy link
Copy Markdown
Member

@ladipro ladipro commented May 24, 2021

Partially fixes #6068

Context

MSBuildFileSystemBase was introduced as a replacement of IFileSystem in #5546. It was added as an abstract class so potentially with the same constraints as an interface:

  • Versioning constraints. We can't add a new public member to the class, unless we make it non-abstract and provide a default implementation of new members.
  • Usability constraints. It is not possible to use MSBuildFileSystemBase to intercept calls or override a subset of them because the default MSBuild-provided file system is not exposed.

Changes Made

To address the constraints above, I am making the class non-abstract and having it by default forward all calls to the default MSBuild file system. This way the caller may choose to override only a subset of methods (e.g. file enumeration and existence/metadata checks) leaving the rest as is (e.g. actual file reads).

As a result I was able to delete both IFileSystemAdapter.cs and MSBuildFileSystemAdapter.cs because they're not needed anymore.

The difference between IFileSystem methods and public MSBuildFileSystemBase methods was just one method having a different name. I have renamed the one on the internal interface, assuming that this does not cause any troubles with the old NuGet, as tested by TestOldNuget(). This enabled further simplification and reduce the number of the "adapter" call hops.

With the changes in this PR, we have:

  • An internal interface IFileSystem, kept around for compat reasons.
  • A public class MSBuildFileSystemBase, which implements IFileSystem with virtual methods. The class is meant to be derived from and its methods overridden.

If we find ourselves adding new methods to the contract, it won't break existing MSBuildFileSystemBase because the new calls will just call through to the default implementation. If the change we need to make requires an orchestrated behavior change, we can always add a virtual 'version' prop, overriding which the derived class tells us which version of the contract it supports.

Testing

Existing unit test coverage.

Notes

This change is meant to be non-breaking. I'm basically just making an abstract class non-abstract (would have to be done at some point anyways if we were to add a new method). The rest of the changes are internal.

@ladipro ladipro requested a review from cdmihai May 24, 2021 11:33
Copy link
Copy Markdown
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Looks great! Always happy to see some code deleted 😊

@ladipro ladipro force-pushed the 6068-MSBuildFileSystemBase branch from 76b174a to b6a357c Compare May 27, 2021 12:21
@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label May 28, 2021
@Forgind Forgind merged commit f453334 into dotnet:main May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid disk scans for projects by relying on DirectoryTree from CPS

4 participants