Skip to content

Commit 5ed5e21

Browse files
committed
[ANE-1070] Pass licenseScanPathFilters to lernie
1 parent 99c8247 commit 5ed5e21

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

src/App/Fossa/Analyze.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ analyze cfg = Diag.context "fossa-analyze" $ do
338338
then do
339339
logInfo "Running in VSI only mode, skipping keyword search and custom-license search"
340340
pure Nothing
341-
else Diag.context "custom-license & keyword search" . runStickyLogger SevInfo $ analyzeWithLernie basedir maybeApiOpts grepOptions
341+
else Diag.context "custom-license & keyword search" . runStickyLogger SevInfo $ analyzeWithLernie basedir maybeApiOpts grepOptions $ Config.licenseScanPathFilters vendoredDepsOptions
342342
let lernieResults = join . resultToMaybe $ maybeLernieResults
343343

344344
let -- This makes nice with additionalSourceUnits below, but throws out additional Result data.

src/App/Fossa/Config/Common.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ collectBaseFile ::
286286
, Has (Lift IO) sig m
287287
, Has ReadFS sig m
288288
) =>
289-
FilePath -> m (Path Abs File)
289+
FilePath ->
290+
m (Path Abs File)
290291
collectBaseFile = validateFile
291292

292293
validateDir ::

src/App/Fossa/Config/Report.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ mergeOpts cfgfile envvars ReportCliOptions{..} = do
243243
, Has ReadFS sig m
244244
, Has Diagnostics sig m
245245
) =>
246-
Text -> OverrideProject -> m (ProjectRevision, ReportBase)
246+
Text ->
247+
OverrideProject ->
248+
m (ProjectRevision, ReportBase)
247249
generateDirOrSBOMBase path projectOverride = do
248250
basedir <- Diag.recover $ collectBaseDir (Conv.toString path)
249251
case basedir of

src/App/Fossa/Lernie/Analyze.hs

+15-11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import Effect.ReadFS (ReadFS)
5454
import Fossa.API.Types (ApiOpts, Organization (..), orgFileUpload)
5555
import Path (Abs, Dir, File, Path)
5656
import Srclib.Types (LicenseScanType (..), LicenseSourceUnit (..), LicenseUnit (..), LicenseUnitData (..), LicenseUnitInfo (..), LicenseUnitMatchData (..))
57+
import Types (LicenseScanPathFilters)
5758

5859
newtype CustomLicensePath = CustomLicensePath {unCustomLicensePath :: Text}
5960
deriving (Eq, Ord, Show, Hashable)
@@ -72,12 +73,13 @@ analyzeWithLernie ::
7273
Path Abs Dir ->
7374
Maybe ApiOpts ->
7475
GrepOptions ->
76+
Maybe LicenseScanPathFilters ->
7577
m (Maybe LernieResults)
76-
analyzeWithLernie rootDir maybeApiOpts grepOptions = do
78+
analyzeWithLernie rootDir maybeApiOpts grepOptions filters = do
7779
case (maybeApiOpts, orgWideCustomLicenseScanConfigPolicy grepOptions) of
78-
(_, Ignore) -> analyzeWithLernieMain rootDir grepOptions FileUploadMatchData
79-
(Nothing, Use) -> analyzeWithLernieMain rootDir grepOptions FileUploadMatchData
80-
(Just apiOpts, Use) -> runFossaApiClient apiOpts $ analyzeWithLernieWithOrgInfo rootDir grepOptions
80+
(_, Ignore) -> analyzeWithLernieMain rootDir grepOptions filters FileUploadMatchData
81+
(Nothing, Use) -> analyzeWithLernieMain rootDir grepOptions filters FileUploadMatchData
82+
(Just apiOpts, Use) -> runFossaApiClient apiOpts $ analyzeWithLernieWithOrgInfo rootDir grepOptions filters
8183

8284
analyzeWithLernieWithOrgInfo ::
8385
( Has Diagnostics sig m
@@ -89,14 +91,15 @@ analyzeWithLernieWithOrgInfo ::
8991
) =>
9092
Path Abs Dir ->
9193
GrepOptions ->
94+
Maybe LicenseScanPathFilters ->
9295
m (Maybe LernieResults)
93-
analyzeWithLernieWithOrgInfo rootDir grepOptions = do
96+
analyzeWithLernieWithOrgInfo rootDir grepOptions filters = do
9497
org <- getOrganization
9598
let orgWideCustomLicenses = orgCustomLicenseScanConfigs org
9699
uploadKind = orgFileUpload org
97100

98101
let options = grepOptions{customLicenseSearch = nub $ orgWideCustomLicenses <> customLicenseSearch grepOptions}
99-
analyzeWithLernieMain rootDir options uploadKind
102+
analyzeWithLernieMain rootDir options filters uploadKind
100103

101104
analyzeWithLernieMain ::
102105
( Has Diagnostics sig m
@@ -107,10 +110,11 @@ analyzeWithLernieMain ::
107110
) =>
108111
Path Abs Dir ->
109112
GrepOptions ->
113+
Maybe LicenseScanPathFilters ->
110114
FileUpload ->
111115
m (Maybe LernieResults)
112-
analyzeWithLernieMain rootDir grepOptions uploadKind = do
113-
let maybeLernieConfig = grepOptionsToLernieConfig rootDir grepOptions uploadKind
116+
analyzeWithLernieMain rootDir grepOptions filters uploadKind = do
117+
let maybeLernieConfig = grepOptionsToLernieConfig rootDir grepOptions filters uploadKind
114118
case maybeLernieConfig of
115119
Just lernieConfig -> do
116120
unless (null $ customLicenseSearch grepOptions) $ trackUsage CustomLicenseSearchUsage
@@ -120,11 +124,11 @@ analyzeWithLernieMain rootDir grepOptions uploadKind = do
120124
pure $ Just lernieResults
121125
Nothing -> pure Nothing
122126

123-
grepOptionsToLernieConfig :: Path Abs Dir -> GrepOptions -> FileUpload -> Maybe LernieConfig
124-
grepOptionsToLernieConfig rootDir grepOptions uploadKind =
127+
grepOptionsToLernieConfig :: Path Abs Dir -> GrepOptions -> Maybe LicenseScanPathFilters -> FileUpload -> Maybe LernieConfig
128+
grepOptionsToLernieConfig rootDir grepOptions filters uploadKind =
125129
case (customLicenseSearches <> keywordSearches) of
126130
[] -> Nothing
127-
res -> Just . LernieConfig rootDir res $ case uploadKind of
131+
res -> Just . LernieConfig rootDir res filters $ case uploadKind of
128132
FileUploadMatchData -> False
129133
FileUploadFullContent -> True
130134
where

src/App/Fossa/Lernie/Types.hs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Data.Text (Text)
2424
import GHC.Generics (Generic)
2525
import Path (Abs, Dir, File, Path)
2626
import Srclib.Types (LicenseSourceUnit)
27+
import Types (LicenseScanPathFilters (..))
2728

2829
data OrgWideCustomLicenseConfigPolicy = Use | Ignore
2930
deriving (Eq, Ord, Show)
@@ -72,6 +73,7 @@ instance FromJSON GrepEntry where
7273
data LernieConfig = LernieConfig
7374
{ rootDir :: Path Abs Dir
7475
, regexes :: [LernieRegex]
76+
, licenseScanPathFilters :: Maybe LicenseScanPathFilters
7577
, fullFiles :: Bool
7678
}
7779
deriving (Eq, Ord, Show, Generic)
@@ -81,6 +83,7 @@ instance ToJSON LernieConfig where
8183
object
8284
[ "root_dir" .= toText rootDir
8385
, "regexes" .= toJSON regexes
86+
, "license_scan_path_filters" .= toJSON licenseScanPathFilters
8487
, "full_files" .= fullFiles
8588
]
8689

test/App/Fossa/LernieSpec.hs

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Test.Effect (expectationFailure', it', shouldBe')
2626
import Test.Fixtures qualified as Fixtures
2727
import Test.Hspec (Spec, describe, it, runIO, shouldBe)
2828
import Test.MockApi (alwaysReturns)
29+
import Types (GlobFilter (GlobFilter), LicenseScanPathFilters (..))
2930

3031
customLicenseLernieMatchData :: LernieMatchData
3132
customLicenseLernieMatchData =
@@ -264,6 +265,13 @@ expectedLernieConfig =
264265
LernieConfig
265266
{ rootDir = absDir
266267
, regexes = [customLicenseLernieRegex, keywordSearchLernieRegex]
268+
, licenseScanPathFilters =
269+
Just
270+
LicenseScanPathFilters
271+
{ licenseScanPathFiltersOnly = [GlobFilter "/*", GlobFilter "/**"]
272+
, licenseScanPathFiltersExclude = [GlobFilter "/*", GlobFilter "/**"]
273+
, licenseScanPathFilterFileExclude = []
274+
}
267275
, fullFiles = False
268276
}
269277

0 commit comments

Comments
 (0)