Search in sources :

Example 21 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class LocalFileDependencyBackedArtifactSet method visit.

@Override
public void visit(Visitor listener) {
    FileCollectionStructureVisitor.VisitType visitType = listener.prepareForVisit(this);
    if (visitType == FileCollectionStructureVisitor.VisitType.NoContents) {
        listener.visitArtifacts(new EndCollection(this));
        return;
    }
    ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
    if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
        listener.visitArtifacts(new EndCollection(this));
        return;
    }
    FileCollectionInternal fileCollection = dependencyMetadata.getFiles();
    Set<File> files;
    try {
        files = fileCollection.getFiles();
    } catch (Exception throwable) {
        listener.visitArtifacts(new BrokenArtifacts(throwable));
        return;
    }
    ImmutableList.Builder<ResolvedArtifactSet> selectedArtifacts = ImmutableList.builderWithExpectedSize(files.size());
    for (File file : files) {
        ComponentArtifactIdentifier artifactIdentifier;
        if (componentIdentifier == null) {
            artifactIdentifier = new OpaqueComponentArtifactIdentifier(file);
            if (!componentFilter.isSatisfiedBy(artifactIdentifier.getComponentIdentifier())) {
                continue;
            }
        } else {
            artifactIdentifier = new ComponentFileArtifactIdentifier(componentIdentifier, file.getName());
        }
        ImmutableAttributes variantAttributes = artifactTypeRegistry.mapAttributesFor(file);
        SingletonFileResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, LOCAL_FILE, variantAttributes, dependencyMetadata, calculatedValueContainerFactory);
        selectedArtifacts.add(selector.select(variant, this));
    }
    CompositeResolvedArtifactSet.of(selectedArtifacts.build()).visit(listener);
    if (visitType == FileCollectionStructureVisitor.VisitType.Spec) {
        listener.visitArtifacts(new CollectionSpec(fileCollection));
    }
}
Also used : OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableList(com.google.common.collect.ImmutableList) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ComponentFileArtifactIdentifier(org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) FileCollectionStructureVisitor(org.gradle.api.internal.file.FileCollectionStructureVisitor) File(java.io.File)

Example 22 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class JsonProjectDependencyRenderer method collectModules.

private Set<ModuleIdentifier> collectModules(Configuration configuration) {
    RenderableDependency root;
    if (canBeResolved(configuration)) {
        ResolutionResult result = configuration.getIncoming().getResolutionResult();
        root = new RenderableModuleResult(result.getRoot());
    } else {
        root = new UnresolvableConfigurationResult(configuration);
    }
    Set<ModuleIdentifier> modules = Sets.newHashSet();
    Set<ComponentIdentifier> visited = Sets.newHashSet();
    populateModulesWithChildDependencies(root, visited, modules);
    return modules;
}
Also used : RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) UnresolvableConfigurationResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) RenderableModuleResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableModuleResult)

Example 23 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class AbstractRenderableDependencyResult method getName.

@Override
public String getName() {
    ComponentSelector requested = getRequested();
    ComponentIdentifier selected = getActual();
    if (exactMatch(requested, selected)) {
        return getSimpleName();
    }
    if (requested instanceof ModuleComponentSelector && selected instanceof ModuleComponentIdentifier) {
        ModuleComponentSelector requestedModuleComponentSelector = (ModuleComponentSelector) requested;
        ModuleComponentIdentifier selectedModuleComponentedIdentifier = (ModuleComponentIdentifier) selected;
        if (requestedModuleComponentSelector.getModuleIdentifier().equals(selectedModuleComponentedIdentifier.getModuleIdentifier())) {
            return getSimpleName() + " -> " + selectedModuleComponentedIdentifier.getVersion();
        }
    }
    return getSimpleName() + " -> " + selected.getDisplayName();
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier)

Example 24 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class DependencyInsightReporter method convertToRenderableItems.

public Collection<RenderableDependency> convertToRenderableItems(Collection<DependencyResult> dependencies, boolean singlePathToDependency) {
    LinkedList<RenderableDependency> out = new LinkedList<>();
    Collection<DependencyEdge> sortedEdges = toDependencyEdges(dependencies);
    // remember if module id was annotated
    Set<ComponentIdentifier> annotated = Sets.newHashSet();
    Set<Throwable> alreadyReportedErrors = Sets.newHashSet();
    RequestedVersion current = null;
    for (DependencyEdge dependency : sortedEdges) {
        // add description only to the first module
        if (annotated.add(dependency.getActual())) {
            DependencyReportHeader header = createHeaderForDependency(dependency, alreadyReportedErrors);
            out.add(header);
            current = newRequestedVersion(out, dependency);
        } else if (!current.getRequested().equals(dependency.getRequested())) {
            current = newRequestedVersion(out, dependency);
        }
        if (!singlePathToDependency || current.getChildren().isEmpty()) {
            current.addChild(dependency);
        }
    }
    return out;
}
Also used : RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) RequestedVersion(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RequestedVersion) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) DependencyReportHeader(org.gradle.api.tasks.diagnostics.internal.graph.nodes.DependencyReportHeader) ResolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.ResolvedDependencyEdge) DependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.DependencyEdge) UnresolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvedDependencyEdge) LinkedList(java.util.LinkedList)

Example 25 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project SpongeCommon by SpongePowered.

the class OutputDependenciesToJson method configToDescriptor.

private List<DependencyDescriptor> configToDescriptor(final ArtifactCollection conf, final Set<ModuleComponentIdentifier> excludedDeps) {
    return conf.getArtifacts().stream().filter(dep -> {
        final ComponentIdentifier ident = dep.getId().getComponentIdentifier();
        return ident instanceof ModuleComponentIdentifier && !excludedDeps.contains(ident);
    }).distinct().map(dependency -> {
        final ModuleComponentIdentifier id = (ModuleComponentIdentifier) dependency.getId().getComponentIdentifier();
        // Get file input stream for reading the file content
        final String md5hash;
        try (final InputStream in = new FileInputStream(dependency.getFile())) {
            final MessageDigest hasher = MessageDigest.getInstance("MD5");
            final byte[] buf = new byte[4096];
            int read;
            while ((read = in.read(buf)) != -1) {
                hasher.update(buf, 0, read);
            }
            md5hash = OutputDependenciesToJson.toHexString(hasher.digest());
        } catch (final IOException | NoSuchAlgorithmException ex) {
            throw new GradleException("Failed to create hash for " + dependency, ex);
        }
        // create descriptor
        return new DependencyDescriptor(id.getGroup(), id.getModule(), id.getVersion(), md5hash);
    }).sorted(// sort dependencies for stable output
    Comparator.naturalOrder()).collect(Collectors.toList());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) FileInputStream(java.io.FileInputStream) GradleException(org.gradle.api.GradleException) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) MessageDigest(java.security.MessageDigest)

Aggregations

ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)39 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)17 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)15 File (java.io.File)14 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)10 OpaqueComponentArtifactIdentifier (org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier)7 NonNull (com.android.annotations.NonNull)6 ArtifactCollection (org.gradle.api.artifacts.ArtifactCollection)6 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)6 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 Module (org.gradle.api.internal.artifacts.Module)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)4 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)4 ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)4 ResolvedVariantResult (org.gradle.api.artifacts.result.ResolvedVariantResult)4 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)4 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)4