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

The following examples show how to use org.apache.ivy.plugins.matcher.ExactPatternMatcher. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #10
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #11
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #12
Source File: IvyNodeUsage.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static IncludeRule includeAllArtifacts() {
    final ArtifactId aid = new ArtifactId(
            new ModuleId(PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION),
            PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION);
    return new DefaultIncludeRule(aid, ExactPatternMatcher.INSTANCE, null);
}
 
Example #13
Source File: MatcherLookup.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Add matcher.
 *
 * If matcher is exact pattern matcher, it will be associated with a key and placed in keyed
 * collection.
 *
 * If matcher is not exact pattern matcher, it will be placed into non-keyed collection
 *
 * @param matcher MapMatcher
 */
public void add(MapMatcher matcher) {
    if (!(matcher.getPatternMatcher() instanceof ExactPatternMatcher)) {
        nonExactMatchers.add(matcher);
        return;
    }
    String key = key(matcher.getAttributes());
    List<MapMatcher> exactMatchers = lookup.get(key);
    if (exactMatchers == null) {
        exactMatchers = new ArrayList<>();
        lookup.put(key, exactMatchers);
    }
    exactMatchers.add(matcher);
}
 
Example #14
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void setSettings(final IvySettings settings) {
    this.settings = settings;
    packagingManager.setSettings(settings);
    // process and setup the configured TTLs (which weren't yet processed since they needed
    // a settings instance to be present)
    for (final ConfiguredTTL configuredTTL : configuredTTLs) {
        this.addTTL(configuredTTL.attributes,
                configuredTTL.matcher == null ? ExactPatternMatcher.INSTANCE : settings.getMatcher(configuredTTL.matcher), configuredTTL.duration);
    }
    // clear off the configured TTLs since we have now processed them and created TTL rules
    // out of them
    this.configuredTTLs.clear();
}
 
Example #15
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void addDependencyMgt(PomDependencyMgt dep) {
    ivyModuleDescriptor.addDependencyManagement(dep);

    String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
    overwriteExtraInfoIfExists(key, dep.getVersion());
    if (dep.getScope() != null) {
        String scopeKey = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(),
            dep.getArtifactId());
        overwriteExtraInfoIfExists(scopeKey, dep.getScope());
    }
    if (!dep.getExcludedModules().isEmpty()) {
        String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion(dep.getGroupId(),
            dep.getArtifactId());
        int index = 0;
        for (ModuleId excludedModule : dep.getExcludedModules()) {
            overwriteExtraInfoIfExists(
                exclusionPrefix + index,
                excludedModule.getOrganisation() + EXTRA_INFO_DELIMITER
                        + excludedModule.getName());
            index++;
        }
    }
    // dependency management info is also used for version mediation of transitive dependencies
    ivyModuleDescriptor.addDependencyDescriptorMediator(
        ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()),
        ExactPatternMatcher.INSTANCE,
        new OverrideDependencyDescriptorMediator(null, dep.getVersion()));
}
 
Example #16
Source File: DefaultExcludeRuleConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #17
Source File: GradlePomModuleDescriptorBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
    if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
        return;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = determineExtension(type);
        handleSpecialTypes(type, extraAtt);

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put(EXTRA_ATTRIBUTE_CLASSIFIER, dep.getClassifier());
        }
        DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
        // here we have to assume a type and ext for the artifact, so this is a limitation
        // compared to how m2 behave with classifiers
        String optionalizedScope = dep.isOptional() ? "optional" : scope;
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List /*<ModuleId>*/ excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #18
Source File: GradlePomModuleDescriptorBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
    if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
        return;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = type;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // Cfr. http://maven.apache.org/guides/mini/guide-attached-tests.html
        if ("test-jar".equals(type)) {
            ext = "jar";
            extraAtt.put("m:classifier", "tests");
        } else if (JAR_PACKAGINGS.contains(type)) {
            ext = "jar";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put("m:classifier", dep.getClassifier());
        }
        DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
        // here we have to assume a type and ext for the artifact, so this is a limitation
        // compared to how m2 behave with classifiers
        String optionalizedScope = dep.isOptional() ? "optional" : scope;
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List /*<ModuleId>*/ excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #19
Source File: GradlePomModuleDescriptorBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
    if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
        return;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = determineExtension(type);
        handleSpecialTypes(type, extraAtt);

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put(EXTRA_ATTRIBUTE_CLASSIFIER, dep.getClassifier());
        }
        DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
        // here we have to assume a type and ext for the artifact, so this is a limitation
        // compared to how m2 behave with classifiers
        String optionalizedScope = dep.isOptional() ? "optional" : scope;
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List /*<ModuleId>*/ excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #20
Source File: GradlePomModuleDescriptorBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependency(PomDependencyData dep) {
    String scope = dep.getScope();
    if ((scope != null) && (scope.length() > 0) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = determineVersion(dep);
    ModuleRevisionId moduleRevId = IvyUtil.createModuleRevisionId(dep.getGroupId(), dep.getArtifactId(), version);

    // Some POMs depend on themselves, don't add this dependency: Ivy doesn't allow this!
    // Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
    if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
        return;
    }

    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ivyModuleDescriptor, moduleRevId, true, false, true);
    scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<String, String>();
    boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
    boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
    if (hasClassifier || hasNonJarType) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = type;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // Cfr. http://maven.apache.org/guides/mini/guide-attached-tests.html
        if ("test-jar".equals(type)) {
            ext = "jar";
            extraAtt.put("m:classifier", "tests");
        } else if (JAR_PACKAGINGS.contains(type)) {
            ext = "jar";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put("m:classifier", dep.getClassifier());
        }
        DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
        // here we have to assume a type and ext for the artifact, so this is a limitation
        // compared to how m2 behave with classifiers
        String optionalizedScope = dep.isOptional() ? "optional" : scope;
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List /*<ModuleId>*/ excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(dep);
    }
    for (Object anExcluded : excluded) {
        ModuleId excludedModule = (ModuleId) anExcluded;
        String[] confs = dd.getModuleConfigurations();
        for (String conf : confs) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(
                    excludedModule, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION),
                    ExactPatternMatcher.INSTANCE, null));
        }
    }

    ivyModuleDescriptor.addDependency(dd);
}
 
Example #21
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public void addDependency(Resource res, PomDependencyData dep) {
    String scope = dep.getScope();
    if (!isNullOrEmpty(scope) && !MAVEN2_CONF_MAPPING.containsKey(scope)) {
        // unknown scope, defaulting to 'compile'
        scope = "compile";
    }

    String version = dep.getVersion();
    if (isNullOrEmpty(version)) {
        version = getDefaultVersion(dep);
    }
    ModuleRevisionId moduleRevId = ModuleRevisionId.newInstance(dep.getGroupId(),
        dep.getArtifactId(), version);

    // Some POMs depend on themselves; Ivy doesn't allow this. Don't add this dependency!
    // Example: https://repo1.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
    ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
    if (mRevId != null && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
        return;
    }
    // experimentation shows the following, excluded modules are
    // inherited from parent POMs if either of the following is true:
    // the <exclusions> element is missing or the <exclusions> element
    // is present, but empty.
    List<ModuleId> excluded = dep.getExcludedModules();
    if (excluded.isEmpty()) {
        excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(),
                dep.getArtifactId());
    }
    final boolean excludeAllTransitiveDeps = shouldExcludeAllTransitiveDeps(excluded);
    // the same dependency mrid could appear twice in the module descriptor,
    // so we check if we already have created a dependency descriptor for the dependency mrid
    final DependencyDescriptor existing = this.ivyModuleDescriptor.depDescriptors.get(moduleRevId);
    final DefaultDependencyDescriptor dd = (existing != null && existing instanceof DefaultDependencyDescriptor)
            ? (DefaultDependencyDescriptor) existing
            : new PomDependencyDescriptor(dep, ivyModuleDescriptor, moduleRevId, !excludeAllTransitiveDeps);
    if (isNullOrEmpty(scope)) {
        scope = getDefaultScope(dep);
    }
    ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
    mapping.addMappingConfs(dd, dep.isOptional());
    Map<String, String> extraAtt = new HashMap<>();
    if (dep.getClassifier() != null || dep.getType() != null && !"jar".equals(dep.getType())) {
        String type = "jar";
        if (dep.getType() != null) {
            type = dep.getType();
        }
        String ext = type;

        // if type is 'test-jar', the extension is 'jar' and the classifier is 'tests'
        // Cfr. http://maven.apache.org/guides/mini/guide-attached-tests.html
        if ("test-jar".equals(type)) {
            ext = "jar";
            extraAtt.put("m:classifier", "tests");
        } else if (JAR_PACKAGINGS.contains(type)) {
            ext = "jar";
        }

        // we deal with classifiers by setting an extra attribute and forcing the
        // dependency to assume such an artifact is published
        if (dep.getClassifier() != null) {
            extraAtt.put("m:classifier", dep.getClassifier());
        }
        final DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(
                dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
        // here we have to assume a type and ext for the artifact, so this is a limitation
        // compared to how m2 behave with classifiers
        final String optionalizedScope = dep.isOptional() ? "optional" : scope;
        depArtifact.addConfiguration(optionalizedScope);
        dd.addDependencyArtifact(optionalizedScope, depArtifact);
    }

    for (ModuleId excludedModule : excluded) {
        // This represents exclude all transitive dependencies, which we have already taken
        // in account while defining the DefaultDependencyDescriptor itself
        if ("*".equals(excludedModule.getOrganisation()) && "*".equals(excludedModule.getName())) {
            continue;
        }
        for (String conf : dd.getModuleConfigurations()) {
            dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId(excludedModule,
                    PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
                    PatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, null));
        }
    }
    // intentional identity check to make sure we don't re-add the same dependency
    if (existing != dd) {
        ivyModuleDescriptor.addDependency(dd);
    }
}
 
Example #22
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Test
public void testBintrayArtifacts() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());

    ModuleRevisionId mrid = ModuleRevisionId
            .newInstance("org.apache.ant", "ant-antunit", "1.2");
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(),
            "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(),
            "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
    ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(),
            "ant-antunit", "javadoc", "jar");
    DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit",
            "sources", "jar");
    DownloadReport report = resolver.download(new Artifact[] {profiler, trace},
        downloadOptions());
    assertNotNull(report);

    assertEquals(2, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(profiler);
    assertNotNull(ar);

    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());

    ar = report.getArtifactReport(trace);
    assertNotNull(ar);

    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());

    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] {profiler, trace}, downloadOptions());
    assertNotNull(report);

    assertEquals(2, report.getArtifactsReports().length);

    ar = report.getArtifactReport(profiler);
    assertNotNull(ar);

    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());

    ar = report.getArtifactReport(trace);
    assertNotNull(ar);

    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}