use of org.gradle.api.artifacts.component.ComponentIdentifier in project atlas by alibaba.
the class DependencyManager method resolveDependency.
/**
* 解析依赖
*
* @param resolvedDependencyContainer
* @param parent
* @param resolvedComponentResult
* @param artifacts
* @param configDependencies
* @param indent
*/
private void resolveDependency(ResolvedDependencyContainer resolvedDependencyContainer, ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node) {
ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
if (configDependencies.getChecker().checkForExclusion(moduleVersion)) {
return;
}
if (moduleVersion.getName().equals("support-annotations") && moduleVersion.getGroup().equals("com.android.support")) {
configDependencies.setAnnotationsPresent(true);
}
// now loop on all the artifact for this modules.
List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
ComponentIdentifier id = resolvedComponentResult.getId();
String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
// 如果同时找到多个依赖,暂时没法判断是那个真正有用
for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), resolvedArtifact.getType(), resolvedArtifact.getClassifier());
resolvedDependencyInfo.setIndent(indent);
resolvedDependencyInfo.setGradlePath(gradlePath);
resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
String path = computeArtifactPath(moduleVersion, resolvedArtifact);
String name = computeArtifactName(moduleVersion, resolvedArtifact);
File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-" + resolvedArtifact.getType().toLowerCase() + "/" + path);
resolvedDependencyInfo.setExplodedDir(explodedDir);
resolvedDependencyInfo.setDependencyName(name);
if (null == parent) {
parent = resolvedDependencyInfo;
} else {
resolvedDependencyInfo.setParent(parent);
parent.getChildren().add(resolvedDependencyInfo);
}
Set<? extends DependencyResult> dependencies = resolvedComponentResult.getDependencies();
for (DependencyResult dep : dependencies) {
if (dep instanceof ResolvedDependencyResult) {
ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
CircleDependencyCheck.DependencyNode childNode = circleDependencyCheck.addDependency(childResolvedComponentResult.getModuleVersion(), node, indent + 1);
CircleDependencyCheck.CircleResult circleResult = circleDependencyCheck.checkCircle(logger);
if (circleResult.hasCircle) {
logger.warning("[CircleDependency]" + StringUtils.join(circleResult.detail, ";"));
} else {
resolveDependency(resolvedDependencyContainer, parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode);
}
}
}
resolvedDependencyContainer.addDependency(resolvedDependencyInfo);
}
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class DefaultResolvedArtifactsBuilder method visitArtifacts.
@Override
public void visitArtifacts(DependencyGraphNode from, DependencyGraphNode to, int artifactSetId, ArtifactSet artifacts) {
// Don't collect build dependencies if not required
if (!buildProjectDependencies) {
artifacts = new NoBuildDependenciesArtifactSet(artifacts);
} else {
ConfigurationMetadata configurationMetadata = to.getMetadata();
if (configurationMetadata instanceof LocalConfigurationMetadata) {
// For a dependency from _another_ build to _this_ build, don't make the artifact buildable
// Making these artifacts buildable leads to poor error reporting due to direct task dependency cycle (losing the intervening build dependencies)
ComponentIdentifier incomingId = from.getOwner().getComponentId();
ComponentIdentifier outgoingId = to.getOwner().getComponentId();
if (incomingId instanceof ProjectComponentIdentifier && outgoingId instanceof ProjectComponentIdentifier) {
if (!isCurrentBuild(incomingId) && isCurrentBuild(outgoingId)) {
artifacts = new NoBuildDependenciesArtifactSet(artifacts);
}
}
}
}
collectArtifacts(artifactSetId, artifacts);
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class LocalFileDependencyBackedArtifactSet method startVisit.
@Override
public Completion startVisit(BuildOperationQueue<RunnableBuildOperation> actions, AsyncArtifactListener listener) {
if (!listener.includeFileDependencies()) {
return EMPTY_RESULT;
}
ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
return EMPTY_RESULT;
}
Set<File> files;
try {
files = dependencyMetadata.getFiles().getFiles();
} catch (Throwable throwable) {
return new BrokenResolvedArtifactSet(throwable);
}
List<ResolvedArtifactSet> selectedArtifacts = Lists.newArrayListWithCapacity(files.size());
for (File file : files) {
ComponentArtifactIdentifier artifactIdentifier;
if (componentIdentifier == null) {
artifactIdentifier = new OpaqueComponentArtifactIdentifier(file);
if (!componentFilter.isSatisfiedBy(artifactIdentifier.getComponentIdentifier())) {
continue;
}
} else {
artifactIdentifier = new ComponentFileArtifactIdentifier(componentIdentifier, file.getName());
}
AttributeContainerInternal variantAttributes = artifactTypeRegistry.mapAttributesFor(file);
SingletonFileResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, "local file", variantAttributes, dependencyMetadata);
selectedArtifacts.add(selector.select(variant));
}
return CompositeResolvedArtifactSet.of(selectedArtifacts).startVisit(actions, listener);
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class DependencyGraphBuilder method toComponentId.
private ComponentIdentifier toComponentId(ModuleVersionIdentifier id, Map<ModuleVersionIdentifier, ComponentIdentifier> componentIdentifierCache) {
ComponentIdentifier identifier = componentIdentifierCache.get(id);
if (identifier == null) {
identifier = DefaultModuleComponentIdentifier.newId(id);
componentIdentifierCache.put(id, identifier);
}
return identifier;
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class DefaultArtifactResolutionQuery method createResult.
private ArtifactResolutionResult createResult(ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {
Set<ComponentResult> componentResults = Sets.newHashSet();
for (ComponentIdentifier componentId : componentIds) {
try {
ComponentIdentifier validId = validateComponentIdentifier(componentId);
componentResults.add(buildComponentResult(validId, componentMetaDataResolver, artifactResolver));
} catch (Throwable t) {
componentResults.add(new DefaultUnresolvedComponentResult(componentId, t));
}
}
return new DefaultArtifactResolutionResult(componentResults);
}
Aggregations