Search in sources :

Example 1 with DefaultResolvedDependencyResult

use of org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult in project atlas by alibaba.

the class DependencyGroup method getProjectBundleCompile.

private Map<String, Set<DependencyResult>> getProjectBundleCompile(Configuration configuration, Set<String> bundleAddedSets) {
    Map<String, Set<DependencyResult>> bundleMap = new HashMap<>();
    configuration.getAllDependencies().forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            if (dependency instanceof DefaultProjectDependency) {
                DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency;
                String key = "project " + ":" + projectDependency.getName();
                if (!bundleAddedSets.contains(key)) {
                    return;
                }
                Set<DependencyResult> compileSets = new HashSet<>();
                try {
                    Set<ResolvedArtifact> resolvedArtifacts = projectDependency.getDependencyProject().getConfigurations().getByName("compile").getResolvedConfiguration().getResolvedArtifacts();
                    projectDependency.getDependencyProject().getConfigurations().getByName("compile").getIncoming().getResolutionResult().getRoot().getDependencies().forEach(new Consumer<DependencyResult>() {

                        @Override
                        public void accept(DependencyResult dependencyResult) {
                            if (!mainDexs.contains(dependencyResult.toString())) {
                                compileSets.add(dependencyResult);
                                if (dependencyResult instanceof DefaultResolvedDependencyResult) {
                                    ModuleVersionIdentifier moduleVersionIdentifier = ((DefaultResolvedDependencyResult) dependencyResult).getSelected().getModuleVersion();
                                    for (ResolvedArtifact resolvedArtifact : resolvedArtifacts) {
                                        if (resolvedArtifact.getModuleVersion().getId().equals(moduleVersionIdentifier)) {
                                            bundleCompileId.put(moduleVersionIdentifier, resolvedArtifact);
                                        }
                                    }
                                }
                            }
                        }
                    });
                } catch (UnknownConfigurationException e) {
                }
                bundleMap.put(projectDependency.getGroup() + ":" + projectDependency.getName(), compileSets);
            }
        }
    });
    return bundleMap;
}
Also used : DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Consumer(java.util.function.Consumer) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult)

Example 2 with DefaultResolvedDependencyResult

use of org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult in project gradle by gradle.

the class ResolvedComponentResultSerializer method writeComponent.

private void writeComponent(Encoder encoder, ResolvedComponentResult component, Map<ResolvedComponentResult, Integer> components) throws Exception {
    Integer id = components.get(component);
    if (id != null) {
        // Already seen
        encoder.writeSmallInt(id);
        return;
    }
    id = components.size();
    components.put(component, id);
    encoder.writeSmallInt(id);
    moduleVersionIdSerializer.write(encoder, component.getModuleVersion());
    componentIdSerializer.write(encoder, component.getId());
    componentSelectionReasonSerializer.write(encoder, component.getSelectionReason());
    List<ResolvedVariantResult> variants = component.getVariants();
    encoder.writeSmallInt(variants.size());
    for (ResolvedVariantResult variant : variants) {
        resolvedVariantResultSerializer.write(encoder, variant);
    }
    Set<? extends DependencyResult> dependencies = component.getDependencies();
    encoder.writeSmallInt(dependencies.size());
    for (DependencyResult dependency : dependencies) {
        boolean successful = dependency instanceof ResolvedDependencyResult;
        encoder.writeBoolean(successful);
        if (successful) {
            DefaultResolvedDependencyResult dependencyResult = (DefaultResolvedDependencyResult) dependency;
            componentSelectorSerializer.write(encoder, dependencyResult.getRequested());
            writeComponent(encoder, dependencyResult.getSelected(), components);
        } else {
            DefaultUnresolvedDependencyResult dependencyResult = (DefaultUnresolvedDependencyResult) dependency;
            componentSelectorSerializer.write(encoder, dependencyResult.getRequested());
        }
    }
}
Also used : DefaultUnresolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedDependencyResult) ResolvedVariantResult(org.gradle.api.artifacts.result.ResolvedVariantResult) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) DefaultUnresolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedDependencyResult) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult)

Aggregations

DependencyResult (org.gradle.api.artifacts.result.DependencyResult)2 DefaultResolvedDependencyResult (org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult)2 Consumer (java.util.function.Consumer)1 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)1 ResolvedVariantResult (org.gradle.api.artifacts.result.ResolvedVariantResult)1 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)1 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)1 DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency)1 DefaultUnresolvedDependencyResult (org.gradle.api.internal.artifacts.result.DefaultUnresolvedDependencyResult)1