Java Code Examples for org.apache.ivy.plugins.resolver.DependencyResolver#listTokenValues()

The following examples show how to use org.apache.ivy.plugins.resolver.DependencyResolver#listTokenValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public ModuleEntry[] listModuleEntries(OrganisationEntry org) {
    Set<ModuleEntry> entries = new HashSet<>();

    Map<String, Object> tokenValues = new HashMap<>();
    tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] modules = resolver.listTokenValues(
            new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
        for (Map<String, String> me : modules) {
            String module = me.get(IvyPatternHelper.MODULE_KEY);
            entries.add(new ModuleEntry(org, module));
        }
    }

    return entries.toArray(new ModuleEntry[entries.size()]);
}
 
Example 2
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public String[] listModules(String org) {
    Set<String> entries = new HashSet<>();

    Map<String, Object> tokenValues = new HashMap<>();
    tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org);

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] modules = resolver.listTokenValues(
            new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
        for (Map<String, String> module : modules) {
            entries.add(module.get(IvyPatternHelper.MODULE_KEY));
        }
    }

    return entries.toArray(new String[entries.size()]);
}
 
Example 3
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public RevisionEntry[] listRevisionEntries(ModuleEntry module) {
    Set<RevisionEntry> entries = new HashSet<>();

    Map<String, Object> tokenValues = new HashMap<>();
    tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, module.getOrganisation());
    tokenValues.put(IvyPatternHelper.MODULE_KEY, module.getModule());

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] revisions = resolver.listTokenValues(
            new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
        for (Map<String, String> revision : revisions) {
            entries.add(new RevisionEntry(module, revision.get(IvyPatternHelper.REVISION_KEY)));
        }
    }

    return entries.toArray(new RevisionEntry[entries.size()]);
}
 
Example 4
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public String[] listRevisions(String org, String module) {
    Set<String> entries = new HashSet<>();

    Map<String, Object> tokenValues = new HashMap<>();
    tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org);
    tokenValues.put(IvyPatternHelper.MODULE_KEY, module);

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] revisions = resolver.listTokenValues(
            new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
        for (Map<String, String> revision : revisions) {
            entries.add(revision.get(IvyPatternHelper.REVISION_KEY));
        }
    }

    return entries.toArray(new String[entries.size()]);
}
 
Example 5
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * List module ids of the module accessible through the current resolvers matching the given mid
 * criteria according to the given matcher.
 * <p>
 * ModuleId are returned in the system namespace.
 * </p>
 *
 * @param moduleCrit ModuleId
 * @param matcher PatternMatcher
 * @return ModuleId[]
 */
public ModuleId[] listModules(ModuleId moduleCrit, PatternMatcher matcher) {
    List<ModuleId> ret = new ArrayList<>();

    Map<String, Object> criteria = new HashMap<>();
    addMatcher(matcher, moduleCrit.getOrganisation(), criteria,
        IvyPatternHelper.ORGANISATION_KEY);
    addMatcher(matcher, moduleCrit.getName(), criteria, IvyPatternHelper.MODULE_KEY);

    String[] tokensToList = new String[] {IvyPatternHelper.ORGANISATION_KEY,
            IvyPatternHelper.MODULE_KEY};

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
        for (Map<String, String> moduleId : moduleIdAsMap) {
            String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
            String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
            ModuleId modId = ModuleId.newInstance(org, name);
            ret.add(NameSpaceHelper.transform(modId, resolver.getNamespace()
                    .getToSystemTransformer()));
        }
    }

    return ret.toArray(new ModuleId[ret.size()]);
}
 
Example 6
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an empty array when no token values are found.
 *
 * @param token
 *            ditto
 * @param otherTokenValues Map
 * @return String[]
 */
public String[] listTokenValues(String token, Map<String, Object> otherTokenValues) {
    Set<String> entries = new LinkedHashSet<>();

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] values = resolver.listTokenValues(new String[] {token},
            otherTokenValues);
        for (Map<String, String> value : values) {
            entries.add(value.get(token));
        }
    }

    return entries.toArray(new String[entries.size()]);
}
 
Example 7
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public OrganisationEntry[] listOrganisationEntries() {
    Set<OrganisationEntry> entries = new HashSet<>();

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] orgs = resolver.listTokenValues(
            new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
        for (Map<String, String> oe : orgs) {
            String org = oe.get(IvyPatternHelper.ORGANISATION_KEY);
            entries.add(new OrganisationEntry(resolver, org));
        }
    }

    return entries.toArray(new OrganisationEntry[entries.size()]);
}
 
Example 8
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public String[] listOrganisations() {
    Set<String> entries = new HashSet<>();

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] orgs = resolver.listTokenValues(
            new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
        for (Map<String, String> org : orgs) {
            entries.add(org.get(IvyPatternHelper.ORGANISATION_KEY));
        }
    }

    return entries.toArray(new String[entries.size()]);
}
 
Example 9
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * List module revision ids of the module accessible through the current resolvers matching the
 * given mrid criteria according to the given matcher.
 * <p>
 * ModuleRevisionId are returned in the system namespace.
 * </p>
 *
 * @param moduleCrit ModuleRevisionId
 * @param matcher PatternMatcher
 * @return ModuleRevisionId[]
 */
public ModuleRevisionId[] listModules(ModuleRevisionId moduleCrit, PatternMatcher matcher) {
    List<ModuleRevisionId> ret = new ArrayList<>();

    Map<String, Object> criteria = new HashMap<>();
    for (Map.Entry<String, String> entry : moduleCrit.getAttributes().entrySet()) {
        addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
    }

    String[] tokensToList = moduleCrit.getAttributes().keySet()
            .toArray(new String[moduleCrit.getAttributes().size()]);

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
        for (Map<String, String> moduleId : moduleIdAsMap) {
            String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
            String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
            String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
            String rev = moduleId.get(IvyPatternHelper.REVISION_KEY);

            Map<String, String> foundExtraAtts = new HashMap<>();
            for (String qualifiedKey : moduleCrit.getQualifiedExtraAttributes().keySet()) {
                String value = null;
                int colonIndex = qualifiedKey.indexOf(':');
                if (colonIndex == -1) {
                    value = moduleId.get(qualifiedKey);
                } else {
                    value = moduleId.get(qualifiedKey.substring(colonIndex + 1));
                }

                if (value != null) {
                    foundExtraAtts.put(qualifiedKey, value);
                }
            }

            ModuleRevisionId modRevId = ModuleRevisionId.newInstance(org, name, branch, rev,
                foundExtraAtts);
            ret.add(resolver.getNamespace().getToSystemTransformer().transform(modRevId));
        }
    }

    return ret.toArray(new ModuleRevisionId[ret.size()]);
}
 
Example 10
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * List modules matching a given criteria, available in the given dependency resolver.
 * <p>
 * ModuleRevisionId are returned in the system namespace.
 * </p>
 *
 * @param resolver
 *            the resolver in which modules should looked up
 * @param moduleCrit
 *            the criteria to match
 * @param matcher
 *            the matcher to use to match criteria
 * @return an array of matching module revision ids
 */
public ModuleRevisionId[] listModules(DependencyResolver resolver, ModuleRevisionId moduleCrit,
        PatternMatcher matcher) {
    Map<String, Object> criteria = new HashMap<>();
    for (Map.Entry<String, String> entry : moduleCrit.getAttributes().entrySet()) {
        addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
    }

    String[] tokensToList = moduleCrit.getAttributes().keySet()
            .toArray(new String[moduleCrit.getAttributes().size()]);

    Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
    Set<ModuleRevisionId> result = new LinkedHashSet<>(); // we use a Set to remove duplicates
    for (Map<String, String> moduleId : moduleIdAsMap) {
        String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
        String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
        String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
        String rev = moduleId.get(IvyPatternHelper.REVISION_KEY);

        Map<String, String> foundExtraAtts = new HashMap<>();
        for (String qualifiedKey : moduleCrit.getQualifiedExtraAttributes().keySet()) {
            String value = null;
            int colonIndex = qualifiedKey.indexOf(':');
            if (colonIndex == -1) {
                value = moduleId.get(qualifiedKey);
            } else {
                value = moduleId.get(qualifiedKey.substring(colonIndex + 1));
            }

            if (value != null) {
                foundExtraAtts.put(qualifiedKey, value);
            }
        }

        ModuleRevisionId modRevId = ModuleRevisionId.newInstance(org, name, branch, rev,
            foundExtraAtts);
        result.add(resolver.getNamespace().getToSystemTransformer().transform(modRevId));
    }

    return result.toArray(new ModuleRevisionId[result.size()]);
}