use of org.gradle.api.artifacts.ModuleVersionIdentifier 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.ModuleVersionIdentifier in project atlas by alibaba.
the class ResolvedDependencyContainer method addResolvedDependencyInfo.
/**
* 通过递归的方式进行依赖的解析
*
* @param parentDependency
* @param resolvedDependenciesMap
*/
private void addResolvedDependencyInfo(ResolvedDependencyInfo parentDependency, Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap) {
int indent = parentDependency.getIndent();
ModuleVersionIdentifier identifier = parentDependency.getModuleVersionIdentifier();
Collection<ResolvedDependencyInfo> childDependencies = resolvedDependenciesMap.get(identifier);
//TODO here
for (ResolvedDependencyInfo childDependency : childDependencies) {
if (childDependency.getIndent() > indent) {
// System.out.println(parentDependency + " indent " + indent + "->" + childDependency + " indent " + childDependency.getIndent());
parentDependency.getChildren().add(childDependency);
if (childDependency.getIndent() <= 1) {
addResolvedDependencyInfo(childDependency, resolvedDependenciesMap);
}
}
}
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project atlas by alibaba.
the class ResolvedDependencyContainer method reslovedDependencies.
/**
* 进行依赖仲裁
*/
public synchronized DependencyTree reslovedDependencies() {
if (inited) {
return dependencyTree;
}
if (!conflictDependencies.isEmpty()) {
for (String str : conflictDependencies) {
logger.error(str);
}
if (null == forceMap) {
throw new GradleException("conflict dependencis");
} else {
AtlasBuildContext.conflictDependencies = conflictDependencies;
}
}
// 仲裁后的依赖关系.结构为父类-子类
Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap = LinkedHashMultimap.create();
Map<ModuleVersionIdentifier, ResolvedDependencyInfo> directDependencies = new HashMap<ModuleVersionIdentifier, ResolvedDependencyInfo>();
for (String key : dependenciesMap.keySet()) {
Collection<ResolvedDependencyInfo> dependencyLevels = dependenciesMap.get(key);
if (dependencyLevels.size() > 0) {
List<ResolvedDependencyInfo> resolvedDependencyInfos = Lists.newArrayList();
resolvedDependencyInfos.addAll(dependencyLevels);
Collections.sort(resolvedDependencyInfos);
ResolvedDependencyInfo resolvedDependencyInfo = resolvedDependencyInfos.get(0);
ResolvedDependencyInfo parent = resolvedDependencyInfo.getParent();
//对于放入resolvedDependenciesMap中的信息不需要加入children
resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
if (null != parent) {
//如果存在的父依赖,就把当前依赖加入到父依赖的子依赖中
resolvedDependenciesMap.put(parent.getModuleVersionIdentifier(), resolvedDependencyInfo);
} else {
//如果没有父依赖,就是一级依赖
directDependencies.put(resolvedDependencyInfo.getModuleVersionIdentifier(), resolvedDependencyInfo);
}
}
}
// 开始构建依赖树
dependencyTree.clear();
for (ModuleVersionIdentifier key : directDependencies.keySet()) {
ResolvedDependencyInfo resolvedDependencyInfo = directDependencies.get(key);
//清空children
resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
addResolvedDependencyInfo(resolvedDependencyInfo, resolvedDependenciesMap);
dependencyTree.addDependency(resolvedDependencyInfo);
}
inited = true;
return dependencyTree;
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class DefaultIdeDependencyResolver method getIdeRepoFileDependencies.
/**
* Gets IDE repository file dependencies.
*
* @param configuration Configuration
* @return IDE repository file dependencies
*/
public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) {
ResolutionResult result = getIncomingResolutionResult(configuration);
final Set<ResolvedComponentResult> resolvedRepoFileComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() {
@Override
public boolean isSatisfiedBy(ResolvedComponentResult element) {
return element.getId() instanceof ModuleComponentIdentifier;
}
});
Set<ModuleVersionIdentifier> mappedResolvedDependencies = mapResolvedDependencies(resolvedRepoFileComponents);
Set<ResolvedArtifact> artifacts = getExternalArtifacts(configuration);
List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>();
for (ResolvedArtifact artifact : artifacts) {
if (mappedResolvedDependencies.contains(artifact.getModuleVersion().getId())) {
IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency(artifact.getFile());
ideRepoFileDependency.setId(artifact.getModuleVersion().getId());
externalDependencies.add(ideRepoFileDependency);
}
}
return externalDependencies;
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class DefaultIvyPublication method addProjectDependency.
private void addProjectDependency(ProjectDependency dependency, String confMapping) {
ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(dependency);
ivyDependencies.add(new DefaultIvyDependency(identifier.getGroup(), identifier.getName(), identifier.getVersion(), confMapping, dependency.isTransitive(), Collections.<DependencyArtifact>emptyList(), dependency.getExcludeRules()));
}
Aggregations