Search in sources :

Example 6 with ResolvedArtifact

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

the class DefaultIdeDependencyResolver method getIdeRepoFileDependencies.

/**
     * Gets IDE repository file dependencies.
     *
     * @param configuration Configuration
     * @return IDE repository file dependencies
     */
public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    final Set<ResolvedComponentResult> resolvedRepoFileComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() {

        @Override
        public boolean isSatisfiedBy(ResolvedComponentResult element) {
            return element.getId() instanceof ModuleComponentIdentifier;
        }
    });
    Set<ModuleVersionIdentifier> mappedResolvedDependencies = mapResolvedDependencies(resolvedRepoFileComponents);
    Set<ResolvedArtifact> artifacts = getExternalArtifacts(configuration);
    List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>();
    for (ResolvedArtifact artifact : artifacts) {
        if (mappedResolvedDependencies.contains(artifact.getModuleVersion().getId())) {
            IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency(artifact.getFile());
            ideRepoFileDependency.setId(artifact.getModuleVersion().getId());
            externalDependencies.add(ideRepoFileDependency);
        }
    }
    return externalDependencies;
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ArrayList(java.util.ArrayList) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult)

Example 7 with ResolvedArtifact

use of org.gradle.api.artifacts.ResolvedArtifact in project flyway by flyway.

the class AbstractFlywayTask method addDependenciesWithScope.

private void addDependenciesWithScope(List<URL> urls, String scope) throws IOException {
    for (ResolvedArtifact artifact : getProject().getConfigurations().getByName(scope).getResolvedConfiguration().getResolvedArtifacts()) {
        URL artifactUrl = artifact.getFile().toURI().toURL();
        getLogger().debug("Adding Dependency to Classpath: " + artifactUrl);
        urls.add(artifactUrl);
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) URL(java.net.URL)

Example 8 with ResolvedArtifact

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

the class DefaultResolvedDependency method getAllArtifacts.

public Set<ResolvedArtifact> getAllArtifacts(ResolvedDependency parent) {
    if (allArtifactsCache.get(parent) == null) {
        Set<ResolvedArtifact> allArtifacts = new LinkedHashSet<ResolvedArtifact>();
        allArtifacts.addAll(getArtifacts(parent));
        for (ResolvedDependency childResolvedDependency : getChildren()) {
            for (ResolvedDependency childParent : childResolvedDependency.getParents()) {
                allArtifacts.addAll(childResolvedDependency.getAllArtifacts(childParent));
            }
        }
        allArtifactsCache.put(parent, allArtifacts);
    }
    return allArtifactsCache.get(parent);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedDependency(org.gradle.api.artifacts.ResolvedDependency)

Example 9 with ResolvedArtifact

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

the class DefaultArtifactSet method snapshot.

@Override
public ArtifactSet snapshot() {
    ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builder();
    for (VariantMetadata variant : variants) {
        Set<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
        Set<ResolvedArtifact> resolvedArtifacts = new LinkedHashSet<ResolvedArtifact>(artifacts.size());
        // Add artifact format as an implicit attribute when all artifacts have the same format
        AttributeContainerInternal attributes = variant.getAttributes();
        if (!attributes.contains(ArtifactAttributes.ARTIFACT_FORMAT)) {
            String format = null;
            for (ComponentArtifactMetadata artifact : artifacts) {
                String candidateFormat = artifact.getName().getType();
                if (format == null) {
                    format = candidateFormat;
                } else if (!format.equals(candidateFormat)) {
                    format = null;
                    break;
                }
            }
            if (format != null) {
                attributes = attributesFactory.concat(attributes.asImmutable(), ArtifactAttributes.ARTIFACT_FORMAT, format);
            }
        }
        for (ComponentArtifactMetadata artifact : artifacts) {
            IvyArtifactName artifactName = artifact.getName();
            if (exclusions.excludeArtifact(moduleVersionIdentifier.getModule(), artifactName)) {
                continue;
            }
            ResolvedArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
            if (resolvedArtifact == null) {
                Factory<File> artifactSource = new BuildOperationArtifactSource(buildOperationExecutor, artifact.getId(), new LazyArtifactSource(artifact, moduleSource, artifactResolver));
                resolvedArtifact = new DefaultResolvedArtifact(moduleVersionIdentifier, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource);
                allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
            }
            resolvedArtifacts.add(resolvedArtifact);
        }
        result.add(ArtifactBackedResolvedVariant.create(attributes, resolvedArtifacts));
    }
    return new ArtifactSetSnapshot(id, componentIdentifier, result.build());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariantMetadata(org.gradle.internal.component.model.VariantMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 10 with ResolvedArtifact

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

the class DependencyResolvingClasspath method getFiles.

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

        @Override
        public void visitArtifact(AttributeContainer variant, ResolvedArtifact artifact) {
            result.add(artifact.getFile());
        }

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

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

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

Aggregations

ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)19 File (java.io.File)6 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)6 LinkedHashSet (java.util.LinkedHashSet)5 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)4 ArrayList (java.util.ArrayList)3 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)3 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)3 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)3 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3 JarDependency (com.android.builder.dependency.JarDependency)2 Configuration (org.gradle.api.artifacts.Configuration)2 ResolvedDependency (org.gradle.api.artifacts.ResolvedDependency)2 LibraryDependency (com.android.builder.dependency.LibraryDependency)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CircleDependencyCheck (com.taobao.android.builder.dependency.CircleDependencyCheck)1