Search in sources :

Example 1 with ArtifactVisitor

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor 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) {
    final SelectedArtifactResults artifactResults;
    final SelectedFileDependencyResults fileDependencyResults;
    VariantSelector selector = artifactTransforms.variantSelector(requestedAttributes);
    artifactResults = this.artifactResults.select(componentSpec, selector);
    fileDependencyResults = this.fileDependencyResults.select(componentSpec, selector);
    return new SelectedArtifactSet() {

        @Override
        public <T extends Collection<Object>> T collectBuildDependencies(T dest) {
            artifactResults.getArtifacts().collectBuildDependencies(dest);
            fileDependencyResults.getArtifacts().collectBuildDependencies(dest);
            return dest;
        }

        @Override
        public void visitArtifacts(ArtifactVisitor visitor) {
            DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
        }

        /**
             * Collects files reachable from first level dependencies that satisfy the given spec. Fails when any file cannot be resolved
             */
        @Override
        public <T extends Collection<? super File>> T collectFiles(T dest) throws ResolveException {
            rethrowFailure();
            ResolvedFilesCollectingVisitor visitor = new ResolvedFilesCollectingVisitor(dest);
            try {
                DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
                // The visitor adds file dependencies directly to the destination collection however defers adding the artifacts.
                // This is to ensure a fixed order regardless of whether the first level dependencies are filtered or not
                // File dependencies and artifacts are currently treated separately as a migration step
                visitor.addArtifacts();
            } catch (Throwable t) {
                visitor.failures.add(t);
            }
            if (!visitor.failures.isEmpty()) {
                throw new ArtifactResolveException("files", configuration.getPath(), configuration.getDisplayName(), visitor.failures);
            }
            return dest;
        }

        /**
             * Collects all resolved artifacts. Fails when any artifact cannot be resolved.
             */
        @Override
        public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException {
            rethrowFailure();
            ResolvedArtifactCollectingVisitor visitor = new ResolvedArtifactCollectingVisitor(dest);
            try {
                DefaultLenientConfiguration.this.visitArtifacts(dependencySpec, artifactResults, fileDependencyResults, visitor);
            } catch (Throwable t) {
                visitor.failures.add(t);
            }
            if (!visitor.failures.isEmpty()) {
                throw new ArtifactResolveException("artifacts", configuration.getPath(), configuration.getDisplayName(), visitor.failures);
            }
            return dest;
        }
    };
}
Also used : SelectedFileDependencyResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedFileDependencyResults) 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) Collection(java.util.Collection) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) DefaultResolvedArtifactResult(org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult) File(java.io.File)

Example 2 with ArtifactVisitor

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor 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 3 with ArtifactVisitor

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor in project gradle by gradle.

the class DependencyResolvingClasspath method getFiles.

@Override
public Set<File> getFiles() {
    ensureResolved(true);
    final Set<File> result = new LinkedHashSet<File>();
    ParallelResolveArtifactSet artifacts = ParallelResolveArtifactSet.wrap(resolveResult.artifactsResults.getArtifacts(), buildOperationExecutor);
    artifacts.visit(new ArtifactVisitor() {

        @Override
        public void visitArtifact(String variantName, AttributeContainer variantAttributes, ResolvableArtifact artifact) {
            result.add(artifact.getFile());
        }

        @Override
        public void visitFailure(Throwable failure) {
            throw UncheckedException.throwAsUncheckedException(failure);
        }

        @Override
        public boolean includeFiles() {
            return true;
        }

        @Override
        public boolean requireArtifactFiles() {
            return true;
        }

        @Override
        public void visitFile(ComponentArtifactIdentifier artifactIdentifier, String variantName, AttributeContainer variantAttributes, File file) {
            result.add(file);
        }
    });
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ResolvableArtifact(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvableArtifact) AttributeContainer(org.gradle.api.attributes.AttributeContainer) File(java.io.File) ArtifactVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor) ParallelResolveArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ParallelResolveArtifactSet)

Aggregations

ArtifactVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactVisitor)3 File (java.io.File)2 SelectedArtifactResults (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactResults)2 SelectedArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactSet)2 VariantSelector (org.gradle.api.internal.artifacts.transform.VariantSelector)2 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 UnresolvedDependency (org.gradle.api.artifacts.UnresolvedDependency)1 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)1 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)1 AttributeContainer (org.gradle.api.attributes.AttributeContainer)1 DependencyVerificationOverride (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride)1 ParallelResolveArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ParallelResolveArtifactSet)1 ResolvableArtifact (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvableArtifact)1 SelectedFileDependencyResults (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedFileDependencyResults)1 DefaultResolvedArtifactResult (org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult)1 TaskDependencyResolveContext (org.gradle.api.internal.tasks.TaskDependencyResolveContext)1