How to make wildcard search for repository workspaces using Plain Java API
In Eclipse I can serach for repository workspaces using a pattern including the wildcards * and ?, where * means any sequence of chars, and ? means any single char.
I tried this using plain java api, but found that it did not work.
String pattern = "abc-???_cde"; IWorkspaceSearchCriteria wsSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance(); wsSearchCriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES); wsSearchCriteria.setPartialName(pattern);The search did not find the workspaces with names 'abc-123_cde' or 'abc-666_cde'
After some investigation I found that the eclipse client calls a Util class that converts the search pattern, before calling the API.
The conversion looks like this
switch (ch) { case '*': buffer.append("%"); break; case '?': buffer.append("_"); break; case '%': buffer.append("\\%"); break; case '_': buffer.append("\\_"); break; case '\\': buffer.append("\\\\"); break; default: buffer.append(ch); }
So to the above search pattern should be converted to "abc-___\\_cde" then it worked just fine, and it finds both of the above workspaces,
Hope someone can make use of this information.
|
Accepted answer
As explained in the question, it can be done by converting * and ? properly.
Ralph Schoon selected this answer as the correct answer
Comments
Ralph Schoon
commented Oct 09 '14, 10:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Thanks for sharing Martin!
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.