use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultDependencyMetadata method withTarget.
@Override
public DependencyMetadata withTarget(ComponentSelector target) {
if (target instanceof ModuleComponentSelector) {
ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion());
if (requestedVersion.equals(requested)) {
return this;
}
return withRequested(requestedVersion);
} else if (target instanceof ProjectComponentSelector) {
ProjectComponentSelector projectTarget = (ProjectComponentSelector) target;
return new DefaultProjectDependencyMetadata(projectTarget, this);
} else {
throw new IllegalArgumentException("Unexpected selector provided: " + target);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class LocalComponentDependencyMetadata method withTarget.
@Override
public LocalOriginDependencyMetadata withTarget(ComponentSelector target) {
if (target instanceof ModuleComponentSelector) {
ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion());
if (selector.equals(target) && requested.equals(requestedVersion)) {
return this;
}
return copyWithTarget(moduleTarget, requestedVersion);
} else if (target instanceof ProjectComponentSelector) {
if (target.equals(selector)) {
return this;
}
return copyWithTarget(target, requested);
} else {
throw new AssertionError("Invalid component selector type for substitution: " + target);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class ExternalModuleIvyDependencyDescriptorFactory method createDependencyDescriptor.
public DslOriginDependencyMetadata createDependencyDescriptor(String clientConfiguration, AttributeContainer clientAttributes, ModuleDependency dependency) {
ExternalModuleDependency externalModuleDependency = (ExternalModuleDependency) dependency;
boolean force = externalModuleDependency.isForce();
boolean changing = externalModuleDependency.isChanging();
boolean transitive = externalModuleDependency.isTransitive();
ModuleVersionSelector requested = new DefaultModuleVersionSelector(nullToEmpty(dependency.getGroup()), nullToEmpty(dependency.getName()), nullToEmpty(dependency.getVersion()));
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(requested);
List<Exclude> excludes = convertExcludeRules(clientConfiguration, dependency.getExcludeRules());
LocalComponentDependencyMetadata dependencyMetaData = new LocalComponentDependencyMetadata(selector, requested, clientConfiguration, clientAttributes, dependency.getTargetConfiguration(), convertArtifacts(dependency.getArtifacts()), excludes, force, changing, transitive);
return new DslOriginDependencyMetadataWrapper(dependencyMetaData, dependency);
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DynamicVersionResolver method resolve.
public void resolve(ModuleDependencyMetadata dependency, VersionSelector versionSelector, VersionSelector rejectedVersionSelector, BuildableComponentIdResolveResult result) {
ModuleComponentSelector requested = dependency.getSelector();
LOGGER.debug("Attempting to resolve version for {} using repositories {}", requested, repositoryNames);
List<Throwable> errors = new ArrayList<Throwable>();
List<RepositoryResolveState> resolveStates = Lists.newArrayListWithCapacity(repositories.size());
for (ModuleComponentRepository repository : repositories) {
resolveStates.add(new RepositoryResolveState(versionedComponentChooser, dependency, repository, versionSelector, rejectedVersionSelector));
}
final RepositoryChainModuleResolution latestResolved = findLatestModule(resolveStates, errors);
if (latestResolved != null) {
LOGGER.debug("Using {} from {}", latestResolved.module.getModuleVersionId(), latestResolved.repository);
for (Throwable error : errors) {
LOGGER.debug("Discarding resolve failure.", error);
}
result.resolved(metaDataFactory.transform(latestResolved));
return;
}
if (!errors.isEmpty()) {
result.failed(new ModuleVersionResolveException(requested, errors));
} else {
notFound(result, requested, resolveStates);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class GradlePomModuleDescriptorBuilder method doAddDependency.
private void doAddDependency(PomDependencyMgt dep, boolean optional, boolean useCompileScope) {
MavenScope scope;
if (useCompileScope) {
scope = MavenScope.Compile;
} else {
String scopeString = dep.getScope();
if (scopeString == null || scopeString.length() == 0) {
scopeString = getDefaultScope(dep);
}
if (SCOPES.containsKey(scopeString)) {
scope = SCOPES.get(scopeString);
} else {
// unknown scope, defaulting to 'compile'
scope = MavenScope.Compile;
}
}
String version = determineVersion(dep);
String mappedVersion = convertVersionFromMavenSyntax(version);
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(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.getGroup().equals(componentIdentifier.getGroup()) && selector.getModule().equals(componentIdentifier.getModule())) {
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, optional, selector, dependencyArtifact, excludes));
}
Aggregations