Skip to content

Commit

Permalink
🐛 AND chain items more intelligently
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Feb 8, 2024
1 parent e066e5a commit 26f85e8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func ConvertWindupRulesetToAnalyzer(ruleset windup.Ruleset) []map[string]interfa
if len(when) == 1 {
rule["when"] = when[0]
} else if len(when) > 1 {
rule["when"] = map[string]interface{}{"or": when}
if canUseAndToChain(when) {
rule["when"] = map[string]interface{}{"and": when}
} else {
rule["when"] = map[string]interface{}{"or": when}
}
} else {
continue
}
Expand Down Expand Up @@ -983,3 +987,28 @@ func escapeParens(s string) string {
s = strings.Replace(s, ")", "\\)", -1)
return s
}

// canUseAndToChain when converting chained conditions, we check if they can
// be ANDed...it improves accuracy: https://github.com/konveyor/rulesets/issues/41
// we can only do this for builtin conditions reliably
func canUseAndToChain(when []map[string]interface{}) bool {
canDetermine := true
fromUsed := false
asUsed := false
for _, cond := range when {
for key := range cond {
// if any one condition is java, we can't make this an AND
if strings.HasPrefix(key, "java") {
canDetermine = false
break
}
if key == "from" {
fromUsed = true
}
if key == "as" {
asUsed = true
}
}
}
return canDetermine && fromUsed && asUsed
}

0 comments on commit 26f85e8

Please sign in to comment.