Search in sources :

Example 1 with MapMatcher

use of org.apache.ivy.plugins.matcher.MapMatcher in project ant-ivy by apache.

the class MatcherLookup method get.

/**
 * @param attrs
 *            A map of attributes that matcher should match.
 *
 * @return a list of matchers that can apply to module withs specified attributes
 */
public List<MapMatcher> get(Map<String, String> attrs) {
    List<MapMatcher> matchers = new ArrayList<>();
    // Step 1: find matchers from nonExactMatchers list
    if (!nonExactMatchers.isEmpty()) {
        for (MapMatcher matcher : nonExactMatchers) {
            if (matcher.matches(attrs)) {
                matchers.add(matcher);
            }
        }
    }
    // Step 2: find matchers from exactMatchers list of key
    String key = key(attrs);
    List<MapMatcher> exactMatchers = lookup.get(key);
    if (exactMatchers != null) {
        for (MapMatcher matcher : exactMatchers) {
            if (matcher.matches(attrs)) {
                matchers.add(matcher);
            }
        }
    }
    // Step 3: (iff key != DEFAULT) find matchers from exactMatchers of DEFAULT
    if (!DEFAULT.equals(key)) {
        List<MapMatcher> defaultExactMatchers = lookup.get(DEFAULT);
        if (defaultExactMatchers != null) {
            for (MapMatcher matcher : defaultExactMatchers) {
                if (matcher.matches(attrs)) {
                    matchers.add(matcher);
                }
            }
        }
    }
    return matchers;
}
Also used : ArrayList(java.util.ArrayList) MapMatcher(org.apache.ivy.plugins.matcher.MapMatcher)

Example 2 with MapMatcher

use of org.apache.ivy.plugins.matcher.MapMatcher in project ant-ivy by apache.

the class ModuleRules method dump.

/**
 * Dump the list of rules to {@link Message#debug(String)}
 *
 * @param prefix
 *            the prefix to use for each line dumped
 */
public void dump(String prefix) {
    if (rules.isEmpty()) {
        Message.debug(prefix + "NONE");
        return;
    }
    for (Map.Entry<MapMatcher, T> entry : rules.entrySet()) {
        MapMatcher midm = entry.getKey();
        T rule = entry.getValue();
        Message.debug(prefix + midm + " -> " + rule);
    }
}
Also used : MapMatcher(org.apache.ivy.plugins.matcher.MapMatcher) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with MapMatcher

use of org.apache.ivy.plugins.matcher.MapMatcher in project ant-ivy by apache.

the class IvySettings method addModuleConfiguration.

/**
 * regular expressions as explained in Pattern class may be used in attributes
 *
 * @param attributes Map
 * @param matcher PatternMatcher
 * @param resolverName String
 * @param branch String
 * @param conflictManager String
 * @param resolveMode String
 */
public synchronized void addModuleConfiguration(Map<String, String> attributes, PatternMatcher matcher, String resolverName, String branch, String conflictManager, String resolveMode) {
    checkResolverName(resolverName);
    moduleSettings.defineRule(new MapMatcher(attributes, matcher), new ModuleSettings(resolverName, branch, conflictManager, resolveMode));
}
Also used : MapMatcher(org.apache.ivy.plugins.matcher.MapMatcher)

Example 4 with MapMatcher

use of org.apache.ivy.plugins.matcher.MapMatcher in project ant-ivy by apache.

the class XmlModuleDescriptorWriter method printAllMediators.

private static void printAllMediators(ModuleDescriptor md, PrintWriter out) {
    Map<MapMatcher, DependencyDescriptorMediator> mediators = md.getAllDependencyDescriptorMediators().getAllRules();
    for (Map.Entry<MapMatcher, DependencyDescriptorMediator> mediatorRule : mediators.entrySet()) {
        MapMatcher matcher = mediatorRule.getKey();
        DependencyDescriptorMediator mediator = mediatorRule.getValue();
        if (mediator instanceof OverrideDependencyDescriptorMediator) {
            OverrideDependencyDescriptorMediator oddm = (OverrideDependencyDescriptorMediator) mediator;
            out.print(String.format("\t\t<override org=\"%s\" module=\"%s\" matcher=\"%s\"", XMLHelper.escape(matcher.getAttributes().get(IvyPatternHelper.ORGANISATION_KEY)), XMLHelper.escape(matcher.getAttributes().get(IvyPatternHelper.MODULE_KEY)), XMLHelper.escape(matcher.getPatternMatcher().getName())));
            if (oddm.getBranch() != null) {
                out.print(" branch=\"" + XMLHelper.escape(oddm.getBranch()) + "\"");
            }
            if (oddm.getVersion() != null) {
                out.print(" rev=\"" + XMLHelper.escape(oddm.getVersion()) + "\"");
            }
            out.println("/>");
        } else {
            Message.verbose("ignoring unhandled DependencyDescriptorMediator: " + mediator.getClass());
        }
    }
}
Also used : OverrideDependencyDescriptorMediator(org.apache.ivy.core.module.descriptor.OverrideDependencyDescriptorMediator) OverrideDependencyDescriptorMediator(org.apache.ivy.core.module.descriptor.OverrideDependencyDescriptorMediator) DependencyDescriptorMediator(org.apache.ivy.core.module.descriptor.DependencyDescriptorMediator) MapMatcher(org.apache.ivy.plugins.matcher.MapMatcher) Map(java.util.Map)

Aggregations

MapMatcher (org.apache.ivy.plugins.matcher.MapMatcher)4 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 DependencyDescriptorMediator (org.apache.ivy.core.module.descriptor.DependencyDescriptorMediator)1 OverrideDependencyDescriptorMediator (org.apache.ivy.core.module.descriptor.OverrideDependencyDescriptorMediator)1