PatternMatcher matcher) {
Collection mrids = new ArrayList();
String resolverName = resolver.getName();
Message.verbose("looking for modules matching " + pattern + " using " + matcher.getName());
Namespace fromNamespace = null;
if (resolver instanceof AbstractResolver) {
fromNamespace = ((AbstractResolver) resolver).getNamespace();
}
Collection modules = new ArrayList();
OrganisationEntry[] orgs = resolver.listOrganisations();
if (orgs == null || orgs.length == 0) {
// hack for resolvers which are not able to list organisation, we try to see if the
// asked organisation is not an exact one:
String org = pattern.getOrganisation();
if (fromNamespace != null) {
org = NameSpaceHelper.transform(pattern.getModuleId(),
fromNamespace.getFromSystemTransformer()).getOrganisation();
}
modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(resolver, org))));
} else {
Matcher orgMatcher = matcher.getMatcher(pattern.getOrganisation());
for (int i = 0; i < orgs.length; i++) {
String org = orgs[i].getOrganisation();
String systemOrg = org;
if (fromNamespace != null) {
systemOrg = NameSpaceHelper.transformOrganisation(org,
fromNamespace.getToSystemTransformer());
}
if (orgMatcher.matches(systemOrg)) {
modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(
resolver, org))));
}
}
}
Message.debug("found " + modules.size() + " modules for " + pattern.getOrganisation()
+ " on " + resolverName);
boolean foundModule = false;
for (Iterator iter = modules.iterator(); iter.hasNext();) {
ModuleEntry mEntry = (ModuleEntry) iter.next();
ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
ModuleId systemMid = foundMid;
if (fromNamespace != null) {
systemMid = NameSpaceHelper.transform(foundMid,
fromNamespace.getToSystemTransformer());
}
if (MatcherHelper.matches(matcher, pattern.getModuleId(), systemMid)) {
// The module corresponds to the searched module pattern
foundModule = true;
RevisionEntry[] rEntries = resolver.listRevisions(mEntry);
Message.debug("found " + rEntries.length + " revisions for ["
+ mEntry.getOrganisation() + ", " + mEntry.getModule() + "] on "
+ resolverName);
boolean foundRevision = false;
for (int j = 0; j < rEntries.length; j++) {
RevisionEntry rEntry = rEntries[j];
ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(
mEntry.getOrganisation(), mEntry.getModule(), rEntry.getRevision());
ModuleRevisionId systemMrid = foundMrid;
if (fromNamespace != null) {
systemMrid = fromNamespace.getToSystemTransformer().transform(foundMrid);
}
if (MatcherHelper.matches(matcher, pattern, systemMrid)) {
// We have a matching module revision
foundRevision = true;