use of org.gradle.api.artifacts.component.ComponentIdentifier in project atlas by alibaba.
the class TDependencyManager 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, Set<String> resolvedModules) {
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);
if (null == moduleArtifacts) {
return;
}
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 parentVersionString = parent.getType();
String moduleVersonString = moduleVersion.toString() + "." + resolvedArtifact.getType() + "." + resolvedArtifact.getClassifier() + "." + indent;
if (null != parent) {
if ("awb".equals(parent.getType())) {
moduleVersonString = parent.toString() + "->" + moduleVersonString;
}
}
if (resolvedModules.contains(moduleVersonString)) {
logger.info(moduleVersonString);
continue;
} else {
resolvedModules.add(moduleVersonString);
}
String path = computeArtifactPath(moduleVersion, resolvedArtifact);
String name = computeArtifactName(moduleVersion, resolvedArtifact);
File explodedDir = project.file(project.getBuildDir() + "/" + FD_INTERMEDIATES + "/exploded-" + resolvedArtifact.getType().toLowerCase() + "/" + path);
resolvedDependencyInfo.setExplodedDir(explodedDir);
resolvedDependencyInfo.setDependencyName(name);
if (null == parent) {
parent = resolvedDependencyInfo;
} else {
if (null == resolvedDependencyInfo.getParent()) {
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, resolvedModules);
}
}
}
resolvedDependencyContainer.addDependency(resolvedDependencyInfo);
}
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class ComponentResultSerializer method read.
public ComponentResult read(Decoder decoder) throws IOException {
long resultId = decoder.readSmallLong();
ModuleVersionIdentifier id = idSerializer.read(decoder);
ComponentSelectionReason reason = reasonSerializer.read(decoder);
ComponentIdentifier componentId = componentIdSerializer.read(decoder);
String variantName = decoder.readString();
AttributeContainer attributes = attributeContainerSerializer.read(decoder);
return new DetachedComponentResult(resultId, id, reason, componentId, variantName, attributes);
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class DependencyInsightReporter method prepare.
public Collection<RenderableDependency> prepare(Collection<DependencyResult> input, VersionSelectorScheme versionSelectorScheme, VersionComparator versionComparator) {
LinkedList<RenderableDependency> out = new LinkedList<RenderableDependency>();
List<DependencyEdge> dependencies = CollectionUtils.collect(input, new Transformer<DependencyEdge, DependencyResult>() {
@Override
public DependencyEdge transform(DependencyResult result) {
if (result instanceof UnresolvedDependencyResult) {
return new UnresolvedDependencyEdge((UnresolvedDependencyResult) result);
} else {
return new ResolvedDependencyEdge((ResolvedDependencyResult) result);
}
}
});
Collection<DependencyEdge> sorted = DependencyResultSorter.sort(dependencies, versionSelectorScheme, versionComparator);
// remember if module id was annotated
HashSet<ComponentIdentifier> annotated = new HashSet<ComponentIdentifier>();
RequestedVersion current = null;
for (DependencyEdge dependency : sorted) {
ResolvedVariantResult selectedVariant = dependency.getSelectedVariant();
// add description only to the first module
if (annotated.add(dependency.getActual())) {
// add a heading dependency with the annotation if the dependency does not exist in the graph
if (!dependency.getRequested().matchesStrictly(dependency.getActual())) {
out.add(new DependencyReportHeader(dependency, selectedVariant));
current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null, selectedVariant);
out.add(current);
} else {
current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), getReasonDescription(dependency.getReason()), selectedVariant);
out.add(current);
}
} else if (!current.getRequested().equals(dependency.getRequested())) {
current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null, selectedVariant);
out.add(current);
}
current.addChild(dependency);
}
return out;
}
Aggregations