From 11e55d41e3650033605b39bc74e3de2defd212fb Mon Sep 17 00:00:00 2001 From: spatten Date: Mon, 16 Sep 2024 16:51:01 -0700 Subject: [PATCH] just use lists --- src/App/Fossa/Lernie/Analyze.hs | 2 +- src/App/Fossa/ManualDeps.hs | 18 +++++++++--------- src/Srclib/Converter.hs | 2 +- src/Srclib/Types.hs | 16 ++++++++-------- test/App/Fossa/Analyze/UploadSpec.hs | 4 ++-- test/App/Fossa/Container/AnalyzeNativeSpec.hs | 2 +- test/App/Fossa/FirstPartyScanSpec.hs | 10 +++++----- test/App/Fossa/LernieSpec.hs | 2 +- test/App/Fossa/LicenseScannerSpec.hs | 6 +++--- test/Test/Fixtures.hs | 4 ++-- 10 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/App/Fossa/Lernie/Analyze.hs b/src/App/Fossa/Lernie/Analyze.hs index 2a7532f7c2..555b8b5116 100644 --- a/src/App/Fossa/Lernie/Analyze.hs +++ b/src/App/Fossa/Lernie/Analyze.hs @@ -304,6 +304,6 @@ createLicenseUnitSingles ((path, title), licenseUnitData) = , licenseUnitDir = "" , licenseUnitFiles = NE.singleton (unCustomLicensePath path) , licenseUnitData = NE.singleton licenseUnitData - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] , licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Just $ "custom license search " <> unCustomLicenseTitle title} } diff --git a/src/App/Fossa/ManualDeps.hs b/src/App/Fossa/ManualDeps.hs index fb15ca9fe4..58e9429a7b 100644 --- a/src/App/Fossa/ManualDeps.hs +++ b/src/App/Fossa/ManualDeps.hs @@ -206,7 +206,7 @@ toSourceUnit root depsFile manualDeps@ManualDependencies{..} maybeApiOpts vendor , sourceUnitType = "user-specific-yaml" , sourceUnitBuild = build , sourceUnitGraphBreadth = Complete - , sourceUnitNoticeFiles = Nothing + , sourceUnitNoticeFiles = [] , sourceUnitOriginPaths = [someBaseToOriginPath originPath] , additionalData = additional } @@ -427,24 +427,24 @@ instance FromJSON ReferencedDependency where <$> (obj `neText` "name") <*> pure depType <*> (unTextLike <$$> obj .:? "version") - <* forbidNonRefDepFields obj - <* forbidLinuxFields depType obj - <* forbidEpoch depType obj + <* forbidNonRefDepFields obj + <* forbidLinuxFields depType obj + <* forbidEpoch depType obj ) parseApkOrDebDependency :: Object -> DepType -> Parser ReferencedDependency parseApkOrDebDependency obj depType = LinuxApkDebDep <$> parseLinuxDependency obj depType - <* forbidNonRefDepFields obj - <* forbidEpoch depType obj + <* forbidNonRefDepFields obj + <* forbidEpoch depType obj parseRpmDependency :: Object -> DepType -> Parser ReferencedDependency parseRpmDependency obj depType = LinuxRpmDep <$> parseLinuxDependency obj depType <*> (unTextLike <$$> obj .:? "epoch") - <* forbidNonRefDepFields obj + <* forbidNonRefDepFields obj parseLinuxDependency :: Object -> DepType -> Parser LinuxReferenceDependency parseLinuxDependency obj depType = @@ -511,7 +511,7 @@ instance FromJSON CustomDependency where <*> (obj `neText` "license") <*> obj .:? "metadata" - <* forbidMembers "custom dependencies" ["type", "path", "url"] obj + <* forbidMembers "custom dependencies" ["type", "path", "url"] obj instance FromJSON RemoteDependency where parseJSON = withObject "RemoteDependency" $ \obj -> do @@ -521,7 +521,7 @@ instance FromJSON RemoteDependency where <*> (obj `neText` "url") <*> obj .:? "metadata" - <* forbidMembers "remote dependencies" ["license", "path", "type"] obj + <* forbidMembers "remote dependencies" ["license", "path", "type"] obj validateRemoteDep :: (Has Diagnostics sig m) => RemoteDependency -> Organization -> m RemoteDependency validateRemoteDep r org = diff --git a/src/Srclib/Converter.hs b/src/Srclib/Converter.hs index 52e13df544..7e4d61f838 100644 --- a/src/Srclib/Converter.hs +++ b/src/Srclib/Converter.hs @@ -71,7 +71,7 @@ toSourceUnit leaveUnfiltered path dependencies projectType graphBreadth originPa , buildDependencies = deps } , sourceUnitGraphBreadth = graphBreadth - , sourceUnitNoticeFiles = Nothing + , sourceUnitNoticeFiles = [] , sourceUnitOriginPaths = originPaths , additionalData = Nothing } diff --git a/src/Srclib/Types.hs b/src/Srclib/Types.hs index bf1fbaadb3..8cfda99519 100644 --- a/src/Srclib/Types.hs +++ b/src/Srclib/Types.hs @@ -116,7 +116,7 @@ textToOriginPath = OriginPath . toString data SourceUnitNoticeFile = SourceUnitNoticeFile { sourceUnitNoticeFilePath :: Text , sourceUnitNoticeFileContents :: Text - , sourceUnitNoticeFileCopyrights :: Maybe (NonEmpty Text) + , sourceUnitNoticeFileCopyrights :: [Text] } deriving (Eq, Ord, Show) @@ -133,7 +133,7 @@ instance FromJSON SourceUnitNoticeFile where SourceUnitNoticeFile <$> obj .: "path" <*> obj .: "contents" - <*> obj .:? "copyrights" + <*> obj .:? "copyrights" .!= [] data FullSourceUnit = FullSourceUnit { fullSourceUnitName :: Text @@ -142,7 +142,7 @@ data FullSourceUnit = FullSourceUnit , fullSourceUnitManifest :: Maybe Text , fullSourceUnitBuild :: Maybe SourceUnitBuild , fullSourceUnitGraphBreadth :: GraphBreadth - , fullSourceUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile) + , fullSourceUnitNoticeFiles :: [SourceUnitNoticeFile] , fullSourceUnitOriginPaths :: [OriginPath] , fullSourceUnitAdditionalData :: Maybe AdditionalDepData , fullSourceUnitFiles :: Maybe (NonEmpty Text) @@ -231,7 +231,7 @@ data LicenseUnit = LicenseUnit , licenseUnitDir :: Text , licenseUnitFiles :: (NonEmpty Text) , licenseUnitData :: (NonEmpty LicenseUnitData) - , licenseUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile) + , licenseUnitNoticeFiles :: [SourceUnitNoticeFile] , licenseUnitInfo :: LicenseUnitInfo } deriving (Eq, Ord, Show) @@ -245,7 +245,7 @@ emptyLicenseUnit = , licenseUnitDir = "" , licenseUnitFiles = "" :| [] , licenseUnitData = emptyLicenseUnitData :| [] - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] , licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Nothing} } @@ -277,7 +277,7 @@ instance FromJSON LicenseUnit where <*> obj .: "Dir" <*> obj .: "Files" <*> obj .: "Data" - <*> obj .:? "NoticeFiles" + <*> obj .:? "NoticeFiles" .!= [] <*> obj .: "Info" newtype LicenseUnitInfo = LicenseUnitInfo @@ -381,7 +381,7 @@ data SourceUnit = SourceUnit -- ^ path to manifest file , sourceUnitBuild :: Maybe SourceUnitBuild , sourceUnitGraphBreadth :: GraphBreadth - , sourceUnitNoticeFiles :: Maybe (NonEmpty SourceUnitNoticeFile) + , sourceUnitNoticeFiles :: [SourceUnitNoticeFile] , sourceUnitOriginPaths :: [OriginPath] , additionalData :: Maybe AdditionalDepData } @@ -476,7 +476,7 @@ instance FromJSON SourceUnit where <*> obj .: "Manifest" <*> obj .:? "Build" <*> obj .: "GraphBreadth" - <*> obj .:? "NoticeFiles" + <*> obj .:? "NoticeFiles" .!= [] <*> obj .: "OriginPaths" <*> obj .:? "AdditionalDependencyData" diff --git a/test/App/Fossa/Analyze/UploadSpec.hs b/test/App/Fossa/Analyze/UploadSpec.hs index d99f8fe2bf..3a7452449c 100644 --- a/test/App/Fossa/Analyze/UploadSpec.hs +++ b/test/App/Fossa/Analyze/UploadSpec.hs @@ -88,7 +88,7 @@ expectedMergedFullSourceUnits = NE.fromList [fullSourceUnit, fullLicenseUnit] , fullSourceUnitFiles = Nothing , fullSourceUnitData = Nothing , fullSourceUnitInfo = Nothing - , fullSourceUnitNoticeFiles = Nothing + , fullSourceUnitNoticeFiles = [] } fullLicenseUnit = FullSourceUnit @@ -103,7 +103,7 @@ expectedMergedFullSourceUnits = NE.fromList [fullSourceUnit, fullLicenseUnit] , fullSourceUnitFiles = Just $ "" NE.:| [] , fullSourceUnitData = Just $ emptyLicenseUnitData NE.:| [] , fullSourceUnitInfo = Just LicenseUnitInfo{licenseUnitInfoDescription = Nothing} - , fullSourceUnitNoticeFiles = Nothing + , fullSourceUnitNoticeFiles = [] } expectGetSuccessWithReachability :: Has MockApi sig m => m () diff --git a/test/App/Fossa/Container/AnalyzeNativeSpec.hs b/test/App/Fossa/Container/AnalyzeNativeSpec.hs index 598578874c..70c5cabef7 100644 --- a/test/App/Fossa/Container/AnalyzeNativeSpec.hs +++ b/test/App/Fossa/Container/AnalyzeNativeSpec.hs @@ -236,7 +236,7 @@ jarsInContainerSpec = describe "Jars in Containers" $ do } , sourceUnitGraphBreadth = Complete , sourceUnitOriginPaths = [textToOriginPath "package-lock.json"] - , sourceUnitNoticeFiles = Nothing + , sourceUnitNoticeFiles = [] , additionalData = Nothing } diff --git a/test/App/Fossa/FirstPartyScanSpec.hs b/test/App/Fossa/FirstPartyScanSpec.hs index 0408ee04e7..826deb14cb 100644 --- a/test/App/Fossa/FirstPartyScanSpec.hs +++ b/test/App/Fossa/FirstPartyScanSpec.hs @@ -9,7 +9,7 @@ import Control.Algebra (Has) import Control.Effect.FossaApiClient (FossaApiClientF (..)) import Data.List qualified as List import Data.List.NonEmpty qualified as NE -import Data.Maybe (fromMaybe, isJust) +import Data.Maybe (isJust) import Data.Text (strip) import Fossa.API.Types (Organization (..)) import Path (Dir, Path, Rel, mkRelDir, ()) @@ -114,12 +114,12 @@ spec = do let noticeUnit = NE.head units licenseUnitName noticeUnit `shouldBe'` "" licenseUnitType noticeUnit `shouldBe'` "NoticeFileMatches" - let noticeFiles = fromMaybe (NE.fromList []) (licenseUnitNoticeFiles noticeUnit) + let noticeFiles = licenseUnitNoticeFiles noticeUnit length noticeFiles `shouldBe'` 1 - let noticeFile = NE.head noticeFiles - let copyrights = fromMaybe (NE.fromList []) (sourceUnitNoticeFileCopyrights noticeFile) + let noticeFile = head noticeFiles + let copyrights = sourceUnitNoticeFileCopyrights noticeFile length copyrights `shouldBe'` 1 - let copyright = NE.head copyrights + let copyright = head copyrights copyright `shouldBe'` "2024 Frank Frankson" strip (sourceUnitNoticeFileContents noticeFile) `shouldBe'` "This is a notice file that is copyright 2024 Frank Frankson" sourceUnitNoticeFilePath noticeFile `shouldBe'` "NOTICE.txt" diff --git a/test/App/Fossa/LernieSpec.hs b/test/App/Fossa/LernieSpec.hs index f4fa4575bd..69535b0dd4 100644 --- a/test/App/Fossa/LernieSpec.hs +++ b/test/App/Fossa/LernieSpec.hs @@ -172,7 +172,7 @@ expectedLicenseUnit = , licenseUnitFiles = NE.singleton $ toText . toFilePath $ absDir $(mkRelDir "two.txt") , licenseUnitData = NE.singleton expectedUnitData , licenseUnitInfo = LicenseUnitInfo{licenseUnitInfoDescription = Just "custom license search Proprietary License"} - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] } expectedDoubleSourceUnit :: LicenseSourceUnit diff --git a/test/App/Fossa/LicenseScannerSpec.hs b/test/App/Fossa/LicenseScannerSpec.hs index 67974127c6..b2a9ffaf65 100644 --- a/test/App/Fossa/LicenseScannerSpec.hs +++ b/test/App/Fossa/LicenseScannerSpec.hs @@ -43,7 +43,7 @@ unitOne = , licenseUnitFiles = NE.fromList ["foo/bar/LICENSE", "foo/bar/one.txt"] , licenseUnitInfo = info - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] } unitTwo :: LicenseUnit @@ -56,7 +56,7 @@ unitTwo = , licenseUnitData = NE.fromList [emptyLicenseUnitData{licenseUnitDataPath = "foo/bar/baz/ANOTHER_LICENSE"}, emptyLicenseUnitData{licenseUnitDataPath = "foo/bar/baz/two.txt"}] , licenseUnitFiles = NE.fromList ["foo/bar/baz/ANOTHER_LICENSE", "foo/bar/baz/two.txt"] , licenseUnitInfo = info - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] } expectedCombinedUnit :: LicenseUnit expectedCombinedUnit = @@ -80,7 +80,7 @@ expectedCombinedUnit = , "foo/bar/one.txt" ] , licenseUnitInfo = info - , licenseUnitNoticeFiles = Nothing + , licenseUnitNoticeFiles = [] } fixtureDir :: Path Rel Dir diff --git a/test/Test/Fixtures.hs b/test/Test/Fixtures.hs index 41aa63336d..7bc753afc4 100644 --- a/test/Test/Fixtures.hs +++ b/test/Test/Fixtures.hs @@ -244,7 +244,7 @@ sourceUnits = [unit] , sourceUnitBuild = Nothing , sourceUnitGraphBreadth = Complete , sourceUnitOriginPaths = [] - , sourceUnitNoticeFiles = Nothing + , sourceUnitNoticeFiles = [] , additionalData = Nothing } @@ -311,7 +311,7 @@ vsiSourceUnit = } , sourceUnitGraphBreadth = Complete , sourceUnitOriginPaths = ["/tmp/one/two"] - , sourceUnitNoticeFiles = Nothing + , sourceUnitNoticeFiles = [] , additionalData = Nothing }