use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class GradlePomModuleDescriptorParser method parseImportedDependencyMgts.
/**
* Parses imported dependency management information.
*
* @param parseContext Parse context
* @param currentDependencyMgts Current dependency management information
* @return Imported dependency management information
*/
private Map<MavenDependencyKey, PomDependencyMgt> parseImportedDependencyMgts(DescriptorParseContext parseContext, Collection<PomDependencyMgt> currentDependencyMgts) throws IOException, SAXException {
Map<MavenDependencyKey, PomDependencyMgt> importedDependencyMgts = new LinkedHashMap<>();
for (PomDependencyMgt currentDependencyMgt : currentDependencyMgts) {
if (isDependencyImportScoped(currentDependencyMgt)) {
ModuleComponentSelector importedId = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(currentDependencyMgt.getGroupId(), currentDependencyMgt.getArtifactId()), new DefaultImmutableVersionConstraint(currentDependencyMgt.getVersion()));
PomReader importedPom = parsePomForSelector(parseContext, importedId, Maps.newHashMap());
for (Map.Entry<MavenDependencyKey, PomDependencyMgt> entry : importedPom.getDependencyMgt().entrySet()) {
if (!importedDependencyMgts.containsKey(entry.getKey())) {
importedDependencyMgts.put(entry.getKey(), entry.getValue());
}
}
}
}
return importedDependencyMgts;
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class RepositoryChainDependencyToComponentIdResolver method resolve.
@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, @Nullable VersionSelector rejector, BuildableComponentIdResolveResult result) {
ComponentSelector componentSelector = dependency.getSelector();
if (componentSelector instanceof ModuleComponentSelector) {
ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
if (acceptor.isDynamic()) {
dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), acceptor, rejector, consumerAttributes, result);
} else {
String version = acceptor.getSelector();
ModuleIdentifier moduleId = module.getModuleIdentifier();
ModuleComponentIdentifier id = DefaultModuleComponentIdentifier.newId(moduleId, version);
ModuleVersionIdentifier mvId = DefaultModuleVersionIdentifier.newId(moduleId, version);
if (rejector != null && rejector.accept(version)) {
result.rejected(id, mvId);
} else {
result.resolved(id, mvId);
}
}
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class IvyModuleDescriptorConverter method addDependency.
private void addDependency(List<IvyDependencyDescriptor> result, DependencyDescriptor dependencyDescriptor) {
ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
ModuleComponentSelector requested = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(revisionId.getOrganisation(), revisionId.getName()), new DefaultImmutableVersionConstraint(revisionId.getRevision()));
ListMultimap<String, String> configMappings = ArrayListMultimap.create();
for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
configMappings.putAll(entry.getKey(), entry.getValue());
}
List<Artifact> artifacts = Lists.newArrayList();
for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
}
List<Exclude> excludes = Lists.newArrayList();
for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
excludes.add(forIvyExclude(excludeRule));
}
result.add(new IvyDependencyDescriptor(requested, dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(), dependencyDescriptor.isChanging(), dependencyDescriptor.isTransitive(), false, configMappings, artifacts, excludes));
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class GradlePomModuleDescriptorBuilder method doAddDependency.
private void doAddDependency(PomDependencyMgt dep, MavenDependencyType dependencyType) {
MavenScope scope;
if (dependencyType == MavenDependencyType.DEPENDENCY_MANAGEMENT) {
scope = MavenScope.Compile;
} else {
String scopeString = dep.getScope();
if (scopeString == null || scopeString.length() == 0) {
scopeString = getDefaultScope(dep);
}
// unknown scope, defaulting to 'compile'
scope = SCOPES.getOrDefault(scopeString, MavenScope.Compile);
}
String version = determineVersion(dep);
String mappedVersion = convertVersionFromMavenSyntax(version);
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(dep.getGroupId(), dep.getArtifactId()), new DefaultImmutableVersionConstraint(mappedVersion));
// Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
if (selector.getModuleIdentifier().equals(componentIdentifier.getModuleIdentifier())) {
return;
}
IvyArtifactName dependencyArtifact = null;
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);
String classifier = hasClassifier ? dep.getClassifier() : getClassifierForType(type);
dependencyArtifact = new DefaultIvyArtifactName(selector.getModule(), type, ext, classifier);
}
// 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<ExcludeMetadata> excludes = Lists.newArrayList();
List<ModuleIdentifier> excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
excluded = getDependencyMgtExclusions(dep);
}
for (ModuleIdentifier excludedModule : excluded) {
DefaultExclude rule = new DefaultExclude(excludedModule);
excludes.add(rule);
}
dependencies.add(new MavenDependencyDescriptor(scope, dependencyType, selector, dependencyArtifact, excludes));
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultDependencyResolveDetails method complete.
public void complete() {
if (!dirty) {
return;
}
ComponentSelectionDescriptorInternal selectionReason = selectionReason();
if (useSelector != null) {
delegate.useTarget(useSelector, selectionReason);
} else if (useVersion != null) {
if (delegate.getTarget() instanceof ModuleComponentSelector) {
ModuleComponentSelector target = (ModuleComponentSelector) delegate.getTarget();
if (!useVersion.equals(target.getVersionConstraint())) {
delegate.useTarget(DefaultModuleComponentSelector.newSelector(target.getModuleIdentifier(), useVersion, target.getAttributes(), target.getRequestedCapabilities()), selectionReason);
} else {
// Still 'updated' with reason when version remains the same.
delegate.useTarget(delegate.getTarget(), selectionReason);
}
} else {
// If the current target is a project component, it must be unmodified from the requested
ModuleComponentSelector newTarget = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(requested.getGroup(), requested.getName()), useVersion);
delegate.useTarget(newTarget, selectionReason);
}
}
delegate.artifactSelection(artifactSelectionAction);
dirty = false;
}
Aggregations