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());
}
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);
}
}
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;
}
Aggregations