Search in sources :

Example 46 with ProjectComponentIdentifier

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));
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Example 47 with ProjectComponentIdentifier

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);
    });
}
Also used : ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 48 with ProjectComponentIdentifier

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);
        }
    }
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 49 with ProjectComponentIdentifier

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;
}
Also used : Path(org.gradle.util.Path) StateTransitionControllerFactory(org.gradle.internal.model.StateTransitionControllerFactory) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultProjectComponentIdentifier(org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier)

Example 50 with ProjectComponentIdentifier

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);
    }
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) File(java.io.File) NonNull(com.android.annotations.NonNull)

Aggregations

ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)52 File (java.io.File)12 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)12 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)9 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)9 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)7 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)6 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)6 Project (org.gradle.api.Project)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)5 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 LocalComponentRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.LocalComponentRegistry)5 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3