Skip to content

Commit

Permalink
✨ add file pattern to filecontent rules (#92)
Browse files Browse the repository at this point in the history
* ✨ add file pattern to filecontent rules

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>

* ✨ fix more regexes

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>

---------

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Sep 20, 2023
1 parent 3167090 commit 241f23d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string
//}
condition := map[string]interface{}{
"builtin.filecontent": map[string]interface{}{
"pattern": convertWindupRegex(substituteWhere(where, fc.Pattern)),
//"filePattern": files,
"pattern": convertWindupRegex(substituteWhere(where, fc.Pattern)),
"filePattern": escapeDots(convertWindupRegex(substituteWhere(where, fc.Filename))),
},
}
if fc.As != "" {
Expand All @@ -405,9 +405,15 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string
pattern = strings.Replace(pattern, `(.*)?.`, ".*", -1)
pattern = strings.Replace(pattern, `.[^.]+`, "*", -1)
pattern = strings.Replace(pattern, `[^.]+`, "*", -1)
pattern = strings.Replace(pattern, `[^.()]+`, "*", -1)
pattern = strings.Replace(pattern, `(.[^.]*)*`, "*", -1)
pattern = strings.Replace(pattern, `+[^.]*?`, "*", -1)
pattern = strings.Replace(pattern, `[*]`, `\[*\]`, -1)
pattern = strings.Replace(pattern, `([a-z]+.)`, `*`, -1)
// remove open paranthesis which will be otherwise interpreted as wildcards
pattern = regexp.MustCompile(`\(\*$`).ReplaceAllString(pattern, "*")
pattern = regexp.MustCompile(`\(\)`).ReplaceAllString(pattern, "*")
pattern = regexp.MustCompile(`\[\]`).ReplaceAllString(pattern, "*")
// cascade multiple dots and stars
pattern = regexp.MustCompile(`[\.]{2,}\*`).ReplaceAllString(pattern, ".*")
pattern = regexp.MustCompile(`[\*]{2,}`).ReplaceAllString(pattern, "*")
Expand Down

0 comments on commit 241f23d

Please sign in to comment.