use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class PomModuleDescriptorBuilder method addDependency.
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;
// 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";
}
// 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);
}
for (ModuleId excludedModule : excluded) {
// 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);
}
}
use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class PomModuleDescriptorBuilder method getDefaultVersion.
private String getDefaultVersion(PomDependencyData dep) {
ModuleId moduleId = ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId());
if (ivyModuleDescriptor.getDependencyManagementMap().containsKey(moduleId)) {
return ivyModuleDescriptor.getDependencyManagementMap().get(moduleId).getVersion();
}
String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
return ivyModuleDescriptor.getExtraInfoContentByTagName(key);
}
use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class PomModuleDescriptorBuilder method addDependencyMgt.
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()));
}
use of org.apache.ivy.core.module.id.ModuleId 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.core.module.id.ModuleId in project ant-ivy by apache.
the class SearchEngine method listModules.
/**
* 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()]);
}
Aggregations