use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class IdeaProject method includeModulesFromComposite.
private void includeModulesFromComposite(Project xmlProject) {
PathFactory pathFactory = getPathFactory();
Set<ProjectComponentIdentifier> projectsInComposite = compositeContext.getAllProjects();
for (ProjectComponentIdentifier otherProjectId : projectsInComposite) {
File imlFile = moduleToProjectMapper.buildArtifactFile(otherProjectId, "iml");
if (imlFile != null) {
xmlProject.getModulePaths().add(pathFactory.relativePath("PROJECT_DIR", imlFile));
}
}
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier 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.ProjectComponentIdentifier in project gradle by gradle.
the class ProjectDependencyResolver method resolve.
@Override
public void resolve(ComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, BuildableComponentResolveResult result) {
if (isProjectModule(identifier)) {
ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) identifier;
LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
if (componentMetaData == null) {
result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(projectId), projectId + " not found."));
} else {
result.resolved(componentMetaData);
}
}
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class ProjectDependencyForcingResolver method select.
@Override
public <T extends ComponentResolutionState> void select(ConflictResolverDetails<T> details) {
// the collection will only be initialized if more than one project candidate is found
Collection<T> projectCandidates = null;
T foundProjectCandidate = null;
// fine one or more project dependencies among conflicting modules
for (T candidate : details.getCandidates()) {
ComponentResolveMetadata metaData = candidate.getMetadata();
if (metaData != null && metaData.getId() instanceof ProjectComponentIdentifier) {
if (foundProjectCandidate == null) {
// found the first project dependency
foundProjectCandidate = candidate;
} else {
// found more than one
if (projectCandidates == null) {
projectCandidates = new ArrayList<T>();
projectCandidates.add(foundProjectCandidate);
}
projectCandidates.add(candidate);
}
}
}
// let the delegate resolver select among them
if (projectCandidates != null) {
ConflictResolverDetails<T> projectDetails = new DefaultConflictResolverDetails<T>(Cast.<List<T>>uncheckedCast(projectCandidates));
delegate.select(projectDetails);
details.select(projectDetails.getSelected());
return;
}
// if found only one project dependency - return it, otherwise call the next resolver
if (foundProjectCandidate != null) {
details.select(foundProjectCandidate);
} else {
delegate.select(details);
}
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class VcsDependencyResolver method resolve.
@Override
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint versionConstraint, BuildableComponentIdResolveResult result) {
if (dependency.getSelector() instanceof ModuleComponentSelector) {
final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
// TODO: Need failure handling, e.g., cannot clone repository
if (spec != null) {
VersionControlSystem versionControlSystem = versionControlSystemFactory.create(spec);
VersionRef selectedVersion = selectVersion(depSelector, spec, versionControlSystem);
if (selectedVersion == null) {
result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
return;
}
File dependencyWorkingDir = new File(populateWorkingDirectory(baseWorkingDir, spec, versionControlSystem, selectedVersion), spec.getRootDir());
// TODO: This shouldn't rely on the service registry to find NestedBuildFactory
IncludedBuildRegistry includedBuildRegistry = serviceRegistry.get(IncludedBuildRegistry.class);
NestedBuildFactory nestedBuildFactory = serviceRegistry.get(NestedBuildFactory.class);
IncludedBuildInternal includedBuild = includedBuildRegistry.addImplicitBuild(((AbstractVersionControlSpec) spec).getBuildDefinition(dependencyWorkingDir), nestedBuildFactory);
Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {
@Override
public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
ModuleVersionIdentifier possibleMatch = entry.left;
return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
}
});
if (entry == null) {
result.failed(new ModuleVersionResolveException(depSelector, spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
} else {
LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
if (componentMetaData == null) {
result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(includedBuild.getModel(), entry.right.getProjectPath()), spec.getDisplayName() + " could not be resolved into a usable project."));
} else {
result.resolved(componentMetaData);
}
return;
}
}
}
projectDependencyResolver.resolve(dependency, versionConstraint, result);
}
Aggregations