org.apache.ivy.plugins.matcher.PatternMatcher Java Examples

The following examples show how to use org.apache.ivy.plugins.matcher.PatternMatcher. 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: IvyBuildList.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private String extractModuleNames(Set<MapMatcher> matchers) {
    StringBuilder result = new StringBuilder();

    String sep = "";
    for (MapMatcher matcher : matchers) {
        result.append(sep);

        Map<String, String> attributes = matcher.getAttributes();
        String organisation = attributes.get(IvyPatternHelper.ORGANISATION_KEY);
        if (organisation != null && !PatternMatcher.ANY_EXPRESSION.equals(organisation)) {
            result.append(organisation);
            result.append('#');
        }
        result.append(attributes.get(IvyPatternHelper.MODULE_KEY));
        sep = ", ";
    }

    return result.toString();
}
 
Example #2
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected void ivyModuleStarted(Attributes attributes) throws SAXException {
    descriptorVersion = attributes.getValue("version");
    int versionIndex = ALLOWED_VERSIONS.indexOf(descriptorVersion);
    if (versionIndex == -1) {
        addError("invalid version " + descriptorVersion);
        throw new SAXException("invalid version " + descriptorVersion);
    }
    if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
        Message.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT
                + " as default matcher");
        defaultMatcher = settings.getMatcher(PatternMatcher.EXACT);
    } else {
        Message.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP
                + " as default matcher");
        defaultMatcher = settings.getMatcher(PatternMatcher.EXACT_OR_REGEXP);
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.getQName(i).startsWith("xmlns:")) {
            getMd().addExtraAttributeNamespace(
                attributes.getQName(i).substring("xmlns:".length()), attributes.getValue(i));
        }
    }
}
 
Example #3
Source File: ModuleVersionSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ExcludeRuleBackedSpec(Iterable<ExcludeRule> excludeRules) {
    for (ExcludeRule rule : excludeRules) {
        if (!(rule.getMatcher() instanceof ExactPatternMatcher)) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
            continue;
        }
        ModuleId moduleId = rule.getId().getModuleId();
        boolean wildcardGroup = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getOrganisation());
        boolean wildcardModule = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getName());
        if (wildcardGroup && wildcardModule) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
        } else if (wildcardGroup) {
            excludeSpecs.add(new ModuleNameSpec(moduleId.getName()));
        } else if (wildcardModule) {
            excludeSpecs.add(new GroupNameSpec(moduleId.getOrganisation()));
        } else {
            excludeSpecs.add(new ModuleIdSpec(moduleId));
        }
    }
}
 
Example #4
Source File: ModuleVersionSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ExcludeRuleBackedSpec(Iterable<ExcludeRule> excludeRules) {
    for (ExcludeRule rule : excludeRules) {
        if (!(rule.getMatcher() instanceof ExactPatternMatcher)) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
            continue;
        }
        ModuleId moduleId = rule.getId().getModuleId();
        boolean wildcardGroup = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getOrganisation());
        boolean wildcardModule = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getName());
        if (wildcardGroup && wildcardModule) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
        } else if (wildcardGroup) {
            excludeSpecs.add(new ModuleNameSpec(moduleId.getName()));
        } else if (wildcardModule) {
            excludeSpecs.add(new GroupNameSpec(moduleId.getOrganisation()));
        } else {
            excludeSpecs.add(new ModuleIdSpec(moduleId));
        }
    }
}
 
Example #5
Source File: ChangingModuleDetector.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Matcher getChangingMatcher() {
    if (!(resolver instanceof AbstractResolver)) {
        return NoMatcher.INSTANCE;
    }

    AbstractResolver abstractResolver = (AbstractResolver) resolver;
    String changingMatcherName = JavaReflectionUtil.method(AbstractResolver.class, String.class, "getChangingMatcherName").invoke(abstractResolver);
    String changingPattern = JavaReflectionUtil.method(AbstractResolver.class, String.class, "getChangingPattern").invoke(abstractResolver);
    if (changingMatcherName == null || changingPattern == null) {
        return NoMatcher.INSTANCE;
    }
    PatternMatcher matcher = abstractResolver.getSettings().getMatcher(changingMatcherName);
    if (matcher == null) {
        throw new IllegalStateException("unknown matcher '" + changingMatcherName
                + "'. It is set as changing matcher in " + this);
    }
    return matcher.getMatcher(changingPattern);
}
 
Example #6
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void ivyModuleStarted(Attributes attributes) throws SAXException {
    descriptorVersion = attributes.getValue("version");
    int versionIndex = ALLOWED_VERSIONS.indexOf(descriptorVersion);
    if (versionIndex == -1) {
        addError("invalid version " + descriptorVersion);
        throw new SAXException("invalid version " + descriptorVersion);
    }
    if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
        LOGGER.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT);
    } else {
        LOGGER.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT_OR_REGEXP);
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.getQName(i).startsWith("xmlns:")) {
            getMd().addExtraAttributeNamespace(attributes.getQName(i).substring("xmlns:".length()), attributes.getValue(i));
        }
    }
}
 
Example #7
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected void mediationOverrideStarted(Attributes attributes) {
    String org = settings.substitute(attributes.getValue("org"));
    if (org == null) {
        org = PatternMatcher.ANY_EXPRESSION;
    }
    String mod = settings.substitute(attributes.getValue("module"));
    if (mod == null) {
        mod = PatternMatcher.ANY_EXPRESSION;
    }
    String rev = settings.substitute(attributes.getValue("rev"));
    String branch = settings.substitute(attributes.getValue("branch"));
    String matcherName = settings.substitute(attributes.getValue("matcher"));
    PatternMatcher matcher = (matcherName == null) ? defaultMatcher
            : settings.getMatcher(matcherName);
    if (matcher == null) {
        addError("unknown matcher: " + matcherName);
        return;
    }
    getMd().addDependencyDescriptorMediator(new ModuleId(org, mod), matcher,
        new OverrideDependencyDescriptorMediator(branch, rev));
}
 
Example #8
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegexpMatcher() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1", "install",
        new InstallOptions().setMatcherName(PatternMatcher.REGEXP).setOverwrite(true));

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.1.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.1.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());

    // mod1.3 is split because Ivy thinks there are two versions of the module:
    // this is the normal behaviour in this case
    assertTrue(new File("build/test/install/org1/mod1.3/ivy-B-3.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/ivy-A-3.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-A-3.0.jar").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-B-3.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());
}
 
Example #9
Source File: IvyEventFilter.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public IvyEventFilter(String event, String filterExpression, PatternMatcher matcher) {
    this.matcher = (matcher == null) ? ExactPatternMatcher.INSTANCE : matcher;
    if (event == null) {
        nameFilter = NoFilter.instance();
    } else {
        final Matcher eventNameMatcher = this.matcher.getMatcher(event);
        nameFilter = new Filter<IvyEvent>() {
            public boolean accept(IvyEvent e) {
                return eventNameMatcher.matches(e.getName());
            }
        };
    }
    if (isNullOrEmpty(filterExpression)) {
        attFilter = NoFilter.instance();
    } else {
        attFilter = parseExpression(filterExpression);
    }
}
 
Example #10
Source File: IvyXmlModuleDescriptorParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void ivyModuleStarted(Attributes attributes) throws SAXException {
    descriptorVersion = attributes.getValue("version");
    int versionIndex = ALLOWED_VERSIONS.indexOf(descriptorVersion);
    if (versionIndex == -1) {
        addError("invalid version " + descriptorVersion);
        throw new SAXException("invalid version " + descriptorVersion);
    }
    if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
        LOGGER.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT);
    } else {
        LOGGER.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT_OR_REGEXP);
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.getQName(i).startsWith("xmlns:")) {
            getMd().addExtraAttributeNamespace(attributes.getQName(i).substring("xmlns:".length()), attributes.getValue(i));
        }
    }
}
 
Example #11
Source File: MavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public MavenResolver(String name, URI rootUri, RepositoryTransport transport,
                     LocallyAvailableResourceFinder<ModuleVersionArtifactMetaData> locallyAvailableResourceFinder,
                     ResolverStrategy resolverStrategy) {
    super(name, transport.getRepository(),
            new ChainedVersionLister(new MavenVersionLister(transport.getRepository()), new ResourceVersionLister(transport.getRepository())),
            locallyAvailableResourceFinder, new GradlePomModuleDescriptorParser(), resolverStrategy);
    transport.configureCacheManager(this);

    this.mavenMetaDataLoader = new MavenMetadataLoader(transport.getRepository());
    this.transport = transport;
    this.root = transport.convertToPath(rootUri);

    super.setM2compatible(true);

    // SNAPSHOT revisions are changing revisions
    setChangingMatcher(PatternMatcher.REGEXP);
    setChangingPattern(".*-SNAPSHOT");

    updatePatterns();
}
 
Example #12
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 #13
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller",
					"working"));
		}
		DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0],
				dep[1], dep[2]), false, false, true);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example #14
Source File: ModuleVersionSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ExcludeRuleBackedSpec(Iterable<ExcludeRule> excludeRules) {
    for (ExcludeRule rule : excludeRules) {
        if (!(rule.getMatcher() instanceof ExactPatternMatcher)) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
            continue;
        }
        ModuleId moduleId = rule.getId().getModuleId();
        boolean wildcardGroup = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getOrganisation());
        boolean wildcardModule = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getName());
        if (wildcardGroup && wildcardModule) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
        } else if (wildcardGroup) {
            excludeSpecs.add(new ModuleNameSpec(moduleId.getName()));
        } else if (wildcardModule) {
            excludeSpecs.add(new GroupNameSpec(moduleId.getOrganisation()));
        } else {
            excludeSpecs.add(new ModuleIdSpec(moduleId));
        }
    }
}
 
Example #15
Source File: IvyConfigurationProvider.java    From walkmod-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addArtifact(String groupId, String artifactId, String version) throws Exception {

		artifacts.add(groupId+":"+artifactId+":"+version);

		String[] dep = null;
		dep = new String[] { groupId, artifactId, version };
		if (md == null) {
			md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller",
					"working"));
		}
		DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0],
				dep[1], dep[2]), false, false, true);
		md.addDependency(dd);
		ExcludeRule er = new DefaultExcludeRule(new ArtifactId(new ModuleId("org.walkmod", "walkmod-core"),
				PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
				ExactPatternMatcher.INSTANCE, null);
		dd.addExcludeRule(null, er);
	}
 
Example #16
Source File: ChangingModuleDetector.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Matcher getChangingMatcher() {
    if (!(resolver instanceof AbstractResolver)) {
        return NoMatcher.INSTANCE;
    }

    AbstractResolver abstractResolver = (AbstractResolver) resolver;
    String changingMatcherName = JavaReflectionUtil.method(AbstractResolver.class, String.class, "getChangingMatcherName").invoke(abstractResolver);
    String changingPattern = JavaReflectionUtil.method(AbstractResolver.class, String.class, "getChangingPattern").invoke(abstractResolver);
    if (changingMatcherName == null || changingPattern == null) {
        return NoMatcher.INSTANCE;
    }
    PatternMatcher matcher = abstractResolver.getSettings().getMatcher(changingMatcherName);
    if (matcher == null) {
        throw new IllegalStateException("unknown matcher '" + changingMatcherName
                + "'. It is set as changing matcher in " + this);
    }
    return matcher.getMatcher(changingPattern);
}
 
Example #17
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void ivyModuleStarted(Attributes attributes) throws SAXException {
    descriptorVersion = attributes.getValue("version");
    int versionIndex = ALLOWED_VERSIONS.indexOf(descriptorVersion);
    if (versionIndex == -1) {
        addError("invalid version " + descriptorVersion);
        throw new SAXException("invalid version " + descriptorVersion);
    }
    if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
        LOGGER.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT);
    } else {
        LOGGER.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT_OR_REGEXP);
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.getQName(i).startsWith("xmlns:")) {
            getMd().addExtraAttributeNamespace(attributes.getQName(i).substring("xmlns:".length()), attributes.getValue(i));
        }
    }
}
 
Example #18
Source File: IvyXmlModuleDescriptorParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void ivyModuleStarted(Attributes attributes) throws SAXException {
    descriptorVersion = attributes.getValue("version");
    int versionIndex = ALLOWED_VERSIONS.indexOf(descriptorVersion);
    if (versionIndex == -1) {
        addError("invalid version " + descriptorVersion);
        throw new SAXException("invalid version " + descriptorVersion);
    }
    if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
        LOGGER.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT);
    } else {
        LOGGER.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP + " as default matcher");
        defaultMatcher = getMatcher(PatternMatcher.EXACT_OR_REGEXP);
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        if (attributes.getQName(i).startsWith("xmlns:")) {
            getMd().addExtraAttributeNamespace(attributes.getQName(i).substring("xmlns:".length()), attributes.getValue(i));
        }
    }
}
 
Example #19
Source File: ModuleVersionSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ExcludeRuleBackedSpec(Iterable<ExcludeRule> excludeRules) {
    for (ExcludeRule rule : excludeRules) {
        if (!(rule.getMatcher() instanceof ExactPatternMatcher)) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
            continue;
        }
        ModuleId moduleId = rule.getId().getModuleId();
        boolean wildcardGroup = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getOrganisation());
        boolean wildcardModule = PatternMatcher.ANY_EXPRESSION.equals(moduleId.getName());
        if (wildcardGroup && wildcardModule) {
            excludeSpecs.add(new ExcludeRuleSpec(rule));
        } else if (wildcardGroup) {
            excludeSpecs.add(new ModuleNameSpec(moduleId.getName()));
        } else if (wildcardModule) {
            excludeSpecs.add(new GroupNameSpec(moduleId.getOrganisation()));
        } else {
            excludeSpecs.add(new ModuleIdSpec(moduleId));
        }
    }
}
 
Example #20
Source File: MavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public MavenResolver(String name, URI rootUri, RepositoryTransport transport,
                     LocallyAvailableResourceFinder<ModuleVersionArtifactMetaData> locallyAvailableResourceFinder,
                     ResolverStrategy resolverStrategy) {
    super(name, transport.getRepository(),
            new ChainedVersionLister(new MavenVersionLister(transport.getRepository()), new ResourceVersionLister(transport.getRepository())),
            locallyAvailableResourceFinder, new GradlePomModuleDescriptorParser(), resolverStrategy);
    transport.configureCacheManager(this);

    this.mavenMetaDataLoader = new MavenMetadataLoader(transport.getRepository());
    this.transport = transport;
    this.root = transport.convertToPath(rootUri);

    super.setM2compatible(true);

    // SNAPSHOT revisions are changing revisions
    setChangingMatcher(PatternMatcher.REGEXP);
    setChangingPattern(".*-SNAPSHOT");

    updatePatterns();
}
 
Example #21
Source File: IvyTranslations.java    From jeka with Apache License 2.0 6 votes vote down vote up
private static DefaultExcludeRule toExcludeRule(JkDepExclude depExclude, Iterable<String> allRootConfs) {
    final String type = depExclude.getType() == null ? PatternMatcher.ANY_EXPRESSION : depExclude
            .getType();
    final String ext = depExclude.getExt() == null ? PatternMatcher.ANY_EXPRESSION : depExclude
            .getExt();
    final ArtifactId artifactId = new ArtifactId(toModuleId(depExclude.getModuleId()), "*", type,
            ext);
    final DefaultExcludeRule result = new DefaultExcludeRule(artifactId,
            ExactPatternMatcher.INSTANCE, null);
    for (final JkScope scope : depExclude.getScopes()) {
        result.addConfiguration(scope.getName());
    }
    if (depExclude.getScopes().isEmpty()) {
        for (final String conf : allRootConfs) {
            result.addConfiguration(conf);
        }

    }
    return result;
}
 
Example #22
Source File: IvyDependencyInclude.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
DefaultIncludeRule asRule(IvySettings settings) {
    String matcherName = matcher == null ? PatternMatcher.EXACT : matcher;
    String namePattern = name == null ? PatternMatcher.ANY_EXPRESSION : name;
    String typePattern = type == null ? PatternMatcher.ANY_EXPRESSION : type;
    String extPattern = ext == null ? typePattern : ext;
    ArtifactId aid = new ArtifactId(new ModuleId(PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION), namePattern, typePattern, extPattern);
    return new DefaultIncludeRule(aid, settings.getMatcher(matcherName), null);
}
 
Example #23
Source File: XmlSettingsParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void moduleStarted(Map<String, String> attributes) {
    attributes.put(IvyPatternHelper.MODULE_KEY, attributes.remove("name"));
    String resolver = attributes.remove("resolver");
    String branch = attributes.remove("branch");
    String cm = attributes.remove("conflict-manager");
    String resolveMode = attributes.remove("resolveMode");
    String matcher = attributes.remove("matcher");
    matcher = (matcher == null) ? PatternMatcher.EXACT_OR_REGEXP : matcher;
    ivy.addModuleConfiguration(attributes, ivy.getMatcher(matcher), resolver, branch, cm,
        resolveMode);
}
 
Example #24
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void managerStarted(Attributes attributes, String managerAtt) {
    String org = settings.substitute(attributes.getValue("org"));
    if (org == null) {
        org = PatternMatcher.ANY_EXPRESSION;
    }
    String mod = settings.substitute(attributes.getValue("module"));
    if (mod == null) {
        mod = PatternMatcher.ANY_EXPRESSION;
    }
    ConflictManager cm;
    String name = settings.substitute(attributes.getValue(managerAtt));
    String rev = settings.substitute(attributes.getValue("rev"));
    if (rev != null) {
        cm = new FixedConflictManager(splitToArray(rev));
    } else if (name != null) {
        cm = settings.getConflictManager(name);
        if (cm == null) {
            addError("unknown conflict manager: " + name);
            return;
        }
    } else {
        addError("bad conflict manager: no manager nor rev");
        return;
    }
    String matcherName = settings.substitute(attributes.getValue("matcher"));
    PatternMatcher matcher = (matcherName == null) ? defaultMatcher
            : settings.getMatcher(matcherName);
    if (matcher == null) {
        addError("unknown matcher: " + matcherName);
        return;
    }
    getMd().addConflictManager(new ModuleId(org, mod), matcher, cm);
}
 
Example #25
Source File: SearchEngine.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void addMatcher(PatternMatcher patternMatcher, String expression,
        Map<String, Object> criteria, String key) {
    if (expression == null) {
        return;
    }

    Matcher matcher = patternMatcher.getMatcher(expression);
    if (matcher.isExact()) {
        criteria.put(key, expression);
    } else {
        criteria.put(key, matcher);
    }
}
 
Example #26
Source File: IvyConflict.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
void addConflict(DefaultModuleDescriptor md, IvySettings settings) {
    String matcherName = (matcher == null) ? PatternMatcher.EXACT : matcher;
    String orgPattern = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
    String modulePattern = (module == null) ? PatternMatcher.ANY_EXPRESSION : module;
    ConflictManager cm = null;
    if (rev != null) {
        cm = new FixedConflictManager(splitToArray(rev));
    } else if (manager != null) {
        cm = settings.getConflictManager(manager);
    }
    md.addConflictManager(new ModuleId(orgPattern, modulePattern),
        settings.getMatcher(matcherName), cm);
}
 
Example #27
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected PatternMatcher getPatternMatcher(String m) {
    String matcherName = settings.substitute(m);
    PatternMatcher matcher = matcherName == null ? defaultMatcher : settings
            .getMatcher(matcherName);
    if (matcher == null) {
        throw new IllegalArgumentException("unknown matcher " + matcherName);
    }
    return matcher;
}
 
Example #28
Source File: IvyDependencyExclude.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
DefaultExcludeRule asRule(IvySettings settings) {
    String matcherName = (matcher == null) ? PatternMatcher.EXACT : matcher;
    String orgPattern = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
    String modulePattern = (module == null) ? PatternMatcher.ANY_EXPRESSION : module;
    String namePattern = (name == null) ? PatternMatcher.ANY_EXPRESSION : name;
    String typePattern = (type == null) ? PatternMatcher.ANY_EXPRESSION : type;
    String extPattern = (ext == null) ? typePattern : ext;
    ArtifactId aid = new ArtifactId(new ModuleId(orgPattern, modulePattern), namePattern,
            typePattern, extPattern);
    return new DefaultExcludeRule(aid, settings.getMatcher(matcherName), null);
}
 
Example #29
Source File: SearchTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testListModulesWithExtraAttributes() throws ParseException, IOException {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/IVY-1128/ivysettings.xml"));
    IvySettings settings = ivy.getSettings();

    Map<String, String> extendedAttributes = new HashMap<>();
    extendedAttributes.put("e:att1", "extraatt");
    extendedAttributes.put("e:att2", "extraatt2");
    ModuleRevisionId criteria = ModuleRevisionId.newInstance("test", "a", "*",
        extendedAttributes);

    ModuleRevisionId[] mrids = ivy.listModules(criteria,
        settings.getMatcher(PatternMatcher.REGEXP));

    assertEquals(2, mrids.length);
    ModuleRevisionId mrid = mrids[0];
    assertEquals("extraatt", mrid.getExtraAttribute("att1"));

    Map<String, String> extraAttributes = mrid.getExtraAttributes();
    assertEquals(2, extraAttributes.size());
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att1"));
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att2"));

    Map<String, String> qualifiedExtraAttributes = mrid.getQualifiedExtraAttributes();
    assertEquals(2, qualifiedExtraAttributes.size());
    assertTrue(qualifiedExtraAttributes.toString(),
        qualifiedExtraAttributes.keySet().contains("e:att1"));
    assertTrue(qualifiedExtraAttributes.toString(),
        qualifiedExtraAttributes.keySet().contains("e:att2"));
}
 
Example #30
Source File: MatcherLookup.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Create a key from specified attributes
 *
 * @param attrs
 *            A map of attributes
 * @return key object
 */
private String key(Map<String, String> attrs) {
    String org = attrs.get(IvyPatternHelper.ORGANISATION_KEY);
    String module = attrs.get(IvyPatternHelper.MODULE_KEY);
    if (org == null || PatternMatcher.ANY_EXPRESSION.equals(org) || module == null
            || PatternMatcher.ANY_EXPRESSION.equals(module)) {
        return DEFAULT;
    }
    return "{org:" + org + ", module:" + module + "}";
}