use of org.apache.ivy.plugins.namespace.Namespace in project ant-ivy by apache.
the class SearchEngine method findModuleRevisionIds.
public Collection<ModuleRevisionId> findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern, PatternMatcher matcher) {
Collection<ModuleRevisionId> 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 = resolver.getNamespace();
}
Collection<ModuleEntry> 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 (OrganisationEntry oe : orgs) {
String org = oe.getOrganisation();
String systemOrg = (fromNamespace == null) ? org : 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 (ModuleEntry mEntry : modules) {
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 (RevisionEntry rEntry : rEntries) {
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;
mrids.add(systemMrid);
}
}
if (!foundRevision) {
Message.debug("no revision found matching " + pattern + " in [" + mEntry.getOrganisation() + "," + mEntry.getModule() + "] using " + resolverName);
}
}
}
if (!foundModule) {
Message.debug("no module found matching " + pattern + " using " + resolverName);
}
return mrids;
}
use of org.apache.ivy.plugins.namespace.Namespace in project ant-ivy by apache.
the class XmlModuleDescriptorParser method toIvyFile.
public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) throws IOException, ParseException {
try {
Namespace ns = null;
if (md instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
ns = dmd.getNamespace();
}
XmlModuleDescriptorUpdater.update(is, res, destFile, new UpdateOptions().setSettings(IvyContext.getContext().getSettings()).setStatus(md.getStatus()).setRevision(md.getResolvedModuleRevisionId().getRevision()).setPubdate(md.getResolvedPublicationDate()).setUpdateBranch(false).setNamespace(ns));
} catch (SAXException e) {
ParseException pe = new ParseException("exception occurred while parsing " + res, 0);
pe.initCause(e);
throw pe;
} finally {
if (is != null) {
is.close();
}
}
}
Aggregations