From f25396f5bc949ae7e5b929ba38018db77e32ae6c Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Wed, 23 Aug 2023 11:30:30 +0200 Subject: [PATCH 1/4] Handle public-id and system-id XML attributes XML buildin rule supported only "matches" option, enabling system-id and public-id. Related to https://github.com/konveyor/analyzer-lsp/issues/221 Signed-off-by: Marek Aufart --- pkg/conversion/convert.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index 6efea8d8..440bf87c 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -455,21 +455,43 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string } if windupWhen.Xmlfile != nil { for _, xf := range windupWhen.Xmlfile { - if xf.Matches == "" { - // TODO handle systemid and publicid - continue - } - matches := strings.Replace(xf.Matches, "windup:", "", -1) + var xmlCond map[string]interface{} + namespaces := map[string]string{} if xf.Namespace != nil { for _, ns := range xf.Namespace { namespaces[ns.Prefix] = ns.Uri } } - xmlCond := map[string]interface{}{ - "xpath": substituteWhere(where, matches), - "namespaces": namespaces, + + if xf.Matches != "" { + matches := strings.Replace(xf.Matches, "windup:", "", -1) + xmlCond = map[string]interface{}{ + "xpath": substituteWhere(where, matches), + "namespaces": namespaces, + } + } + + if xf.Publicid != "" { // + matches := strings.Replace(xf.Matches, "windup:", "", -1) + xmlCond = map[string]interface{}{ + "xpath": "//*[@public-id='regexp:"+substituteWhere(where, matches)+"']", + "namespaces": namespaces, + } + } + + if xf.Systemid != "" { // + matches := strings.Replace(xf.Matches, "windup:", "", -1) + xmlCond = map[string]interface{}{ + "xpath": "//*[@system-id='"+substituteWhere(where, matches)+"']", + "namespaces": namespaces, + } + } + + if xmlCond == nil { + continue } + // TODO We don't support regexes here, may need to break it out into a separate lookup that gets passed through if xf.In != "" { in := substituteWhere(where, xf.In) From a437cf216c97a7112d2bd5ad7a0ed25777b299fc Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Fri, 25 Aug 2023 11:05:31 +0200 Subject: [PATCH 2/4] Add XMLPublicid condition Signed-off-by: Marek Aufart --- pkg/conversion/convert.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index 440bf87c..e2b44025 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -455,6 +455,7 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string } if windupWhen.Xmlfile != nil { for _, xf := range windupWhen.Xmlfile { + var condType = "builtin.xml" var xmlCond map[string]interface{} namespaces := map[string]string{} @@ -472,18 +473,19 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string } } - if xf.Publicid != "" { // + if xf.Systemid != "" { matches := strings.Replace(xf.Matches, "windup:", "", -1) xmlCond = map[string]interface{}{ - "xpath": "//*[@public-id='regexp:"+substituteWhere(where, matches)+"']", + "xpath": "//*[@system-id='"+substituteWhere(where, matches)+"']", "namespaces": namespaces, } } - if xf.Systemid != "" { // + if xf.Publicid != "" { + condType = "builtin.xmlPublicid" matches := strings.Replace(xf.Matches, "windup:", "", -1) xmlCond = map[string]interface{}{ - "xpath": "//*[@system-id='"+substituteWhere(where, matches)+"']", + "regex": substituteWhere(where, matches), "namespaces": namespaces, } } @@ -492,7 +494,6 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string continue } - // TODO We don't support regexes here, may need to break it out into a separate lookup that gets passed through if xf.In != "" { in := substituteWhere(where, xf.In) if strings.Contains(in, "{*}") { @@ -517,7 +518,7 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string } } condition := map[string]interface{}{ - "builtin.xml": xmlCond, + condType: xmlCond, } if xf.As != "" { condition["as"] = xf.As From d193d5eebc3839e64b21b2eb4794599cd84b38b5 Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Fri, 25 Aug 2023 11:08:09 +0200 Subject: [PATCH 3/4] Fix formatting Signed-off-by: Marek Aufart --- pkg/conversion/convert.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index e2b44025..4fc8a728 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -467,33 +467,32 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string if xf.Matches != "" { matches := strings.Replace(xf.Matches, "windup:", "", -1) - xmlCond = map[string]interface{}{ - "xpath": substituteWhere(where, matches), - "namespaces": namespaces, - } + xmlCond = map[string]interface{}{ + "xpath": substituteWhere(where, matches), + "namespaces": namespaces, + } } if xf.Systemid != "" { matches := strings.Replace(xf.Matches, "windup:", "", -1) - xmlCond = map[string]interface{}{ - "xpath": "//*[@system-id='"+substituteWhere(where, matches)+"']", - "namespaces": namespaces, - } + xmlCond = map[string]interface{}{ + "xpath": "//*[@system-id='" + substituteWhere(where, matches) + "']", + "namespaces": namespaces, + } } if xf.Publicid != "" { - condType = "builtin.xmlPublicid" + condType = "builtin.xmlPublicid" matches := strings.Replace(xf.Matches, "windup:", "", -1) - xmlCond = map[string]interface{}{ - "regex": substituteWhere(where, matches), - "namespaces": namespaces, - } + xmlCond = map[string]interface{}{ + "regex": substituteWhere(where, matches), + "namespaces": namespaces, + } } if xmlCond == nil { continue } - if xf.In != "" { in := substituteWhere(where, xf.In) if strings.Contains(in, "{*}") { From 5fc2a1a3538186903f1e1ef9b7e636ef94bbd64a Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Wed, 22 Nov 2023 15:12:21 +0100 Subject: [PATCH 4/4] Update XMLPublicID condition name Signed-off-by: Marek Aufart --- pkg/conversion/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/conversion/convert.go b/pkg/conversion/convert.go index 4fc8a728..c44b4c8d 100644 --- a/pkg/conversion/convert.go +++ b/pkg/conversion/convert.go @@ -482,7 +482,7 @@ func convertWindupWhenToAnalyzer(windupWhen windup.When, where map[string]string } if xf.Publicid != "" { - condType = "builtin.xmlPublicid" + condType = "builtin.xmlPublicID" matches := strings.Replace(xf.Matches, "windup:", "", -1) xmlCond = map[string]interface{}{ "regex": substituteWhere(where, matches),