Search in sources :

Example 1 with DependencyGraphs

use of com.android.builder.model.level2.DependencyGraphs in project atlas by alibaba.

the class AtlasDependencyGraph method clone.

public static DependencyGraphs clone(@NonNull DependencyGraphs dependencyGraphs, int modelLevel, boolean modelWithFullDependency) {
    if (modelLevel < AndroidProject.MODEL_LEVEL_4_NEW_DEP_MODEL) {
        return EMPTY_DEPENDENCY_GRAPH;
    }
    Preconditions.checkState(dependencyGraphs instanceof ConfigurationDependencyGraphs);
    ConfigurationDependencyGraphs cdg = (ConfigurationDependencyGraphs) dependencyGraphs;
    // these items are already ready for serializable, all we need to clone is
    // the DependencyGraphs instance.
    List<Library> libs = cdg.getLibraries();
    synchronized (sGlobalLibrary) {
        for (Library library : libs) {
            sGlobalLibrary.put(library.getArtifactAddress(), library);
        }
    }
    final List<GraphItem> nodes = cdg.getCompileDependencies();
    if (modelWithFullDependency) {
        return new FullDependencyGraphsImpl(nodes, nodes, ImmutableList.of(), ImmutableList.of());
    }
    // just need to register the libraries in the global libraries.
    return new SimpleDependencyGraphsImpl(nodes, cdg.getProvidedLibraries());
}
Also used : ConfigurationDependencyGraphs(com.android.build.gradle.internal.dependency.ConfigurationDependencyGraphs) GraphItem(com.android.builder.model.level2.GraphItem) JvmLibrary(org.gradle.jvm.JvmLibrary) Library(com.android.builder.model.level2.Library)

Example 2 with DependencyGraphs

use of com.android.builder.model.level2.DependencyGraphs in project atlas by alibaba.

the class AtlasDependencyGraph method createLevel4DependencyGraph.

/**
 * Create a level 4 dependency graph.
 *
 * @see AndroidProject#MODEL_LEVEL_4_NEW_DEP_MODEL
 */
public DependencyGraphs createLevel4DependencyGraph(@NonNull VariantScope variantScope, boolean withFullDependency, boolean downloadSources, @NonNull Consumer<SyncIssue> failureConsumer) {
    try {
        // get the compile artifact first.
        Set<AtlasDependencyGraph.HashableResolvedArtifactResult> compileArtifacts = getAllArtifacts(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.COMPILE_CLASSPATH, dependencyFailureHandler);
        compileArtifacts.addAll(getAllArtifacts(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.BUNDLECOMPILE_CLASSPATH, dependencyFailureHandler));
        // the runtime-only is never used from the IDE.
        if (downloadSources) {
            Set<ComponentIdentifier> ids = Sets.newHashSetWithExpectedSize(compileArtifacts.size());
            for (HashableResolvedArtifactResult artifact : compileArtifacts) {
                ids.add(artifact.getId().getComponentIdentifier());
            }
            handleSources(variantScope.getGlobalScope().getProject(), ids, failureConsumer);
        }
        // provided bit.
        if (!withFullDependency) {
            // get the runtime artifacts. We only care about the ComponentIdentifier so we don't
            // need to call getAllArtifacts() which computes a lot more many things, and takes
            // longer on large projects.
            // Instead just get all the jars to get all the dependencies.
            ArtifactCollection runtimeArtifactCollection = computeArtifactList(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, AndroidArtifacts.ArtifactScope.ALL, AtlasAndroidArtifacts.AtlasArtifactType.JAR);
            // build a list of the runtime ComponentIdentifiers
            final Set<ResolvedArtifactResult> runtimeArtifacts = runtimeArtifactCollection.getArtifacts();
            final Set<ComponentIdentifier> runtimeIdentifiers = Sets.newHashSetWithExpectedSize(runtimeArtifacts.size());
            for (ResolvedArtifactResult result : runtimeArtifacts) {
                runtimeIdentifiers.add(result.getId().getComponentIdentifier());
            }
            List<String> providedAddresses = Lists.newArrayList();
            List<GraphItem> compileItems = Lists.newArrayListWithCapacity(compileArtifacts.size());
            for (AtlasDependencyGraph.HashableResolvedArtifactResult artifact : compileArtifacts) {
                final GraphItemImpl graphItem = new GraphItemImpl(computeAddress(artifact), ImmutableList.of());
                compileItems.add(graphItem);
                sLibraryCache.get(artifact);
                sLibraryMap.put(computeAddress(artifact), artifact);
                if (!runtimeIdentifiers.contains(artifact.getId().getComponentIdentifier())) {
                    providedAddresses.add(graphItem.getArtifactAddress());
                }
            }
            return new SimpleDependencyGraphsImpl(compileItems, providedAddresses);
        }
        // now build the list of compile items
        List<GraphItem> compileItems = Lists.newArrayListWithCapacity(compileArtifacts.size());
        for (AtlasDependencyGraph.HashableResolvedArtifactResult artifact : compileArtifacts) {
            compileItems.add(new GraphItemImpl(computeAddress(artifact), ImmutableList.of()));
            sLibraryCache.get(artifact);
            sLibraryMap.put(computeAddress(artifact), artifact);
        }
        // in this mode, compute GraphItem for the runtime configuration
        // get the runtime artifacts.
        Set<AtlasDependencyGraph.HashableResolvedArtifactResult> runtimeArtifacts = getAllArtifacts(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, dependencyFailureHandler);
        runtimeArtifacts.addAll(getAllArtifacts(variantScope, AtlasAndroidArtifacts.ConsumedConfigType.BUNDLECOMPILE_CLASSPATH, dependencyFailureHandler));
        List<GraphItem> runtimeItems = Lists.newArrayListWithCapacity(runtimeArtifacts.size());
        for (AtlasDependencyGraph.HashableResolvedArtifactResult artifact : runtimeArtifacts) {
            runtimeItems.add(new GraphItemImpl(computeAddress(artifact), ImmutableList.of()));
            sLibraryCache.get(artifact);
            sLibraryMap.put(computeAddress(artifact), artifact);
        }
        // compute the provided dependency list, by comparing the compile and runtime items
        List<GraphItem> providedItems = Lists.newArrayList(compileItems);
        providedItems.removeAll(runtimeItems);
        final ImmutableList<String> providedAddresses = providedItems.stream().map(GraphItem::getArtifactAddress).collect(ImmutableCollectors.toImmutableList());
        return new FullDependencyGraphsImpl(compileItems, runtimeItems, providedAddresses, // FIXME: actually get skip list
        ImmutableList.of());
    } finally {
        dependencyFailureHandler.collectIssues().forEach(failureConsumer);
    }
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ArtifactCollection(org.gradle.api.artifacts.ArtifactCollection) FilteredArtifactCollection(com.android.build.gradle.internal.dependency.FilteredArtifactCollection) GraphItem(com.android.builder.model.level2.GraphItem) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult)

Example 3 with DependencyGraphs

use of com.android.builder.model.level2.DependencyGraphs in project atlas by alibaba.

the class AtlasDependencyManager2 method resolveDependencies.

public Set<AndroidDependency> resolveDependencies(@NonNull VariantScope variantScope) {
    // this.apDependencies = resolveApDependencies(variantDeps);
    AtlasDependencyGraph artifactDependencyGraph = new AtlasDependencyGraph();
    DependencyGraphs dependencyGraphs = artifactDependencyGraph.createLevel4DependencyGraph(variantScope, false, true, new Consumer<SyncIssue>() {

        @Override
        public void accept(SyncIssue syncIssue) {
            sLogger.error(syncIssue.getMessage());
        }
    });
    return null;
}
Also used : DependencyGraphs(com.android.builder.model.level2.DependencyGraphs) SyncIssue(com.android.builder.model.SyncIssue) AtlasDependencyGraph(com.android.build.gradle.internal.ide.AtlasDependencyGraph)

Aggregations

GraphItem (com.android.builder.model.level2.GraphItem)2 ConfigurationDependencyGraphs (com.android.build.gradle.internal.dependency.ConfigurationDependencyGraphs)1 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)1 AtlasDependencyGraph (com.android.build.gradle.internal.ide.AtlasDependencyGraph)1 SyncIssue (com.android.builder.model.SyncIssue)1 DependencyGraphs (com.android.builder.model.level2.DependencyGraphs)1 Library (com.android.builder.model.level2.Library)1 ArtifactCollection (org.gradle.api.artifacts.ArtifactCollection)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)1 JvmLibrary (org.gradle.jvm.JvmLibrary)1