-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfbcd5b
commit ff29631
Showing
14 changed files
with
182 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# .NET Analysis | ||
|
||
There are several different methods of .NET analysis, that use both the `NuGet` (`nuspec`, `PackageReference`, `packages.config`, `project.json`, `project.assets.json`) and `Paket` package managers. | ||
There are several different methods of .NET analysis, that use both the [NuGet](./nuget.md) (`nuspec`, `PackageReference`, `packages.config`, `project.json`, `project.assets.json`) and [Paket](./paket.md) package managers. | ||
|
||
| Strategy | Direct Deps | Transitive Deps | Edges | | ||
| ---------------------------------------- | ----------- | --------- | ----- | | ||
| [nuspec](nuspec.md) | ✅ | ❌ | ❌ | | ||
| [PackageReference](packagereference.md) | ✅ | ❌ | ❌ | | ||
| [packages.config](packagesconfig.md) | ✅ | ❌ | ❌ | | ||
| [paket](paket.md) | ✅ | ✅ | ✅ | | ||
| [project.assets.json](projectassetsjson.md) | ✅ | ✅ | ✅ | | ||
| [project.json](projectjson.md) | ✅ | ❌ | ❌ | | ||
| [PackageReference](packagereference.md) | ✅ | ❌ | ❌ | | ||
| [project.json](projectjson.md) | ✅ | ❌ | ❌ | | ||
| [packages.config](packagesconfig.md) | ✅ | ❌ | ❌ | | ||
| [nuspec](nuspec.md) | ✅ | ❌ | ❌ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Quick reference: NuGet | ||
|
||
## Requirements | ||
|
||
**Ideal/Minimum** | ||
|
||
One more more of the following: | ||
|
||
- [`.nuspec`](https://docs.microsoft.com/en-us/nuget/reference/nuspec) formatted file in your directory. | ||
- [Package reference](https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files) file present in your project. Commonly with an ending such as `.csproj`, `xproj`, `vbproj` and others. | ||
- `project.assets.json` | ||
- `packages.config` | ||
- `project.json` | ||
|
||
## Project discovery | ||
|
||
Directories containing any of the files listed above are considered NuGet projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
# Quick reference: NuGet | ||
# NuGet Analysis | ||
|
||
## Requirements | ||
| Strategy | Direct Deps | Transitive Deps | Edges | | ||
| ---------------------------------------- | ----------- | --------- | ----- | | ||
| [project.assets.json](projectassetsjson.md) | ✅ | ✅ | ✅ | | ||
| [PackageReference](packagereference.md) | ✅ | ❌ | ❌ | | ||
| [project.json](projectjson.md) | ✅ | ❌ | ❌ | | ||
| [packages.config](packagesconfig.md) | ✅ | ❌ | ❌ | | ||
| [nuspec](nuspec.md) | ✅ | ❌ | ❌ | | ||
|
||
**Ideal/Minimum** | ||
NuGet analysis follows these strategies in sequence: | ||
1. `project.assets.json` | ||
2. `PackageReference` | ||
|
||
One more more of the following: | ||
`project.assets.json` files and their dependencies are generated from `.csproj` files. `PackageReference` dependencies can be found in `.csproj`, `.xproj`, `.vbproj`, `.dbproj`, or `.fsproj` files. To consolidate findings from these two strategies, `project.assets.json` analysis is attempted first and falls back to `PackageReference` analysis. | ||
|
||
- [`.nuspec`](https://docs.microsoft.com/en-us/nuget/reference/nuspec) formatted file in your directory. | ||
- [Package reference](https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files) file present in your project. Commonly with an ending such as `.csproj`, `xproj`, `vbproj` and others. | ||
- `project.assets.json` | ||
- `packages.config` | ||
- `project.json` | ||
The following strategies are executed independently:: | ||
1. `project.json` | ||
2. `packages.config` | ||
3. `nuspec` | ||
|
||
## Project discovery | ||
|
||
Directories containing any of the files listed above are considered NuGet projects. | ||
`project.json` and `packages.config` files are deprecated in favor of `.csproj` and their usage of `PackageReference` format. `nuspec` serves as a manifest containing package metadata, used both for building the package and providing information to consumers. These strategies are isolated from the `project.assets.json` and `PackageReference` approaches and therefore run independently. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{658B52A1-C5F7-4B7E-944F-053941594B2F}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{3B3BB3E9-0869-4F9B-A4C5-C19DF124C9D2}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\NuGet\testdata\test.csproj", "{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{3B3BB3E9-0869-4F9B-A4C5-C19DF124C9D2} = {658B52A1-C5F7-4B7E-944F-053941594B2F} | ||
{EE31BA60-2E5B-4CF6-BD30-1EABD73BB0B6} = {3B3BB3E9-0869-4F9B-A4C5-C19DF124C9D2} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FACD6BBC-C0EA-4521-9831-30EB13595A84} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
module Strategy.NuGet ( | ||
discover, | ||
findProjects, | ||
getDeps, | ||
mkProject, | ||
NuGetProject (..), | ||
) where | ||
|
||
import App.Fossa.Analyze.Types (AnalyzeProject (analyzeProjectStaticOnly), analyzeProject) | ||
import Control.Effect.Diagnostics ( | ||
Diagnostics, | ||
Has, | ||
context, | ||
(<||>), | ||
) | ||
import Control.Effect.Reader (Reader) | ||
import Data.Aeson ( | ||
ToJSON, | ||
) | ||
import Data.Foldable (find) | ||
import Data.List qualified as L | ||
import Discovery.Filters (AllFilters) | ||
import Discovery.Simple (simpleDiscover) | ||
import Discovery.Walk ( | ||
WalkStep (WalkContinue), | ||
fileName, | ||
findFileNamed, | ||
walkWithFilters', | ||
) | ||
import Effect.ReadFS (ReadFS) | ||
import GHC.Generics (Generic) | ||
import Path (Abs, Dir, File, Path, parent) | ||
import Strategy.NuGet.PackageReference qualified as PackageReference | ||
import Strategy.NuGet.PackageReference qualified as ProjectAssetsJson | ||
import Types ( | ||
DependencyResults (..), | ||
DiscoveredProject (..), | ||
DiscoveredProjectType (NuGetProjectType), | ||
) | ||
|
||
discover :: | ||
( Has ReadFS sig m | ||
, Has Diagnostics sig m | ||
, Has (Reader AllFilters) sig m | ||
) => | ||
Path Abs Dir -> | ||
m [DiscoveredProject NuGetProject] | ||
discover = simpleDiscover findProjects mkProject NuGetProjectType | ||
|
||
findProjects :: (Has ReadFS sig m, Has Diagnostics sig m, Has (Reader AllFilters) sig m) => Path Abs Dir -> m [NuGetProject] | ||
findProjects = walkWithFilters' $ \_ _ files -> do | ||
case findProjectAssetsJsonFile files of | ||
Just file -> pure ([NuGetProject file], WalkContinue) | ||
Nothing -> case find isPackageRefFile files of | ||
Just file -> pure ([NuGetProject file], WalkContinue) | ||
Nothing -> pure ([], WalkContinue) | ||
where | ||
findProjectAssetsJsonFile :: [Path Abs File] -> Maybe (Path Abs File) | ||
findProjectAssetsJsonFile = findFileNamed "project.assets.json" | ||
|
||
isPackageRefFile :: Path b File -> Bool | ||
isPackageRefFile file = any (\x -> x `L.isSuffixOf` fileName file) [".csproj", ".xproj", ".vbproj", ".dbproj", ".fsproj"] | ||
|
||
mkProject :: NuGetProject -> DiscoveredProject NuGetProject | ||
mkProject project = | ||
DiscoveredProject | ||
{ projectType = NuGetProjectType | ||
, projectPath = parent $ nugetProjectFile project | ||
, projectBuildTargets = mempty | ||
, projectData = project | ||
} | ||
|
||
newtype NuGetProject = NuGetProject | ||
{ nugetProjectFile :: Path Abs File | ||
} | ||
deriving (Eq, Ord, Show, Generic) | ||
|
||
instance ToJSON NuGetProject | ||
|
||
instance AnalyzeProject NuGetProject where | ||
analyzeProject _ = getDeps | ||
analyzeProjectStaticOnly _ = getDeps | ||
|
||
getDeps :: (Has ReadFS sig m, Has Diagnostics sig m) => NuGetProject -> m DependencyResults | ||
getDeps project = context "NuGet" (getAssetsJsonDeps project <||> getPackageReferenceDeps project) | ||
|
||
getAssetsJsonDeps :: (Has ReadFS sig m, Has Diagnostics sig m) => NuGetProject -> m DependencyResults | ||
getAssetsJsonDeps = context "ProjectAssetsJson" . context "Static analysis" . ProjectAssetsJson.analyze' . nugetProjectFile | ||
|
||
getPackageReferenceDeps :: (Has ReadFS sig m, Has Diagnostics sig m) => NuGetProject -> m DependencyResults | ||
getPackageReferenceDeps = context "PackageReference" . context "Static analysis" . PackageReference.analyze' . nugetProjectFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.