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.