Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle public-id and system-id xmlfile conditions #87

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" { // <xmlfile public-id=".*JBoss.+DTD Java EE.+5.*"/>
matches := strings.Replace(xf.Matches, "windup:", "", -1)
xmlCond = map[string]interface{}{
"xpath": "//*[@public-id='regexp:"+substituteWhere(where, matches)+"']",
Copy link
Member Author

@aufi aufi Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xpath module in analyzer doesn't look to support regexps. Considering update https://github.com/konveyor/analyzer-lsp/blob/main/provider/internal/builtin/service_client.go#L181 with someling like:

  • if the xpath starts with //*[@public-id='regexp:, take the reg.expression and update xpath to //*[@public-id]
  • search for the updated xpath (all nodes with public-id attribute)
  • iterate found nodes in loop and check if regexp matches (by golang)

Other option could be extend xmlCond struct to store regexp there, but I'm open to all possible suggestions!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards storing the regex in the xmlCond explicitly, but if the behavior of pulling it out automatically is consistently unsurprising I'd be cool with that too.

@shawn-hurley thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this,

  1. having some regexp interspersed, for a particular submatch makes me feel like too much magic.
  2. Looks like matches and system-id's will work, without the need for regex

I would vote for a whole new XML cond, xml-publicid or something, that has a regexp as a field. This way it is clear the only thing that will do a regex submatch is this particular condition?

What do you all think? Am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shawn-hurley that sounds good to me too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, going to make a xml-publicid condition.

"namespaces": namespaces,
}
}

if xf.Systemid != "" { // <xmlfile system-id="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" />
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)
Expand Down
Loading