use of org.gradle.api.artifacts.ModuleIdentifier 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.ModuleIdentifier in project gradle by gradle.
the class JsonProjectDependencyRenderer method collectModules.
private Set<ModuleIdentifier> collectModules(Configuration configuration) {
RenderableDependency root;
if (canBeResolved(configuration)) {
ResolutionResult result = configuration.getIncoming().getResolutionResult();
root = new RenderableModuleResult(result.getRoot());
} else {
root = new UnresolvableConfigurationResult(configuration);
}
Set<ModuleIdentifier> modules = Sets.newHashSet();
Set<ComponentIdentifier> visited = Sets.newHashSet();
populateModulesWithChildDependencies(root, visited, modules);
return modules;
}
use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.
the class NodeState method getEndorsedStrictVersions.
private StrictVersionConstraints getEndorsedStrictVersions(EdgeState incomingEdge) {
if (incomingEdge.getFrom().endorsesStrictVersionsFrom == null) {
return StrictVersionConstraints.EMPTY;
}
boolean filterOwn = false;
StrictVersionConstraints singleStrictVersionConstraints = StrictVersionConstraints.EMPTY;
Set<ModuleIdentifier> collectedConstraints = null;
for (EdgeState edgeState : incomingEdge.getFrom().endorsesStrictVersionsFrom) {
if (edgeState == incomingEdge) {
// These are my own constraints. I can not treat them as inherited,
// because that assumes that they are defined in another node as well and might be ignored.
filterOwn = true;
continue;
}
ComponentState targetComponent = edgeState.getTargetComponent();
if (targetComponent != null) {
// may be null if the build is about to fail
for (NodeState sourceNode : targetComponent.getNodes()) {
if (sourceNode.ownStrictVersionConstraints == null) {
// node's dependencies were not yet visited
sourceNode.collectOwnStrictVersions();
}
if (singleStrictVersionConstraints.isEmpty()) {
singleStrictVersionConstraints = sourceNode.ownStrictVersionConstraints;
} else {
if (collectedConstraints == null) {
collectedConstraints = Sets.newHashSet();
collectedConstraints.addAll(singleStrictVersionConstraints.getModules());
}
collectedConstraints.addAll(sourceNode.ownStrictVersionConstraints.getModules());
}
}
}
}
if (filterOwn) {
Set<ModuleIdentifier> resultSet;
if (collectedConstraints != null) {
resultSet = collectedConstraints;
} else {
resultSet = singleStrictVersionConstraints.getModules();
}
if (ownStrictVersionConstraints == null) {
collectOwnStrictVersions();
}
for (ModuleIdentifier ownConstraint : ownStrictVersionConstraints.getModules()) {
if (resultSet.contains(ownConstraint)) {
if (collectedConstraints == null) {
collectedConstraints = Sets.newHashSet();
collectedConstraints.addAll(singleStrictVersionConstraints.getModules());
}
collectedConstraints.remove(ownConstraint);
}
}
}
if (collectedConstraints != null) {
return StrictVersionConstraints.of(collectedConstraints);
} else {
return singleStrictVersionConstraints;
}
}
use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.
the class NodeState method cleanupConstraints.
/*
* When a node exits the graph, its constraints need to be cleaned up.
* This means:
* * Rescheduling any deferred selection impacted by a constraint coming from this node
* * Making sure we no longer are registered as pending interest on nodes pointed by constraints
*/
private void cleanupConstraints() {
// This part covers constraint that were taken into account between a selection being deferred and this node being scheduled for traversal
if (upcomingNoLongerPendingConstraints != null) {
for (ModuleIdentifier identifier : upcomingNoLongerPendingConstraints) {
ModuleResolveState module = resolveState.getModule(identifier);
for (EdgeState unattachedDependency : module.getUnattachedDependencies()) {
if (!unattachedDependency.getSelector().isResolved()) {
// Unresolved - we have a selector that was deferred but the constraint has been removed in between
NodeState from = unattachedDependency.getFrom();
from.prepareToRecomputeEdge(unattachedDependency);
}
}
}
upcomingNoLongerPendingConstraints = null;
}
// This part covers constraint that might be triggered in the future if the node they point gains a real edge
if (cachedFilteredDependencyStates != null && !cachedFilteredDependencyStates.isEmpty()) {
// Let's clear that state since it is no longer part of selection
for (DependencyState dependencyState : cachedFilteredDependencyStates) {
if (dependencyState.getDependency().isConstraint()) {
ModuleResolveState targetModule = resolveState.getModule(dependencyState.getModuleIdentifier());
if (targetModule.isPending()) {
targetModule.unregisterConstraintProvider(this);
}
}
}
}
}
use of org.gradle.api.artifacts.ModuleIdentifier in project gradle by gradle.
the class NodeState method isExcluded.
private boolean isExcluded(ExcludeSpec excludeSpec, DependencyState dependencyState) {
DependencyMetadata dependency = dependencyState.getDependency();
if (!resolveState.getEdgeFilter().isSatisfiedBy(dependency)) {
LOGGER.debug("{} is filtered.", dependency);
return true;
}
if (excludeSpec == moduleExclusions.nothing()) {
return false;
}
ModuleIdentifier targetModuleId = dependencyState.getModuleIdentifier();
if (excludeSpec.excludes(targetModuleId)) {
LOGGER.debug("{} is excluded from {} by {}.", targetModuleId, this, excludeSpec);
return true;
}
return false;
}
Aggregations