Search in sources :

Example 1 with UnresolvedDependency

use of org.gradle.api.artifacts.UnresolvedDependency in project gradle by gradle.

the class ResolutionFailureCollector method complete.

public Set<UnresolvedDependency> complete() {
    if (failuresByRevisionId.isEmpty()) {
        ImmutableSet.of();
    }
    ImmutableSet.Builder<UnresolvedDependency> builder = ImmutableSet.builder();
    for (Map.Entry<ComponentSelector, BrokenDependency> entry : failuresByRevisionId.entrySet()) {
        Collection<List<ComponentIdentifier>> paths = DependencyGraphPathResolver.calculatePaths(entry.getValue().requiredBy, root);
        ComponentSelector key = entry.getKey();
        ModuleVersionSelector moduleVersionSelector = componentSelectorConverter.getSelector(key);
        builder.add(new DefaultUnresolvedDependency(moduleVersionSelector, entry.getValue().failure.withIncomingPaths(paths)));
    }
    return builder.build();
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with UnresolvedDependency

use of org.gradle.api.artifacts.UnresolvedDependency in project gradle by gradle.

the class ResolutionFailureCollector method complete.

public Set<UnresolvedDependency> complete(Set<UnresolvedDependency> extraFailures) {
    if (extraFailures.isEmpty() && failuresByRevisionId.isEmpty()) {
        return ImmutableSet.of();
    }
    ImmutableSet.Builder<UnresolvedDependency> builder = ImmutableSet.builder();
    builder.addAll(extraFailures);
    for (Map.Entry<ComponentSelector, BrokenDependency> entry : failuresByRevisionId.entrySet()) {
        Collection<List<ComponentIdentifier>> paths = DependencyGraphPathResolver.calculatePaths(entry.getValue().requiredBy, root);
        ComponentSelector key = entry.getKey();
        ModuleVersionSelector moduleVersionSelector = componentSelectorConverter.getSelector(key);
        builder.add(new DefaultUnresolvedDependency(moduleVersionSelector, entry.getValue().failure.withIncomingPaths(paths)));
    }
    return builder.build();
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with UnresolvedDependency

use of org.gradle.api.artifacts.UnresolvedDependency in project gradle by gradle.

the class DefaultLenientConfiguration method select.

@Override
public SelectedArtifactSet select(final Spec<? super Dependency> dependencySpec, final AttributeContainerInternal requestedAttributes, final Spec<? super ComponentIdentifier> componentSpec, boolean allowNoMatchingVariants) {
    VariantSelector selector = artifactTransforms.variantSelector(requestedAttributes, allowNoMatchingVariants, configuration.getDependenciesResolver());
    SelectedArtifactResults artifactResults = this.artifactResults.select(componentSpec, selector);
    return new SelectedArtifactSet() {

        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            for (UnresolvedDependency unresolvedDependency : unresolvedDependencies) {
                context.visitFailure(unresolvedDependency.getProblem());
            }
            context.add(artifactResults.getArtifacts());
        }

        @Override
        public void visitArtifacts(ArtifactVisitor visitor, boolean continueOnSelectionFailure) {
            if (!unresolvedDependencies.isEmpty()) {
                for (UnresolvedDependency unresolvedDependency : unresolvedDependencies) {
                    visitor.visitFailure(unresolvedDependency.getProblem());
                }
                if (!continueOnSelectionFailure) {
                    return;
                }
            }
            DefaultLenientConfiguration.this.visitArtifactsWithBuildOperation(dependencySpec, artifactResults, DefaultLenientConfiguration.this.fileDependencyResults, visitor);
        }
    };
}
Also used : TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) SelectedArtifactResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactResults) VariantSelector(org.gradle.api.internal.artifacts.transform.VariantSelector) SelectedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactSet) ArtifactVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor) DependencyVerificationOverride(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride)

Example 4 with UnresolvedDependency

use of org.gradle.api.artifacts.UnresolvedDependency in project gradle by gradle.

the class DependencyLockingArtifactVisitor method createLockingFailures.

private static Set<UnresolvedDependency> createLockingFailures(Map<ModuleIdentifier, ModuleComponentIdentifier> modulesToBeLocked, Set<ModuleComponentIdentifier> extraModules, Map<ModuleComponentIdentifier, String> forcedModules) {
    Set<UnresolvedDependency> completedFailures = Sets.newHashSetWithExpectedSize(modulesToBeLocked.values().size() + extraModules.size());
    for (ModuleComponentIdentifier presentInLock : modulesToBeLocked.values()) {
        completedFailures.add(new DefaultUnresolvedDependency(DefaultModuleVersionSelector.newSelector(presentInLock.getModuleIdentifier(), presentInLock.getVersion()), new LockOutOfDateException("Did not resolve '" + presentInLock.getDisplayName() + "' which is part of the dependency lock state")));
    }
    for (ModuleComponentIdentifier extraModule : extraModules) {
        completedFailures.add(new DefaultUnresolvedDependency(DefaultModuleVersionSelector.newSelector(extraModule.getModuleIdentifier(), extraModule.getVersion()), new LockOutOfDateException("Resolved '" + extraModule.getDisplayName() + "' which is not part of the dependency lock state")));
    }
    for (Map.Entry<ModuleComponentIdentifier, String> entry : forcedModules.entrySet()) {
        ModuleComponentIdentifier forcedModule = entry.getKey();
        completedFailures.add(new DefaultUnresolvedDependency(DefaultModuleVersionSelector.newSelector(forcedModule.getModuleIdentifier(), forcedModule.getVersion()), new LockOutOfDateException("Did not resolve '" + forcedModule.getDisplayName() + "' which has been forced / substituted to a different version: '" + entry.getValue() + "'")));
    }
    return completedFailures;
}
Also used : UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) DefaultUnresolvedDependency(org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) Map(java.util.Map)

Example 5 with UnresolvedDependency

use of org.gradle.api.artifacts.UnresolvedDependency in project atlas by alibaba.

the class TDependencyManager method collectArtifacts.

/**
     * Collects the resolved artifacts and returns a configuration which contains them. If the
     * configuration has unresolved dependencies we check that we have the latest version of the
     * Google repository and the Android Support repository and we install them if not. After this,
     * the resolution is retried with a fresh copy of the configuration, that will contain the newly
     * updated repositories. If this passes, we return the correct configuration and we fill the
     * artifacts map.
     *
     * @param configuration the configuration from which we get the artifacts
     * @param artifacts     the map of artifacts that are being collected
     * @return a valid configuration that has only resolved dependencies.
     */
private Configuration collectArtifacts(Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) {
    Set<ResolvedArtifact> allArtifacts;
    // Make a copy because Gradle keeps a per configuration state of resolution that we
    // need to reset.
    Configuration configurationCopy = configuration.copyRecursive();
    Set<UnresolvedDependency> unresolvedDependencies = configuration.getResolvedConfiguration().getLenientConfiguration().getUnresolvedModuleDependencies();
    if (unresolvedDependencies.isEmpty()) {
        allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts();
    } else {
        if (!repositoriesUpdated && sdkLibData.useSdkDownload()) {
            List<String> repositoryPaths = new ArrayList<>();
            for (UnresolvedDependency dependency : unresolvedDependencies) {
                if (isGoogleOwnedDependency(dependency.getSelector())) {
                    repositoryPaths.add(getRepositoryPath(dependency.getSelector()));
                }
            }
            sdkLibData.setNeedsCacheReset(sdkHandler.checkResetCache());
            List<File> updatedRepositories = sdkHandler.getSdkLoader().updateRepositories(repositoryPaths, sdkLibData, logger);
            // resolution result.
            for (File updatedRepository : updatedRepositories) {
                project.getRepositories().maven(newRepo -> {
                    newRepo.setName("Updated " + updatedRepository.getPath());
                    newRepo.setUrl(updatedRepository.toURI());
                    newRepo.artifactUrls(project.getRootProject().file("sdk-manager"));
                });
            }
            repositoriesUpdated = true;
        }
        if (extraModelInfo.getMode() != STANDARD) {
            allArtifacts = configurationCopy.getResolvedConfiguration().getLenientConfiguration().getArtifacts(Specs.satisfyAll());
        } else {
            allArtifacts = configurationCopy.getResolvedConfiguration().getResolvedArtifacts();
        }
        // Modify the configuration to the one that passed.
        configuration = configurationCopy;
    }
    for (ResolvedArtifact artifact : allArtifacts) {
        ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
        List<ResolvedArtifact> moduleArtifacts = artifacts.get(id);
        if (moduleArtifacts == null) {
            moduleArtifacts = Lists.newArrayList();
            artifacts.put(id, moduleArtifacts);
        }
        if (!moduleArtifacts.contains(artifact)) {
            moduleArtifacts.add(artifact);
        }
    }
    return configuration;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

UnresolvedDependency (org.gradle.api.artifacts.UnresolvedDependency)7 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)3 DefaultUnresolvedDependency (org.gradle.api.internal.artifacts.ivyservice.DefaultUnresolvedDependency)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 DependencyVerificationOverride (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Configuration (org.gradle.api.artifacts.Configuration)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)1 ResolutionStrategyInternal (org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal)1