use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class AbstractCompositeParticipantBuildState method registerProject.
private void registerProject(Set<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> availableModules, ProjectInternal project) {
ProjectComponentIdentifier projectIdentifier = new DefaultProjectComponentIdentifier(getBuildIdentifier(), project.getIdentityPath(), project.getProjectPath(), project.getName());
ModuleVersionIdentifier moduleId = DefaultModuleVersionIdentifier.newId(project.getDependencyMetaDataProvider().getModule());
LOGGER.info("Registering {} in composite build. Will substitute for module '{}'.", project, moduleId.getModule());
availableModules.add(Pair.of(moduleId, projectIdentifier));
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class CompositeBuildDependencySubstitutions method getReplacementFor.
private ProjectComponentIdentifier getReplacementFor(ModuleComponentSelector selector) {
ModuleIdentifier candidateId = selector.getModuleIdentifier();
Collection<ProjectComponentIdentifier> providingProjects = replacementMap.get(candidateId);
if (providingProjects.isEmpty()) {
LOGGER.debug("Found no composite build substitute for module '{}'.", candidateId);
return null;
}
if (providingProjects.size() == 1) {
ProjectComponentIdentifier match = providingProjects.iterator().next();
LOGGER.info("Found project '{}' as substitute for module '{}'.", match, candidateId);
return match;
}
throw new ModuleVersionResolveException(selector, () -> {
SortedSet<String> sortedProjects = providingProjects.stream().map(ComponentIdentifier::getDisplayName).collect(Collectors.toCollection(TreeSet::new));
return String.format("Module version '%s' is not unique in composite: can be provided by %s.", selector.getDisplayName(), sortedProjects);
});
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class CompositeBuildDependencySubstitutions method execute.
@Override
public void execute(DependencySubstitution sub) {
DependencySubstitutionInternal dependencySubstitution = (DependencySubstitutionInternal) sub;
// Use the result of previous rules as the input for dependency substitution
ComponentSelector requested = dependencySubstitution.getTarget();
if (requested instanceof ModuleComponentSelector) {
ModuleComponentSelector selector = (ModuleComponentSelector) requested;
ProjectComponentIdentifier replacement = getReplacementFor(selector);
if (replacement != null) {
ProjectComponentSelector targetProject = DefaultProjectComponentSelector.newSelector(replacement, ((AttributeContainerInternal) requested.getAttributes()).asImmutable(), requested.getRequestedCapabilities());
dependencySubstitution.useTarget(targetProject, ComponentSelectionReasons.COMPOSITE_BUILD);
}
}
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.
the class DefaultProjectStateRegistry method addProject.
private ProjectState addProject(BuildState owner, DefaultBuildProjectRegistry projectRegistry, DefaultProjectDescriptor descriptor) {
Path projectPath = descriptor.path();
Path identityPath = owner.calculateIdentityPathForProject(projectPath);
String name = descriptor.getName();
ProjectComponentIdentifier projectIdentifier = new DefaultProjectComponentIdentifier(owner.getBuildIdentifier(), identityPath, projectPath, name);
IProjectFactory projectFactory = owner.getMutableModel().getServices().get(IProjectFactory.class);
StateTransitionControllerFactory stateTransitionControllerFactory = owner.getMutableModel().getServices().get(StateTransitionControllerFactory.class);
ProjectStateImpl projectState = new ProjectStateImpl(owner, identityPath, projectPath, descriptor.getName(), projectIdentifier, descriptor, projectFactory, stateTransitionControllerFactory);
projectsByPath.put(identityPath, projectState);
projectsById.put(projectIdentifier, projectState);
projectRegistry.add(projectPath, projectState);
return projectState;
}
use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project atlas by alibaba.
the class AtlasDependencyGraph method createDependencies.
/**
* Create a level 1 dependency list.
*/
@NonNull
public DependenciesImpl createDependencies(@NonNull VariantScope variantScope, boolean downloadSources, @NonNull Consumer<SyncIssue> failureConsumer) {
try {
ImmutableList.Builder<String> projects = ImmutableList.builder();
ImmutableList.Builder<AndroidLibrary> androidLibraries = ImmutableList.builder();
ImmutableList.Builder<JavaLibrary> javaLibrary = ImmutableList.builder();
// get the runtime artifact. We only care about the ComponentIdentifier so we don't
// need to call getAllArtifacts() which computes a lot more many things.
// Instead just get all the jars to get all the dependencies.
ArtifactCollection runtimeArtifactCollection = computeArtifactList(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AtlasAndroidArtifacts.AtlasArtifactType.JAR);
// build a list of the artifacts
Set<ComponentIdentifier> runtimeIdentifiers = new HashSet<>(runtimeArtifactCollection.getArtifacts().size());
for (ResolvedArtifactResult result : runtimeArtifactCollection.getArtifacts()) {
runtimeIdentifiers.add(result.getId().getComponentIdentifier());
}
Set<AtlasDependencyGraph.HashableResolvedArtifactResult> artifacts = getAllArtifacts(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, dependencyFailureHandler);
for (AtlasDependencyGraph.HashableResolvedArtifactResult artifact : artifacts) {
ComponentIdentifier id = artifact.getId().getComponentIdentifier();
boolean isProvided = !runtimeIdentifiers.contains(id);
boolean isSubproject = id instanceof ProjectComponentIdentifier;
String projectPath = isSubproject ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
if (artifact.getDependencyType() == DependencyType.JAVA) {
if (projectPath != null) {
projects.add(projectPath);
continue;
}
// FIXME: Dependencies information is not set correctly.
javaLibrary.add(new com.android.build.gradle.internal.ide.JavaLibraryImpl(artifact.getFile(), null, ImmutableList.of(), /* dependencies */
null, /* requestedCoordinates */
Preconditions.checkNotNull(sMavenCoordinatesCache.get(artifact)), false, /* isSkipped */
isProvided));
} else {
if (artifact.isWrappedModule()) {
// force external dependency mode.
projectPath = null;
}
final File explodedFolder = artifact.getFile();
// noinspection VariableNotUsedInsideIf
androidLibraries.add(new com.android.build.gradle.internal.ide.AndroidLibraryImpl(// FIXME: Dependencies information is not set correctly.
Preconditions.checkNotNull(sMavenCoordinatesCache.get(artifact)), projectPath, artifact.bundleResult != null ? artifact.bundleResult.getFile() : explodedFolder, // fallback so that the value is non-null
explodedFolder, /*exploded folder*/
getVariant(artifact), isProvided, false, /* dependencyItem.isSkipped() */
ImmutableList.of(), /* androidLibraries */
ImmutableList.of(), /* javaLibraries */
findLocalJarsAsFiles(explodedFolder)));
}
}
// force download the source artifacts of the compile classpath only.
if (downloadSources) {
Set<ComponentIdentifier> ids = Sets.newHashSetWithExpectedSize(artifacts.size());
for (AtlasDependencyGraph.HashableResolvedArtifactResult artifact : artifacts) {
ids.add(artifact.getId().getComponentIdentifier());
}
handleSources(variantScope.getGlobalScope().getProject(), ids, failureConsumer);
}
return new DependenciesImpl(androidLibraries.build(), javaLibrary.build(), projects.build());
} finally {
dependencyFailureHandler.collectIssues().forEach(failureConsumer);
}
}
Aggregations